mirror of https://github.com/ARMmbed/mbed-os.git
Remove use of internal RTX types
Make calls to cmsis-os to get thread state, stack size, and max stack usage rather than accessing internal RTX data directly. Wrap RTX5 specific code in OS_BACKEND_RTX5. Also refactor the code to use mbed types rather than RTX types: os_timer_t -> mbed_rtos_storage_timer_t os_event_flags_t -> mbed_rtos_storage_event_flags_t osRtxMutex_t -> mbed_rtos_storage_thread_tpull/4776/head
parent
5bddd881e9
commit
b2384b1629
|
@ -51,7 +51,7 @@ extern "C" {
|
|||
#include <pthread.h>
|
||||
#elif defined(EQUEUE_PLATFORM_MBED)
|
||||
#include "cmsis_os2.h"
|
||||
#include "rtx_lib.h"
|
||||
#include "mbed_rtos_storage.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -117,7 +117,7 @@ typedef struct equeue_sema {
|
|||
#elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
|
||||
typedef struct equeue_sema {
|
||||
osEventFlagsId_t id;
|
||||
os_event_flags_t mem;
|
||||
mbed_rtos_storage_event_flags_t mem;
|
||||
} equeue_sema_t;
|
||||
#elif defined(EQUEUE_PLATFORM_MBED)
|
||||
typedef volatile int equeue_sema_t;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "Queue.h"
|
||||
#include "MemoryPool.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "rtx_lib.h"
|
||||
#include "mbed_rtos_storage.h"
|
||||
#include "mbed_rtos1_types.h"
|
||||
|
||||
#include "platform/NonCopyable.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include "cmsis_os2.h"
|
||||
#include "rtx_lib.h"
|
||||
#include "mbed_rtos_storage.h"
|
||||
#include "platform/Callback.h"
|
||||
#include "platform/NonCopyable.h"
|
||||
#include "platform/mbed_toolchain.h"
|
||||
|
@ -150,7 +150,7 @@ private:
|
|||
|
||||
osTimerId_t _id;
|
||||
osTimerAttr_t _attr;
|
||||
os_timer_t _obj_mem;
|
||||
mbed_rtos_storage_timer_t _obj_mem;
|
||||
mbed::Callback<void()> _function;
|
||||
};
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ extern "C" {
|
|||
*/
|
||||
|
||||
#include "rtx_lib.h"
|
||||
#include "mbed_rtx_conf.h"
|
||||
|
||||
typedef os_mutex_t mbed_rtos_storage_mutex_t;
|
||||
typedef os_semaphore_t mbed_rtos_storage_semaphore_t;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
#include "mbed_rtx.h"
|
||||
|
||||
/** Any access to RTX5 specific data structures used in common code should be wrapped in ifdef MBED_OS_BACKEND_RTX5 */
|
||||
#define MBED_OS_BACKEND_RTX5
|
||||
|
||||
/** The thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */
|
||||
#ifndef MBED_CONF_APP_THREAD_STACK_SIZE
|
||||
#define MBED_CONF_APP_THREAD_STACK_SIZE 4096
|
||||
|
|
|
@ -168,7 +168,11 @@ Thread::State Thread::get_state() {
|
|||
_mutex.lock();
|
||||
|
||||
if (_tid != NULL) {
|
||||
#if defined(MBED_OS_BACKEND_RTX5)
|
||||
state = _obj_mem.state;
|
||||
#else
|
||||
state = osThreadGetState(_tid);
|
||||
#endif
|
||||
}
|
||||
|
||||
_mutex.unlock();
|
||||
|
@ -185,6 +189,7 @@ Thread::State Thread::get_state() {
|
|||
case osThreadRunning:
|
||||
user_state = Running;
|
||||
break;
|
||||
#if defined(MBED_OS_BACKEND_RTX5)
|
||||
case osRtxThreadWaitingDelay:
|
||||
user_state = WaitingDelay;
|
||||
break;
|
||||
|
@ -212,6 +217,7 @@ Thread::State Thread::get_state() {
|
|||
case osRtxThreadWaitingMessagePut:
|
||||
user_state = WaitingMessagePut;
|
||||
break;
|
||||
#endif
|
||||
case osThreadTerminated:
|
||||
default:
|
||||
user_state = Deleted;
|
||||
|
@ -226,8 +232,7 @@ uint32_t Thread::stack_size() {
|
|||
_mutex.lock();
|
||||
|
||||
if (_tid != NULL) {
|
||||
os_thread_t *thread = (os_thread_t *)_tid;
|
||||
size = thread->stack_size;
|
||||
size = osThreadGetStackSize(_tid);
|
||||
}
|
||||
|
||||
_mutex.unlock();
|
||||
|
@ -238,10 +243,12 @@ uint32_t Thread::free_stack() {
|
|||
uint32_t size = 0;
|
||||
_mutex.lock();
|
||||
|
||||
#if defined(MBED_OS_BACKEND_RTX5)
|
||||
if (_tid != NULL) {
|
||||
os_thread_t *thread = (os_thread_t *)_tid;
|
||||
size = (uint32_t)thread->sp - (uint32_t)thread->stack_mem;
|
||||
}
|
||||
#endif
|
||||
|
||||
_mutex.unlock();
|
||||
return size;
|
||||
|
@ -251,10 +258,12 @@ uint32_t Thread::used_stack() {
|
|||
uint32_t size = 0;
|
||||
_mutex.lock();
|
||||
|
||||
#if defined(MBED_OS_BACKEND_RTX5)
|
||||
if (_tid != NULL) {
|
||||
os_thread_t *thread = (os_thread_t *)_tid;
|
||||
size = ((uint32_t)thread->stack_mem + thread->stack_size) - thread->sp;
|
||||
}
|
||||
#endif
|
||||
|
||||
_mutex.unlock();
|
||||
return size;
|
||||
|
@ -265,11 +274,15 @@ uint32_t Thread::max_stack() {
|
|||
_mutex.lock();
|
||||
|
||||
if (_tid != NULL) {
|
||||
#if defined(MBED_OS_BACKEND_RTX5)
|
||||
os_thread_t *thread = (os_thread_t *)_tid;
|
||||
uint32_t high_mark = 0;
|
||||
while (((uint32_t *)(thread->stack_mem))[high_mark] == 0xE25A2EA5)
|
||||
high_mark++;
|
||||
size = thread->stack_size - (high_mark * sizeof(uint32_t));
|
||||
#else
|
||||
size = osThreadGetStackSize(_tid) - osThreadGetStackSpace(_tid);
|
||||
#endif
|
||||
}
|
||||
|
||||
_mutex.unlock();
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "cmsis_os2.h"
|
||||
#include "mbed_rtos1_types.h"
|
||||
#include "mbed_rtos_storage.h"
|
||||
#include "mbed_rtx_conf.h"
|
||||
#include "platform/Callback.h"
|
||||
#include "platform/mbed_toolchain.h"
|
||||
#include "platform/NonCopyable.h"
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#ifndef RTOS_H
|
||||
#define RTOS_H
|
||||
|
||||
#include "mbed_rtx.h"
|
||||
#include "mbed_rtx_conf.h"
|
||||
#include "mbed_rtos_storage.h"
|
||||
#include "rtos/Thread.h"
|
||||
#include "rtos/Mutex.h"
|
||||
|
|
Loading…
Reference in New Issue