m2mb API docs  25.30.004.0
m2mb API sets documentation
m2mb_uart.h File Reference

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...
 

Enumerations

enum  M2MB_UART_IOCTL_REQUEST {
  M2MB_UART_IOCTL_SET_CFG = 0, M2MB_UART_IOCTL_GET_CFG, M2MB_UART_IOCTL_SET_BR, M2MB_UART_IOCTL_GET_BR,
  M2MB_UART_IOCTL_SET_FCTL, M2MB_UART_IOCTL_GET_FCTL, M2MB_UART_IOCTL_SET_PARITY_MODE, M2MB_UART_IOCTL_GET_PARITY_MODE,
  M2MB_UART_IOCTL_SET_STOP_BITS, M2MB_UART_IOCTL_GET_STOP_BITS, M2MB_UART_IOCTL_SET_BITS_PER_CHAR, M2MB_UART_IOCTL_GET_BITS_PER_CHAR,
  M2MB_UART_IOCTL_SET_TX_TIMEOUT = 14, M2MB_UART_IOCTL_GET_TX_TIMEOUT, M2MB_UART_IOCTL_SET_RX_TIMEOUT, M2MB_UART_IOCTL_GET_RX_TIMEOUT,
  M2MB_UART_IOCTL_SET_CB_FN, M2MB_UART_IOCTL_GET_CB_FN, M2MB_UART_IOCTL_SET_CB_USERDATA, M2MB_UART_IOCTL_GET_CB_USERDATA,
  M2MB_UART_IOCTL_SET_POWER_STATE, M2MB_UART_IOCTL_GET_POWER_STATE, M2MB_UART_IOCTL_GET_OP_MODE, M2MB_UART_IOCTL_GET_RTS_STATE,
  M2MB_UART_IOCTL_GET_DTR_STATE, M2MB_UART_IOCTL_SET_CTS, M2MB_UART_IOCTL_SET_DSR, M2MB_UART_IOCTL_SET_DCD,
  M2MB_UART_IOCTL_SET_RING, M2MB_UART_IOCTL_SET_DTR_FCTL, M2MB_UART_IOCTL_GET_DTR_FCTL, M2MB_UART_IOCTL_GET_RX_ACTIVE,
  M2MB_UART_IOCTL_GET_TX_ACTIVE, M2MB_UART_IOCTL_PURGE_TX, M2MB_UART_IOCTL_NOF_REQ
}
 UART configuration requests. More...
 
enum  M2MB_UART_FCTL_E { M2MB_UART_FCTL_OFF = 0, M2MB_UART_CTSRFR_AUTO_FCTL, M2MB_UART_FCTL_MAX }
 UART flow control type. More...
 
enum  M2MB_UART_PARITY_E {
  M2MB_UART_NO_PARITY = 0, M2MB_UART_ODD_PARITY, M2MB_UART_EVEN_PARITY, M2MB_UART_SPACE_PARITY,
  M2MB_UART_PARITY_MAX
}
 UART parity mode. More...
 
enum  M2MB_UART_STOP_BITS_E {
  M2MB_UART_0_5_STOP_BITS = 0, M2MB_UART_1_0_STOP_BITS, M2MB_UART_1_5_STOP_BITS, M2MB_UART_2_0_STOP_BITS,
  M2MB_UART_STOP_BITS_MAX
}
 UART number of stop bits. More...
 
enum  M2MB_UART_BITS_PER_CHAR_E {
  M2MB_UART_5_BITS_PER_CHAR = 0, M2MB_UART_6_BITS_PER_CHAR, M2MB_UART_7_BITS_PER_CHAR, M2MB_UART_8_BITS_PER_CHAR,
  M2MB_UART_BITS_PER_CHAR_MAX
}
 UART number of bits per character. More...
 
enum  M2MB_UART_IND_E { M2MB_UART_TX_EV, M2MB_UART_RX_EV, M2MB_UART_DTR_EV }
 UART event type. More...
 
enum  M2MB_UART_PIN_VALUE_E { M2MB_UART_LOW_VALUE, M2MB_UART_HIGH_VALUE }
 UART pin voltage value. 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...
 

Detailed Description

UART library implementation.

m2m/m2m_generic/common/m2mb_inc/m2mb_uart.h

The following functions are implemented:

Note
Dependencies: m2m/m2m_generic/common/m2mb_inc/m2mb_types.h
Author
Morgan Deidda
Date
04/01/2018

Typedef Documentation

◆ m2mb_uart_ind_callback

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.

Parameters
[in]fdFile Descriptor returned by m2mb_uart_open()
[in]uart_eventType of event which causet the callback invocation
[in]resp_sizesize in Bytes of the response data, pointed by the parameter resp_struct
[in]resp_structpointer to the response data
[in]userdatapointer to data, previously passed with command M2MB_UART_IOCTL_SET_CB_USERDATA of m2mb_uart_ioctl
Returns
none
Note
If the callback is invoked for event M2MB_UART_TX_EV, resp_size is 4 (Bytes) and resp_struct points to a uint32 which contains the number of Bytes successfully written by the previous asynchronous m2mb_uart_write(). If the callback is invoked for event M2MB_UART_RX_EV, resp_size is 4 (Bytes) and resp_struct points to a uint32 which contains the number of Bytes just received by the UART port, ready to be read by the next asynchronous m2mb_uart_read(). If the callback is invoked for event M2MB_UART_DTR_EV, resp_size is 1 (Bytes) and resp_struct points to a boolean which contains the new logic level of the DTR signal: TRUE if DTR is asserted, FALSE if it is deasserted.

Enumeration Type Documentation

◆ M2MB_UART_BITS_PER_CHAR_E

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

◆ M2MB_UART_FCTL_E

UART flow control type.

This type defines the flow control type that the client can set in the UART open configuration or set/get by m2mb_uart_ioctl API.

Enumerator
M2MB_UART_FCTL_OFF 

Disable flow control

M2MB_UART_CTSRFR_AUTO_FCTL 

Use CTS/RFR flow control with auto RX RFR signal generation

◆ M2MB_UART_IND_E

UART event type.

This type defines the indications which can be passed to the callback.

Enumerator
M2MB_UART_TX_EV 

Transmitted data Event

M2MB_UART_RX_EV 

Received data Event

M2MB_UART_DTR_EV 

Received DTR Event

◆ M2MB_UART_IOCTL_REQUEST

UART configuration requests.

This enum defines the requests wich can be passed to the function m2mb_uart_ioctl()

Enumerator
M2MB_UART_IOCTL_SET_CFG 

set whole uart device configuration

M2MB_UART_IOCTL_GET_CFG 

get whole uart device configuration

M2MB_UART_IOCTL_SET_BR 

set uart baudrate

M2MB_UART_IOCTL_GET_BR 

get uart baudrate

M2MB_UART_IOCTL_SET_FCTL 

set uart flow control type

M2MB_UART_IOCTL_GET_FCTL 

get uart flow control type

M2MB_UART_IOCTL_SET_PARITY_MODE 

set uart parity mode

M2MB_UART_IOCTL_GET_PARITY_MODE 

get uart parity mode

M2MB_UART_IOCTL_SET_STOP_BITS 

set uart number of stop bits

M2MB_UART_IOCTL_GET_STOP_BITS 

get uart number of stop bits

M2MB_UART_IOCTL_SET_BITS_PER_CHAR 

set uart number of bits per character

M2MB_UART_IOCTL_GET_BITS_PER_CHAR 

get uart number of bits per character

M2MB_UART_IOCTL_SET_TX_TIMEOUT 

set synchronous write timeout in ms (if 0, waits indefinitely until the write is completed)

M2MB_UART_IOCTL_GET_TX_TIMEOUT 

get synchronous write timeout in ms (if 0, waits indefinitely until the write is completed)

M2MB_UART_IOCTL_SET_RX_TIMEOUT 

set synchronous read timeout in ms (if 0, waits indefinitely until the read is completed)

M2MB_UART_IOCTL_GET_RX_TIMEOUT 

get synchronous read timeout in ms (if 0, waits indefinitely until the read is completed)

M2MB_UART_IOCTL_SET_CB_FN 

set callback function pointer (if NULL, action is synchronous)

M2MB_UART_IOCTL_GET_CB_FN 

get callback function pointer (if NULL, action is synchronous)

M2MB_UART_IOCTL_SET_CB_USERDATA 

set callback data pointer

M2MB_UART_IOCTL_GET_CB_USERDATA 

get callback data pointer

M2MB_UART_IOCTL_SET_POWER_STATE 

set current power state

M2MB_UART_IOCTL_GET_POWER_STATE 

get current power state

M2MB_UART_IOCTL_GET_OP_MODE 

get current operational mode of device (see +CFUN)

M2MB_UART_IOCTL_GET_RTS_STATE 

get uart RTS state

M2MB_UART_IOCTL_GET_DTR_STATE 

get uart DTR state

M2MB_UART_IOCTL_SET_CTS 

set uart CTS pin

M2MB_UART_IOCTL_SET_DSR 

set uart DSR pin

M2MB_UART_IOCTL_SET_DCD 

set uart DCD pin

M2MB_UART_IOCTL_SET_RING 

set uart RING pin

M2MB_UART_IOCTL_SET_DTR_FCTL 

set uart DTR flow control

M2MB_UART_IOCTL_GET_DTR_FCTL 

get uart DTR flow control

M2MB_UART_IOCTL_GET_RX_ACTIVE 

get uart RX activity

M2MB_UART_IOCTL_GET_TX_ACTIVE 

get TX activity

M2MB_UART_IOCTL_PURGE_TX 

purge TX FIFO

◆ M2MB_UART_PARITY_E

UART parity mode.

This type defines the parity mode that the client can set in the UART open configuration or get by m2mb_uart_ioctl API.

Enumerator
M2MB_UART_NO_PARITY 

no parity

M2MB_UART_ODD_PARITY 

odd parity

M2MB_UART_EVEN_PARITY 

even parity

M2MB_UART_SPACE_PARITY 

space parity

◆ M2MB_UART_PIN_VALUE_E

UART pin voltage value.

This type defines the pin output voltage that the client can set by m2mb_uart_ioctl API.

Enumerator
M2MB_UART_LOW_VALUE 

Set pin output LOW.

M2MB_UART_HIGH_VALUE 

Set pin output HIGH

◆ M2MB_UART_STOP_BITS_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

Function Documentation

◆ m2mb_uart_close()

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.

Parameters
[in]fdFile Descriptor returned by m2mb_uart_open()
Returns
returns 0 on SUCCESS, -1 on FAILURE.
Note

m2mb_uart_close(fd);

int main()
{
INT32 fd;
INT32 retVal;
fd = m2mb_uart_open("/dev/tty1", 0);
//... use UART device ...
retVal = m2mb_uart_close(fd);
if ( retVal != -1 )
printf( "m2mb_uart_close succeeded");
}

◆ m2mb_uart_ioctl()

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.

Parameters
[in]fdFile Descriptor returned by m2mb_uart_open()
[in]requestsecond parameter indicates the action to be performed. The allowed values ??are those listed in enum M2MB_UART_IOCTL_REQUEST.
[in,out]cfgthird 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).
Returns
returns 0 on SUCCESS, -1 on FAILURE.
Note
Use cases:
  • 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);

int main()
{
INT32 fd;
INT32 retVal;
fd = m2mb_uart_open("/dev/tty1", 0);
//...
if ( retVal != -1 )
printf( "m2mb_uart_ioctl: get cfg struct succeeded");
// modify some configuration structure fields...
cfg.baud_rate = 9600;
//...
if ( retVal != -1 )
printf( "m2mb_uart_ioctl: set cfg struct succeeded");
}

◆ m2mb_uart_open()

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.

Parameters
[in]pathpath 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]flagsaccess mode flags. Currently unused
Returns
returns the File Descriptor on SUCCESS, -1 on FAILURE.
Note
A default configuration is applied, with following values:
  • Baud rate: 115200 bps
  • Flow Control: off
  • Parity Mode: none
  • Stop Bits: 1
  • Bits Per Char: 8
  • Loopback Mode: disabled
  • Synchronous Write Timeout: 0 ms
  • Synchronous Read Timeout: 0 ms
  • Callback Function: none
  • Callback Data: none

m2mb_uart_open(path, flags);

int main()
{
INT32 fd;
fd = m2mb_uart_open("/dev/tty1", 0);
if ( fd != -1 )
printf( "m2mb_uart_open succeeded");
}

◆ m2mb_uart_read()

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.

Parameters
[in]fdFile Descriptor returned by m2mb_uart_open()
[in]bufdestination buffer, previously allocated.
[in]nbytelength of the destination buffer in Bytes.
Returns
returns the number of read Bytes on SUCCESS, -1 on FAILURE.
Note
Reading can be synchronous or asynchronous. If the callback has been registered (by means of m2mb_uart_ioctl), the function m2mb_uart_read() has an asynchronous behavior: when new data is available from the UART device, the registered callback is invoked with argument M2MB_UART_RX_EV in order to signal that a not blocking reading can be performed. If no callback has been registered, the function m2mb_uart_read() has a synchronous behavior and the reading remains blocked until new data is available from the UART device or for a timeout set by means of m2mb_uart_ioctl.

m2mb_uart_read(fd, buf, nbyte);

#define BUF_LEN 32
static M2MB_OS_EV_HANDLE uartEvtHandle = M2MB_OS_EV_INVALID;
static UINT32 availBytes = 0;
static void m2mb_rx_cb_fn( INT32 fd, M2MB_UART_IND_E uart_event, UINT16 resp_size,
void *num_bytes, void *userdata )
{
if( ( uart_event == M2MB_UART_RX_EV ) && ( num_bytes != NULL ) )
{
availBytes = *( ( UINT32 * )num_bytes );
m2mb_trace_printf( M2MB_TC_UART, M2MB_TL_LOG, "m2mb_rx_cb_fn %d Bytes available", availBytes );
m2mb_os_ev_set( uartEvtHandle, MY_UART_RX_EVT, M2MB_OS_EV_SET );
}
}
int main()
{
INT32 fd;
INT32 rdBytes;
UINT8 dstBuf[BUF_LEN];
UINT32 cur_evt_bits = 0;
fd = m2mb_uart_open("/dev/tty1", 0);
//...
// synchronous read
rdBytes = m2mb_uart_read(fd, dstBuf, BUF_LEN);
if ( rdBytes > 0 )
printf( "synchronous m2mb_uart_read succeeded, read %d Bytes", rdBytes );
else
printf( "synchronous m2mb_uart_read failure" );
// asynchronous read
// initialize event handle uartEvtHandle
// ...
// register the callback
// wait for the event set by the callback
m2mb_os_ev_get( uartEvtHandle, MY_UART_RX_EVT, M2MB_OS_EV_GET_ANY_AND_CLEAR,
&cur_evt_bits, M2MB_OS_WAIT_FOREVER );
if( availBytes < BUF_LEN )
{
rdBytes = m2mb_uart_read( fd, rx_buf, BUF_LEN );
if( ( rdBytes >= 0 ) && ( rdBytes == availBytes ) )
printf( "asynchronous m2mb_uart_read succeeded, read %d Bytes", rdBytes );
}
else
{
while( availBytes > 0 )
{
rdBytes = m2mb_uart_read( fd, rx_buf, BUF_LEN );
if( rdBytes >= 0 )
{
printf( "asynchronous m2mb_uart_read succeeded, read %d Bytes", rdBytes );
availBytes -= rdBytes;
// ...
}
else
{
printf( "asynchronous m2mb_uart_read failure" );
break;
}
}
}
}

◆ m2mb_uart_write()

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.

Parameters
[in]fdFile Descriptor returned by m2mb_uart_open()
[in]bufsource buffer, previously allocated.
[in]nbytelength of the source buffer in Bytes.
Returns
on SUCCESS for synchronous write: number of written Bytes on SUCCESS for asynchronous write: 0 on FAILURE: -1
Note
Writing can be synchronous or asynchronous. If the callback has been registered (by means of m2mb_uart_ioctl), the function m2mb_uart_write() has an asynchronous behavior: after a not blocking writing has been performed, the API returns 0 in case of success and the registered callback is invoked with argument M2MB_UART_TX_EV in order to signal that the whole data has been successfully transmitted to the UART device. If no callback has been registered, the function m2mb_uart_write() has a synchronous behavior and the writing remains blocked until the data transmission to the UART device is completed or for a timeout set by means of m2mb_uart_ioctl.

m2mb_uart_write(fd, buf, nbyte);

#define BUF_LEN 32
static M2MB_OS_EV_HANDLE uartEvtHandle = M2MB_OS_EV_INVALID;
static UINT32 sentBytes = 0;
static void m2mb_tx_cb_fn( INT32 fd, M2MB_UART_IND_E uart_event, UINT16 resp_size,
void *num_bytes, void *userdata )
{
if( ( uart_event == M2MB_UART_TX_EV ) && ( num_bytes != NULL ) )
{
sentBytes = *( ( UINT32 * )num_bytes );
m2mb_trace_printf( M2MB_TC_UART, M2MB_TL_LOG, "m2mb_rx_cb_fn %d Bytes sent", sentBytes );
m2mb_os_ev_set( uartEvtHandle, MY_UART_TX_EVT, M2MB_OS_EV_SET );
}
}
int main()
{
INT32 fd;
INT32 wrBytes;
UINT8 srcBuf[BUF_LEN];
UINT32 cur_evt_bits = 0;
fd = m2mb_uart_open("/dev/tty1", 0);
//...
// copy in srcBuf data to be sent to the UART port
// ...
// synchronous write
wrBytes = m2mb_uart_write(fd, srcBuf, BUF_LEN);
if ( wrBytes == BUF_LEN )
printf( "m2mb_uart_write succeeded, written %d Bytes", wrBytes );
else
printf( "synchronous m2mb_uart_write failure" );
// asynchronous write
// initialize event handle uartEvtHandle
// ...
// register the callback
wrBytes = m2mb_uart_write(fd, srcBuf, BUF_LEN);
if ( wrBytes < 0 )
printf( "synchronous m2mb_uart_write failure" );
else
{
// wait for the event set by the callback
m2mb_os_ev_get( uartEvtHandle, MY_UART_TX_EVT, M2MB_OS_EV_GET_ANY_AND_CLEAR,
&cur_evt_bits, M2MB_OS_WAIT_FOREVER );
if( sentBytes == BUF_LEN )
printf( "m2mb_uart_write succeeded, written %d Bytes", wrBytes );
}
}
m2mb_uart_close
INT32 m2mb_uart_close(INT32 fd)
m2mb_uart_close closes a UART device.
M2MB_UART_CFG_T
UART ioctl configuration.
Definition: m2mb_uart.h:220
m2mb_os_ev_set
M2MB_OS_RESULT_E m2mb_os_ev_set(M2MB_OS_EV_HANDLE evHandle, UINT32 evBits, M2MB_OS_EV_SET_OPT_E optSet)
Set bits of event in a specified event.
M2MB_UART_IOCTL_SET_CFG
Definition: m2mb_uart.h:46
m2mb_uart_open
INT32 m2mb_uart_open(const CHAR *path, INT32 flags,...)
m2mb_uart_open opens a UART device.
M2MB_UART_IOCTL_SET_CB_FN
Definition: m2mb_uart.h:66
M2MB_UART_IOCTL_GET_CFG
Definition: m2mb_uart.h:47
m2mb_uart_read
SSIZE_T m2mb_uart_read(INT32 fd, void *buf, SIZE_T nbyte)
m2mb_uart_read reads data from an open UART device.
M2MB_UART_RX_EV
Definition: m2mb_uart.h:157
M2MB_UART_TX_EV
Definition: m2mb_uart.h:156
m2mb_os_ev_get
M2MB_OS_RESULT_E m2mb_os_ev_get(M2MB_OS_EV_HANDLE evHandle, UINT32 reqEvBits, M2MB_OS_EV_GET_OPT_E optGet, UINT32 *pCurEvBits, UINT32 timeout)
Get an application event.
m2mb_uart_write
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_ioctl
INT32 m2mb_uart_ioctl(INT32 fd, INT32 request,...)
m2mb_uart_ioctl configures an open UART device.
M2MB_UART_IND_E
M2MB_UART_IND_E
UART event type.
Definition: m2mb_uart.h:154
M2MB_UART_CFG_T::baud_rate
UINT32 baud_rate
Definition: m2mb_uart.h:222