/******************************************************************************
 * @file     ymodem.h
 * @brief    Y-Modem protocol header file.
 * @version  V4.0.3
 * @date     30-July-2026
 *
 * @note
 * Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd.. All rights reserved.
 *
 * @attention
 * THIS SOFTWARE JUST PROVIDES CUSTOMERS WITH CODING INFORMATION REGARDING
 * THEIR PRODUCTS, WHICH AIMS AT SAVING TIME FOR THEM. SPINTROL SHALL NOT BE
 * LIABLE FOR THE USE OF THE SOFTWARE. SPINTROL DOES NOT GUARANTEE THE
 * CORRECTNESS OF THIS SOFTWARE AND RESERVES THE RIGHT TO MODIFY THE SOFTWARE
 * WITHOUT NOTIFICATION.
 *
 ******************************************************************************/

#ifndef YMODEM_H
#define YMODEM_H

#ifdef __cplusplus
extern "C" {
#endif


#if defined(SPC1158)
#include "spc1158.h"
#elif defined(SPD1148)
#include "spd1148.h"
#elif defined(SPD1178)
#include "spd1178.h"
#elif defined(SPD1188)
#include "spd1188.h"
#elif defined(SPD1163)
#include "spd1163.h"
#else
#include "spc1168.h"
#endif




#define PACKET_SEQNUM_INDEX       (1)       /*      */
#define PACKET_SEQNUM_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 MODEM_SOH                 (0x01)    /* Start of 128-byte data packet   */
#define MODEM_STX                 (0x02)    /* Start of 1024-byte data packet  */
#define MODEM_EOT                 (0x04)    /* End of transmission             */
#define MODEM_ACK                 (0x06)    /* Acknowledge                     */
#define MODEM_NAK                 (0x15)    /* Negative acknowledge            */
#define MODEM_CAN                 (0x18)    /* Two of these in succession aborts transfer */
#define MODEM_C                   (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)





/**
 *  @brief  Y-Modem Public Function Declaration
 */
int32_t YModem_Receive(void);
int32_t YModem_Transmit(uint8_t *pu8PacketData, const uint8_t *pu8FileName, uint32_t u32FileSize);


#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* YMODEM_H */


/******************* Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd. ***** END OF FILE ****/
