Microchip® Advanced Software Framework

usart_serial_example_pdc.c File Reference

USART Serial example for SAM.

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

#include <string.h>
#include "asf.h"
#include "stdio_serial.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 PDC, in bytes. More...
 
#define BYTE_TRANSFER   0
 USART FIFO transfer type definition. More...
 
#define MAX_BUF_NUM   1
 Max buffer number. More...
 
#define PDC_TRANSFER   1
 USART PDC transfer type definition. More...
 
#define STRING_EOL   "\r"
 
#define STRING_HEADER
 
#define TC_FREQ   1
 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...
 
static void configure_usart (void)
 Configure USART in normal (serial rs232) mode, asynchronous, 8 bits, 1 stop bit, no parity, 115200 bauds and enable its transmitter and receiver. More...
 
static void display_main_menu (void)
 Display main menu. More...
 
int main (void)
 Application entry point for usart_serial example. More...
 
void TC0_Handler (void)
 Interrupt handler for TC0. More...
 
static void usart_clear (void)
 Reset the TX & RX, and clear the PDC counter. More...
 
void USART_Handler (void)
 Interrupt handler for USART. More...
 

Variables

Pdc * g_p_pdc
 Pointer to PDC register base. More...
 
pdc_packet_t g_st_nextpacket
 
pdc_packet_t g_st_packet
 PDC data packet. More...
 
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 uint8_t gs_uc_trans_mode = PDC_TRANSFER
 Current transfer mode. More...
 
static uint32_t gs_ul_read_buffer = 0
 Byte mode read buffer. 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...
 

#define ALL_INTERRUPT_MASK   0xffffffff

All interrupt mask.

Referenced by configure_usart().

#define BUFFER_SIZE   100

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

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

#define BYTE_TRANSFER   0

USART FIFO transfer type definition.

Referenced by main().

#define MAX_BUF_NUM   1

Max buffer number.

Referenced by USART_Handler().

#define PDC_TRANSFER   1

USART PDC transfer type definition.

Referenced by main(), TC0_Handler(), 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 BOARD_NAME
Definition: inc/app_init.h:140
#define STRING_EOL
Definition: usart_serial_example_pdc.c:110

Referenced by main().

#define TC_FREQ   1

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 pmc_enable_periph_clk(), sysclk_get_cpu_hz(), tc_enable_interrupt(), tc_find_mck_divisor(), TC_FREQ, tc_init(), and tc_write_rc().

Referenced by main().

static void configure_usart ( void  )
static

Configure USART in normal (serial rs232) mode, asynchronous, 8 bits, 1 stop bit, no parity, 115200 bauds and enable its transmitter and receiver.

References ALL_INTERRUPT_MASK, SAM4L, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_hz(), usart_disable_interrupt(), usart_enable_rx(), usart_enable_tx(), and usart_init_rs232().

static void display_main_menu ( void  )
static

Display main menu.

Referenced by main().

void TC0_Handler ( void  )

Interrupt handler for TC0.

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

References BUFFER_SIZE, g_p_pdc, g_uc_transend_flag, gs_uc_trans_mode, gs_ul_size_buffer, gs_ul_size_nextbuffer, pdc_read_rx_counter(), pdc_read_rx_next_counter(), pdc_rx_clear_cnt(), PDC_TRANSFER, and tc_get_status().

static void usart_clear ( void  )
static

Reset the TX & RX, and clear the PDC counter.

References g_p_pdc, pdc_rx_init(), pdc_packet::ul_addr, pdc_packet::ul_size, usart_enable_rx(), usart_enable_tx(), usart_reset_rx(), and usart_reset_tx().

Referenced by main().

Pdc* g_p_pdc

Pointer to PDC register base.

pdc_packet_t g_st_nextpacket
pdc_packet_t g_st_packet

PDC data packet.

uint8_t g_uc_transend_flag = 0
static

Flag of one transfer end.

Referenced by TC0_Handler(), and USART_Handler().

uint8_t gs_puc_buffer[2][BUFFER_SIZE]
static

Receive buffer.

Referenced by main(), and USART_Handler().

uint8_t gs_puc_nextbuffer[2][BUFFER_SIZE]
static

Next Receive buffer.

Referenced by main(), and USART_Handler().

uint8_t gs_uc_buf_num = 0
static

Buffer number in use.

Referenced by main(), and USART_Handler().

uint8_t gs_uc_trans_mode = PDC_TRANSFER
static

Current transfer mode.

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

uint32_t gs_ul_read_buffer = 0
static

Byte mode read buffer.

Referenced by USART_Handler().

uint32_t gs_ul_size_buffer = BUFFER_SIZE
static

Current bytes in buffer.

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

uint32_t gs_ul_size_nextbuffer = BUFFER_SIZE
static

Current bytes in next buffer.

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