From 655d3cc2b0f616ac53ffe46c40f48577e40ad70c Mon Sep 17 00:00:00 2001 From: Carlos Stuart Date: Wed, 6 Feb 2019 08:43:27 +0000 Subject: [PATCH] lib: cmsis_rtos_v2: Default thread prioity If an unitialized/zeroed optional attribute was passed to osThreadNew the priority would be osThreadNone i.e. uninitialized. This causes an ASSERT to be hit as the priority isn't valid (it is not between osPriorityIdle and osPriorityISR). The fix checks the passed in priority is not osPriorityNone and assigns osPriorityNormal. This is the correct CMSIS behaviour. The ASSERT will still be hit if the priority is invalid (<0). Signed-off-by: Carlos Stuart --- lib/cmsis_rtos_v2/thread.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/cmsis_rtos_v2/thread.c b/lib/cmsis_rtos_v2/thread.c index 14c2ed22b15..7fd97208301 100644 --- a/lib/cmsis_rtos_v2/thread.c +++ b/lib/cmsis_rtos_v2/thread.c @@ -98,6 +98,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, const osThreadAttr_t *attr) { s32_t prio; + osPriority_t cv2_prio; struct cv2_thread *tid; static u32_t one_time; void *stack; @@ -117,6 +118,12 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, attr = &init_thread_attrs; } + if (attr->priority == osPriorityNone) { + cv2_prio = osPriorityNormal; + } else { + cv2_prio = attr->priority; + } + if ((attr->stack_mem == NULL) && (thread_num_dynamic >= CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT)) { return NULL; @@ -136,8 +143,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, __ASSERT(attr->stack_size <= CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE, "invalid stack size\n"); - __ASSERT((attr->priority >= osPriorityIdle) && - (attr->priority <= osPriorityISR), + __ASSERT((cv2_prio >= osPriorityIdle) && (cv2_prio <= osPriorityISR), "invalid priority\n"); if (attr->stack_mem != NULL) { @@ -146,7 +152,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, } } - prio = cmsis_to_zephyr_priority(attr->priority); + prio = cmsis_to_zephyr_priority(cv2_prio); this_thread_num = atomic_inc((atomic_t *)&thread_num);