![]() |
m2mb API docs
30.00.007
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 functions that the client can set in the UART open configuration or get by m2mb_uart_ioctl API.
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 | first parameter is the 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)
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 | first parameter is the 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 | second parameter is the 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 | first parameter is the File Descriptor returned by m2mb_uart_open() |
| [in] | buf | second parameter is the destination buffer, previously allocated. |
| [in] | nbyte | third parameter is the 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 | first parameter is the File Descriptor returned by m2mb_uart_open() |
| [in] | buf | second parameter is the source buffer, previously allocated. |
| [in] | nbyte | third parameter is the length of the source buffer in Bytes. |
m2mb_uart_read(fd, buf, nbyte);