From f54f2c2c917e6237567c4cc7a8d94dbba327747d Mon Sep 17 00:00:00 2001 From: wdfk-prog <1425075683@qq.com> Date: Tue, 29 Nov 2022 10:00:21 +0800 Subject: [PATCH] =?UTF-8?q?[ymodem]=E6=B7=BB=E5=8A=A0=E4=BC=A0=E8=BE=93?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/utilities/ymodem/ymodem.c | 20 ++++++++++++++++++-- components/utilities/ymodem/ymodem.h | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index 5a2d443d01..52f5e52692 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -1,5 +1,5 @@ /* - * COPYRIGHT (C) 2011-2021, Real-Thread Information Technology Ltd + * COPYRIGHT (C) 2011-2022, Real-Thread Information Technology Ltd * All rights reserved * * SPDX-License-Identifier: Apache-2.0 @@ -362,6 +362,7 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx) _rym_putchar(ctx, RYM_CODE_ACK); _rym_putchar(ctx, RYM_CODE_C); ctx->stage = RYM_STAGE_ESTABLISHED; + rt_size_t errors; while (1) { @@ -387,7 +388,22 @@ static rt_err_t _rym_do_trans(struct rym_ctx *ctx) err = _rym_trans_data(ctx, data_sz, &code); if (err != RT_EOK) - return err; + { + errors++; + if(errors > RYM_MAX_ERRORS) + { + return err;/* Abort communication */ + } + else + { + _rym_putchar(ctx, RYM_CODE_NAK);/* Ask for a packet */ + continue; + } + } + else + { + errors = 0; + } switch (code) { case RYM_CODE_CAN: diff --git a/components/utilities/ymodem/ymodem.h b/components/utilities/ymodem/ymodem.h index 398e168dfa..25f05e9148 100644 --- a/components/utilities/ymodem/ymodem.h +++ b/components/utilities/ymodem/ymodem.h @@ -58,6 +58,11 @@ enum rym_code #define RYM_END_SESSION_SEND_CAN_NUM 0x07 #endif +/* how many retries were made when the error occurred */ +#ifndef RYM_MAX_ERRORS +#define RYM_MAX_ERRORS ((rt_size_t)5) +#endif + enum rym_stage { RYM_STAGE_NONE = 0, -- GitLab