WE310F5  39.00.000
M2MB UART

This section describes the M2MB APIs to perform various UART operations. More...

#define M2MB_CONSOLE_PORT   M2MB_UART_HS_PORT_E
 
enum  M2MB_UART_PORT_ID_E {
  M2MB_UART_HS_PORT_E = 0,
  M2MB_UART_DEBUG_PORT_E = 1,
  M2MB_UART_MAX_PORTS_E
}
 UART Port Identifier enumeration. More...
 
enum  M2MB_UART_PARITY_MODE_E {
  M2MB_UART_NO_PARITY_E = 0,
  M2MB_UART_ODD_PARITY_E = 1,
  M2MB_UART_EVEN_PARITY_E = 2,
  M2MB_UART_SPACE_PARITY_E = 3
}
 UART parity mode configuration enumeration. More...
 
enum  M2MB_UART_BITS_PER_CHAR_E {
  M2MB_UART_5_BITS_PER_CHAR_E = 0,
  M2MB_UART_6_BITS_PER_CHAR_E = 1,
  M2MB_UART_7_BITS_PER_CHAR_E = 2,
  M2MB_UART_8_BITS_PER_CHAR_E = 3
}
 UART bits per character configuration enumeration. More...
 
enum  M2MB_UART_NUM_STOP_BITS_E {
  M2MB_UART_0_5_STOP_BITS_E = 0,
  M2MB_UART_1_0_STOP_BITS_E = 1,
  M2MB_UART_1_5_STOP_BITS_E = 2,
  M2MB_UART_2_0_STOP_BITS_E = 3
}
 UART number of stop bits configuration enumeration. More...
 
typedef VOIDM2MB_UART_HANDLE_T
 UART Handle pointer. More...
 
typedef VOID(* M2MB_UART_CB_T) (UINT32 num_bytes, VOID *p_cb_data)
 UART call back prototype. More...
 
typedef struct M2MB_UART_CONFIG M2MB_UART_CONFIG_T
 Structure to configure UART module. More...
 
M2MB_STATUS_T m2mb_uart_open (M2MB_UART_HANDLE_T *p_handle, M2MB_UART_PORT_ID_E id, M2MB_UART_CONFIG_T *p_config)
 Opens the UART port. More...
 
M2MB_STATUS_T m2mb_uart_close (M2MB_UART_HANDLE_T p_handle)
 Close UART port. More...
 
M2MB_STATUS_T m2mb_uart_write (M2MB_UART_HANDLE_T p_handle, CHAR *p_buf, UINT32 bytes_to_tx, VOID *p_cb_data)
 Transmits data over UART port. More...
 
UINT8m2mb_uart_read (HANDLE h, UINT32 *size, UINT32 timeout, UINT8 *buff, VOID *p_cb_data)
 Receives data from UART port. More...
 

Detailed Description

This section describes the M2MB APIs to perform various UART operations.

Macro Definition Documentation

◆ M2MB_CONSOLE_PORT

#define M2MB_CONSOLE_PORT   M2MB_UART_HS_PORT_E

Definition at line 52 of file m2mb_uart.h.

Typedef Documentation

◆ M2MB_UART_CB_T

typedef VOID(* M2MB_UART_CB_T) (UINT32 num_bytes, VOID *p_cb_data)

UART call back prototype.

Type definition of the user callback to handle UART receive and transmit events. num_bytes represent the number of bytes transmitted/received, p_cb_data represents data for the callback.

Type definition of the user callback to handle UART receive and transmit events.

Parameters
[in]num_bytesrepresent the number of bytes transmitted/received
[in]p_cb_datarepresents data for the callback given as the input to UART read or write request.
Note
Registered during m2mb_uart_open. Will be called from UART module ISR when read/write operation is completed.

Example

VOID m2m_uart_rx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Receive call back
}
VOID m2m_uart_tx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Transmit call back
}
int main()
{
M2MB_UART_HANDLE_T uart_handle = NULL;
CHAR buffer[10] = { 0 };
uart_cfg.baud_rate = 115200;
uart_cfg.enable_loopback = FALSE;
uart_cfg.enable_flow_ctrl = FALSE;
uart_cfg.tx_cb = m2m_uart_tx_cb;
uart_cfg.rx_cb = m2m_uart_rx_cb;
if( m2mb_uart_open( &uart_handle, M2MB_UART_HS_PORT_E, &uart_cfg ) != M2MB_OK )
{
return M2MB_ERROR;
}
}

Definition at line 122 of file m2mb_uart.h.

◆ M2MB_UART_CONFIG_T

Structure to configure UART module.

Structure for storing the configuration of UART module. This will be used by m2mb_uart_open API to open UART module with given configuration.

◆ M2MB_UART_HANDLE_T

UART Handle pointer.

This pointer represents the UART context.

Definition at line 61 of file m2mb_uart.h.

Enumeration Type Documentation

◆ M2MB_UART_BITS_PER_CHAR_E

UART bits per character configuration enumeration.

This enumeration defines macros for configuration of bits per character of UART.

Enumerator
M2MB_UART_5_BITS_PER_CHAR_E 

5 bits per character.

M2MB_UART_6_BITS_PER_CHAR_E 

6 bits per character.

M2MB_UART_7_BITS_PER_CHAR_E 

7 bits per character.

M2MB_UART_8_BITS_PER_CHAR_E 

8 bits per character.

Definition at line 155 of file m2mb_uart.h.

◆ M2MB_UART_NUM_STOP_BITS_E

UART number of stop bits configuration enumeration.

This enumeration defines macros for number of stop bits configuration.

Enumerator
M2MB_UART_0_5_STOP_BITS_E 

0.5 stop bits.

M2MB_UART_1_0_STOP_BITS_E 

1.0 stop bit.

M2MB_UART_1_5_STOP_BITS_E 

1.5 stop bits.

M2MB_UART_2_0_STOP_BITS_E 

2.0 stop bits.

Definition at line 168 of file m2mb_uart.h.

◆ M2MB_UART_PARITY_MODE_E

UART parity mode configuration enumeration.

This enumeration defines macros for UART parity mode configuration.

Enumerator
M2MB_UART_NO_PARITY_E 

No parity.

M2MB_UART_ODD_PARITY_E 

Odd parity.

M2MB_UART_EVEN_PARITY_E 

Even parity.

M2MB_UART_SPACE_PARITY_E 

Space parity.

Definition at line 142 of file m2mb_uart.h.

◆ M2MB_UART_PORT_ID_E

UART Port Identifier enumeration.

This enumeration defines macros for UART Port Identifiers.

Enumerator
M2MB_UART_HS_PORT_E 

High speed port.

M2MB_UART_DEBUG_PORT_E 

Debug port.

M2MB_UART_MAX_PORTS_E 

Maximum number of ports.

Definition at line 129 of file m2mb_uart.h.

Function Documentation

◆ m2mb_uart_close()

M2MB_STATUS_T m2mb_uart_close ( M2MB_UART_HANDLE_T  p_handle)

Close UART port.

This service closes the UART

Parameters
[in]p_handlePointer to the handle of UART module
Returns
M2MB_OK Port close successful. M2MB_ERROR Port close failed.
Note
Allowed From Application Preemption Possible No

m2mb_uart_close( uart_handle );

VOID m2m_uart_rx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Receive call back
}
VOID m2m_uart_tx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Transmit call back
}
int main()
{
M2MB_UART_HANDLE_T uart_handle = NULL;
uart_cfg.baud_rate = 115200;
uart_cfg.enable_loopback = FALSE;
uart_cfg.enable_flow_ctrl = FALSE;
uart_cfg.tx_cb = m2m_uart_tx_cb;
uart_cfg.rx_cb = m2m_uart_rx_cb;
if( m2mb_uart_open( &uart_handle, M2MB_UART_HS_PORT_E, &uart_cfg ) != M2MB_OK )
{
return M2MB_ERROR;
}
...
if( m2mb_uart_close( uart_handle ) == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_uart_open()

M2MB_STATUS_T m2mb_uart_open ( M2MB_UART_HANDLE_T p_handle,
M2MB_UART_PORT_ID_E  id,
M2MB_UART_CONFIG_T p_config 
)

Opens the UART port.

Opens the UART port and configures the corresponding clocks, interrupts, and GPIO.

Parameters
[in]p_handlePointer to the handle of UART module
[in]idEnumeration of type M2MB_UART_PORT_ID_E that specifies PORT ID
[in]p_configPointer to the configuration structure of UART module
Returns
M2MB_OK Port open successful. M2MB_ERROR Port open failed.
Note
Allowed From Application Preemption Possible No

m2mb_uart_open( &uart_handle, M2MB_UART_HS_PORT_E, &uart_cfg );

VOID m2m_uart_rx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Receive call back
}
VOID m2m_uart_tx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Transmit call back
}
int main()
{
M2MB_UART_HANDLE_T uart_handle = NULL;
uart_cfg.baud_rate = 115200;
uart_cfg.enable_loopback = FALSE;
uart_cfg.enable_flow_ctrl = FALSE;
uart_cfg.tx_cb = m2m_uart_tx_cb;
uart_cfg.rx_cb = m2m_uart_rx_cb;
if( m2mb_uart_open( &uart_handle, M2MB_UART_HS_PORT_E, &uart_cfg ) == 0 )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_uart_read()

UINT8* m2mb_uart_read ( HANDLE  h,
UINT32 size,
UINT32  timeout,
UINT8 buff,
VOID p_cb_data 
)

Receives data from UART port.

This service receives the data from UART port.

Parameters
[in]hUART handle provided by m2mb_uart_open().
[out]sizeSize pointer. it stroes the size of data received.
[in]timeouttimeout to wait for data.
Returns
Pointer Pointer to the buffer where data receoved over UART is kept
Note
Allowed From Application Preemption Possible No

Example

VOID m2m_uart_tx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Transmit call back
}
int main()
{
M2MB_UART_HANDLE_T uart_handle = NULL;
UINT8* buffer;
UINT32 len;
uart_cfg.baud_rate = 115200;
uart_cfg.enable_loopback = FALSE;
uart_cfg.enable_flow_ctrl = FALSE;
uart_cfg.tx_cb = m2m_uart_tx_cb;
if( m2mb_uart_open( &uart_handle, M2MB_UART_HS_PORT_E, &uart_cfg ) != M2MB_OK )
{
return M2MB_ERROR;
}
...
if(( buffer = m2mb_uart_read( uart_handle, &len, NULL )) != NULL )
return M2MB_OK;
else
return M2MB_ERROR;
}

◆ m2mb_uart_write()

M2MB_STATUS_T m2mb_uart_write ( M2MB_UART_HANDLE_T  p_handle,
CHAR p_buf,
UINT32  bytes_to_tx,
VOID p_cb_data 
)

Transmits data over UART port.

This service transmits the given data over UART

Parameters
[in]p_handlePointer to the handle of UART module
[in]p_buf`Pointer to the buffer of data to be transmitted
[in]bytes_to_txNumber of bytes to be transmitted
[in]p_cb_dataCallback data to be passed when tx_cb is called during TX completion.
Returns
M2MB_OK Data Transmission successful. M2MB_ERROR Data Transmission failed.
Note
Allowed From Application Preemption Possible No

m2mb_uart_write( handle, "Hello", strlen("Hello"), NULL );

VOID m2m_uart_rx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Receive call back
}
VOID m2m_uart_tx_cb( UINT32 num_bytes, VOID *p_cb_data )
{
//Handle Transmit call back
}
int main()
{
M2MB_UART_HANDLE_T uart_handle = NULL;
uart_cfg.baud_rate = 115200;
uart_cfg.enable_loopback = FALSE;
uart_cfg.enable_flow_ctrl = FALSE;
uart_cfg.tx_cb = m2m_uart_tx_cb;
uart_cfg.rx_cb = m2m_uart_rx_cb;
if( m2mb_uart_open( &uart_handle, M2MB_UART_HS_PORT_E, &uart_cfg ) != M2MB_OK )
{
return M2MB_ERROR;
}
...
if( m2mb_uart_write( uart_handle, "Hello", strlen("Hello"), NULL ) == M2MB_OK )
return M2MB_OK;
else
return M2MB_ERROR;
}