Firmware SDK
twr_uart

Driver for UART (universal asynchronous receiver/transmitter) More...

Enumerations

enum  twr_uart_channel_t {
  TWR_UART_UART0 = 0,
  TWR_UART_UART1 = 1,
  TWR_UART_UART2 = 2
}
 UART channels. More...
 
enum  twr_uart_baudrate_t {
  TWR_UART_BAUDRATE_9600 = 0,
  TWR_UART_BAUDRATE_19200 = 1,
  TWR_UART_BAUDRATE_38400 = 2,
  TWR_UART_BAUDRATE_57600 = 3,
  TWR_UART_BAUDRATE_115200 = 4,
  TWR_UART_BAUDRATE_921600 = 5
}
 UART baudrate. More...
 
enum  twr_uart_setting_t {
  TWR_UART_SETTING_8N1 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_1,
  TWR_UART_SETTING_8E1 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_EVEN | _TWR_UART_SETTING_STOP_BIT_1,
  TWR_UART_SETTING_8O1 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_ODD | _TWR_UART_SETTING_STOP_BIT_1,
  TWR_UART_SETTING_8N2 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_2,
  TWR_UART_SETTING_8E2 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_EVEN | _TWR_UART_SETTING_STOP_BIT_2,
  TWR_UART_SETTING_8O2 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_2,
  TWR_UART_SETTING_8N1_5 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_15,
  TWR_UART_SETTING_8E1_5 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_EVEN | _TWR_UART_SETTING_STOP_BIT_15,
  TWR_UART_SETTING_8O1_5 = _TWR_UART_SETTING_DATA_BITS_8 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_15,
  TWR_UART_SETTING_7N1 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_1,
  TWR_UART_SETTING_7E1 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_EVEN | _TWR_UART_SETTING_STOP_BIT_1,
  TWR_UART_SETTING_7O1 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_ODD | _TWR_UART_SETTING_STOP_BIT_1,
  TWR_UART_SETTING_7N2 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_2,
  TWR_UART_SETTING_7E2 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_EVEN | _TWR_UART_SETTING_STOP_BIT_2,
  TWR_UART_SETTING_7O2 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_2,
  TWR_UART_SETTING_7N1_5 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_15,
  TWR_UART_SETTING_7E1_5 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_EVEN | _TWR_UART_SETTING_STOP_BIT_15,
  TWR_UART_SETTING_7O1_5 = _TWR_UART_SETTING_DATA_BITS_7 | _TWR_UART_SETTING_PARITY_NONE | _TWR_UART_SETTING_STOP_BIT_15
}
 UART setting. More...
 
enum  twr_uart_event_t {
  TWR_UART_EVENT_ASYNC_WRITE_DONE = 0,
  TWR_UART_EVENT_ASYNC_READ_DATA = 1,
  TWR_UART_EVENT_ASYNC_READ_TIMEOUT = 2
}
 Callback events. More...
 

Functions

void twr_uart_init (twr_uart_channel_t channel, twr_uart_baudrate_t baudrate, twr_uart_setting_t setting)
 Initialize UART channel. More...
 
void twr_uart_deinit (twr_uart_channel_t channel)
 Deinitialize UART channel. More...
 
size_t twr_uart_write (twr_uart_channel_t channel, const void *buffer, size_t length)
 Write data to UART channel (blocking call) More...
 
size_t twr_uart_read (twr_uart_channel_t channel, void *buffer, size_t length, twr_tick_t timeout)
 Read data from UART channel (blocking call) More...
 
void twr_uart_set_event_handler (twr_uart_channel_t channel, void(*event_handler)(twr_uart_channel_t, twr_uart_event_t, void *), void *event_param)
 Set callback function. More...
 
void twr_uart_set_async_fifo (twr_uart_channel_t channel, twr_fifo_t *write_fifo, twr_fifo_t *read_fifo)
 Set buffers for async transfers. More...
 
size_t twr_uart_async_write (twr_uart_channel_t channel, const void *buffer, size_t length)
 Add data to be transmited in async mode. More...
 
bool twr_uart_async_read_start (twr_uart_channel_t channel, twr_tick_t timeout)
 Start async reading. More...
 
bool twr_uart_async_read_cancel (twr_uart_channel_t channel)
 Cancel async reading. More...
 
size_t twr_uart_async_read (twr_uart_channel_t channel, void *buffer, size_t length)
 Get data that has been received in async mode. More...
 

Detailed Description

Driver for UART (universal asynchronous receiver/transmitter)

Enumeration Type Documentation

◆ twr_uart_baudrate_t

UART baudrate.

Enumerator
TWR_UART_BAUDRATE_9600 

UART baudrat 9600 bps.

TWR_UART_BAUDRATE_19200 

UART baudrat 19200 bps.

TWR_UART_BAUDRATE_38400 

UART baudrat 38400 bps.

TWR_UART_BAUDRATE_57600 

UART baudrat 57600 bps.

TWR_UART_BAUDRATE_115200 

UART baudrat 115200 bps.

TWR_UART_BAUDRATE_921600 

UART baudrat 921600 bps.

Definition at line 28 of file twr_uart.h.

◆ twr_uart_channel_t

UART channels.

Enumerator
TWR_UART_UART0 

UART channel UART0.

TWR_UART_UART1 

UART channel UART1.

TWR_UART_UART2 

UART channel UART2.

Definition at line 13 of file twr_uart.h.

◆ twr_uart_event_t

Callback events.

Enumerator
TWR_UART_EVENT_ASYNC_WRITE_DONE 

Event is writting done.

TWR_UART_EVENT_ASYNC_READ_DATA 

Event is reading done.

TWR_UART_EVENT_ASYNC_READ_TIMEOUT 

Event is timeout.

Definition at line 127 of file twr_uart.h.

◆ twr_uart_setting_t

UART setting.

Enumerator
TWR_UART_SETTING_8N1 

8N1: 8 data bits, none parity bit, 1 stop bit

TWR_UART_SETTING_8E1 

8E1: 8 data bits, even parity bit, 1 stop bit

TWR_UART_SETTING_8O1 

8O1: 8 data bits, odd parity bit, 1 stop bit

TWR_UART_SETTING_8N2 

8N2: 8 data bits, none parity bit, 2 stop bits

TWR_UART_SETTING_8E2 

8E2: 8 data bits, even parity bit, 2 stop bit

TWR_UART_SETTING_8O2 

8O2: 8 data bits, odd parity bit, 2 stop bit

TWR_UART_SETTING_8N1_5 

8N1_5: 8 data bits, none parity bit, 1.5 stop bits

TWR_UART_SETTING_8E1_5 

8E1_5: 8 data bits, even parity bit, 1.5 stop bit

TWR_UART_SETTING_8O1_5 

8O1_5: 8 data bits, odd parity bit, 1.5 stop bit

TWR_UART_SETTING_7N1 

7N1: 7 data bits, none parity bit, 1 stop bit

TWR_UART_SETTING_7E1 

7E1: 7 data bits, even parity bit, 1 stop bit

TWR_UART_SETTING_7O1 

7O1: 7 data bits, odd parity bit, 1 stop bit

TWR_UART_SETTING_7N2 

7N2: 7 data bits, none parity bit, 2 stop bits

TWR_UART_SETTING_7E2 

7E2: 7 data bits, even parity bit, 2 stop bit

TWR_UART_SETTING_7O2 

7O2: 7 data bits, odd parity bit, 2 stop bit

TWR_UART_SETTING_7N1_5 

7N1_5: 7 data bits, none parity bit, 1.5 stop bits

TWR_UART_SETTING_7E1_5 

7E1_5: 7 data bits, even parity bit, 1.5 stop bit

TWR_UART_SETTING_7O1_5 

7O1_5: 7 data bits, odd parity bit, 1.5 stop bit

Definition at line 67 of file twr_uart.h.

Function Documentation

◆ twr_uart_async_read()

size_t twr_uart_async_read ( twr_uart_channel_t  channel,
void *  buffer,
size_t  length 
)

Get data that has been received in async mode.

Parameters
[in]channelUART channel
[in]bufferPointer to buffer
[in]lengthMaximum length of received data
Returns
Number of received bytes

Definition at line 547 of file twr_uart.c.

Referenced by twr_atci_help_action(), twr_cmwx1zzabz_get_error_response(), twr_cmwx1zzabz_set_debug(), twr_esp8266_get_received_message_data(), twr_td1207r_send_rf_frame(), and twr_wssfm10r1at_continuous_wave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_uart_async_read_cancel()

bool twr_uart_async_read_cancel ( twr_uart_channel_t  channel)

Cancel async reading.

Parameters
[in]channelUART channel
Returns
true On success
false On failure

Definition at line 507 of file twr_uart.c.

Referenced by twr_uart_deinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_uart_async_read_start()

bool twr_uart_async_read_start ( twr_uart_channel_t  channel,
twr_tick_t  timeout 
)

Start async reading.

Parameters
[in]channelUART channel
[in]timeoutMaximum timeout in ms
Returns
true On success
false On failure

Definition at line 451 of file twr_uart.c.

Referenced by twr_cmwx1zzabz_init(), twr_td1207r_init(), and twr_wssfm10r1at_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_uart_async_write()

size_t twr_uart_async_write ( twr_uart_channel_t  channel,
const void *  buffer,
size_t  length 
)

Add data to be transmited in async mode.

Parameters
[in]channelUART channel
[in]bufferPointer to buffer
[in]lengthLength of data to be added
Returns
Number of bytes added

Definition at line 404 of file twr_uart.c.

Referenced by twr_cmwx1zzabz_set_debug(), twr_td1207r_send_rf_frame(), and twr_wssfm10r1at_continuous_wave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_uart_deinit()

void twr_uart_deinit ( twr_uart_channel_t  channel)

Deinitialize UART channel.

Parameters
[in]channelUART channel

Definition at line 233 of file twr_uart.c.

Here is the call graph for this function:

◆ twr_uart_init()

void twr_uart_init ( twr_uart_channel_t  channel,
twr_uart_baudrate_t  baudrate,
twr_uart_setting_t  setting 
)

Initialize UART channel.

Parameters
[in]channelUART channel
[in]configUART configuration

Definition at line 54 of file twr_uart.c.

Referenced by twr_atci_set_uart_active_callback(), twr_cmwx1zzabz_init(), twr_log_init(), twr_td1207r_init(), and twr_wssfm10r1at_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_uart_read()

size_t twr_uart_read ( twr_uart_channel_t  channel,
void *  buffer,
size_t  length,
twr_tick_t  timeout 
)

Read data from UART channel (blocking call)

Parameters
[in]channelUART channel
[in]bufferPointer to destination buffer
[in]lengthNumber of bytes to be read
[in]timeoutRead operation timeout in ticks
Returns
Number of bytes read

Definition at line 348 of file twr_uart.c.

Here is the call graph for this function:

◆ twr_uart_set_async_fifo()

void twr_uart_set_async_fifo ( twr_uart_channel_t  channel,
twr_fifo_t write_fifo,
twr_fifo_t read_fifo 
)

Set buffers for async transfers.

Parameters
[in]channelUART channel
[in]write_fifoPointer to writing fifo
[in]read_fifoPointer to reader fifo

Definition at line 398 of file twr_uart.c.

Referenced by twr_cmwx1zzabz_init(), twr_td1207r_init(), and twr_wssfm10r1at_init().

Here is the caller graph for this function:

◆ twr_uart_set_event_handler()

void twr_uart_set_event_handler ( twr_uart_channel_t  channel,
void(*)(twr_uart_channel_t, twr_uart_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]channelUART channel
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 392 of file twr_uart.c.

Referenced by twr_cmwx1zzabz_init().

Here is the caller graph for this function:

◆ twr_uart_write()

size_t twr_uart_write ( twr_uart_channel_t  channel,
const void *  buffer,
size_t  length 
)

Write data to UART channel (blocking call)

Parameters
[in]channelUART channel
[in]bufferPointer to source buffer
[in]lengthNumber of bytes to be written
Returns
Number of bytes written

Definition at line 306 of file twr_uart.c.

Referenced by twr_atci_printf(), twr_atci_write_error(), and twr_atci_write_ok().

Here is the caller graph for this function: