Microchip® Advanced Software Framework

usart_serial_example_pdca.c File Reference

USART Serial example for SAM.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include <string.h>
#include <asf.h>
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_example.h"

Macros

#define ALL_INTERRUPT_MASK   0xffffffff
 All interrupt mask. More...
 
#define BUFFER_SIZE   100
 Size of the receive buffer used by the PDCA, in bytes. More...
 
#define MAX_BUF_NUM   1
 Max buffer number. More...
 
#define PDCA_RX_CHANNEL   0
 
#define PDCA_TX_CHANNEL   1
 
#define STRING_EOL   "\r"
 
#define STRING_HEADER
 
#define TC_FREQ   10
 Timer counter frequency in Hz. More...
 

Functions

static void configure_console (void)
 Configure UART for debug message output. More...
 
static void configure_tc (void)
 Configure Timer Counter 0 (TC0) to generate an interrupt every 200ms. More...
 
int main (void)
 Application entry point for usart_serial example. More...
 
void TC00_Handler (void)
 Interrupt handler for TC00. More...
 
void USART_Handler (void)
 Interrupt handler for USART. More...
 

Variables

static uint8_t g_uc_transend_flag = 0
 Flag of one transfer end. More...
 
static uint8_t gs_puc_buffer [2][BUFFER_SIZE]
 Receive buffer. More...
 
static uint8_t gs_puc_nextbuffer [2][BUFFER_SIZE]
 Next Receive buffer. More...
 
static uint8_t gs_uc_buf_num = 0
 Buffer number in use. More...
 
static uint32_t gs_ul_size_buffer = BUFFER_SIZE
 Current bytes in buffer. More...
 
static uint32_t gs_ul_size_nextbuffer = BUFFER_SIZE
 Current bytes in next buffer. More...
 
pdca_channel_config_t pdca_rx_options
 PDCA channel options. More...
 
pdca_channel_config_t pdca_tx_options
 

#define ALL_INTERRUPT_MASK   0xffffffff

All interrupt mask.

#define BUFFER_SIZE   100

Size of the receive buffer used by the PDCA, in bytes.

Referenced by TC00_Handler(), and USART_Handler().

#define MAX_BUF_NUM   1

Max buffer number.

Referenced by USART_Handler().

#define PDCA_RX_CHANNEL   0

Referenced by main(), TC00_Handler(), and USART_Handler().

#define PDCA_TX_CHANNEL   1

Referenced by main(), and USART_Handler().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"-- USART Serial Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define STRING_EOL
Definition: usart_serial_example_pdca.c:103
#define BOARD_NAME
Name string macro.
Definition: sam4l8_xplained_pro.h:86

Referenced by main().

#define TC_FREQ   10

Timer counter frequency in Hz.

Referenced by configure_tc().

static void configure_console ( void  )
static
static void configure_tc ( void  )
static

Configure Timer Counter 0 (TC0) to generate an interrupt every 200ms.

This interrupt will be used to flush USART input and echo back.

References sysclk_enable_peripheral_clock(), sysclk_get_peripheral_bus_hz(), tc_enable_interrupt(), tc_find_mck_divisor(), TC_FREQ, tc_init(), and tc_write_rc().

Referenced by main().

int main ( void  )
void TC00_Handler ( void  )

Interrupt handler for TC00.

Record the number of bytes received, and then restart a read transfer on the USART if the transfer was stopped.

References BUFFER_SIZE, g_uc_transend_flag, gs_puc_buffer, gs_puc_nextbuffer, gs_uc_buf_num, gs_ul_size_buffer, gs_ul_size_nextbuffer, pdca_channel_read_load_size(), pdca_channel_read_reload_size(), pdca_channel_write_load(), pdca_channel_write_reload(), PDCA_RX_CHANNEL, and tc_get_status().

uint8_t g_uc_transend_flag = 0
static

Flag of one transfer end.

Referenced by TC00_Handler(), and USART_Handler().

uint8_t gs_puc_buffer[2][BUFFER_SIZE]
static

Receive buffer.

Referenced by TC00_Handler(), and USART_Handler().

uint8_t gs_puc_nextbuffer[2][BUFFER_SIZE]
static

Next Receive buffer.

Referenced by TC00_Handler(), and USART_Handler().

uint8_t gs_uc_buf_num = 0
static

Buffer number in use.

Referenced by TC00_Handler(), and USART_Handler().

uint32_t gs_ul_size_buffer = BUFFER_SIZE
static

Current bytes in buffer.

Referenced by TC00_Handler(), and USART_Handler().

uint32_t gs_ul_size_nextbuffer = BUFFER_SIZE
static

Current bytes in next buffer.

Referenced by TC00_Handler(), and USART_Handler().

pdca_channel_config_t pdca_rx_options
Initial value:
= {
.addr = (void *)gs_puc_buffer,
.size = BUFFER_SIZE,
.r_addr = (void *)gs_puc_nextbuffer,
.r_size = BUFFER_SIZE,
.transfer_size = PDCA_MR_SIZE_BYTE,
.etrig = false,
.ring = false
}
#define BUFFER_SIZE
Size of the receive buffer used by the PDCA, in bytes.
Definition: usart_serial_example_pdca.c:92
static uint8_t gs_puc_buffer[2][BUFFER_SIZE]
Receive buffer.
Definition: usart_serial_example_pdca.c:112
#define PDCA_PID_USART_RX
Definition: conf_example.h:53
static uint8_t gs_puc_nextbuffer[2][BUFFER_SIZE]
Next Receive buffer.
Definition: usart_serial_example_pdca.c:115

PDCA channel options.

pdca_channel_config_t pdca_tx_options
Initial value:
= {
.addr = (void *)gs_puc_buffer,
.size = 0,
.r_addr = (void *)gs_puc_nextbuffer,
.r_size = 0,
.transfer_size = PDCA_MR_SIZE_BYTE,
.etrig = false,
.ring = false
}
static uint8_t gs_puc_buffer[2][BUFFER_SIZE]
Receive buffer.
Definition: usart_serial_example_pdca.c:112
static uint8_t gs_puc_nextbuffer[2][BUFFER_SIZE]
Next Receive buffer.
Definition: usart_serial_example_pdca.c:115
#define PDCA_PID_USART_TX
Definition: conf_example.h:55