diff options
| author | 陈豪 <[email protected]> | 2014-08-06 22:55:49 +0800 |
|---|---|---|
| committer | 陈豪 <[email protected]> | 2014-08-06 22:55:49 +0800 |
| commit | 5fc32bf12ef4356ecbd46cfa21079cddb522b5c7 (patch) | |
| tree | 8f77e59c1bcec59c3c5efd0fe022f3dc0a0c901e /components/utilities | |
| parent | 0c8335d5ab046ce9fe36c4e01d5d40e4ba152b49 (diff) | |
| parent | a8fadf15b1828569e7684049d983cc6cb7fda2c9 (diff) | |
Merge pull request #1 from RT-Thread/master
sync
Diffstat (limited to 'components/utilities')
| -rw-r--r-- | components/utilities/ymodem/ymodem.c | 25 | ||||
| -rw-r--r-- | components/utilities/ymodem/ymodem.h | 2 |
2 files changed, 16 insertions, 11 deletions
diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index fdd1950cc0..f5ebeab832 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -70,18 +70,23 @@ static enum rym_code _rym_read_code( struct rym_ctx *ctx, rt_tick_t timeout) { - /* consume the available sem and read the data in buffer if possible */ - while (rt_sem_trytake(&ctx->sem) == RT_EOK) - ; + /* Fast path */ if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1) return *ctx->buf; - /* no data yet, wait for one */ - if (rt_sem_take(&ctx->sem, timeout) != RT_EOK) - return RYM_CODE_NONE; - /* read one */ - if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1) - return *ctx->buf; - return RYM_CODE_NONE; + + /* Slow path */ + do { + rt_size_t rsz; + + /* No data yet, wait for one */ + if (rt_sem_take(&ctx->sem, timeout) != RT_EOK) + return RYM_CODE_NONE; + + /* Try to read one */ + rsz = rt_device_read(ctx->dev, 0, ctx->buf, 1); + if (rsz == 1) + return *ctx->buf; + } while (1); } /* the caller should at least alloc _RYM_STX_PKG_SZ buffer */ diff --git a/components/utilities/ymodem/ymodem.h b/components/utilities/ymodem/ymodem.h index daed61d15f..43ee6f5c10 100644 --- a/components/utilities/ymodem/ymodem.h +++ b/components/utilities/ymodem/ymodem.h @@ -52,7 +52,7 @@ enum rym_code { #endif /* how many ticks between two handshake code. */ #ifndef RYM_CHD_INTV_TICK -#define RYM_CHD_INTV_TICK (RT_TICK_PER_SECOND / 4) +#define RYM_CHD_INTV_TICK (RT_TICK_PER_SECOND * 3) #endif enum rym_stage { |
