Microchip® Advanced Software Framework

usart_sam_ba.h File Reference

USART functions for SAM-BA on SAM0.

Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.

Macros

#define ACK   0x06
 
#define CAN   0x18
 
#define CRC16POLY   0x1021
 
#define EOT   0x04
 
#define ESC   0x1b
 
#define NAK   0x15
 
#define PKTLEN_128   128
 
#define SHARP_CHARACTER   '#'
 
#define SOH   0x01
 
#define USART_BUFFER_SIZE   128
 
#define USART_DEFAULT_TIMEOUT   1000
 

Functions

unsigned short add_crc (char ptr, unsigned short crc)
 Gets data from usart line using Xmodem protocol. More...
 
uint8_t getPacket (uint8_t *pData, uint8_t sno)
 Used by Xdown to retrieve packets. More...
 
void usart_close (void)
 Stops the USART. More...
 
int usart_getc (void)
 Waits and gets a value on usart line. More...
 
uint32_t usart_getdata (void *data, uint32_t length)
 Gets data from usart line. More...
 
uint32_t usart_getdata_xmd (void *data, uint32_t length)
 Gets data from usart line using Xmodem protocol. More...
 
bool usart_is_rx_ready (void)
 This function checks if a character has been received on the usart line. More...
 
void usart_open (void)
 Open the given USART. More...
 
int usart_putc (int value)
 Puts a byte on usart line. More...
 
uint32_t usart_putdata (void const *data, uint32_t length)
 Send buffer on usart line. More...
 
uint32_t usart_putdata_xmd (void const *data, uint32_t length)
 Send buffer on usart line using Xmodem protocol. 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...
 

#define ACK   0x06
#define CAN   0x18
#define CRC16POLY   0x1021

Referenced by add_crc().

#define EOT   0x04
#define ESC   0x1b

Referenced by usart_getdata_xmd().

#define NAK   0x15

Referenced by usart_putdata_xmd().

#define PKTLEN_128   128
#define SHARP_CHARACTER   '#'

Referenced by usart_sharp_received().

#define SOH   0x01

Referenced by putPacket(), and usart_getdata_xmd().

#define USART_BUFFER_SIZE   128

Referenced by usart_readc().

#define USART_DEFAULT_TIMEOUT   1000

unsigned short add_crc ( char  ptr,
unsigned short  crc 
)

Gets data from usart line using Xmodem protocol.

Parameters
datapointer
numberof data to get
Returns
value read on usart line

Gets data from usart line using Xmodem protocol.

References CRC16POLY.

Referenced by getbytes(), and putPacket().

uint8_t getPacket ( uint8_t *  pData,
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().

void usart_close ( void  )
int usart_getc ( void  )

Waits and gets a value on usart line.

Returns
value read 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 
)

Gets data from usart line.

Parameters
datapointer
numberof data to get
Returns
value read on usart line

Gets data from usart line.

References usart_getc().

uint32_t usart_getdata_xmd ( void *  data,
uint32_t  length 
)

Gets data from usart line using Xmodem protocol.

Parameters
datapointer
numberof data to get
Returns
value read on usart line

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.

Returns
1 if a byte is ready to be read.

Referenced by usart_getc(), usart_getdata_xmd(), and usart_sharp_received().

int usart_putc ( int  value)

Puts a byte on usart line.

Parameters
valueValue to put
Returns
1 if function was successfully done, otherwise 0.

Puts a byte on usart line.

Parameters
valueValue to put
Returns
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 
)

Send buffer on usart line.

Parameters
datapointer
numberof data to send
Returns
number of data sent

Send buffer on usart line.

References i, length, and usart_putc().

uint32_t usart_putdata_xmd ( void const *  data,
uint32_t  length 
)

Send buffer on usart line using Xmodem protocol.

Parameters
datapointer
numberof data to send
Returns
number of data sent

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.

Returns
value read 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.

Returns
Returns true if the SAM-BA Uart received the sharp char

References SHARP_CHARACTER, usart_getc(), and usart_is_rx_ready().

Referenced by main().