From 8faa787ebe7a161a1947afd0d37525cd99d6b141 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 24 Feb 2016 15:30:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8942 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/common/abstractions/nasa_osal/src/osapi.c | 60 +++++++++++++++++++++------- os/rt/src/chregistry.c | 6 +++ release_note_next.txt | 7 +++- 3 files changed, 57 insertions(+), 16 deletions(-) diff --git a/os/common/abstractions/nasa_osal/src/osapi.c b/os/common/abstractions/nasa_osal/src/osapi.c index 367d0f2d4..9d02cd05e 100644 --- a/os/common/abstractions/nasa_osal/src/osapi.c +++ b/os/common/abstractions/nasa_osal/src/osapi.c @@ -37,6 +37,10 @@ #error "CH_CFG_ST_FREQUENCY is not a multiple of 1000" #endif +#if CH_CFG_USE_REGISTRY == FALSE +#error "NASA OSAL requires CH_CFG_USE_REGISTRY" +#endif + #if CH_CFG_USE_EVENTS == FALSE #error "NASA OSAL requires CH_CFG_USE_EVENTS" #endif @@ -49,10 +53,6 @@ #error "NASA OSAL requires CH_CFG_USE_SEMAPHORES" #endif -#if CH_CFG_USE_REGISTRY == FALSE -#error "NASA OSAL requires CH_CFG_USE_REGISTRY" -#endif - #if CH_CFG_USE_MEMCORE == FALSE #error "NASA OSAL requires CH_CFG_USE_MEMCORE" #endif @@ -61,6 +61,10 @@ #error "NASA OSAL requires CH_CFG_USE_MEMPOOLS" #endif +#if CH_CFG_USE_DYNAMIC == FALSE +#error "NASA OSAL requires CH_CFG_USE_DYNAMIC" +#endif + /*===========================================================================*/ /* Module local definitions. */ /*===========================================================================*/ @@ -1279,6 +1283,9 @@ int32 OS_TaskCreate(uint32 *task_id, /* Converting priority to RT type.*/ rt_prio = (tprio_t)256 - (tprio_t)priority; + if (rt_prio == 1) { + rt_prio = 2; + } tp = chThdCreateFromHeap(NULL, (size_t)stack_size, task_name, rt_prio, (tfunc_t)function_pointer, NULL); @@ -1325,6 +1332,15 @@ int32 OS_TaskDelete(uint32 task_id) { return OS_ERR_INVALID_ID; } + /* Asking for thread termination.*/ + chThdTerminate(tp); + + /* Releasing the thread reference.*/ + chThdRelease(tp); + + /* Waiting for termination.*/ + chThdWait(tp); + return OS_ERR_NOT_IMPLEMENTED; } @@ -1354,6 +1370,8 @@ int32 OS_TaskDelay(uint32 milli_second) { /** * @brief Change task priority. + * @note Priority 255 is not available and it is transformed internally in + * 254. * * @param[in] task_id the task id * @param[in] new_priority the task new priority @@ -1365,11 +1383,6 @@ int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) { tprio_t rt_newprio; thread_t *tp = (thread_t *)task_id; - /* Check for thread validity.*/ - if (chRegFindThreadByPointer(tp) == NULL) { - return OS_ERR_INVALID_ID; - } - /* Checking priority range.*/ if ((new_priority < MIN_PRIORITY) || (new_priority > MAX_PRIORITY)) { return OS_ERR_INVALID_PRIORITY; @@ -1377,11 +1390,19 @@ int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) { /* Converting priority to RT type.*/ rt_newprio = (tprio_t)256 - (tprio_t)new_priority; + if (rt_newprio == 1) { + rt_newprio = 2; + } if (chThdGetPriorityX() == rt_newprio) { return OS_SUCCESS; } + /* Check for thread validity.*/ + if (chRegFindThreadByPointer(tp) == NULL) { + return OS_ERR_INVALID_ID; + } + chSysLock(); /* Changing priority.*/ @@ -1420,6 +1441,9 @@ int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) { chSchRescheduleS(); chSysUnlock(); + /* Releasing the thread reference.*/ + chThdRelease(tp); + return OS_SUCCESS; } @@ -1479,6 +1503,9 @@ int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name) { *task_id = (uint32)tp; + /* Releasing the thread reference.*/ + chThdRelease(tp); + return OS_SUCCESS; } @@ -1486,6 +1513,8 @@ int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name) { * @brief Returns task information. * @note This function can be safely called from timer callbacks or ISRs. * @note It is not currently implemented. + * @note Priority 255 is not available and it is transformed internally in + * 254. * * @param[in] task_id the task id * @param[in] task_prop task properties @@ -1497,22 +1526,25 @@ int32 OS_TaskGetInfo(uint32 task_id, OS_task_prop_t *task_prop) { thread_t *tp = (thread_t *)task_id; size_t wasize = (size_t)tp - (size_t)tp->stklimit + sizeof (thread_t); - /* Check for thread validity.*/ - if (chRegFindThreadByPointer(tp) == NULL) { - return OS_ERR_INVALID_ID; - } - /* NULL pointer checks.*/ if (task_prop == NULL) { return OS_INVALID_POINTER; } + /* Check for thread validity.*/ + if (chRegFindThreadByPointer(tp) == NULL) { + return OS_ERR_INVALID_ID; + } + strncpy(task_prop->name, tp->name, OS_MAX_API_NAME - 1); task_prop->creator = (uint32)chSysGetIdleThreadX(); task_prop->stack_size = (uint32)MEM_ALIGN_NEXT(wasize, PORT_STACK_ALIGN); task_prop->priority = (uint32)256U - (uint32)tp->realprio; task_prop->OStask_id = task_id; + /* Releasing the thread reference.*/ + chThdRelease(tp); + return OS_SUCCESS; } diff --git a/os/rt/src/chregistry.c b/os/rt/src/chregistry.c index 7d870897b..ec90b4168 100644 --- a/os/rt/src/chregistry.c +++ b/os/rt/src/chregistry.c @@ -181,6 +181,9 @@ thread_t *chRegNextThread(thread_t *tp) { /** * @brief Retrieves a thread pointer by name. + * @note The reference counter of the found thread is increased by one so + * it cannot be disposed incidentally after the pointer has been + * returned. * * @param[in] name the thread name * @return A pointer to the found thread. @@ -205,6 +208,9 @@ thread_t *chRegFindThreadByName(const char *name) { /** * @brief Confirms that a pointer is a valid thread pointer. + * @note The reference counter of the found thread is increased by one so + * it cannot be disposed incidentally after the pointer has been + * returned. * * @param[in] tp pointer to the thread * @return A pointer to the found thread. diff --git a/release_note_next.txt b/release_note_next.txt index 525aa8a9c..0bb3bce0c 100644 --- a/release_note_next.txt +++ b/release_note_next.txt @@ -17,6 +17,7 @@ a series of important new features. are usable by both RT and NIL. - Shared ports architecture. Now RTOS ports work for both RT and NIL, no more duplication. +- MPU use for hardware stack checking in ARMCMx port. - Enhanced shell. *** What's new in RT 4.0.0 *** @@ -24,10 +25,12 @@ a series of important new features. - Common ports architecture. - Ability to use the new shared RTOS components. - Enhanced trace buffer, it is able to store events regarding not just threads - but also IRQs, halts and user events. + but also IRQs, halts and user events. The trace record now stores both the + "slow" system time and a RT stamp for increased accuracy. - Enhanced Registry, it is now possible to find threads by name or by pointer. - New threading API, now creating static threads is even faster. - Extended priority range to 1..255. +- New kernel hooks for a more flexible code instrumentation. - Experimental NASA OSAL implementation. *** What's new in HAL 4.1.0 *** @@ -38,4 +41,4 @@ a series of important new features. - Common ports architecture. - Ability to use the new shared RTOS components. - State checker. -- Parameter checks. +- Parameters checks. -- cgit v1.2.3