fix memory leak problem

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1358 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
itspy.wei 2011-03-31 05:39:43 +00:00
parent a019ea904f
commit ac97bc17bd
6 changed files with 115 additions and 70 deletions

View File

@ -53,6 +53,7 @@ void zr_start(char *path)
rt_kprintf("size: %ld bytes\r\n",zf->bytes_received); rt_kprintf("size: %ld bytes\r\n",zf->bytes_received);
rt_kprintf("receive completed.\r\n"); rt_kprintf("receive completed.\r\n");
close(zf->fd); close(zf->fd);
rt_free(zf->fname);
rt_free(zf); rt_free(zf);
} }
else else
@ -60,8 +61,12 @@ void zr_start(char *path)
rt_kprintf("\b\b\bfile: %s \r\n",zf->fname+1); rt_kprintf("\b\b\bfile: %s \r\n",zf->fname+1);
rt_kprintf("size: 0 bytes\r\n"); rt_kprintf("size: 0 bytes\r\n");
rt_kprintf("receive failed.\r\n"); rt_kprintf("receive failed.\r\n");
if (zf->fd >= 0)
{
close(zf->fd); close(zf->fd);
unlink(zf->fname); /* remove this file */ unlink(zf->fname); /* remove this file */
}
rt_free(zf->fname);
rt_free(zf); rt_free(zf);
} }
/* waiting,clear console buffer */ /* waiting,clear console buffer */
@ -101,7 +106,7 @@ again:
res = zget_data(rxbuf, RX_BUFFER_SIZE); res = zget_data(rxbuf, RX_BUFFER_SIZE);
if (res == GOTCRCW) if (res == GOTCRCW)
{ {
if (zget_file_info((char*)rxbuf,zf) != RT_EOK) if ((res =zget_file_info((char*)rxbuf,zf))!= RT_EOK)
{ {
zsend_hex_header(ZSKIP, tx_header); zsend_hex_header(ZSKIP, tx_header);
return (res); return (res);
@ -149,7 +154,7 @@ static rt_err_t zrec_files(struct zfile *zf)
rt_kprintf("rz: ready...\r\n"); /* here ready to receive things */ rt_kprintf("rz: ready...\r\n"); /* here ready to receive things */
if ((res = zrec_init(rxbuf,zf))!= RT_EOK) if ((res = zrec_init(rxbuf,zf))!= RT_EOK)
{ {
rt_kprintf("receive init failed !\r\n"); rt_kprintf("\b\b\breceive init failed\r\n");
rt_free(rxbuf); rt_free(rxbuf);
return -RT_ERROR; return -RT_ERROR;
} }
@ -254,7 +259,8 @@ static rt_err_t zget_file_info(char *name,struct zfile *zf)
ftemp = rt_malloc(len); ftemp = rt_malloc(len);
if (ftemp == RT_NULL) if (ftemp == RT_NULL)
{ {
rt_kprintf("ftemp: out of memory\n"); zsend_can();
rt_kprintf("\b\b\bftemp: out of memory\n");
return -RT_ERROR; return -RT_ERROR;
} }
memset(ftemp,0,len); memset(ftemp,0,len);
@ -265,7 +271,8 @@ static rt_err_t zget_file_info(char *name,struct zfile *zf)
/* check if is a directory */ /* check if is a directory */
if ((zf->fd=open(ftemp, DFS_O_DIRECTORY,0)) < 0) if ((zf->fd=open(ftemp, DFS_O_DIRECTORY,0)) < 0)
{ {
rt_kprintf("can not open file:%s\r\n",zf->fname+1); zsend_can();
rt_kprintf("\b\b\bcan not open file:%s\r\n",zf->fname+1);
close(zf->fd); close(zf->fd);
zf->fd = -1; zf->fd = -1;
return res; return res;
@ -286,14 +293,16 @@ static rt_err_t zget_file_info(char *name,struct zfile *zf)
dfs_statfs(working_directory,&buf); dfs_statfs(working_directory,&buf);
if (zf->bytes_total > (buf.f_blocks * buf.f_bfree)) if (zf->bytes_total > (buf.f_blocks * buf.f_bfree))
{ {
rt_kprintf(" not enough disk space !\r\n"); zsend_can();
rt_kprintf("\b\b\bnot enough disk space\r\n");
zf->fd = -1;
return -RT_ERROR; return -RT_ERROR;
} }
zf->bytes_received = 0L; zf->bytes_received = 0L;
if ((zf->fd = open(zf->fname,DFS_O_CREAT|DFS_O_WRONLY,0)) < 0) /* create or replace exist file */ if ((zf->fd = open(zf->fname,DFS_O_CREAT|DFS_O_WRONLY,0)) < 0) /* create or replace exist file */
{ {
rt_kprintf("can not create file:%s \r\n",zf->fname); zsend_can();
rt_free(ftemp); rt_kprintf("\b\b\bcan not create file:%s \r\n",zf->fname);
return -RT_ERROR; return -RT_ERROR;
} }
return RT_EOK; return RT_EOK;
@ -346,6 +355,7 @@ more_data:
/* write file */ /* write file */
static rt_err_t zwrite_file(rt_uint8_t *buf,rt_uint16_t size,struct zfile *zf) static rt_err_t zwrite_file(rt_uint8_t *buf,rt_uint16_t size,struct zfile *zf)
{ {
// return 0;
return (write(zf->fd,buf,size)); return (write(zf->fd,buf,size));
} }

View File

@ -39,6 +39,7 @@ void zs_start(char *path)
{ {
struct zfile *zf; struct zfile *zf;
rt_err_t res = RT_ERROR; rt_err_t res = RT_ERROR;
zf = rt_malloc(sizeof(struct zfile)); zf = rt_malloc(sizeof(struct zfile));
if (zf == RT_NULL) if (zf == RT_NULL)
{ {
@ -59,12 +60,14 @@ void zs_start(char *path)
rt_kprintf("\r\nfile: %s \r\nsize: 0 bytes\r\nsend failed.\r\n",zf->fname+1); rt_kprintf("\r\nfile: %s \r\nsize: 0 bytes\r\nsend failed.\r\n",zf->fname+1);
} }
rt_free(zf); rt_free(zf);
return; return;
} }
/* init the parameters */ /* init the parameters */
static void zsend_init(void) static void zsend_init(void)
{ {
rt_err_t res = -RT_ERROR; rt_err_t res = -RT_ERROR;
zinit_parameter(); zinit_parameter();
for(;;) /* wait ZPAD */ for(;;) /* wait ZPAD */
{ {
@ -153,6 +156,7 @@ static rt_err_t zsend_file(struct zfile *zf,rt_uint8_t *buf, rt_uint16_t len)
{ {
rt_uint8_t cnt; rt_uint8_t cnt;
rt_err_t res = -RT_ERROR; rt_err_t res = -RT_ERROR;
for (cnt=0;cnt<5;cnt++) for (cnt=0;cnt<5;cnt++)
{ {
tx_header[ZF0] = ZF0_CMD; /* file conversion option */ tx_header[ZF0] = ZF0_CMD; /* file conversion option */
@ -195,6 +199,7 @@ loop:
break; break;
} }
} }
return res; return res;
} }
@ -256,6 +261,7 @@ static rt_uint16_t zfill_buffer(struct zfile *zf,rt_uint8_t *buf,rt_uint16_t siz
static rt_err_t zget_sync(void) static rt_err_t zget_sync(void)
{ {
rt_err_t res = -RT_ERROR; rt_err_t res = -RT_ERROR;
for (;;) for (;;)
{ {
res = zget_header(rx_header); res = zget_header(rx_header);

View File

@ -29,7 +29,8 @@ rt_uint32_t Rxpos; /* received file position */
rt_uint32_t Txpos; /* transmitted file position */ rt_uint32_t Txpos; /* transmitted file position */
rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */ rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS */
rt_uint8_t TxCRC; /* controls 32 bit CRC being sent */ rt_uint8_t TxCRC; /* controls 32 bit CRC being sent */
rt_uint8_t RxCRC; /* indicates/controls 32 bit CRC being received */ /* 0 == CRC16, 1 == CRC32, 2 == CRC32 + RLE */ rt_uint8_t RxCRC; /* indicates/controls 32 bit CRC being received */
/* 0 == CRC16, 1 == CRC32, 2 == CRC32 + RLE */
char Attn[ZATTNLEN+1]; /* attention string rx sends to tx on err */ char Attn[ZATTNLEN+1]; /* attention string rx sends to tx on err */
void zinit_parameter(void); void zinit_parameter(void);
@ -59,7 +60,7 @@ void zinit_parameter(void)
{ {
rt_uint8_t i; rt_uint8_t i;
ZF0_CMD = /*CANFC32|*/CANFDX|CANOVIO; /* not chose CANFC32,CANRLE,although it have been supported */ ZF0_CMD = CANFC32|CANFDX|CANOVIO; /* not chose CANFC32,CANRLE,although it have been supported */
ZF1_CMD = 0; /* fix header length,not support CANVHDR */ ZF1_CMD = 0; /* fix header length,not support CANVHDR */
ZF2_CMD = 0; ZF2_CMD = 0;
ZF3_CMD = 0; ZF3_CMD = 0;
@ -70,6 +71,7 @@ void zinit_parameter(void)
Rxpos = Txpos = 0; Rxpos = Txpos = 0;
RxCRC = 0; RxCRC = 0;
Txfcs32 = 0; Txfcs32 = 0;
return ; return ;
} }
@ -136,6 +138,7 @@ void zsend_bin_header(rt_uint8_t type, rt_uint8_t *hdr)
crc >>= 8; crc >>= 8;
} }
} }
return; return;
} }
@ -162,6 +165,7 @@ void zsend_hex_header(rt_uint8_t type, rt_uint8_t *hdr)
if (type != ZFIN && type != ZACK) if (type != ZFIN && type != ZACK)
zsend_line(021); zsend_line(021);
TxCRC = 0; /* clear tx crc type */ TxCRC = 0; /* clear tx crc type */
return; return;
} }
@ -262,6 +266,7 @@ void zsend_bin_data(rt_uint8_t *buf, rt_int16_t len, rt_uint8_t frameend)
} }
if (frameend == ZCRCW) if (frameend == ZCRCW)
zsend_byte(XON); zsend_byte(XON);
return; return;
} }
@ -272,9 +277,11 @@ static rt_int16_t zrec_data16(rt_uint8_t *buf,rt_uint16_t len)
rt_uint16_t crc; rt_uint16_t crc;
rt_err_t res = -RT_ERROR; rt_err_t res = -RT_ERROR;
rt_uint8_t *p,flag = 0; rt_uint8_t *p,flag = 0;
rt_uint8_t i =0, debug[20];
p = buf; p = buf;
crc = 0L; crc = 0L;
Rxcount = 0; Rxcount = 0;
debug[0] = debug[4] = 0;
while(buf <= p+len) while(buf <= p+len)
{ {
if ((res = zread_byte()) & ~0377) if ((res = zread_byte()) & ~0377)
@ -282,6 +289,9 @@ static rt_int16_t zrec_data16(rt_uint8_t *buf,rt_uint16_t len)
if (res == GOTCRCE || res == GOTCRCG || if (res == GOTCRCE || res == GOTCRCG ||
res == GOTCRCQ || res == GOTCRCW) res == GOTCRCQ || res == GOTCRCW)
{ {
c = res;
debug[i++] = res;
c = debug[0];
c = res; c = res;
crc = updcrc16(res&0377, crc); crc = updcrc16(res&0377, crc);
flag = 1; flag = 1;
@ -298,6 +308,7 @@ static rt_int16_t zrec_data16(rt_uint8_t *buf,rt_uint16_t len)
{ {
crc = updcrc16(res, crc); crc = updcrc16(res, crc);
crc_cnt++; crc_cnt++;
debug[i++] = res;
if (crc_cnt < 2) continue; if (crc_cnt < 2) continue;
if ((crc & 0xffff)) if ((crc & 0xffff))
{ {
@ -316,6 +327,7 @@ static rt_int16_t zrec_data16(rt_uint8_t *buf,rt_uint16_t len)
} }
} }
} }
return -RT_ERROR; return -RT_ERROR;
} }
@ -370,6 +382,7 @@ static rt_int16_t zrec_data32(rt_uint8_t *buf,rt_int16_t len)
} }
} }
} }
return -RT_ERROR; return -RT_ERROR;
} }
/* receive data,with RLE encoded,32bits CRC check */ /* receive data,with RLE encoded,32bits CRC check */
@ -480,6 +493,7 @@ rt_int16_t zget_data(rt_uint8_t *buf, rt_uint16_t len)
{ {
res = zrec_data32r(buf, len); res = zrec_data32r(buf, len);
} }
return res; return res;
} }
/* get type and cmd of header, fix lenght */ /* get type and cmd of header, fix lenght */
@ -489,7 +503,7 @@ rt_int16_t zget_header(rt_uint8_t *hdr)
rt_uint32_t bit; rt_uint32_t bit;
rt_uint16_t get_can,step_out; rt_uint16_t get_can,step_out;
bit = get_device_speed(); /* getbaudrate */ bit = get_device_baud(); /* get console baud rate */
Rxframeind = header_type = 0; Rxframeind = header_type = 0;
step_out = 0; step_out = 0;
prev_char = 0xff; prev_char = 0xff;
@ -613,6 +627,7 @@ static rt_int16_t zget_bin_header(rt_uint8_t *hdr)
rt_kprintf("CRC error\n"); rt_kprintf("CRC error\n");
return -RT_ERROR; return -RT_ERROR;
} }
return header_type; return header_type;
} }
@ -649,6 +664,7 @@ static rt_int16_t zget_bin_fcs(rt_uint8_t *hdr)
#endif #endif
return -RT_ERROR; return -RT_ERROR;
} }
return header_type; return header_type;
} }
@ -690,6 +706,7 @@ rt_int16_t zget_hex_header(rt_uint8_t *hdr)
res = zread_line(100); res = zread_line(100);
if (res < 0) if (res < 0)
return res; return res;
return header_type; return header_type;
} }
@ -700,6 +717,7 @@ static void zsend_ascii(rt_uint8_t c)
zsend_line(hex[(c&0xF0)>>4]); zsend_line(hex[(c&0xF0)>>4]);
zsend_line(hex[(c)&0xF]); zsend_line(hex[(c)&0xF]);
return; return;
} }
@ -754,6 +772,7 @@ static rt_int16_t zget_hex(void)
if (res & ~0x0f) if (res & ~0x0f)
return -RT_ERROR; return -RT_ERROR;
res += (n<<4); res += (n<<4);
return res; return res;
} }
@ -814,6 +833,7 @@ again2:
return (res ^ 0100); return (res ^ 0100);
break; break;
} }
return -RT_ERROR; return -RT_ERROR;
} }
@ -850,6 +870,7 @@ void zput_pos(rt_uint32_t pos)
tx_header[ZP1] = pos>>8; tx_header[ZP1] = pos>>8;
tx_header[ZP2] = pos>>16; tx_header[ZP2] = pos>>16;
tx_header[ZP3] = pos>>24; tx_header[ZP3] = pos>>24;
return; return;
} }
@ -860,6 +881,8 @@ void zget_pos(rt_uint32_t pos)
Rxpos = (Rxpos << 8) | (rx_header[ZP2] & 0377); Rxpos = (Rxpos << 8) | (rx_header[ZP2] & 0377);
Rxpos = (Rxpos << 8) | (rx_header[ZP1] & 0377); Rxpos = (Rxpos << 8) | (rx_header[ZP1] & 0377);
Rxpos = (Rxpos << 8) | (rx_header[ZP0] & 0377); Rxpos = (Rxpos << 8) | (rx_header[ZP0] & 0377);
return;
} }
/* End of zm.c */ /* end of zcore.c */

View File

@ -65,20 +65,20 @@
#define ZP2 2 #define ZP2 2
#define ZP3 3 /* high order 8 bits of file position */ #define ZP3 3 /* high order 8 bits of file position */
/* Parameters for ZRINIT header */ /* parameters for ZRINIT header */
#define ZRPXWN 8 /* 9th byte in header contains window size/256 */ #define ZRPXWN 8 /* 9th byte in header contains window size/256 */
#define ZRPXQQ 9 /* 10th to 14th bytes contain quote mask */ #define ZRPXQQ 9 /* 10th to 14th bytes contain quote mask */
/* Bit Masks for ZRINIT flags byte ZF0 */ /* bit Masks for ZRINIT flags byte ZF0 */
#define CANFDX 01 /* rx can send and receive true FDX */ #define CANFDX 0x01 /* rx can send and receive true FDX */
#define CANOVIO 02 /* rx can receive data during disk I/O */ #define CANOVIO 0x02 /* rx can receive data during disk I/O */
#define CANBRK 04 /* rx can send a break signal */ #define CANBRK 0x04 /* rx can send a break signal */
#define CANRLE 010 /* receiver can decode RLE */ #define CANRLE 0x10 /* receiver can decode RLE */
#define CANLZW 020 /* receiver can uncompress */ #define CANLZW 0x20 /* receiver can uncompress */
#define CANFC32 040 /* receiver can use 32 bit Frame Check */ #define CANFC32 0x28 /* receiver can use 32 bit Frame Check */
#define ESCCTL 0100 /* receiver expects ctl chars to be escaped */ #define ESCCTL 0x64 /* receiver expects ctl chars to be escaped */
#define ESC8 0200 /* receiver expects 8th bit to be escaped */ #define ESC8 0xc8 /* receiver expects 8th bit to be escaped */
/* Bit Masks for ZRINIT flags byte ZF1 */ /* bit Masks for ZRINIT flags byte ZF1 */
#define CANVHDR 01 /* variable headers OK */ #define CANVHDR 01 /* variable headers OK */
#define ZRRQWN 8 /* receiver specified window size in ZRPXWN */ #define ZRRQWN 8 /* receiver specified window size in ZRPXWN */
#define ZRRQQQ 16 /* additional control chars to quote in ZRPXQQ */ #define ZRRQQQ 16 /* additional control chars to quote in ZRPXQQ */
@ -93,33 +93,33 @@
#define ZCBIN 1 /* binary transfer - inhibit conversion */ #define ZCBIN 1 /* binary transfer - inhibit conversion */
#define ZCNL 2 /* convert NL to local end of line convention */ #define ZCNL 2 /* convert NL to local end of line convention */
#define ZCRESUM 3 /* resume interrupted file transfer */ #define ZCRESUM 3 /* resume interrupted file transfer */
/* Management include options, one of these ored in ZF1 */ /* management include options, one of these ored in ZF1 */
#define ZMSKNOLOC 0200 /* skip file if not present at rx */ #define ZMSKNOLOC 0200 /* skip file if not present at rx */
/* Management options, one of these ored in ZF1 */ /* management options, one of these ored in ZF1 */
#define ZMMASK 037 /* mask for the choices below */ #define ZMMASK 037 /* mask for the choices below */
#define ZMNEWL 1 /* transfer if source newer or longer */ #define ZMNEWL 1 /* transfer if source newer or longer */
#define ZMCRC 2 /* transfer if different file CRC or length */ #define ZMCRC 2 /* transfer if different file CRC or length */
#define ZMAPND 3 /* append contents to existing file (if any) */ #define ZMAPND 3 /* append contents to existing file (if any) */
#define ZMCLOB 4 /* replace existing file */ #define ZMCLOB 4 /* replace existing file */
#define ZMNEW 5 /* transfer if source newer */ #define ZMNEW 5 /* transfer if source newer */
/* Number 5 is alive ... */ /* number 5 is alive ... */
#define ZMDIFF 6 /* transfer if dates or lengths different */ #define ZMDIFF 6 /* transfer if dates or lengths different */
#define ZMPROT 7 /* protect destination file */ #define ZMPROT 7 /* protect destination file */
#define ZMCHNG 8 /* change filename if destination exists */ #define ZMCHNG 8 /* change filename if destination exists */
/* Transport options, one of these in ZF2 */ /* transport options, one of these in ZF2 */
#define ZTLZW 1 /* lempel-Ziv compression */ #define ZTLZW 1 /* lempel-Ziv compression */
#define ZTRLE 3 /* run Length encoding */ #define ZTRLE 3 /* run Length encoding */
/* Extended options for ZF3, bit encoded */ /* extended options for ZF3, bit encoded */
#define ZXSPARS 64 /* encoding for sparse file operations */ #define ZXSPARS 64 /* encoding for sparse file operations */
#define ZCANVHDR 01 /* variable headers OK */ #define ZCANVHDR 01 /* variable headers OK */
/* Receiver window size override */ /* receiver window size override */
#define ZRWOVR 4 /* byte position for receive window override/256 */ #define ZRWOVR 4 /* byte position for receive window override/256 */
/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */ /* parameters for ZCOMMAND frame ZF0 (otherwise 0) */
#define ZCACK1 1 /* acknowledge, then do command */ #define ZCACK1 1 /* acknowledge, then do command */
extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */ extern char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
/* Globals used by ZMODEM functions */ /* globals used by ZMODEM functions */
extern rt_uint8_t Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */ extern rt_uint8_t Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame */
extern char header_type; /* type of header received */ extern char header_type; /* type of header received */
extern rt_uint8_t rx_header[4]; /* received header */ extern rt_uint8_t rx_header[4]; /* received header */
@ -153,8 +153,8 @@ extern rt_uint8_t Txfcs32; /* TURE means send binary frames with 32 bit FCS
#define ERRORMAX 5 #define ERRORMAX 5
#define RETRYMAX 5 #define RETRYMAX 5
#define WCEOT (-10) #define WCEOT (-10)
#define PATHLEN 257 /* ready for 4.2 bsd ? */
#define UNIXFILE 0xF000 /* the S_IFMT file mask bit for stat */
@ -191,7 +191,7 @@ struct zfile
}; };
extern struct finsh_shell* shell; extern struct finsh_shell* shell;
#define ZDEBUG 1 #define ZDEBUG 0
/* sz.c */ /* sz.c */
extern void zs_start(char *path); extern void zs_start(char *path);
/* rz.c */ /* rz.c */
@ -207,7 +207,7 @@ 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 zput_pos(rt_uint32_t pos);
extern void zget_pos(rt_uint32_t pos); extern void zget_pos(rt_uint32_t pos);
/* zdevice.c */ /* zdevice.c */
extern rt_uint32_t get_device_speed(void); extern rt_uint32_t get_device_baud(void);
extern void zsend_byte(rt_uint16_t c); extern void zsend_byte(rt_uint16_t c);
extern void zsend_line(rt_uint16_t c); extern void zsend_line(rt_uint16_t c);
extern rt_int16_t zread_line(rt_uint16_t timeout); extern rt_int16_t zread_line(rt_uint16_t timeout);

View File

@ -22,7 +22,7 @@ rt_uint32_t Baudrate = BITRATE; /* console baudrate */
rt_uint32_t get_device_speed(void) rt_uint32_t get_device_baud(void)
{ {
return(Baudrate); return(Baudrate);
} }
@ -35,22 +35,24 @@ rt_uint32_t get_sys_time(void)
void zsend_byte(rt_uint16_t ch) void zsend_byte(rt_uint16_t ch)
{ {
rt_device_write(zmodem.device,0,&ch,1); rt_device_write(zmodem.device,0,&ch,1);
return; return;
} }
void zsend_line(rt_uint16_t c) void zsend_line(rt_uint16_t c)
{ {
rt_uint16_t ch; rt_uint16_t ch;
ch = (c & 0377); ch = (c & 0377);
rt_device_write(zmodem.device,0,&ch,1); rt_device_write(zmodem.device,0,&ch,1);
return; return;
} }
static char buf[RX_BUFFER_SIZE + 1];
rt_int16_t zread_line(rt_uint16_t timeout) rt_int16_t zread_line(rt_uint16_t timeout)
{ {
char *str; char *str;
static char buf[10];
if (Line_left > 0) if (Line_left > 0)
{ {
@ -61,7 +63,7 @@ rt_int16_t zread_line(rt_uint16_t timeout)
timeout/=5; timeout/=5;
while (1) while (1)
{ {
if (rt_sem_take(&zmodem.zsem, RT_TICK_PER_SECOND*timeout) != RT_EOK) continue; // if (rt_sem_take(&zmodem.zsem, RT_TICK_PER_SECOND*timeout) != RT_EOK) continue;
Line_left = rt_device_read(shell->device, 0, buf, 1); Line_left = rt_device_read(shell->device, 0, buf, 1);
if (Line_left) if (Line_left)
{ {
@ -72,6 +74,7 @@ rt_int16_t zread_line(rt_uint16_t timeout)
} }
if (Line_left < 1) return TIMEOUT; if (Line_left < 1) return TIMEOUT;
Line_left -=1; Line_left -=1;
return (*str++ & 0377); return (*str++ & 0377);
} }
@ -101,9 +104,12 @@ void zsend_break(char *cmd)
void zsend_can(void) void zsend_can(void)
{ {
static char cmd[] = {24,24,24,24,24,24,24,24,24,24,0}; static char cmd[] = {24,24,24,24,24,24,24,24,24,24,0};
zsend_break(cmd); zsend_break(cmd);
rt_kprintf("\x0d"); rt_kprintf("\x0d");
Line_left=0; /* clear Line_left */ Line_left=0; /* clear Line_left */
return;
} }
/* end of rbsb.c */ /* end of zdevice.c */

View File

@ -38,7 +38,7 @@ void finsh_rz(void *parameter)
/* save old rx_indicate */ /* save old rx_indicate */
rx_indicate = zmodem.device->rx_indicate; rx_indicate = zmodem.device->rx_indicate;
/* set new rx_indicate */ /* set new rx_indicate */
rt_device_set_rx_indicate(zmodem.device, zmodem_rx_ind); rt_device_set_rx_indicate(zmodem.device, RT_NULL);
/* start receive remote files */ /* start receive remote files */
zr_start(path); zr_start(path);
zmodem.device->flag |=flag; zmodem.device->flag |=flag;