Microchip® Advanced Software Framework

usart_synchronous_example_canopus.c File Reference

USART Synchronous example for SAM.

Copyright (c) 2015-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...
 
static uint8_t transmit_mode_sync (uint8_t *p_buff, uint32_t ulsize)
 transmit data in synchronous mode. More...
 
void USART0_Handler (void)
 USART IRQ handler. More...
 

Variables

uint8_t g_c_recv_buff [BUFFER_SIZE] = { 0 }
 Buffer for receiving. 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...
 
uint32_t g_ulcount = 0
 count number for received data. More...
 
uint8_t * p_revdata = &g_c_recv_buff[0]
 Pointer to receive buffer base. 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(), and USART0_Handler().

#define FREQ_OPTIONS_NUM   4
#define STATE_READ   0

USART is reading.

Referenced by main(), and USART0_Handler().

#define STATE_WRITE   1

USART is writing.

Referenced by main().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"--USART Synchronous Mode Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define STRING_EOL
Definition: usart_synchronous_example_canopus.c:123
#define BOARD_NAME
Name of the board.
Definition: same70_xplained.h:75

Referenced by main().

#define SYNC_MASTER   1

USART synchronous master.

Referenced by main().

#define SYNC_SLAVE   0

USART synchronous slave.

Referenced by main().

static void configure_console ( void  )
static
static void configure_usart ( uint32_t  ul_ismaster,
uint32_t  ul_baudrate 
)
static

Configure USART in synchronous mode.

Parameters
ul_ismaster1 for master, 0 for slave.
ul_baudrateBaudrate for synchronous communication.

References ALL_INTERRUPT_MASK, sam_usart_opt_t::baudrate, BOARD_ID_USART, BOARD_USART, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_hz(), usart_disable_interrupt(), usart_enable_rx(), usart_enable_tx(), usart_init_sync_master(), usart_init_sync_slave(), and USART_IRQn.

Referenced by main().

static void display_main_menu ( void  )
static

Display main menu.

Referenced by main().

static void dump_info ( char *  p_buf,
uint32_t  ul_size 
)
static

Dump buffer to uart.

Referenced by main().

static uint8_t transmit_mode_sync ( uint8_t *  p_buff,
uint32_t  ulsize 
)
static

transmit data in synchronous mode.

Parameters
*p_buffdata to be transmitted
ulsizesize of all data.

References Assert, BOARD_USART, g_ul_sent_done, usart_enable_interrupt(), usart_is_tx_empty(), and usart_write().

Referenced by main().

void USART0_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 BOARD_USART, BUFFER_SIZE, g_uc_state, g_ul_recv_done, g_ulcount, p_revdata, STATE_READ, usart_disable_interrupt(), usart_get_status(), and usart_read().

uint8_t g_c_recv_buff[BUFFER_SIZE] = { 0 }

Buffer for receiving.

Referenced by main().

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(), and USART0_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]
Initial value:
=
{ 1000000UL, 4000000UL, 10000000UL, 16000000UL }

Clock freq.

Referenced by main().

volatile uint32_t g_ul_recv_done = false

Reception is done.

Referenced by main(), and USART0_Handler().

volatile uint32_t g_ul_sent_done = false

Sending is done.

Referenced by main(), and transmit_mode_sync().

uint32_t g_ulcount = 0

count number for received data.

Referenced by main(), and USART0_Handler().

uint8_t* p_revdata = &g_c_recv_buff[0]

Pointer to receive buffer base.

Referenced by main(), and USART0_Handler().

char tran_buff[BUFFER_SIZE]
Initial value:
= "DESCRIPTION of this example: \r\n \
**************************************************************************\r\n\
* This application gives an example of how to use USART in synchronous mode.\r\n\
* Synchronous operations provide a high speed transfer capability. The\r\n\
* transfer under this mode needs a pair of master and slave, which is\r\n\
* determined by which one offers the clock source.\r\n\
* \r\n\
* The example initialized USART as master by default. To enable the \r\n\
* communication between each side of the connection. The user should change\r\n\
* the mode of another side to slave through user interface. If well configured,\r\n\
* transfer could be started by typing 'r' and 'w' from terminal application.\r\n\
* This example also leaves the interface to select the clock freq.\r\n\
* \r\n\
* The meaning of each input character could be found in items of the main menu.\r\n\
* \r\n\
**************************************************************************\r\n\
END of DESCRIPTION \r\n\
"

Transmit buffer.

Referenced by main().