USART IrDA 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 10 |
Buffer size for PDC transfer. More... | |
#define | STATE_IDLE 3 |
#define | STATE_RECEIVE 1 |
#define | STATE_TRANSMIT 0 |
Communication state. More... | |
#define | STRING_EOL "\r" |
#define | STRING_HEADER |
Functions | |
static void | configure_console (void) |
Configure UART for debug message output. More... | |
static void | configure_usart (void) |
Configure board USART communication with PC or other terminal. More... | |
static void | dump_recv_buf (uint8_t *p_buf, uint8_t uc_size) |
Dump received buffer to uart. More... | |
static void | func_receiver (void) |
Disable transmitter and Enable receiver. More... | |
static void | func_transmitter (void) |
Disable receiver and Enable transmitter. More... | |
int | main (void) |
Application entry point. More... | |
void | USART_Handler (void) |
USART IRQ Handler, handling RXBUFF and TXBUFE status. More... | |
Variables | |
Pdc * | g_p_pdc |
Pointer to PDC register base. More... | |
pdc_packet_t | g_st_packet |
PDC data packet. More... | |
uint8_t | g_uc_recv_data [BUFFER_SIZE] = { 0x0 } |
Data buffer for receiving. More... | |
uint8_t | g_uc_send_data [BUFFER_SIZE] |
Data buffer for transmitting. More... | |
uint8_t | g_uc_state = STATE_IDLE |
State of BOARD_USART_BASE. More... | |
volatile uint32_t | g_ul_recv_done = false |
Receiving Done status. More... | |
volatile uint32_t | g_ul_sent_done = false |
Transmitting Done status. More... | |
#define ALL_INTERRUPT_MASK 0xffffffff |
All interrupt mask.
Referenced by configure_usart().
#define BUFFER_SIZE 10 |
Buffer size for PDC transfer.
Referenced by main().
#define STATE_IDLE 3 |
Referenced by main().
#define STATE_RECEIVE 1 |
Referenced by main(), and USART_Handler().
#define STATE_TRANSMIT 0 |
Communication state.
Referenced by main(), and USART_Handler().
#define STRING_EOL "\r" |
#define STRING_HEADER |
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 board USART communication with PC or other terminal.
References ALL_INTERRUPT_MASK, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_hz(), usart_disable_interrupt(), usart_enable_rx(), usart_enable_tx(), and usart_init_irda().
Referenced by main().
|
static |
Dump received buffer to uart.
p_buf | Pointer to received buffer. |
uc_size | The size of the buffer. |
Referenced by main().
|
static |
Disable transmitter and Enable receiver.
References pio_configure_pin(), pio_set_pin_low(), UNUSED, usart_disable_tx(), usart_enable_rx(), usart_is_rx_ready(), and usart_read().
Referenced by main().
|
static |
Disable receiver and Enable transmitter.
References pio_configure_pin(), usart_disable_rx(), and usart_enable_tx().
Referenced by main().
int main | ( | void | ) |
Application entry point.
Initialize the IrDA and start the main loop.
References board_init(), BUFFER_SIZE, configure_console(), configure_usart(), dump_recv_buf(), func_receiver(), func_transmitter(), g_p_pdc, g_uc_recv_data, g_uc_send_data, g_uc_state, g_ul_recv_done, g_ul_sent_done, NULL, pdc_enable_transfer(), pdc_rx_init(), pdc_tx_init(), STATE_IDLE, STATE_RECEIVE, STATE_TRANSMIT, STRING_HEADER, sysclk_init(), uart_read(), pdc_packet::ul_addr, pdc_packet::ul_size, usart_enable_interrupt(), and usart_get_pdc_base().
void USART_Handler | ( | void | ) |
USART IRQ Handler, handling RXBUFF and TXBUFE status.
References g_uc_state, g_ul_recv_done, g_ul_sent_done, STATE_RECEIVE, STATE_TRANSMIT, usart_disable_interrupt(), and usart_get_status().
Pdc* g_p_pdc |
Pointer to PDC register base.
pdc_packet_t g_st_packet |
PDC data packet.
uint8_t g_uc_recv_data[BUFFER_SIZE] = { 0x0 } |
Data buffer for receiving.
Referenced by main().
uint8_t g_uc_send_data[BUFFER_SIZE] |
Data buffer for transmitting.
Referenced by main().
uint8_t g_uc_state = STATE_IDLE |
State of BOARD_USART_BASE.
volatile uint32_t g_ul_recv_done = false |
Receiving Done status.
volatile uint32_t g_ul_sent_done = false |
Transmitting Done status.