Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PLC Buffered PDC UART

This module provides configuration and utils for PLC Buffered UART service interface.

Data Structures

struct  buart_comm_data_t
 Communications Queue Info. More...
 

Macros

#define FREQ_TIMER_POLL_UART   100
 
#define SERIAL_UART_0   0
 
#define SERIAL_UART_1   1
 
#define TIMER_UART_PRIO   10
 
#define UART0_PRIO   10
 
#define UART1_PRIO   10
 
#define UART_BUFFER_SIZE   1024
 

Functions

int8_t buart_if_close (uint8_t chn)
 This function closes and disables communication in the specified UART. More...
 
int8_t buart_if_open (uint8_t chn, uint32_t bauds)
 This function opens an UART. More...
 
uint16_t buart_if_read (uint8_t chn, void *buffer, uint16_t len)
 This function receives a message. More...
 
int buart_if_rx_char (uint8_t chn)
 Get byte from UART. More...
 
uint16_t buart_if_tx_char (uint8_t chn, char data)
 Sent byte to UART. More...
 
uint16_t buart_if_write (uint8_t chn, const void *buffer, uint16_t len)
 This function transmits a message. More...
 

Variables

static uint8_t buart_chn_open [2]
 

#define FREQ_TIMER_POLL_UART   100
#define SERIAL_UART_0   0
#define SERIAL_UART_1   1
#define TIMER_UART_PRIO   10
#define UART0_PRIO   10

Referenced by buart_if_open().

#define UART1_PRIO   10

Referenced by buart_if_open().

#define UART_BUFFER_SIZE   1024

Referenced by buart_if_open().

int8_t buart_if_close ( uint8_t  chn)

This function closes and disables communication in the specified UART.

Parameters
chnCommunication channel [0, 1]
Return values
trueon success.
falseon failure.

References tc_stop(), uart_disable(), and uart_disable_interrupt().

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
chnCommunication channel [0, 1]
baudsCommunication speed in bauds
Return values
trueon success.
falseon failure.

References NULL, pdc_enable_transfer(), pdc_rx_init(), pdc_tx_init(), pmc_enable_periph_clk(), buart_comm_data_t::puc_rq_buf, buart_comm_data_t::puc_tq_buf, sysclk_get_cpu_hz(), tc_start(), 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 
)

This function receives a message.

Note
This function receives a given number of characters from the specified UART. If so configured, the function waits until all characters are received. In this case, the watchdog timer must be reloaded to avoid a program reset.
Parameters
chnCommunication channel [0, 1]
bufferPointer to buffer for information
lenNumber of characters to receive
Return values
Numberof received characters

References buart_comm_data_t::puc_rq_buf, UNUSED, buart_comm_data_t::us_rq_count, and buart_comm_data_t::us_rq_idx.

Referenced by buart_if_rx_char(), and usi_process().

int buart_if_rx_char ( uint8_t  chn)

Get byte from UART.

Parameters
chnCommunication channel [0, 1]
Return values
Bytereceived
-1in case of no reception

References buart_if_read().

uint16_t buart_if_tx_char ( uint8_t  chn,
char  data 
)

Sent byte to UART.

Parameters
chnCommunication channel [0, 1]
dataData to sent
Return values
Numberof characters sent

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
chnCommunication channel [0, 1]
bufferPointer to information to transmit
lenNumber of characters to transmit
Return values
Numberof characters sent

References NULL, pdc_read_tx_counter(), pdc_tx_init(), buart_comm_data_t::puc_tq_buf, pdc_packet::ul_addr, pdc_packet::ul_size, and UNUSED.

Referenced by _usi_encode_and_send(), and buart_if_tx_char().

uint8_t buart_chn_open[2]
static
Initial value:
= {
false,
false
}