Atmel Software Framework

usart_synchronous_example.c File Reference

USART Synchronous example for SAM.

Copyright (c) 2011-2016 Atmel Corporation. All rights reserved.

#include <string.h>
#include "asf.h"
#include "stdio_serial.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_example.h"
#include "flexcom.h"


#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 SYNC_MASTER   1
 USART synchronous master. More...
#define SYNC_SLAVE   0
 USART synchronous slave. More...


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...


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"
"--USART Synchronous Mode Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define STRING_EOL
Definition: usart_synchronous_example.c:136
#define BOARD_NAME
Name of the board.
Definition: sam3u_ek.h:89

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 void configure_usart ( uint32_t  ul_ismaster,
uint32_t  ul_baudrate 

Configure USART in synchronous mode.

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  )

Display main menu.

Referenced by main().

static void dump_info ( char *  p_buf,
uint32_t  ul_size 

Dump buffer to uart.

Referenced by main().

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 BOARD_USART, 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().

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(), 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]
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 USART_Handler().

volatile uint32_t g_ul_sent_done = false

Sending is done.

Referenced by main(), and USART_Handler().

char tran_buff[BUFFER_SIZE]
Initial value:
= "DESCRIPTION of this example: \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\

Transmit buffer.

Referenced by main().