XCore SDK
XCore Software Development Kit
Classes | Macros | Typedefs | Enumerations | Functions
hil_uart

Classes

struct  uart_tx_t
 
struct  uart_rx_t
 

Macros

#define UART_START_BIT_ERROR_VAL   2
 
#define HIL_UART_TX_CALLBACK_ATTR   __attribute__((fptrgroup("hil_uart_tx_callback")))
 
#define HIL_UART_RX_CALLBACK_ATTR   __attribute__((fptrgroup("hil_uart_rx_callback")))
 

Typedefs

typedef enum uart_parity_t uart_parity_t
 

Enumerations

enum  uart_parity_t { UART_PARITY_NONE = 0 , UART_PARITY_EVEN , UART_PARITY_ODD }
 
enum  uart_callback_code_t {
  UART_RX_COMPLETE = 0 , UART_UNDERRUN_ERROR = 1 , UART_START_BIT_ERROR = UART_START_BIT_ERROR_VAL , UART_PARITY_ERROR = UART_START_BIT_ERROR_VAL + 1 ,
  UART_FRAMING_ERROR = UART_START_BIT_ERROR_VAL + 2 , UART_OVERRUN_ERROR = UART_START_BIT_ERROR_VAL + 3
}
 
enum  uart_state_t {
  UART_IDLE = 0 , UART_START , UART_DATA , UART_PARITY ,
  UART_STOP
}
 

Functions

void uart_tx_init (uart_tx_t *uart, port_t tx_port, uint32_t baud_rate, uint8_t data_bits, uart_parity_t parity, uint8_t stop_bits, hwtimer_t tmr, uint8_t *tx_buff, size_t buffer_size_plus_one, void(*uart_tx_empty_callback_fptr)(void *app_data), void *app_data)
 
void uart_tx_blocking_init (uart_tx_t *uart_cfg, port_t tx_port, uint32_t baud_rate, uint8_t num_data_bits, uart_parity_t parity, uint8_t stop_bits, hwtimer_t tmr)
 
void uart_tx (uart_tx_t *uart, uint8_t data)
 
void uart_tx_deinit (uart_tx_t *uart)
 
void uart_rx_init (uart_rx_t *uart, port_t rx_port, uint32_t baud_rate, uint8_t data_bits, uart_parity_t parity, uint8_t stop_bits, hwtimer_t tmr, uint8_t *rx_buff, size_t buffer_size, void(*uart_rx_complete_callback_fptr)(void *app_data), void(*uart_rx_error_callback_fptr)(uart_callback_code_t callback_code, void *app_data), void *app_data)
 
void uart_rx_blocking_init (uart_rx_t *uart, port_t rx_port, uint32_t baud_rate, uint8_t data_bits, uart_parity_t parity, uint8_t stop_bits, hwtimer_t tmr, void(*uart_rx_error_callback_fptr)(uart_callback_code_t callback_code, void *app_data), void *app_data)
 
uint8_t uart_rx (uart_rx_t *uart)
 
void uart_rx_deinit (uart_rx_t *uart)
 

Detailed Description

The public API for using the HIL UART.

Macro Definition Documentation

◆ HIL_UART_TX_CALLBACK_ATTR

#define HIL_UART_TX_CALLBACK_ATTR   __attribute__((fptrgroup("hil_uart_tx_callback")))

This attribute must be specified on the UART callback function provided by the application. It ensures the correct stack usage is calculated.

◆ UART_START_BIT_ERROR_VAL

#define UART_START_BIT_ERROR_VAL   2

Enum type representing the callback error codes.

Typedef Documentation

◆ uart_parity_t

Enum type representing the different options parity types.

Enumeration Type Documentation

◆ uart_parity_t

Enum type representing the different options parity types.

◆ uart_state_t

Enum type representing the different states for the UART logic.

Function Documentation

◆ uart_rx()

uint8_t uart_rx ( uart_rx_t uart)

Receives a single UART frame with parameters as specified in uart_rx_init()

Parameters
uartThe uart_rx_t context to receive from.
Returns
The word received in the UART frame. In buffered mode it gets the oldest received word.

◆ uart_rx_blocking_init()

void uart_rx_blocking_init ( uart_rx_t uart,
port_t  rx_port,
uint32_t  baud_rate,
uint8_t  data_bits,
uart_parity_t  parity,
uint8_t  stop_bits,
hwtimer_t  tmr,
void(*)(uart_callback_code_t callback_code, void *app_data)  uart_rx_error_callback_fptr,
void *  app_data 
)

Initializes a UART Rx I/O interface. This API is fixed to blocking mode which is where the call to uart_rx returns as soon as the stop bit has been sampled.

Parameters
uartThe uart_rx_t context to initialise.
rx_portThe port used receive the UART frames.
baud_rateThe baud rate of the UART in bits per second.
data_bitsThe number of data bits per frame sent.
parityThe type of parity used. See uart_parity_t above.
stop_bitsThe number of stop bits asserted at the of the frame.
tmrThe resource id of the timer to be used. Polling mode will be used if set to 0.
uart_rx_error_callback_fptrCallback function pointer for UART rx errors The error is contained in cb_code in the uart_rx_t struct.
app_dataA pointer to application specific data provided by the application. Used to share data between the error callback function and the application.

◆ uart_rx_deinit()

void uart_rx_deinit ( uart_rx_t uart)

De-initializes the specified UART Rx interface. This disables the port also. The timer, if used, needs to be freed by the application.

Parameters
uartThe uart_rx_t context to de-initialise.

◆ uart_rx_init()

void uart_rx_init ( uart_rx_t uart,
port_t  rx_port,
uint32_t  baud_rate,
uint8_t  data_bits,
uart_parity_t  parity,
uint8_t  stop_bits,
hwtimer_t  tmr,
uint8_t *  rx_buff,
size_t  buffer_size,
void(*)(void *app_data)  uart_rx_complete_callback_fptr,
void(*)(uart_callback_code_t callback_code, void *app_data)  uart_rx_error_callback_fptr,
void *  app_data 
)

Initializes a UART Rx I/O interface. Passing a valid buffer will enable buffered mode with ISR for use in bare-metal applications.

Parameters
uartThe uart_rx_t context to initialise.
rx_portThe port used receive the UART frames.
baud_rateThe baud rate of the UART in bits per second.
data_bitsThe number of data bits per frame sent.
parityThe type of parity used. See uart_parity_t above.
stop_bitsThe number of stop bits asserted at the of the frame.
tmrThe resource id of the timer to be used. Polling mode will be used if set to 0.
rx_buffPointer to a buffer. Optional. If set to zero the UART will run in blocking mode. If initialised to a valid buffer, the UART will be interrupt driven.
buffer_size_plus_oneSize of the buffer if enabled in rx_buff. Note that the buffer allocation and size argument must be one greater than needed. Eg. buff[65] for a 64 byte buffer.
uart_rx_complete_callback_fptrCallback function pointer for UART rx complete (one word) in buffered mode only. Optionally NULL.
uart_rx_error_callback_fptrCallback function pointer for UART rx errors The error is contained in cb_code in the uart_rx_t struct.
app_dataA pointer to application specific data provided by the application. Used to share data between this callback function and the application.

◆ uart_tx()

void uart_tx ( uart_tx_t uart,
uint8_t  data 
)

Transmits a single UART frame with parameters as specified in uart_tx_init()

Parameters
uartThe uart_tx_t context to initialise.
dataThe word to transmit.

◆ uart_tx_blocking_init()

void uart_tx_blocking_init ( uart_tx_t uart_cfg,
port_t  tx_port,
uint32_t  baud_rate,
uint8_t  num_data_bits,
uart_parity_t  parity,
uint8_t  stop_bits,
hwtimer_t  tmr 
)

Initializes a UART Tx I/O interface. The API is hard wired to blocking mode where the call to uart_tx will return at the end of sending the stop bit.

Parameters
uartThe uart_tx_t context to initialise.
tx_portThe port used transmit the UART frames.
baud_rateThe baud rate of the UART in bits per second.
data_bitsThe number of data bits per frame sent.
parityThe type of parity used. See uart_parity_t above.
stop_bitsThe number of stop bits asserted at the of the frame.
tmrThe resource id of the timer to be used. Polling mode will be used if set to 0.

◆ uart_tx_deinit()

void uart_tx_deinit ( uart_tx_t uart)

De-initializes the specified UART Tx interface. This disables the port also. The timer, if used, needs to be freed by the application.

Parameters
uartThe uart_tx_t context to de-initialise.

◆ uart_tx_init()

void uart_tx_init ( uart_tx_t uart,
port_t  tx_port,
uint32_t  baud_rate,
uint8_t  data_bits,
uart_parity_t  parity,
uint8_t  stop_bits,
hwtimer_t  tmr,
uint8_t *  tx_buff,
size_t  buffer_size_plus_one,
void(*)(void *app_data)  uart_tx_empty_callback_fptr,
void *  app_data 
)

Initializes a UART Tx I/O interface. Passing a valid buffer will enable buffered mode with ISR for use in bare-metal applications.

Parameters
uartThe uart_tx_t context to initialise.
tx_portThe port used transmit the UART frames.
baud_rateThe baud rate of the UART in bits per second.
data_bitsThe number of data bits per frame sent.
parityThe type of parity used. See uart_parity_t above.
stop_bitsThe number of stop bits asserted at the of the frame.
tmrThe resource id of the timer to be used. Polling mode will be used if set to 0.
tx_buffPointer to a buffer. Optional. If set to zero the UART will run in blocking mode. If initialised to a valid buffer, the UART will be interrupt driven.
buffer_size_plus_oneSize of the buffer if enabled in tx_buff. Note that the buffer allocation and size argument must be one greater than needed. Eg. buff[65] for a 64 byte buffer.
uart_tx_empty_callback_fptrCallback function pointer for UART buffer empty in buffered mode.
app_dataA pointer to application specific data provided by the application. Used to share data between this callback function and the application.