USART Synchronous 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 2000 |
size of the receive buffer used by the PDC, in bytes. More... | |
#define | FREQ_OPTIONS_NUM 4 |
#define | STATE_READ 0 |
USART is reading. More... | |
#define | STATE_WRITE 1 |
USART is writing. More... | |
#define | STRING_EOL "\r" |
#define | STRING_HEADER |
#define | SYNC_MASTER 1 |
USART synchronous master. More... | |
#define | SYNC_SLAVE 0 |
USART synchronous slave. More... | |
Functions | |
static void | configure_console (void) |
Configure UART for debug message output. More... | |
static void | configure_usart (uint32_t ul_ismaster, uint32_t ul_baudrate) |
Configure USART in synchronous mode. More... | |
static void | display_main_menu (void) |
Display main menu. More... | |
static void | dump_info (char *p_buf, uint32_t ul_size) |
Dump buffer to uart. More... | |
int | main (void) |
Application entry point. More... | |
void | USART_Handler (void) |
USART IRQ handler. More... | |
Variables | |
int8_t | g_c_recv_buff [BUFFER_SIZE] = { 0 } |
Buffer for receiving. More... | |
Pdc * | g_p_pdc |
Pointer to PDC register base. More... | |
pdc_packet_t | g_st_packet |
PDC data packet. More... | |
uint8_t | g_uc_freq_idx = 0 |
Present frequency index in list g_ul_freq[]. More... | |
uint8_t | g_uc_state = STATE_WRITE |
State of reading or writing. More... | |
uint8_t | g_uc_transfer_mode = SYNC_MASTER |
Mode for usart, 0 means usart as slave and 1 for master. More... | |
uint32_t | g_ul_freq [FREQ_OPTIONS_NUM] |
Clock freq. More... | |
volatile uint32_t | g_ul_recv_done = false |
Reception is done. More... | |
volatile uint32_t | g_ul_sent_done = false |
Sending is done. More... | |
char | tran_buff [BUFFER_SIZE] |
Transmit buffer. More... | |
#define ALL_INTERRUPT_MASK 0xffffffff |
All interrupt mask.
Referenced by configure_usart().
#define BUFFER_SIZE 2000 |
size of the receive buffer used by the PDC, in bytes.
Referenced by main().
#define FREQ_OPTIONS_NUM 4 |
#define STATE_READ 0 |
USART is reading.
Referenced by main(), and USART_Handler().
#define STATE_WRITE 1 |
USART is writing.
Referenced by main(), and USART_Handler().
#define STRING_EOL "\r" |
#define STRING_HEADER |
Referenced by main().
#define SYNC_MASTER 1 |
USART synchronous master.
Referenced by main().
#define SYNC_SLAVE 0 |
USART synchronous slave.
Referenced by main().
|
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 USART in synchronous mode.
ul_ismaster | 1 for master, 0 for slave. |
ul_baudrate | Baudrate for synchronous communication. |
References ALL_INTERRUPT_MASK, sam_usart_opt_t::baudrate, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_hz(), usart_disable_interrupt(), usart_enable_rx(), usart_enable_tx(), usart_init_sync_master(), and usart_init_sync_slave().
Referenced by main().
|
static |
Display main menu.
Referenced by main().
|
static |
Dump buffer to uart.
Referenced by main().
int main | ( | void | ) |
Application entry point.
Configure USART in synchronous master/slave mode to start a transmission between two boards.
References board_init(), BUFFER_SIZE, configure_console(), configure_usart(), display_main_menu(), dump_info(), g_c_recv_buff, g_p_pdc, g_uc_freq_idx, g_uc_state, g_uc_transfer_mode, g_ul_freq, g_ul_recv_done, g_ul_sent_done, NULL, pdc_enable_transfer(), pdc_rx_init(), pdc_tx_init(), STATE_READ, STATE_WRITE, STRING_HEADER, SYNC_MASTER, SYNC_SLAVE, sysclk_init(), tran_buff, pdc_packet::ul_addr, pdc_packet::ul_size, usart_enable_interrupt(), and usart_get_pdc_base().
void USART_Handler | ( | void | ) |
USART IRQ handler.
Interrupt handler for USART. After reception is done, set g_ul_recv_done to true, and if transmission is done, set g_ul_sent_done to true.
References g_uc_state, g_ul_recv_done, g_ul_sent_done, STATE_READ, STATE_WRITE, usart_disable_interrupt(), and usart_get_status().
int8_t g_c_recv_buff[BUFFER_SIZE] = { 0 } |
Buffer for receiving.
Referenced by main().
Pdc* g_p_pdc |
Pointer to PDC register base.
Referenced by main(), TC0_Handler(), usart_clear(), and USART_Handler().
pdc_packet_t g_st_packet |
PDC data packet.
uint8_t g_uc_freq_idx = 0 |
Present frequency index in list g_ul_freq[].
Referenced by main().
uint8_t g_uc_state = STATE_WRITE |
State of reading or writing.
Referenced by main(), refresh_display(), and USART_Handler().
uint8_t g_uc_transfer_mode = SYNC_MASTER |
Mode for usart, 0 means usart as slave and 1 for master.
Referenced by main().
uint32_t g_ul_freq[FREQ_OPTIONS_NUM] |
volatile uint32_t g_ul_recv_done = false |
Reception is done.
Referenced by main(), and USART_Handler().
volatile uint32_t g_ul_sent_done = false |
Sending is done.
Referenced by main(), and USART_Handler().
char tran_buff[BUFFER_SIZE] |
Transmit buffer.
Referenced by main().