From 8e9024cacaf0677a016e56a586064a2945544cf8 Mon Sep 17 00:00:00 2001 From: vitoswwang Date: Mon, 19 Jul 2021 13:04:02 +0800 Subject: [PATCH] improve tos_at_channel_read_timed,update to 2.4.2 --- kernel/core/include/tos_version.h | 4 ++-- net/at/include/tos_at.h | 1 + net/at/src/tos_at.c | 19 +++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/kernel/core/include/tos_version.h b/kernel/core/include/tos_version.h index e434cc51..88b60a4f 100644 --- a/kernel/core/include/tos_version.h +++ b/kernel/core/include/tos_version.h @@ -25,8 +25,8 @@ #define TOS_VERSION_MAJOR 0x02 #define TOS_VERSION_MINOR 0x04 -#define TOS_VERSION_PATCH 0x01 -#define TOS_VERSION "2.4.1" +#define TOS_VERSION_PATCH 0x02 +#define TOS_VERSION "2.4.2" #endif /* _TOS_VERSION_H_ */ diff --git a/net/at/include/tos_at.h b/net/at/include/tos_at.h index 3d78ebbb..6d085ec7 100644 --- a/net/at/include/tos_at.h +++ b/net/at/include/tos_at.h @@ -95,6 +95,7 @@ typedef struct at_data_channel_st { k_chr_fifo_t rx_fifo; uint8_t *rx_fifo_buffer; k_mutex_t rx_lock; + k_sem_t rx_sem; at_channel_status_t status; diff --git a/net/at/src/tos_at.c b/net/at/src/tos_at.c index e37e4fcc..beb4411b 100644 --- a/net/at/src/tos_at.c +++ b/net/at/src/tos_at.c @@ -688,7 +688,7 @@ __API__ int tos_at_channel_read_timed(int channel_id, uint8_t *buffer, size_t bu { int read_len = 0; size_t total_read_len = 0; - k_tick_t tick, remain_tick; + k_tick_t remain_tick; at_data_channel_t *data_channel = K_NULL; data_channel = at_channel_get(channel_id, K_FALSE); @@ -696,9 +696,9 @@ __API__ int tos_at_channel_read_timed(int channel_id, uint8_t *buffer, size_t bu return -1; } - tick = tos_millisec2tick(timeout); - - tos_stopwatch_countdown(&data_channel->timer, tick); + remain_tick = tos_millisec2tick(timeout); + tos_stopwatch_countdown(&data_channel->timer, remain_tick); + while (!tos_stopwatch_is_expired(&data_channel->timer)) { remain_tick = tos_stopwatch_remain(&data_channel->timer); if (remain_tick == (k_tick_t)0u) { @@ -712,6 +712,10 @@ __API__ int tos_at_channel_read_timed(int channel_id, uint8_t *buffer, size_t bu read_len = tos_chr_fifo_pop_stream(&data_channel->rx_fifo, buffer + read_len, buffer_len - total_read_len); tos_mutex_post(&data_channel->rx_lock); + + if (read_len == 0) { + tos_sem_pend(&data_channel->rx_sem, remain_tick); + } total_read_len += read_len; if (total_read_len < buffer_len) { @@ -741,6 +745,7 @@ __API__ int tos_at_channel_write(int channel_id, uint8_t *buffer, size_t buffer_ ret = tos_chr_fifo_push_stream(&data_channel->rx_fifo, buffer, buffer_len); tos_mutex_post(&data_channel->rx_lock); + tos_sem_post(&data_channel->rx_sem); return ret; } @@ -754,6 +759,10 @@ __STATIC_INLINE__ int at_channel_construct(at_data_channel_t *data_channel, cons if (!fifo_buffer) { return -1; } + + if (tos_sem_create_max(&data_channel->rx_sem, 0, 1) != K_ERR_NONE) { + goto errout; + } if (tos_mutex_create(&data_channel->rx_lock) != K_ERR_NONE) { goto errout; @@ -852,6 +861,8 @@ __API__ int tos_at_channel_free(int channel_id) if (!data_channel) { return -1; } + + tos_sem_destroy(&data_channel->rx_sem); tos_mutex_destroy(&data_channel->rx_lock);