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 |
Referenced by main().
#define TC_FREQ 10 |
Timer counter frequency in Hz.
Referenced by configure_tc().
|
static |
Configure UART for debug message output.
References uart_rs232_options::baudrate, and stdio_serial_init().
Referenced by main().
|
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 | ) |
Application entry point for usart_serial example.
References board_init(), configure_console(), configure_tc(), pdca_channel_enable(), pdca_channel_set_config(), pdca_enable(), PDCA_RX_CHANNEL, PDCA_TX_CHANNEL, STRING_HEADER, sysclk_init(), tc_start(), and usart_enable_interrupt().
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().
void USART_Handler | ( | void | ) |
Interrupt handler for USART.
Echo the bytes received and start the next receive.
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, MAX_BUF_NUM, pdca_channel_write_load(), pdca_channel_write_reload(), PDCA_RX_CHANNEL, PDCA_TX_CHANNEL, tc_start(), tc_stop(), and usart_get_status().
|
static |
Flag of one transfer end.
Referenced by TC00_Handler(), and USART_Handler().
|
static |
Receive buffer.
Referenced by TC00_Handler(), and USART_Handler().
|
static |
Next Receive buffer.
Referenced by TC00_Handler(), and USART_Handler().
|
static |
Buffer number in use.
Referenced by TC00_Handler(), and USART_Handler().
|
static |
Current bytes in buffer.
Referenced by TC00_Handler(), and USART_Handler().
|
static |
Current bytes in next buffer.
Referenced by TC00_Handler(), and USART_Handler().
pdca_channel_config_t pdca_rx_options |
PDCA channel options.
pdca_channel_config_t pdca_tx_options |