www.pudn.com > xModem_vxWorks.rar > Drv_Xmodem.h


#ifndef __XMODEM_H__ 
#define __XMODEM_H__ 
 
#ifdef  __XMODEM_C__ 
 
_U32  Load_xModemDownLoad ( _U32 startaddr,_U32 *pdwLength); 
_U32  Load_xModemStartOfHeader  ( void ) ; 
_U32  Load_xModemSequenceNo     ( void ) ; 
_U32  Load_xModemCompOfSeqNo    ( void ) ; 
_U32  Load_xModemData           ( void ) ; 
_U32  Load_xModemCRC            ( void ) ; 
_U32  Load_xModemEnd            ( void ) ; 
void Load_xModemPurge          ( void ) ; 
 
#if 0 
_U16 CalCRC ( _U8 * , _U32 ) ; 
void make_crc ( _U8 *buffer, _U32 count, _U16 *crc ) ; 
void Purge ( void ) ; 
void init_crc_tab ( void ) ; 
#endif 
 
#define  BIG_ENDIAN 1 
 
/*========================================================================*/ 
/*                      const for Xmodem protocol.                        */ 
/*========================================================================*/ 
#define MAXREPEATTIME_FOR_FIRST_FRAME 500 
#define MAXREPEATTIME  10      /* when appear error, retry times          */ 
 
#define WAITFORSOH     50      /* the time waitting for SOH               */ 
#define WAITFORDATA    100      /* the time waiting for data in the packet */ 
 
#define MAXDATANO     128      /* the maximize no. of data in the packet  */ 
#define MAXCRCNO        2      /* the maximize no. of CRC in the packet   */ 
#define MAXSEQNO      255 
 
enum DownLoadState           /* enum the state of FSM for Xmodem protocol */ 
{ 
    START_OF_HEADER , 
    SEQUENCE_NO , 
    COMP_OF_SEQ_NO , 
    DATA , 
    C_R_C , 
    END 
} ; 
 
enum CNTLCHAR                /* enum the control character used in Xmodem */ 
{ 
    SOH   = 0x01 , 
    EOT   = 0x04 , 
    ACK   = 0x06 , 
    DLE   = 0x10 , 
    X_ON  = 0x11 , 
    X_OFF = 0x13 , 
    NAK   = 0x15 , 
    SYN   = 0x16 , 
    CAN   = 0x18 , 
    OUTCC     = 0x43 
} ; 
 
/* calculate the compensate for packet sequence no. */ 
#define CompensateTo255(ucSeqNo)  (_U8)(255 - ucSeqNo) 
 
struct XMODEMPacket                    /* struct for Xmodem packet        */ 
{ 
    _U8 ucSOH ;              /* Start of Header                 */ 
    _U8 ucSeqNo ;            /* Sequence No.                    */ 
    _U8 ucCmpOfSeqNo ;       /* Compensate of Sequence No.      */ 
    _U8 ucData[ MAXDATANO ] ;/* Data                            */ 
    _U8 ucCRC[ MAXCRCNO ] ;  /* CRC                             */ 
} ; 
 
struct XMODEMPacket XModemPacket ;        /* Xmodem packet                */ 
 
_U32 (*( DownLoadFSM[ 6 ] ))( void ) =      /* FSM of Xmodem protocol      */ 
{ 
    Load_xModemStartOfHeader , 
    Load_xModemSequenceNo , 
    Load_xModemCompOfSeqNo , 
    Load_xModemData , 
    Load_xModemCRC , 
    Load_xModemEnd 
} ; 
 
int iDownLoadState ;                       /* the State of FSM            */ 
int iRepeatTime ;                          /* retry times                 */ 
int iCurrentData ;                         /* have received data no.      */ 
int iCurrentCRC ;                          /* have received CRC no.       */ 
_U8 ucLastSeqNo ;                /* the last sequence no.       */ 
extern volatile _U32 g_DecTimer ;         /* the Timer                   */ 
_U8 gucSOHReceived ; 
 
_U8 * szDram ;                            /* the start address of dram   */ 
_U32 ulLength ;                   /* the length of download file */ 
_U8 * szFlash ;                           /* the start address of flash  */ 
/* 
 * CRC-CCITT 16 is based on the polynomial x^16+x^12+x^5+1, 
 * and the reference value is 0x1021 
 */ 
// #define CRC16_POLY      0x1021 
 /* Function init_crc_tab() will initialize it */ 
// _U16  crc_tab[256]; 
 
#endif 
#endif