2013-01-08 21:05:02 +08:00
|
|
|
#ifndef __ZDEF_H__
|
|
|
|
#define __ZDEF_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2011-03-30 14:14:22 +08:00
|
|
|
#include "crc.h"
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZPAD '*' /* 052 padding character begins frames */
|
|
|
|
#define ZDLE 030 /* ctrl-X ZMODEM escape - `ala BISYNC DLE */
|
|
|
|
#define ZDLEE (ZDLE^0100) /* escaped ZDLE as transmitted */
|
|
|
|
#define ZBIN 'A' /* binary frame indicator (CRC-16) */
|
|
|
|
#define ZHEX 'B' /* hex frame indicator */
|
|
|
|
#define ZBIN32 'C' /* binary frame with 32 bit FCS */
|
|
|
|
#define ZBINR32 'D' /* RLE packed Binary frame with 32 bit FCS */
|
|
|
|
#define ZVBIN 'a' /* binary frame indicator (CRC-16) */
|
|
|
|
#define ZVHEX 'b' /* hex frame indicator */
|
|
|
|
#define ZVBIN32 'c' /* binary frame with 32 bit FCS */
|
|
|
|
#define ZVBINR32 'd' /* RLE packed Binary frame with 32 bit FCS */
|
|
|
|
#define ZRESC 0176 /* RLE flag/escape character */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Frame types */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZRQINIT 0 /* request receive init */
|
2011-03-30 14:14:22 +08:00
|
|
|
#define ZRINIT 1 /* receive init */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZSINIT 2 /* send init sequence (optional) */
|
|
|
|
#define ZACK 3 /* ACK to above */
|
|
|
|
#define ZFILE 4 /* file name from sender */
|
|
|
|
#define ZSKIP 5 /* ro sender: skip this file */
|
|
|
|
#define ZNAK 6 /* last packet was garbled */
|
|
|
|
#define ZABORT 7 /* abort batch transfers */
|
|
|
|
#define ZFIN 8 /* finish session */
|
|
|
|
#define ZRPOS 9 /* resume data trans at this position */
|
2011-03-30 14:14:22 +08:00
|
|
|
#define ZDATA 10 /* data packet(s) follow */
|
|
|
|
#define ZEOF 11 /* end of file */
|
|
|
|
#define ZFERR 12 /* fatal Read or Write error Detected */
|
|
|
|
#define ZCRC 13 /* request for file CRC and response */
|
|
|
|
#define ZCHALLENGE 14 /* receiver's Challenge */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZCOMPL 15 /* request is complete */
|
|
|
|
#define ZCAN 16 /* other end canned session with CAN*5 */
|
|
|
|
#define ZFREECNT 17 /* request for free bytes on filesystem */
|
|
|
|
#define ZCOMMAND 18 /* command from sending program */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
|
|
|
/* ZDLE sequfences */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
|
|
|
|
#define ZCRCG 'i' /* CRC next, frame continues nonstop */
|
|
|
|
#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
|
|
|
|
#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
|
|
|
|
#define ZRUB0 'l' /* translate to rubout 0177 */
|
|
|
|
#define ZRUB1 'm' /* translate to rubout 0377 */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
|
|
|
/* zdlread return values (internal) */
|
|
|
|
/* -1 is general error, -2 is timeout */
|
|
|
|
#define GOTOR 0400
|
2021-03-08 18:19:04 +08:00
|
|
|
#define GOTCRCE (ZCRCE|GOTOR) /* ZDLE-ZCRCE received */
|
|
|
|
#define GOTCRCG (ZCRCG|GOTOR) /* ZDLE-ZCRCG received */
|
|
|
|
#define GOTCRCQ (ZCRCQ|GOTOR) /* ZDLE-ZCRCQ received */
|
|
|
|
#define GOTCRCW (ZCRCW|GOTOR) /* ZDLE-ZCRCW received */
|
|
|
|
#define GOTCAN (GOTOR|030) /* CAN*5 seen */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
|
|
|
/* Byte positions within header array */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZF0 3 /* first flags byte */
|
|
|
|
#define ZF1 2
|
|
|
|
#define ZF2 1
|
|
|
|
#define ZF3 0
|
|
|
|
#define ZP0 0 /* low order 8 bits of position */
|
|
|
|
#define ZP1 1
|
|
|
|
#define ZP2 2
|
|
|
|
#define ZP3 3 /* high order 8 bits of file position */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
2011-03-31 13:39:43 +08:00
|
|
|
/* parameters for ZRINIT header */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZRPXWN 8 /* 9th byte in header contains window size/256 */
|
|
|
|
#define ZRPXQQ 9 /* 10th to 14th bytes contain quote mask */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* bit Masks for ZRINIT flags byte ZF0 */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define CANFDX 0x01 /* rx can send and receive true FDX */
|
|
|
|
#define CANOVIO 0x02 /* rx can receive data during disk I/O */
|
|
|
|
#define CANBRK 0x04 /* rx can send a break signal */
|
|
|
|
#define CANRLE 0x10 /* receiver can decode RLE */
|
|
|
|
#define CANLZW 0x20 /* receiver can uncompress */
|
|
|
|
#define CANFC32 0x28 /* receiver can use 32 bit Frame Check */
|
|
|
|
#define ESCCTL 0x64 /* receiver expects ctl chars to be escaped */
|
|
|
|
#define ESC8 0xc8 /* receiver expects 8th bit to be escaped */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
2011-03-31 13:39:43 +08:00
|
|
|
/* bit Masks for ZRINIT flags byte ZF1 */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define CANVHDR 01 /* variable headers OK */
|
|
|
|
#define ZRRQWN 8 /* receiver specified window size in ZRPXWN */
|
|
|
|
#define ZRRQQQ 16 /* additional control chars to quote in ZRPXQQ */
|
|
|
|
#define ZRQNVH (ZRRQWN|ZRRQQQ) /* variable len hdr reqd to access info */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
|
|
|
/* Parameters for ZSINIT frame */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZATTNLEN 32 /* max length of attention string */
|
|
|
|
#define ALTCOFF ZF1 /* offset to alternate canit string, 0 if not used */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
|
|
|
/* Parameters for ZFILE frame */
|
|
|
|
/* Conversion options one of these in ZF0 */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZCBIN 1 /* binary transfer - inhibit conversion */
|
|
|
|
#define ZCNL 2 /* convert NL to local end of line convention */
|
|
|
|
#define ZCRESUM 3 /* resume interrupted file transfer */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* management include options, one of these ored in ZF1 */
|
2011-03-30 14:14:22 +08:00
|
|
|
#define ZMSKNOLOC 0200 /* skip file if not present at rx */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* management options, one of these ored in ZF1 */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZMMASK 037 /* mask for the choices below */
|
|
|
|
#define ZMNEWL 1 /* transfer if source newer or longer */
|
|
|
|
#define ZMCRC 2 /* transfer if different file CRC or length */
|
|
|
|
#define ZMAPND 3 /* append contents to existing file (if any) */
|
|
|
|
#define ZMCLOB 4 /* replace existing file */
|
|
|
|
#define ZMNEW 5 /* transfer if source newer */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* number 5 is alive ... */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZMDIFF 6 /* transfer if dates or lengths different */
|
|
|
|
#define ZMPROT 7 /* protect destination file */
|
|
|
|
#define ZMCHNG 8 /* change filename if destination exists */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* transport options, one of these in ZF2 */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZTLZW 1 /* lempel-Ziv compression */
|
|
|
|
#define ZTRLE 3 /* run Length encoding */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* extended options for ZF3, bit encoded */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZXSPARS 64 /* encoding for sparse file operations */
|
2011-03-30 14:14:22 +08:00
|
|
|
#define ZCANVHDR 01 /* variable headers OK */
|
2011-03-31 13:39:43 +08:00
|
|
|
/* receiver window size override */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZRWOVR 4 /* byte position for receive window override/256 */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
2011-03-31 13:39:43 +08:00
|
|
|
/* parameters for ZCOMMAND frame ZF0 (otherwise 0) */
|
2021-03-08 18:19:04 +08:00
|
|
|
#define ZCACK1 1 /* acknowledge, then do command */
|
|
|
|
extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
|
2011-03-30 14:14:22 +08:00
|
|
|
|
2011-03-31 13:39:43 +08:00
|
|
|
/* globals used by ZMODEM functions */
|
|
|
|
extern rt_uint8_t Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
|
2021-03-08 18:19:04 +08:00
|
|
|
extern char header_type; /* type of header received */
|
2011-03-31 13:39:43 +08:00
|
|
|
extern rt_uint8_t rx_header[4]; /* received header */
|
|
|
|
extern rt_uint8_t tx_header[4]; /* transmitted header */
|
2021-03-08 18:19:04 +08:00
|
|
|
extern rt_uint8_t Txfcs32; /* TRUE means send binary frames with 32 bit FCS */
|
|
|
|
extern rt_uint16_t Rxcount; /* count of data bytes received */
|
2011-03-31 13:39:43 +08:00
|
|
|
extern rt_uint16_t Rxtimeout; /* tenths of seconds to wait for something */
|
2021-03-08 18:19:04 +08:00
|
|
|
extern rt_uint32_t Rxpos; /* received file position */
|
|
|
|
extern rt_uint32_t Txpos; /* transmitted file position */
|
|
|
|
extern rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */
|
2013-01-08 21:05:02 +08:00
|
|
|
|
2011-03-30 14:14:22 +08:00
|
|
|
/* ward Christensen / CP/M parameters - Don't change these! */
|
|
|
|
#define ENQ 005
|
|
|
|
#define CAN ('X'&037)
|
|
|
|
#define XOFF ('s'&037)
|
|
|
|
#define XON ('q'&037)
|
|
|
|
#define SOH 1
|
2013-01-08 21:05:02 +08:00
|
|
|
#define STX 2
|
|
|
|
#define ETX 3
|
|
|
|
#define SYN 026
|
|
|
|
#define ESC 033
|
2021-03-08 18:19:04 +08:00
|
|
|
#define WANTG 0107 /* send G not NAK to get nonstop batch xmsn */
|
2011-03-30 14:14:22 +08:00
|
|
|
#define EOT 4
|
|
|
|
#define ACK 6
|
|
|
|
#define NAK 025
|
|
|
|
#define CPMEOF 032
|
2021-03-08 18:19:04 +08:00
|
|
|
#define WANTCRC 0103 /* send C not NAK to get crc not checksum */
|
2011-03-30 14:14:22 +08:00
|
|
|
#define TIMEOUT (-2)
|
|
|
|
#define RCDO (-3)
|
|
|
|
#define GCOUNT (-4)
|
|
|
|
#define ERRORMAX 5
|
|
|
|
#define RETRYMAX 5
|
|
|
|
#define WCEOT (-10)
|
2021-03-08 18:19:04 +08:00
|
|
|
|
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BITRATE 115200
|
|
|
|
#define TX_BUFFER_SIZE 1024
|
2021-03-08 18:19:04 +08:00
|
|
|
#define RX_BUFFER_SIZE 1024 /* sender or receiver's max buffer size */
|
|
|
|
extern char ZF0_CMD; /* local ZMODEM file conversion request */
|
|
|
|
extern char ZF1_CMD; /* local ZMODEM file management request */
|
|
|
|
extern char ZF2_CMD; /* local ZMODEM file management request */
|
|
|
|
extern char ZF3_CMD; /* local ZMODEM file management request */
|
2013-01-08 21:05:02 +08:00
|
|
|
extern rt_uint32_t Baudrate ;
|
|
|
|
extern rt_uint32_t Left_bytes;
|
|
|
|
extern rt_uint32_t Left_sizes;
|
2021-03-08 18:19:04 +08:00
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
|
|
|
|
struct zmodemf
|
|
|
|
{
|
|
|
|
struct rt_semaphore zsem;
|
|
|
|
rt_device_t device;
|
|
|
|
};
|
|
|
|
extern struct zmodemf zmodem;
|
|
|
|
|
|
|
|
struct zfile
|
|
|
|
{
|
2021-03-08 18:19:04 +08:00
|
|
|
char *fname;
|
|
|
|
rt_int32_t fd;
|
|
|
|
rt_uint32_t ctime;
|
2011-03-30 14:14:22 +08:00
|
|
|
rt_uint32_t mode;
|
2021-03-08 18:19:04 +08:00
|
|
|
rt_uint32_t bytes_total;
|
|
|
|
rt_uint32_t bytes_sent;
|
|
|
|
rt_uint32_t bytes_received;
|
|
|
|
rt_uint32_t file_end;
|
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
};
|
|
|
|
extern struct finsh_shell* shell;
|
2021-03-08 18:19:04 +08:00
|
|
|
|
2013-01-08 21:05:02 +08:00
|
|
|
#define ZDEBUG 0
|
|
|
|
/* sz.c */
|
|
|
|
extern void zs_start(char *path);
|
|
|
|
/* rz.c */
|
|
|
|
extern void zr_start(char *path);
|
|
|
|
|
|
|
|
/* zcore.c */
|
|
|
|
extern void zinit_parameter(void);
|
|
|
|
extern rt_int16_t zget_header(rt_uint8_t *hdr);
|
|
|
|
extern void zsend_bin_header(rt_uint8_t type, rt_uint8_t *hdr);
|
|
|
|
extern void zsend_hex_header(rt_uint8_t type, rt_uint8_t *hdr);
|
|
|
|
extern rt_int16_t zget_data(rt_uint8_t *buf, rt_uint16_t len);
|
|
|
|
extern void zsend_bin_data(rt_uint8_t *buf, rt_int16_t len, rt_uint8_t frameend);
|
|
|
|
extern void zput_pos(rt_uint32_t pos);
|
|
|
|
extern void zget_pos(rt_uint32_t pos);
|
|
|
|
/* zdevice.c */
|
|
|
|
extern rt_uint32_t get_device_baud(void);
|
|
|
|
extern void zsend_byte(rt_uint16_t c);
|
|
|
|
extern void zsend_line(rt_uint16_t c);
|
|
|
|
extern rt_int16_t zread_line(rt_uint16_t timeout);
|
|
|
|
extern void zsend_break(char *cmd);
|
2011-03-30 14:14:22 +08:00
|
|
|
extern void zsend_can(void);
|
2021-03-08 18:19:04 +08:00
|
|
|
|
2011-03-30 14:14:22 +08:00
|
|
|
#endif /* __ZDEF_H__ */
|