mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-15 22:48:14 +08:00
76 lines
3.4 KiB
C
76 lines
3.4 KiB
C
/**
|
|
******************************************************************************
|
|
* @file ymodem.c
|
|
* @author William Xu
|
|
* @version V2.0.0
|
|
* @date 05-Oct-2014
|
|
* @brief This file provides all the software function headers related to the
|
|
* Ymodem protocol.
|
|
******************************************************************************
|
|
*
|
|
* The MIT License
|
|
* Copyright (c) 2014 MXCHIP Inc.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is furnished
|
|
* to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Define to prevent recursive inclusion -------------------------------------*/
|
|
#ifndef __YMODEM_H_
|
|
#define __YMODEM_H_
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "platform.h"
|
|
#include "common.h"
|
|
/* Exported types ------------------------------------------------------------*/
|
|
/* Exported constants --------------------------------------------------------*/
|
|
/* Exported macro ------------------------------------------------------------*/
|
|
#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 (1000)
|
|
#define MAX_ERRORS (20)
|
|
|
|
/* Exported functions ------------------------------------------------------- */
|
|
int32_t Ymodem_Receive (uint8_t *buf, mico_flash_t flash, uint32_t flashdestination, int32_t maxRecvSize);
|
|
uint8_t Ymodem_Transmit (mico_flash_t, uint32_t, const uint8_t* , uint32_t );
|
|
|
|
#endif /* __YMODEM_H_ */
|
|
|
|
|