From 98f0cfbf6e37a072ddf3aa2ae6a600c5dee964aa Mon Sep 17 00:00:00 2001 From: mysterywolf <920369182@qq.com> Date: Fri, 23 Oct 2020 01:04:06 +0800 Subject: [PATCH] define maximum value of ipc type --- include/rtdef.h | 8 ++++++++ src/ipc.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/rtdef.h b/include/rtdef.h index 5543b80ab7..0690371c6d 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -33,6 +33,7 @@ * 2019-05-17 Bernard change version number to v4.0.2 * 2019-12-20 Bernard change version number to v4.0.3 * 2020-08-10 Meco Man add macro for struct rt_device_ops + * 2020-10-23 Meco Man define maximum value of ipc type */ #ifndef __RT_DEF_H__ @@ -102,6 +103,13 @@ typedef rt_base_t rt_off_t; /**< Type for offset */ #define RT_UINT32_MAX 0xffffffff /**< Maxium number of UINT32 */ #define RT_TICK_MAX RT_UINT32_MAX /**< Maxium number of tick */ +/* maximum value of ipc type */ +#define RT_SEM_VALUE_MAX RT_UINT16_MAX /**< Maxium number of semaphore .value */ +#define RT_MUTEX_VALUE_MAX RT_UINT16_MAX /**< Maxium number of mutex .value */ +#define RT_MUTEX_HOLD_MAX RT_UINT8_MAX /**< Maxium number of mutex .hold */ +#define RT_MB_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of mailbox .entry */ +#define RT_MQ_ENTRY_MAX RT_UINT16_MAX /**< Maxium number of message queue .entry */ + #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) #define __CLANG_ARM #endif diff --git a/src/ipc.c b/src/ipc.c index 9cd2b8846d..454fcb5439 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -465,7 +465,7 @@ rt_err_t rt_sem_release(rt_sem_t sem) } else { - if(sem->value < 65535u) + if(sem->value < RT_SEM_VALUE_MAX) { sem->value ++; /* increase value */ } @@ -696,7 +696,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time) if (mutex->owner == thread) { - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { /* it's the same thread */ mutex->hold ++; @@ -723,7 +723,7 @@ __again: /* set mutex owner and original priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -888,7 +888,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) /* set new owner and priority */ mutex->owner = thread; mutex->original_priority = thread->current_priority; - if(mutex->hold < 255u) + if(mutex->hold < RT_MUTEX_HOLD_MAX) { mutex->hold ++; } @@ -905,7 +905,7 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex) } else { - if(mutex->value < 65535u) + if(mutex->value < RT_MUTEX_VALUE_MAX) { /* increase value */ mutex->value ++; @@ -1607,7 +1607,7 @@ rt_err_t rt_mb_send_wait(rt_mailbox_t mb, if (mb->in_offset >= mb->size) mb->in_offset = 0; - if(mb->entry < 65535u) + if(mb->entry < RT_MB_ENTRY_MAX) { /* increase message entry */ mb->entry ++; @@ -2179,7 +2179,7 @@ rt_err_t rt_mq_send_wait(rt_mq_t mq, if (mq->msg_queue_head == RT_NULL) mq->msg_queue_head = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++; @@ -2287,7 +2287,7 @@ rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size) if (mq->msg_queue_tail == RT_NULL) mq->msg_queue_tail = msg; - if(mq->entry < 65535u) + if(mq->entry < RT_MQ_ENTRY_MAX) { /* increase message entry */ mq->entry ++;