Microchip® Advanced Software Framework

xmodem.c File Reference

Function for the XMODEM transfer protocol.

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

#include "xmodem.h"
#include "sysclk.h"

Macros

#define CRC16POLY   0x1021
 CRC 16 polynom. More...
 
#define PKTLEN_128   128u
 Packet length. More...
 
#define XMDM_ACK   0x06
 Acknowledge. More...
 
#define XMDM_CAN   0x18
 Cancel. More...
 
#define XMDM_EOT   0x04
 End of text. More...
 
#define XMDM_ESC   0x1b
 Escape. More...
 
#define XMDM_NAK   0x15
 negative acknowledge More...
 
#define XMDM_SOH   0x01
 The definitions are followed by the XMODEM protocol. More...
 

Functions

static uint16_t xmodem_get_bytes (usart_if usart, int8_t *p_data, uint32_t ul_length)
 Get bytes through XMODEM protocol. More...
 
static int32_t xmodem_get_packet (usart_if usart, int8_t *p_data, uint8_t uc_sno)
 Get a packet through XMODEM protocol. More...
 
uint32_t xmodem_receive_file (usart_if usart, int8_t *p_buffer)
 Receive the files through XMODEM protocol. More...
 
void xmodem_send_file (usart_if usart, int8_t *p_buffer, uint32_t ul_length)
 Send the files through XMODEM protocol. More...
 
static uint8_t xmodem_send_packet (usart_if usart, uint8_t *p_data, uint8_t uc_sno)
 Send a packet through XMODEM protocol. More...
 

#define CRC16POLY   0x1021

CRC 16 polynom.

Referenced by xmodem_get_bytes(), and xmodem_send_packet().

#define PKTLEN_128   128u
#define XMDM_ACK   0x06

Acknowledge.

Referenced by xmodem_receive_file(), and xmodem_send_file().

#define XMDM_CAN   0x18
#define XMDM_EOT   0x04

End of text.

Referenced by xmodem_receive_file(), and xmodem_send_file().

#define XMDM_ESC   0x1b

Escape.

Referenced by xmodem_receive_file().

#define XMDM_NAK   0x15

negative acknowledge

Referenced by xmodem_send_file().

#define XMDM_SOH   0x01

The definitions are followed by the XMODEM protocol.

Start of heading

Referenced by xmodem_receive_file(), and xmodem_send_packet().

static uint16_t xmodem_get_bytes ( usart_if  usart,
int8_t *  p_data,
uint32_t  ul_length 
)
static

Get bytes through XMODEM protocol.

Parameters
usartBase address of the USART instance.
p_dataPointer to the data buffer.
ul_lengthLength of data expected.
Returns
Calculated CRC value

References CRC16POLY, and usart_serial_getchar().

Referenced by xmodem_get_packet().

static int32_t xmodem_get_packet ( usart_if  usart,
int8_t *  p_data,
uint8_t  uc_sno 
)
static

Get a packet through XMODEM protocol.

Parameters
usartBase address of the USART instance.
p_dataPointer to the data buffer.
uc_snoSequnce number.
Returns
0 for sucess and other value for XMODEM error

References PKTLEN_128, usart_serial_getchar(), usart_serial_putchar(), XMDM_CAN, and xmodem_get_bytes().

Referenced by xmodem_receive_file().

static uint8_t xmodem_send_packet ( usart_if  usart,
uint8_t *  p_data,
uint8_t  uc_sno 
)
static

Send a packet through XMODEM protocol.

Parameters
usartBase address of the USART instance.
p_dataPointer to the data buffer.
uc_snoSequnce number.
Returns
0 for sucess and other value for XMODEM error

References CRC16POLY, PKTLEN_128, usart_serial_getchar(), usart_serial_putchar(), and XMDM_SOH.

Referenced by xmodem_send_file().