From e2c0749d04652c8ea0934e0d2b3ca26733fad815 Mon Sep 17 00:00:00 2001 From: zylx Date: Thu, 21 Feb 2019 11:09:36 +0800 Subject: [PATCH] =?UTF-8?q?[components][ymodem]ymodem=20=E6=8F=A1=E6=89=8B?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E5=A2=9E=E5=8A=A0=E5=BB=B6=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E6=95=B0=E6=8D=AE=E6=8E=A5=E6=94=B6=E4=B8=8D?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/utilities/ymodem/ymodem.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index c98c7f6cb6..716c702328 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -125,6 +125,7 @@ static rt_err_t _rym_do_handshake( rt_size_t i; rt_uint16_t recv_crc, cal_crc; rt_size_t data_sz; + rt_tick_t tick; ctx->stage = RYM_STAGE_ESTABLISHING; /* send C every second, so the sender could know we are waiting for it. */ @@ -149,8 +150,17 @@ static rt_err_t _rym_do_handshake( return -RYM_ERR_TMO; } - i = _rym_read_data(ctx, data_sz-1); - if (i != (data_sz-1)) + /* receive all data */ + i = 0; + /* automatic exit after receiving specified length data, timeout: 100ms */ + tick = rt_tick_get(); + while (rt_tick_get() <= (tick + rt_tick_from_millisecond(100)) && i < (data_sz-1)) + { + i += _rym_read_data(ctx, data_sz - 1); + rt_thread_mdelay(5); + } + + if (i != (data_sz - 1)) return -RYM_ERR_DSZ; /* sanity check */