USART functions for SAM-BA on SAM0.
Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include "usart_sam_ba.h"
#include "conf_board.h"
#include "conf_clocks.h"
#include "conf_bootloader.h"
Functions | |
unsigned short | add_crc (char ptr, unsigned short crc) |
Compute the CRC. More... | |
static uint16_t | getbytes (uint8_t *ptr_data, uint16_t length) |
uint8_t | getPacket (uint8_t *ptr_data, uint8_t sno) |
Used by Xdown to retrieve packets. More... | |
static int | putPacket (uint8_t *tmppkt, uint8_t sno) |
Used by Xup to send packets. More... | |
void | usart_close (void) |
Close the given USART. More... | |
int | usart_getc (void) |
Waits and gets a value on usart line. More... | |
uint32_t | usart_getdata (void *data, uint32_t length) |
Get data from com device. More... | |
uint32_t | usart_getdata_xmd (void *data, uint32_t length) |
Called when a transfer from host to target is being made (considered an download). More... | |
bool | usart_is_rx_ready (void) |
This function checks if a character has been received on the usart line. More... | |
void | usart_open () |
Open the given USART. More... | |
int | usart_putc (int value) |
Puts a byte on usart line The type int is used to support printf redirection from compiler LIB. More... | |
uint32_t | usart_putdata (void const *data, uint32_t length) |
Send given data (polling) More... | |
uint32_t | usart_putdata_xmd (void const *data, uint32_t length) |
Called when a transfer from target to host is being made(considered an upload). More... | |
int | usart_readc (void) |
Gets a value on usart line. More... | |
int | usart_sharp_received (void) |
Returns true if the SAM-BA Uart received the sharp char. More... | |
Variables | |
volatile uint8_t | b_sharp_received |
volatile uint8_t | buffer_rx_usart [USART_BUFFER_SIZE] |
volatile uint8_t | buffer_tx_usart [USART_BUFFER_SIZE] |
uint8_t | error_timeout |
volatile uint8_t | idx_rx_read |
volatile uint8_t | idx_rx_write |
volatile uint8_t | idx_tx_read |
volatile uint8_t | idx_tx_write |
uint8_t | mode_of_transfer |
uint16_t | size_of_data |
struct usart_module | usart_sam_ba |
unsigned short add_crc | ( | char | ptr, |
unsigned short | crc | ||
) |
Compute the CRC.
Gets data from usart line using Xmodem protocol.
References CRC16POLY.
Referenced by getbytes(), and putPacket().
|
static |
References add_crc(), error_timeout, length, mode_of_transfer, PKTLEN_128, size_of_data, and usart_getc().
Referenced by getPacket().
uint8_t getPacket | ( | uint8_t * | ptr_data, |
uint8_t | sno | ||
) |
Used by Xdown to retrieve packets.
References ACK, CAN, error_timeout, getbytes(), PKTLEN_128, usart_getc(), and usart_putc().
Referenced by usart_getdata_xmd().
|
static |
Used by Xup to send packets.
References add_crc(), data, i, mode_of_transfer, PKTLEN_128, size_of_data, SOH, usart_getc(), and usart_putc().
Referenced by usart_putdata_xmd().
void usart_close | ( | void | ) |
Close the given USART.
Stops the USART.
References usart_disable(), usart_disable_transceiver(), usart_sam_ba, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.
int usart_getc | ( | void | ) |
Waits and gets a value on usart line.
References usart_is_rx_ready(), usart_read_wait(), and usart_sam_ba.
Referenced by getbytes(), getPacket(), putPacket(), usart_getdata(), usart_getdata_xmd(), usart_putdata_xmd(), and usart_sharp_received().
uint32_t usart_getdata | ( | void * | data, |
uint32_t | length | ||
) |
uint32_t usart_getdata_xmd | ( | void * | data, |
uint32_t | length | ||
) |
Called when a transfer from host to target is being made (considered an download).
Gets data from usart line using Xmodem protocol.
References ACK, b_run, CAN, EOT, error_timeout, ESC, getPacket(), length, mode_of_transfer, PKTLEN_128, ptr_data, size_of_data, SOH, system_clock_source_get_hz(), usart_getc(), usart_is_rx_ready(), and usart_putc().
bool usart_is_rx_ready | ( | void | ) |
This function checks if a character has been received on the usart line.
1
if a byte is ready to be read. Referenced by usart_getc(), usart_getdata_xmd(), and usart_sharp_received().
void usart_open | ( | void | ) |
Open the given USART.
References b_sharp_received, usart_config::baudrate, error_timeout, usart_config::generator_source, idx_rx_read, idx_rx_write, idx_tx_read, idx_tx_write, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, STATUS_OK, usart_enable(), usart_enable_transceiver(), usart_get_config_defaults(), usart_init(), usart_sam_ba, USART_TRANSCEIVER_RX, and USART_TRANSCEIVER_TX.
Referenced by main().
int usart_putc | ( | int | value | ) |
Puts a byte on usart line The type int is used to support printf redirection from compiler LIB.
Puts a byte on usart line.
value | Value to put |
1
if function was successfully done, otherwise 0
. References usart_sam_ba, and usart_write_wait().
Referenced by getPacket(), putPacket(), usart_getdata_xmd(), usart_putdata(), and usart_putdata_xmd().
uint32_t usart_putdata | ( | void const * | data, |
uint32_t | length | ||
) |
uint32_t usart_putdata_xmd | ( | void const * | data, |
uint32_t | length | ||
) |
Called when a transfer from target to host is being made(considered an upload).
Send buffer on usart line using Xmodem protocol.
References ACK, CAN, EOT, error_timeout, length, mode_of_transfer, NAK, PKTLEN_128, ptr_data, putPacket(), size_of_data, usart_getc(), and usart_putc().
int usart_readc | ( | void | ) |
Gets a value on usart line.
References buffer_rx_usart, idx_rx_read, and USART_BUFFER_SIZE.
int usart_sharp_received | ( | void | ) |
Returns true if the SAM-BA Uart received the sharp char.
References SHARP_CHARACTER, usart_getc(), and usart_is_rx_ready().
Referenced by main().
volatile uint8_t b_sharp_received |
Referenced by usart_open().
volatile uint8_t buffer_rx_usart[USART_BUFFER_SIZE] |
Referenced by usart_readc().
volatile uint8_t buffer_tx_usart[USART_BUFFER_SIZE] |
uint8_t error_timeout |
Referenced by getbytes(), getPacket(), usart_getdata_xmd(), usart_open(), and usart_putdata_xmd().
volatile uint8_t idx_rx_read |
Referenced by usart_open(), and usart_readc().
volatile uint8_t idx_rx_write |
Referenced by usart_open().
volatile uint8_t idx_tx_read |
Referenced by usart_open().
volatile uint8_t idx_tx_write |
Referenced by usart_open().
uint8_t mode_of_transfer |
Referenced by getbytes(), putPacket(), usart_getdata_xmd(), and usart_putdata_xmd().
uint16_t size_of_data |
Referenced by getbytes(), putPacket(), usart_getdata_xmd(), and usart_putdata_xmd().
struct usart_module usart_sam_ba |
Referenced by usart_close(), usart_getc(), usart_open(), and usart_putc().