Microchip® Advanced Software Framework

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

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

Data Structures

struct  busart_comm_data_t
 Communications Queue Info. More...
 

Macros

#define FREQ_TIMER_POLL_USART   100
 
#define SERIAL_USART_0   0
 
#define SERIAL_USART_1   1
 
#define TIMER_USART_PRIO   10
 
#define USART0_PRIO   10
 
#define USART1_PRIO   10
 
#define USART_BUFFER_SIZE   1024
 

Functions

int8_t busart_if_close (uint8_t chn)
 This function closes and disables communication in the specified USART. More...
 
int8_t busart_if_open (uint8_t chn, uint32_t bauds)
 This function opens an USART. More...
 
uint16_t busart_if_read (uint8_t chn, void *buffer, uint16_t len)
 This function receives a message. More...
 
int busart_if_rx_char (uint8_t chn)
 Get byte from USART. More...
 
uint16_t busart_if_tx_char (uint8_t chn, char data)
 Sent byte to USART. More...
 
uint16_t busart_if_write (uint8_t chn, const void *buffer, uint16_t len)
 This function transmits a message. More...
 

Variables

static uint8_t busart_chn_open [2]
 

#define FREQ_TIMER_POLL_USART   100
#define SERIAL_USART_0   0
#define SERIAL_USART_1   1
#define TIMER_USART_PRIO   10
#define USART0_PRIO   10

Referenced by busart_if_open().

#define USART1_PRIO   10

Referenced by busart_if_open().

#define USART_BUFFER_SIZE   1024

Referenced by busart_if_open().

int8_t busart_if_close ( uint8_t  chn)

This function closes and disables communication in the specified USART.

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

References tc_stop(), usart_disable_interrupt(), usart_disable_rx(), and usart_disable_tx().

int8_t busart_if_open ( uint8_t  chn,
uint32_t  bauds 
)

This function opens an USART.

Note
Opening of the specified USART 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 sam_usart_opt_t::baudrate, sam_usart_opt_t::channel_mode, sam_usart_opt_t::char_length, NULL, sam_usart_opt_t::parity_type, pdc_enable_transfer(), pdc_rx_init(), pdc_tx_init(), pmc_enable_periph_clk(), busart_comm_data_t::puc_rq_buf, busart_comm_data_t::puc_tq_buf, sam_usart_opt_t::stop_bits, sysclk_get_peripheral_hz(), tc_start(), pdc_packet::ul_addr, pdc_packet::ul_size, UNUSED, busart_comm_data_t::us_rq_count, busart_comm_data_t::us_rq_idx, busart_comm_data_t::us_wq_idx, USART0_PRIO, USART1_PRIO, USART_BUFFER_SIZE, usart_disable_interrupt(), usart_enable_interrupt(), usart_enable_rx(), usart_enable_tx(), usart_get_pdc_base(), and usart_init_rs232().

Referenced by usi_init().

uint16_t busart_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 USART. 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 busart_comm_data_t::puc_rq_buf, UNUSED, busart_comm_data_t::us_rq_count, and busart_comm_data_t::us_rq_idx.

Referenced by busart_if_rx_char(), and usi_process().

int busart_if_rx_char ( uint8_t  chn)

Get byte from USART.

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

References busart_if_read().

uint16_t busart_if_tx_char ( uint8_t  chn,
char  data 
)

Sent byte to USART.

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

References busart_if_write().

uint16_t busart_if_write ( uint8_t  chn,
const void *  buffer,
uint16_t  len 
)

This function transmits a message.

Note
This function transmits characters via the specified USART. 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(), busart_comm_data_t::puc_tq_buf, pdc_packet::ul_addr, pdc_packet::ul_size, and UNUSED.

Referenced by _usi_encode_and_send(), and busart_if_tx_char().

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