Wirepas SDK
usart.h File Reference

Go to the source code of this file.

Typedefs

typedef void(* serial_rx_callback_f) (uint8_t *ch, size_t n)
 

Functions

bool Usart_init (uint32_t baudrate, uart_flow_control_e flow_control)
 Initialize all USART blocks Enables peripheral clocks and disables peripherals for the duration of the initialization procedure. Clears all internal variables: Callback handlers Transfer busy flags After the initialization procedure is complete, it enables all peripherals, but leaves peripheral clocks disabled. More...
 
void Usart_setEnabled (bool enabled)
 Enable or disable USART Enables or disables USART clock and configures GPIO pins. More...
 
void Usart_receiverOn (void)
 Enable USART Receiver. More...
 
void Usart_receiverOff (void)
 Disable USART Receiver. More...
 
bool Usart_setFlowControl (uart_flow_control_e flow)
 Set USART flow control mode. More...
 
uint32_t Usart_sendBuffer (const void *buf, uint32_t len)
 Send a buffer to USART. More...
 
void Usart_enableReceiver (serial_rx_callback_f callback)
 Enable UART receiver Set callback handler for character RX event Enables interrupt source and event, and the input pin. More...
 
uint32_t Usart_getMTUSize (void)
 Returns the maximum transmission unit in bytes for the USART (= maximum length of a single message) More...
 
void Usart_flush (void)
 Soft flush (dump data to I/O) UART TX buffer. More...
 

Enumerations

enum  uart_flow_control_e { UART_FLOW_CONTROL_NONE, UART_FLOW_CONTROL_HW }
 

Typedef Documentation

◆ serial_rx_callback_f

typedef void(* serial_rx_callback_f) (uint8_t *ch, size_t n)

User callback for character received event

Definition at line 15 of file usart.h.

Function Documentation

◆ Usart_enableReceiver()

void Usart_enableReceiver ( serial_rx_callback_f  callback)

Enable UART receiver Set callback handler for character RX event Enables interrupt source and event, and the input pin.

Precondition
Usart_init called.
Note
This function should be called after Usart_init and before calling Usart_setEnabled.
Parameters
callbackCallback function for a character rx event
     Can be NULL, which clears the callback and disables IRQ
Returns
none

◆ Usart_flush()

void Usart_flush ( void  )

Soft flush (dump data to I/O) UART TX buffer.

◆ Usart_getMTUSize()

uint32_t Usart_getMTUSize ( void  )

Returns the maximum transmission unit in bytes for the USART (= maximum length of a single message)

◆ Usart_init()

bool Usart_init ( uint32_t  baudrate,
uart_flow_control_e  flow_control 
)

Initialize all USART blocks Enables peripheral clocks and disables peripherals for the duration of the initialization procedure. Clears all internal variables: Callback handlers Transfer busy flags After the initialization procedure is complete, it enables all peripherals, but leaves peripheral clocks disabled.

Parameters
baudrateBaudrate to be used
flow_controlFlow control to be used
Returns
True if successful, false otherwise

◆ Usart_receiverOff()

void Usart_receiverOff ( void  )

Disable USART Receiver.

◆ Usart_receiverOn()

void Usart_receiverOn ( void  )

Enable USART Receiver.

Precondition
Usart_setEnabled is called.

◆ Usart_sendBuffer()

uint32_t Usart_sendBuffer ( const void *  buf,
uint32_t  len 
)

Send a buffer to USART.

Parameters
bufBuffer to send
lenSize of buffer to send (max = Usart_getMTUSize())
Note
This method will either send the whole buffer or nothing at all
Returns
Number of bytes written (zero or len)

◆ Usart_setEnabled()

void Usart_setEnabled ( bool  enabled)

Enable or disable USART Enables or disables USART clock and configures GPIO pins.

Precondition
Usart_enableReceiver is called.
Parameters
enabledTrue, if USART should be enabled

◆ Usart_setFlowControl()

bool Usart_setFlowControl ( uart_flow_control_e  flow)

Set USART flow control mode.

Precondition
USART is not enabled
Parameters
flowDesired flow control mode
Returns
True, if the baud rate was updated successfully

Enumeration Type Documentation

◆ uart_flow_control_e

Enumerator
UART_FLOW_CONTROL_NONE 
UART_FLOW_CONTROL_HW 

Definition at line 17 of file usart.h.

UART_FLOW_CONTROL_HW
@ UART_FLOW_CONTROL_HW
Definition: usart.h:20
UART_FLOW_CONTROL_NONE
@ UART_FLOW_CONTROL_NONE
Definition: usart.h:19
uart_flow_control_e
uart_flow_control_e
Definition: usart.h:17