From 46f6f522993c83a80b4715bbfaa95347325ea019 Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Thu, 20 Jul 2017 11:59:26 -0500 Subject: [PATCH] Move RTX error handlers into RTX handler file Move the RTX error handlers out of mbed_retarget.cpp and into an the dedicated RTX handler file. --- platform/mbed_retarget.cpp | 69 ---------------------------------- rtos/rtx5/mbed_rtx_handlers.c | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 69 deletions(-) diff --git a/platform/mbed_retarget.cpp b/platform/mbed_retarget.cpp index a7092e4fc07..b41138f82fa 100644 --- a/platform/mbed_retarget.cpp +++ b/platform/mbed_retarget.cpp @@ -978,72 +978,3 @@ void operator delete[](void *ptr) free(ptr); } } - -#if defined(MBED_CONF_RTOS_PRESENT) && defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED - -static const char* error_msg(int32_t status) -{ - switch (status) { - case osError: - return "Unspecified RTOS error"; - case osErrorTimeout: - return "Operation not completed within the timeout period"; - case osErrorResource: - return "Resource not available"; - case osErrorParameter: - return "Parameter error"; - case osErrorNoMemory: - return "System is out of memory"; - case osErrorISR: - return "Not allowed in ISR context"; - default: - return "Unknown"; - } -} - -extern "C" void EvrRtxKernelError (int32_t status) -{ - error("Kernel error %i: %s\r\n", status, error_msg(status)); -} - -extern "C" void EvrRtxThreadError (osThreadId_t thread_id, int32_t status) -{ - error("Thread %p error %i: %s\r\n", thread_id, status, error_msg(status)); -} - -extern "C" void EvrRtxTimerError (osTimerId_t timer_id, int32_t status) -{ - error("Timer %p error %i: %s\r\n", timer_id, status, error_msg(status)); -} - -extern "C" void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status) -{ - error("Event %p error %i: %s\r\n", ef_id, status, error_msg(status)); -} - -extern "C" void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status) -{ - error("Mutex %p error %i: %s\r\n", mutex_id, status, error_msg(status)); -} - -extern "C" void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status) -{ - // Ignore semaphore overflow, the count will saturate with a returned error - if (status == osRtxErrorSemaphoreCountLimit) { - return; - } - - error("Semaphore %p error %i\r\n", semaphore_id, status); -} - -extern "C" void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status) -{ - error("Memory Pool %p error %i\r\n", mp_id, status); -} - -extern "C" void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status) -{ - error("Message Queue %p error %i\r\n", mq_id, status); -} - -#endif diff --git a/rtos/rtx5/mbed_rtx_handlers.c b/rtos/rtx5/mbed_rtx_handlers.c index ddc20f79d00..e5dcabaa790 100644 --- a/rtos/rtx5/mbed_rtx_handlers.c +++ b/rtos/rtx5/mbed_rtx_handlers.c @@ -16,6 +16,7 @@ #include "cmsis_compiler.h" #include "rtx_os.h" +#include "rtx_evr.h" #include "mbed_rtx.h" #include "mbed_error.h" @@ -66,3 +67,72 @@ __NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id) /* That shouldn't be reached */ for (;;) {} } + +#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED + +static const char* error_msg(int32_t status) +{ + switch (status) { + case osError: + return "Unspecified RTOS error"; + case osErrorTimeout: + return "Operation not completed within the timeout period"; + case osErrorResource: + return "Resource not available"; + case osErrorParameter: + return "Parameter error"; + case osErrorNoMemory: + return "System is out of memory"; + case osErrorISR: + return "Not allowed in ISR context"; + default: + return "Unknown"; + } +} + +void EvrRtxKernelError (int32_t status) +{ + error("Kernel error %i: %s\r\n", status, error_msg(status)); +} + +void EvrRtxThreadError (osThreadId_t thread_id, int32_t status) +{ + error("Thread %p error %i: %s\r\n", thread_id, status, error_msg(status)); +} + +void EvrRtxTimerError (osTimerId_t timer_id, int32_t status) +{ + error("Timer %p error %i: %s\r\n", timer_id, status, error_msg(status)); +} + +void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status) +{ + error("Event %p error %i: %s\r\n", ef_id, status, error_msg(status)); +} + +void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status) +{ + error("Mutex %p error %i: %s\r\n", mutex_id, status, error_msg(status)); +} + +void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status) +{ + // Ignore semaphore overflow, the count will saturate with a returned error + if (status == osRtxErrorSemaphoreCountLimit) { + return; + } + + error("Semaphore %p error %i\r\n", semaphore_id, status); +} + +void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status) +{ + error("Memory Pool %p error %i\r\n", mp_id, status); +} + +void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status) +{ + error("Message Queue %p error %i\r\n", mq_id, status); +} + +#endif