提交 19ef5537 编写于 作者: B Bernard Xiong

Merge pull request #299 from grissiom/next-ymodem

Next ymodem
...@@ -70,18 +70,23 @@ static enum rym_code _rym_read_code( ...@@ -70,18 +70,23 @@ static enum rym_code _rym_read_code(
struct rym_ctx *ctx, struct rym_ctx *ctx,
rt_tick_t timeout) rt_tick_t timeout)
{ {
/* consume the available sem and read the data in buffer if possible */ /* Fast path */
while (rt_sem_trytake(&ctx->sem) == RT_EOK)
;
if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1) if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1)
return *ctx->buf; return *ctx->buf;
/* no data yet, wait for one */
/* Slow path */
do {
rt_size_t rsz;
/* No data yet, wait for one */
if (rt_sem_take(&ctx->sem, timeout) != RT_EOK) if (rt_sem_take(&ctx->sem, timeout) != RT_EOK)
return RYM_CODE_NONE; return RYM_CODE_NONE;
/* read one */
if (rt_device_read(ctx->dev, 0, ctx->buf, 1) == 1) /* Try to read one */
rsz = rt_device_read(ctx->dev, 0, ctx->buf, 1);
if (rsz == 1)
return *ctx->buf; return *ctx->buf;
return RYM_CODE_NONE; } while (1);
} }
/* the caller should at least alloc _RYM_STX_PKG_SZ buffer */ /* the caller should at least alloc _RYM_STX_PKG_SZ buffer */
......
...@@ -52,7 +52,7 @@ enum rym_code { ...@@ -52,7 +52,7 @@ enum rym_code {
#endif #endif
/* how many ticks between two handshake code. */ /* how many ticks between two handshake code. */
#ifndef RYM_CHD_INTV_TICK #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 #endif
enum rym_stage { enum rym_stage {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册