![]() |
m2mb API docs
25.30.003
m2mb API sets documentation
|
UART library implementation. More...
Go to the source code of this file.
Data Structures | |
| struct | M2MB_UART_CFG_T |
| UART ioctl configuration. More... | |
Macros | |
| #define | NULL 0 |
Typedefs | |
| typedef void(* | m2mb_uart_ind_callback) (INT32 fd, M2MB_UART_IND_E uart_event, UINT16 resp_size, void *resp_struct, void *userdata) |
| Transmit and receive operation callback type. More... | |
Functions | |
| INT32 | m2mb_uart_open (const CHAR *path, INT32 flags,...) |
| m2mb_uart_open opens a UART device. More... | |
| INT32 | m2mb_uart_close (INT32 fd) |
| m2mb_uart_close closes a UART device. More... | |
| INT32 | m2mb_uart_ioctl (INT32 fd, INT32 request,...) |
| m2mb_uart_ioctl configures an open UART device. More... | |
| SSIZE_T | m2mb_uart_read (INT32 fd, void *buf, SIZE_T nbyte) |
| m2mb_uart_read reads data from an open UART device. More... | |
| SSIZE_T | m2mb_uart_write (INT32 fd, const void *buf, SIZE_T nbyte) |
| m2mb_uart_write writes data to an open UART device. More... | |
UART library implementation.
m2m/m2m_generic/common/m2mb_inc/m2mb_uart.h
The following functions are implemented:
| typedef void( * m2mb_uart_ind_callback) (INT32 fd, M2MB_UART_IND_E uart_event, UINT16 resp_size, void *resp_struct, void *userdata) |
Transmit and receive operation callback type.
This type defines the callback function that the client can register by setting it in the UART open configuration or with command M2MB_UART_IOCTL_SET_CB_FN of m2mb_uart_ioctl API. The callback is invoked after an asynchronous read or write has completed or after a DTR toggle.
| [in] | fd | File Descriptor returned by m2mb_uart_open() |
| [in] | uart_event | Type of event which causet the callback invocation |
| [in] | resp_size | size in Bytes of the response data, pointed by the parameter resp_struct |
| [in] | resp_struct | pointer to the response data |
| [in] | userdata | pointer to data, previously passed with command M2MB_UART_IOCTL_SET_CB_USERDATA of m2mb_uart_ioctl |
UART number of bits per character.
This type defines the number of bits per character that the client can set in the UART open configuration or get by m2mb_uart_ioctl API.
| Enumerator | |
|---|---|
| M2MB_UART_5_BITS_PER_CHAR | 5 bits per character |
| M2MB_UART_6_BITS_PER_CHAR | 6 bits per character |
| M2MB_UART_7_BITS_PER_CHAR | 7 bits per character |
| M2MB_UART_8_BITS_PER_CHAR | 8 bits per character |
| enum M2MB_UART_FCTL_E |
| enum M2MB_UART_IND_E |
UART configuration requests.
This enum defines the requests wich can be passed to the function m2mb_uart_ioctl()
| enum M2MB_UART_PARITY_E |
UART number of stop bits.
This type defines the number of stop bits that the client can set in the UART open configuration or get by m2mb_uart_ioctl API.
| Enumerator | |
|---|---|
| M2MB_UART_0_5_STOP_BITS | 0.5 stop bits |
| M2MB_UART_1_0_STOP_BITS | 1.0 stop bits |
| M2MB_UART_1_5_STOP_BITS | 1.5 stop bits |
| M2MB_UART_2_0_STOP_BITS | 2.0 stop bits |
| INT32 m2mb_uart_close | ( | INT32 | fd | ) |
m2mb_uart_close closes a UART device.
m2mb_uart_close closes a UART device freeing the data associated to the file descriptor passed as parameter.
| [in] | fd | File Descriptor returned by m2mb_uart_open() |
m2mb_uart_close(fd);
| INT32 m2mb_uart_ioctl | ( | INT32 | fd, |
| INT32 | request, | ||
| ... | |||
| ) |
m2mb_uart_ioctl configures an open UART device.
m2mb_uart_ioctl sets/gets the full UART configuration or single settings by means of requests listed in enum M2MB_UART_IOCTL_REQUEST.
| [in] | fd | File Descriptor returned by m2mb_uart_open() |
| [in] | request | second parameter indicates the action to be performed. The allowed values ??are those listed in enum M2MB_UART_IOCTL_REQUEST. |
| [in,out] | cfg | third parameter can be a pointer to a previously defined variable or a value, depending on the action requested by the second parameter (see following note for further details). |
Action: M2MB_UART_IOCTL_SET_CFG
Description: set whole uart device configuration
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pCfgStruct(M2MB_UART_CFG_T *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_CFG, &cfgStruct)
Action: M2MB_UART_IOCTL_GET_CFG
Description: get whole uart device configuration
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pCfgStruct(M2MB_UART_CFG_T *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_CFG, &cfgStruct)
Action: M2MB_UART_IOCTL_SET_BR
Description: set uart baudrate
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), baudRate(UINT32)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_BR, 115200)
Action: M2MB_UART_IOCTL_GET_BR
Description: get uart baudrate
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pBaudRate(UINT32 *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_BR, &baudRate)
Action: M2MB_UART_IOCTL_SET_FCTL
Description: set uart flow control type
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), flowControl(M2MB_UART_FCTL_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_FCTL, M2MB_UART_CTSRFR_AUTO_FCTL)
Action: M2MB_UART_IOCTL_GET_FCTL
Description: get uart flow control type
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pFlowControl(M2MB_UART_FCTL_E *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_FCTL, &flowControl)
Action: M2MB_UART_IOCTL_SET_PARITY_MODE
Description: set uart parity mode
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), parityMode(M2MB_UART_PARITY_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_PARITY_MODE, M2MB_UART_NO_PARITY)
Action: M2MB_UART_IOCTL_GET_PARITY_MODE
Description: get uart parity mode
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pParityMode(M2MB_UART_PARITY_E *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_PARITY_MODE, &parityMode)
Action: M2MB_UART_IOCTL_SET_STOP_BITS
Description: set uart number of stop bits
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), stopBits(M2MB_UART_STOP_BITS_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_STOP_BITS, M2MB_UART_1_0_STOP_BITS)
Action: M2MB_UART_IOCTL_GET_STOP_BITS
Description: get uart number of stop bits
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pStopBits(M2MB_UART_STOP_BITS_E *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_STOP_BITS, &stopBits)
Action: M2MB_UART_IOCTL_SET_BITS_PER_CHAR
Description: set uart number of bits per character
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), bitsPerChar(M2MB_UART_BITS_PER_CHAR_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_BITS_PER_CHAR, M2MB_UART_8_BITS_PER_CHAR)
Action: M2MB_UART_IOCTL_GET_BITS_PER_CHAR
Description: get uart number of bits per character
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pBitsPerChar(M2MB_UART_BITS_PER_CHAR_E *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_BITS_PER_CHAR, &bitsPerChar)
Action: M2MB_UART_IOCTL_SET_TX_TIMEOUT
Description: set synchronous write timeout in ms (if 0, waits indefinitely until the write is completed)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), timeout(UINT16)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_TX_TIMEOUT, 100)
Action: M2MB_UART_IOCTL_GET_TX_TIMEOUT
Description: get synchronous write timeout in ms (if 0, waits indefinitely until the write is completed)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pTimeout(UINT16 *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_TX_TIMEOUT, &timeout)
Action: M2MB_UART_IOCTL_SET_RX_TIMEOUT
Description: set synchronous read timeout in ms (if 0, waits indefinitely until the read is completed)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), timeout(UINT16)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_RX_TIMEOUT, 100)
Action: M2MB_UART_IOCTL_GET_RX_TIMEOUT
Description: get synchronous read timeout in ms (if 0, waits indefinitely until the read is completed)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pTimeout(UINT16 *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_RX_TIMEOUT, &timeout)
Action: M2MB_UART_IOCTL_SET_CB_FN
Description: set callback function pointer (if NULL, action is synchronous)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), cb_fn(m2mb_uart_ind_callback)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_CB_FN, cb_fn)
Action: M2MB_UART_IOCTL_GET_CB_FN
Description: get callback function pointer (if NULL, action is synchronous)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pCb_fn(m2mb_uart_ind_callback *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_CB_FN, &cb_fn)
Action: M2MB_UART_IOCTL_SET_CB_USERDATA
Description: set callback data pointer
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), cbData(void *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_CB_USERDATA, cbData)
Action: M2MB_UART_IOCTL_GET_CB_USERDATA
Description: get callback data pointer
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pCbData(void **)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_CB_USERDATA, &cbData)
Action: M2MB_UART_IOCTL_SET_POWER_STATE
Description: set uart power state (TRUE = power on; FALSE = low power)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), powerState(BOOLEAN)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_POWER_STATE, TRUE)
Action: M2MB_UART_IOCTL_GET_POWER_STATE
Description: get uart power state (TRUE = power on; FALSE = low power)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pPowerState(BOOLEAN *)
Example: BOOLEAN powerState; m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_POWER_STATE, &powerState)
Action: M2MB_UART_IOCTL_GET_OP_MODE
Description: get uart operational mode (see +CFUN)
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pOpMode(UINT8 *)
Example: UINT8 opMode; m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_OP_MODE, &opMode)
Action: M2MB_UART_IOCTL_GET_RTS_STATE
Description: get uart RTS state
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pRtsLevel(M2MB_UART_PIN_VALUE_E *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_RTS_STATE, &rtsLevel)
Action: M2MB_UART_IOCTL_GET_DTR_STATE
Description: get uart DTR state
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pDtrLevel(M2MB_UART_PIN_VALUE_E *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_DTR_STATE, &dtrLevel)
Action: M2MB_UART_IOCTL_SET_CTS
Description: set uart CTS level
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), ctsLevel(M2MB_UART_PIN_VALUE_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_CTS, ctsLevel)
Action: M2MB_UART_IOCTL_SET_DSR
Description: set uart DSR level
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), dsrLevel(M2MB_UART_PIN_VALUE_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_DSR, dsrLevel)
Action: M2MB_UART_IOCTL_SET_DCD
Description: set uart DCD level
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), dcdLevel(M2MB_UART_PIN_VALUE_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_DCD, dcdLevel)
Action: M2MB_UART_IOCTL_SET_RING
Description: set uart RING level
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), ringLevel(M2MB_UART_PIN_VALUE_E)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_RING, ringLevel)
Action: M2MB_UART_IOCTL_SET_DTR_FCTL
Description: set uart DTR flow control
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), dtrFctl(INT32)
Note: This command configures the behavior of the outbound flow according to the DTR control line level transitions. Admitted parameter values are: 0 : DTR level transitions are ignored and cannot control the outbound data flow. 1 : DTR level transitions control the outbound data flow (not supported if DTR line is not present). If DTR is asserted, the output data is sent; if DTR is not asserted, the output data is blocked.
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_SET_DTR_FCTL, dtrFctl)
Action: M2MB_UART_IOCTL_GET_DTR_FCTL
Description: get uart DTR flow control
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pDtrFctl(INT32 *)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_DTR_FCTL, &dtrFctl)
Action: M2MB_UART_IOCTL_GET_RX_ACTIVE
Description: get uart RX activity
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pRxActive(BOOLEAN *)
Example: m2mb_usrt_ioctl(fd, M2MB_UART_IOCTL_GET_RX_ACTIVE, &rxActive)
Action: M2MB_UART_IOCTL_GET_TX_ACTIVE
Description: get uart TX activity
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST), pTxActive(BOOLEAN *)
Example: BOOLEAN txActive; m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_GET_TX_ACTIVE, &txActive)
Action: M2MB_UART_IOCTL_PURGE_TX
Description: purge UART device's transmit FIFO and packing buffer
Params(in): fd(INT32), request(M2MB_UART_IOCTL_REQUEST)
Example: m2mb_uart_ioctl(fd, M2MB_UART_IOCTL_PURGE_TX)
m2mb_uart_ioctl(fd, request, cfg);
| INT32 m2mb_uart_open | ( | const CHAR * | path, |
| INT32 | flags, | ||
| ... | |||
| ) |
m2mb_uart_open opens a UART device.
m2mb_uart_open opens a UART device returning the file descriptor that must be passed as first parameter for all the other UART actions. Calling the m2mb_uart_open is mandatory before using the UART device.
| [in] | path | path to the UART device, that will be initialized by the function. It is a string like "/dev/ttyX" where X is the UART instance index. Path "/dev/tty" is equivalent to default "/dev/tty0". |
| [in] | flags | access mode flags. Currently unused |
m2mb_uart_open(path, flags);
| SSIZE_T m2mb_uart_read | ( | INT32 | fd, |
| void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
m2mb_uart_read reads data from an open UART device.
m2mb_uart_read reads up to nbyte Bytes from a UART device into a destination buffer.
| [in] | fd | File Descriptor returned by m2mb_uart_open() |
| [in] | buf | destination buffer, previously allocated. |
| [in] | nbyte | length of the destination buffer in Bytes. |
m2mb_uart_read(fd, buf, nbyte);
| SSIZE_T m2mb_uart_write | ( | INT32 | fd, |
| const void * | buf, | ||
| SIZE_T | nbyte | ||
| ) |
m2mb_uart_write writes data to an open UART device.
m2mb_uart_write writes nbyte Bytes from a source buffer to a UART device.
| [in] | fd | File Descriptor returned by m2mb_uart_open() |
| [in] | buf | source buffer, previously allocated. |
| [in] | nbyte | length of the source buffer in Bytes. |
m2mb_uart_write(fd, buf, nbyte);