This module provides configuration and utils for PLC Buffered UART service interface.
#define FREQ_TIMER_POLL_UART 100 |
#define TIMER_UART_PRIO 10 |
#define UART_BUFFER_SIZE 1024 |
static void _configure_TC_uart |
( |
void |
| ) |
|
|
static |
Configure Timer Counter to generate an interrupt every 10ms.
This interrupt will be used to flush UART input and echo back.
References FREQ_TIMER_POLL_UART, ID_TC_UART, pmc_enable_periph_clk(), sysclk_get_cpu_hz(), tc_enable_interrupt(), tc_find_mck_divisor(), tc_init(), TC_UART, TC_UART_CHN, tc_write_rc(), and TIMER_UART_PRIO.
Referenced by buart_if_open().
int8_t buart_if_close |
( |
uint8_t |
chn | ) |
|
int8_t buart_if_open |
( |
uint8_t |
chn, |
|
|
uint32_t |
bauds |
|
) |
| |
This function opens an UART.
- Note
- Opening of the specified UART implies initializing local variables and opening required hardware with the following configuration:
- bauds as specified
- 8 bits, no parity, 1 stop bit
- enable interrupts
- Parameters
-
chn | Communication channel [0, 1] |
bauds | Communication speed in bauds |
- Return values
-
true | on success. |
false | on failure. |
References _configure_TC_uart(), pdc_enable_transfer(), pdc_rx_init(), pdc_tx_init(), pmc_enable_periph_clk(), ptr_rx_uart_buf0, ptr_tx_uart_buf0, buart_comm_data_t::puc_rq_buf, buart_comm_data_t::puc_tq_buf, sysclk_get_cpu_hz(), tc_start(), TC_UART, TC_UART_CHN, UART0_PRIO, UART1_PRIO, UART_BUFFER_SIZE, uart_disable_interrupt(), uart_enable_interrupt(), uart_enable_rx(), uart_enable_tx(), uart_get_pdc_base(), uart_init(), pdc_packet::ul_addr, sam_uart_opt::ul_baudrate, sam_uart_opt::ul_mck, sam_uart_opt::ul_mode, pdc_packet::ul_size, UNUSED, buart_comm_data_t::us_rq_count, buart_comm_data_t::us_rq_idx, and buart_comm_data_t::us_wq_idx.
Referenced by usi_init().
uint16_t buart_if_read |
( |
uint8_t |
chn, |
|
|
void * |
buffer, |
|
|
uint16_t |
len |
|
) |
| |
int buart_if_rx_char |
( |
uint8_t |
chn | ) |
|
Get byte from UART.
- Parameters
-
chn | Communication channel [0, 1] |
- Return values
-
Byte | received |
-1 | in case of no reception |
References buart_if_read().
uint16_t buart_if_tx_char |
( |
uint8_t |
chn, |
|
|
char |
data |
|
) |
| |
Sent byte to UART.
- Parameters
-
chn | Communication channel [0, 1] |
data | Data to sent |
- Return values
-
References buart_if_write().
uint16_t buart_if_write |
( |
uint8_t |
chn, |
|
|
const void * |
buffer, |
|
|
uint16_t |
len |
|
) |
| |
This function transmits a message.
- Note
- This function transmits characters via the specified UART. If so configured, the function waits until all characters are inserted in the transmission queue. In this case, the watchdog timer must be reloaded to avoid a program reset.
- Parameters
-
chn | Communication channel [0, 1] |
buffer | Pointer to information to transmit |
len | Number of characters to transmit |
- Return values
-
References pdc_read_tx_counter(), pdc_tx_init(), buart_comm_data_t::puc_tq_buf, TX_UART_BUF0_SIZE, TX_UART_BUF1_SIZE, pdc_packet::ul_addr, pdc_packet::ul_size, and UNUSED.
Referenced by _usi_encode_and_send(), and buart_if_tx_char().
void TC_UART_Handler |
( |
void |
| ) |
|
void UART0_Handler |
( |
void |
| ) |
|
Interruption handler for UART0.
References gs_ul_size_uart_buf0, pdc_rx_init(), buart_comm_data_t::puc_rq_buf, RX_UART_BUF0_SIZE, tc_start(), TC_UART, TC_UART_CHN, UART_BUFFER_SIZE, uart_get_status(), pdc_packet::ul_addr, pdc_packet::ul_size, buart_comm_data_t::us_rq_count, and buart_comm_data_t::us_wq_idx.
uint8_t buart_chn_open[2] |
|
static |
uint16_t num_bytes_rx_uart0 |
|
static |
uint8_t* const uartRxBuf0 |
uint8_t* const uartTxBuf0 |