summaryrefslogtreecommitdiff
path: root/components/utilities/ymodem/ymodem.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2014-07-19 06:46:39 +0800
committerBernard Xiong <[email protected]>2014-07-19 06:46:39 +0800
commit350b1080eafb565875f82bfe5da9173fa7f0f149 (patch)
treea044f04e1d200c2421a74e840ab6da143c431b55 /components/utilities/ymodem/ymodem.c
parent61712bbd13b7c820307f0570d49f1bc0fc6b857a (diff)
parent50e7ae7e875c28cdc65baf9c0ec7893a59211a23 (diff)
Merge pull request #303 from BernardXiong/stable-v1.2.xv1.2.2
Merge 2.0.0 modification to prepare v1.2.2 release.
Diffstat (limited to 'components/utilities/ymodem/ymodem.c')
-rw-r--r--components/utilities/ymodem/ymodem.c25
1 files changed, 15 insertions, 10 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 */