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 |
Referenced by main().
#define TC_FREQ 1 |
Timer counter frequency in Hz.
Referenced by configure_tc().
|
static |
Configure UART for debug message output.
References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
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 |
Configure board USART communication with PC or other terminal.
References ALL_INTERRUPT_MASK, NULL, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_hz(), usart_disable_interrupt(), usart_enable_rx(), usart_enable_tx(), and usart_init_hw_handshaking().
Referenced by main().
int main | ( | void | ) |
usart_hard_handshaking_example application entry point.
References board_init(), BUFFER_SIZE, configure_console(), configure_tc(), configure_usart(), g_p_pdc, gs_dump_buffer, gs_puc_buffer, gs_puc_nextbuffer, pdc_enable_transfer(), pdc_rx_init(), STRING_HEADER, sysclk_init(), tc_start(), uart_read(), pdc_packet::ul_addr, pdc_packet::ul_size, usart_enable_interrupt(), usart_get_pdc_base(), and usart_write_line().
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().
|
static |
Dump buffer.
Referenced by main(), TC0_Handler(), and USART_Handler().
|
static |
Receive buffer.
Referenced by main(), TC0_Handler(), and USART_Handler().
|
static |
Referenced by main(), TC0_Handler(), and USART_Handler().