Microchip® Advanced Software Framework

usart_hard_handshaking_example.c File Reference

USART hardware handshaking 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   125
 Size of the receive buffer used by the PDC, in bytes. More...
 
#define MAX_BPS   500
 Maximum Bytes Per Second (BPS) rate that will be forced using the CTS pin. 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 to generate an interrupt every second. More...
 
static void configure_usart (void)
 Configure board USART communication with PC or other terminal. More...
 
int main (void)
 usart_hard_handshaking_example application entry point. More...
 
void TC0_Handler (void)
 Interrupt handler for TC0. More...
 
void USART_Handler (void)
 Interrupt handler for USART. More...
 

Variables

Pdc * g_p_pdc
 Pointer to PDC register base. More...
 
uint8_t g_puc_string [BUFFER_SIZE]
 String g_uc_buffer. More...
 
pdc_packet_t g_st_nextpacket
 
pdc_packet_t g_st_packet
 PDC data packet. More...
 
uint8_t g_uc_buffer
 Receive buffer. More...
 
volatile uint32_t g_ul_bytes_received = 0
 Number of bytes received between two timer ticks. More...
 
static uint8_t gs_dump_buffer [BUFFER_SIZE]
 Dump buffer. More...
 
static uint8_t gs_puc_buffer [BUFFER_SIZE]
 Receive buffer. More...
 
static uint8_t gs_puc_nextbuffer [BUFFER_SIZE]
 

#define ALL_INTERRUPT_MASK   0xffffffff

All interrupt mask.

Referenced by configure_usart().

#define BUFFER_SIZE   125

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

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

#define MAX_BPS   500

Maximum Bytes Per Second (BPS) rate that will be forced using the CTS pin.

Referenced by USART_Handler().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"--USART Hardware Handshaking 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_hard_handshaking_example.c:122

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 to generate an interrupt every second.

Configure TC for a 1Hz frequency and trigger on RC compare.

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
void TC0_Handler ( void  )

Interrupt handler for TC0.

Display the number of bytes received during the last second and the total number of bytes received, and then restart a read transfer on the USART if it was stopped.

References BUFFER_SIZE, g_p_pdc, g_puc_string, g_ul_bytes_received, gs_dump_buffer, gs_puc_buffer, gs_puc_nextbuffer, pdc_read_rx_counter(), pdc_read_rx_next_counter(), pdc_rx_init(), tc_get_status(), pdc_packet::ul_addr, pdc_packet::ul_size, usart_enable_interrupt(), and usart_write_line().

void USART_Handler ( void  )

Interrupt handler for USART.

Increment the number of bytes received in the current second and start another transfer if the desired bps has not been met yet.

References BUFFER_SIZE, g_p_pdc, g_ul_bytes_received, gs_dump_buffer, gs_puc_buffer, gs_puc_nextbuffer, MAX_BPS, pdc_rx_init(), tc_start(), tc_stop(), pdc_packet::ul_addr, pdc_packet::ul_size, usart_disable_interrupt(), and usart_get_status().

Pdc* g_p_pdc

Pointer to PDC register base.

uint8_t g_puc_string[BUFFER_SIZE]

String g_uc_buffer.

Referenced by TC0_Handler().

pdc_packet_t g_st_nextpacket
pdc_packet_t g_st_packet

PDC data packet.

uint8_t g_uc_buffer

Receive buffer.

volatile uint32_t g_ul_bytes_received = 0

Number of bytes received between two timer ticks.

Referenced by TC0_Handler(), and USART_Handler().

uint8_t gs_dump_buffer[BUFFER_SIZE]
static

Dump buffer.

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

uint8_t gs_puc_buffer[BUFFER_SIZE]
static

Receive buffer.

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

uint8_t gs_puc_nextbuffer[BUFFER_SIZE]
static

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