/** ****************************************************************************** * * @file ymodem.c * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. * @brief YModem functions header * @see The GNU Public License (GPL) Version 3 * *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef YMODEM_H #define YMODEM_H /* Global Defines */ #define PACKET_SEQNO_INDEX (1) #define PACKET_SEQNO_COMP_INDEX (2) #define PACKET_HEADER (3) #define PACKET_TRAILER (2) #define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) #define PACKET_SIZE (128) #define PACKET_1K_SIZE (1024) #define FILE_NAME_LENGTH (256) #define FILE_SIZE_LENGTH (16) #define SOH (0x01) /* start of 128-byte data packet */ #define STX (0x02) /* start of 1024-byte data packet */ #define EOT (0x04) /* end of transmission */ #define ACK (0x06) /* acknowledge */ #define NAK (0x15) /* negative acknowledge */ #define CA (0x18) /* two of these in succession aborts transfer */ #define CRC16 (0x43) /* 'C' == 0x43, request 16-bit CRC */ #define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ #define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ #define NAK_TIMEOUT (0x100000) #define MAX_ERRORS (5) /* Global Macros */ #define IS_AF(c) ((c >= 'A') && (c <= 'F')) #define IS_af(c) ((c >= 'a') && (c <= 'f')) #define IS_09(c) ((c >= '0') && (c <= '9')) #define ISVALIDHEX(c) IS_AF(c) || IS_af(c) || IS_09(c) #define ISVALIDDEC(c) IS_09(c) #define CONVERTDEC(c) (c - '0') #define CONVERTHEX_alpha(c) (IS_AF(c) ? (c - 'A'+10) : (c - 'a'+10)) #define CONVERTHEX(c) (IS_09(c) ? (c - '0') : CONVERTHEX_alpha(c)) /* Public Functions */ extern int32_t Ymodem_Receive(uint8_t *buf); #endif /* YMODEM_H */