Microchip® Advanced Software Framework

buffered_uart.c File Reference

SAM UART API Implementations.

Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include <stdio.h>
#include <string.h>
#include "buffered_uart.h"
#include "conf_uart_serial.h"

Functions

uint8_t buffered_uart_getchar (void)
 This function performs a blocking character receive functionality. More...
 
int buffered_uart_getchar_nowait (void)
 This function performs a non-blocking character receive functionality. More...
 
void buffered_uart_init (uint32_t baudrate)
 Initializes the Buffered Serial IO Module. More...
 
void buffered_uart_putchar (uint8_t ch)
 This function prints the character to the host. More...
 
uint8_t buffered_uart_rx (uint8_t *data, uint8_t max_len)
 Receives data from UART. More...
 
void buffered_uart_term (void)
 Terminate the Buffered Serial IO Module. More...
 
uint8_t buffered_uart_tx (uint8_t *data, uint32_t length)
 Transmits data via UART. More...
 
 USART_HOST_ISR_VECT ()
 

Variables

static uint8_t serial_rx_buf [SERIAL_RX_BUF_SIZE_HOST]
 
static uint8_t serial_rx_buf_head
 
static uint8_t serial_rx_buf_tail
 
static usart_serial_options_t usart_serial_options
 

uint8_t buffered_uart_getchar ( void  )

This function performs a blocking character receive functionality.

Returns
returns the data which is received

References buffered_uart_getchar_nowait().

int buffered_uart_getchar_nowait ( void  )

This function performs a non-blocking character receive functionality.

Returns
'-1' if no data is received or returns the data if a character is received

References cpu_irq_disable, cpu_irq_enable, serial_rx_buf, serial_rx_buf_head, SERIAL_RX_BUF_SIZE_HOST, and serial_rx_buf_tail.

Referenced by buffered_uart_getchar().

void buffered_uart_init ( uint32_t  baudrate)

Initializes the Buffered Serial IO Module.

Returns
STATUS_OK for successful initialization and FAILURE in case the IO is not initialized

References uart_rs232_options::baudrate, CONSOLE_UART_ID, serial_rx_buf_head, serial_rx_buf_tail, stdio_serial_init(), sysclk_enable_peripheral_clock(), USART_HOST, and USART_HOST_RX_ISR_ENABLE.

Referenced by main(), and serial_bridge_process_reconfigure().

uint8_t buffered_uart_rx ( uint8_t *  data,
uint8_t  max_length 
)

Receives data from UART.

Parameters
datapointer to the buffer where the received data is to be stored
max_lengthmaximum length of data to be received
Returns
actual number of bytes received

References cpu_irq_disable, cpu_irq_enable, serial_rx_buf, serial_rx_buf_head, SERIAL_RX_BUF_SIZE_HOST, and serial_rx_buf_tail.

Referenced by enter_wifi_firmware_download(), and serial_bridge_frame_receive().

void buffered_uart_term ( void  )

Terminate the Buffered Serial IO Module.

Returns
STATUS_OK for successful initialization and FAILURE in case the IO is not initialized

References USART_HOST_RX_ISR_DISABLE.

Referenced by serial_bridge_process_reconfigure().

uint8_t buffered_uart_tx ( uint8_t *  data,
uint32_t  length 
)

Transmits data via UART.

Parameters
dataPointer to the buffer where the data to be transmitted is present
lengthNumber of bytes to be transmitted
Returns
Number of bytes actually transmitted

References STATUS_OK, USART_HOST, and usart_serial_write_packet().

Referenced by serial_bridge_process_read_block().

uint8_t serial_rx_buf_head
static
uint8_t serial_rx_buf_tail
static
usart_serial_options_t usart_serial_options
static
Initial value:
= {
.baudrate = USART_HOST_BAUDRATE,
.charlength = USART_HOST_CHAR_LENGTH,
.paritytype = USART_HOST_PARITY,
}
#define USART_HOST_CHAR_LENGTH
Character length setting.
Definition: conf_uart_serial.h:42
#define USART_HOST_STOP_BITS
Stop bits setting.
Definition: conf_uart_serial.h:46
#define USART_HOST_PARITY
Parity setting.
Definition: conf_uart_serial.h:44
#define USART_HOST_BAUDRATE
Baudrate setting.
Definition: conf_uart_serial.h:40