Skip to content

Commit b53e31d

Browse files
c1728p9adbridge
authored andcommitted
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_t
1 parent d1b3436 commit b53e31d

File tree

8 files changed

+24
-10
lines changed

8 files changed

+24
-10
lines changed

events/equeue/equeue_platform.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C" {
5151
#include <pthread.h>
5252
#elif defined(EQUEUE_PLATFORM_MBED)
5353
#include "cmsis_os2.h"
54-
#include "rtx_lib.h"
54+
#include "mbed_rtos_storage.h"
5555
#endif
5656

5757

@@ -117,7 +117,7 @@ typedef struct equeue_sema {
117117
#elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
118118
typedef struct equeue_sema {
119119
osEventFlagsId_t id;
120-
os_event_flags_t mem;
120+
mbed_rtos_storage_event_flags_t mem;
121121
} equeue_sema_t;
122122
#elif defined(EQUEUE_PLATFORM_MBED)
123123
typedef volatile int equeue_sema_t;

rtos/Mail.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "Queue.h"
2929
#include "MemoryPool.h"
3030
#include "cmsis_os2.h"
31-
#include "rtx_lib.h"
31+
#include "mbed_rtos_storage.h"
3232
#include "mbed_rtos1_types.h"
3333

3434
#include "platform/NonCopyable.h"

rtos/RtosTimer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include <stdint.h>
2626
#include "cmsis_os2.h"
27-
#include "rtx_lib.h"
27+
#include "mbed_rtos_storage.h"
2828
#include "platform/Callback.h"
2929
#include "platform/NonCopyable.h"
3030
#include "platform/mbed_toolchain.h"
@@ -150,7 +150,7 @@ class RtosTimer : private mbed::NonCopyable<RtosTimer> {
150150

151151
osTimerId_t _id;
152152
osTimerAttr_t _attr;
153-
os_timer_t _obj_mem;
153+
mbed_rtos_storage_timer_t _obj_mem;
154154
mbed::Callback<void()> _function;
155155
};
156156

rtos/Thread.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ Thread::State Thread::get_state() {
168168
_mutex.lock();
169169

170170
if (_tid != NULL) {
171+
#if defined(MBED_OS_BACKEND_RTX5)
171172
state = _obj_mem.state;
173+
#else
174+
state = osThreadGetState(_tid);
175+
#endif
172176
}
173177

174178
_mutex.unlock();
@@ -185,6 +189,7 @@ Thread::State Thread::get_state() {
185189
case osThreadRunning:
186190
user_state = Running;
187191
break;
192+
#if defined(MBED_OS_BACKEND_RTX5)
188193
case osRtxThreadWaitingDelay:
189194
user_state = WaitingDelay;
190195
break;
@@ -212,6 +217,7 @@ Thread::State Thread::get_state() {
212217
case osRtxThreadWaitingMessagePut:
213218
user_state = WaitingMessagePut;
214219
break;
220+
#endif
215221
case osThreadTerminated:
216222
default:
217223
user_state = Deleted;
@@ -226,8 +232,7 @@ uint32_t Thread::stack_size() {
226232
_mutex.lock();
227233

228234
if (_tid != NULL) {
229-
os_thread_t *thread = (os_thread_t *)_tid;
230-
size = thread->stack_size;
235+
size = osThreadGetStackSize(_tid);
231236
}
232237

233238
_mutex.unlock();
@@ -238,10 +243,12 @@ uint32_t Thread::free_stack() {
238243
uint32_t size = 0;
239244
_mutex.lock();
240245

246+
#if defined(MBED_OS_BACKEND_RTX5)
241247
if (_tid != NULL) {
242248
os_thread_t *thread = (os_thread_t *)_tid;
243249
size = (uint32_t)thread->sp - (uint32_t)thread->stack_mem;
244250
}
251+
#endif
245252

246253
_mutex.unlock();
247254
return size;
@@ -251,10 +258,12 @@ uint32_t Thread::used_stack() {
251258
uint32_t size = 0;
252259
_mutex.lock();
253260

261+
#if defined(MBED_OS_BACKEND_RTX5)
254262
if (_tid != NULL) {
255263
os_thread_t *thread = (os_thread_t *)_tid;
256264
size = ((uint32_t)thread->stack_mem + thread->stack_size) - thread->sp;
257265
}
266+
#endif
258267

259268
_mutex.unlock();
260269
return size;
@@ -265,11 +274,15 @@ uint32_t Thread::max_stack() {
265274
_mutex.lock();
266275

267276
if (_tid != NULL) {
277+
#if defined(MBED_OS_BACKEND_RTX5)
268278
os_thread_t *thread = (os_thread_t *)_tid;
269279
uint32_t high_mark = 0;
270280
while (((uint32_t *)(thread->stack_mem))[high_mark] == 0xE25A2EA5)
271281
high_mark++;
272282
size = thread->stack_size - (high_mark * sizeof(uint32_t));
283+
#else
284+
size = osThreadGetStackSize(_tid) - osThreadGetStackSpace(_tid);
285+
#endif
273286
}
274287

275288
_mutex.unlock();

rtos/Thread.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "cmsis_os2.h"
2727
#include "mbed_rtos1_types.h"
2828
#include "mbed_rtos_storage.h"
29-
#include "mbed_rtx_conf.h"
3029
#include "platform/Callback.h"
3130
#include "platform/mbed_toolchain.h"
3231
#include "platform/NonCopyable.h"

rtos/mbed_rtos_storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern "C" {
4141
*/
4242

4343
#include "rtx_lib.h"
44+
#include "mbed_rtx_conf.h"
4445

4546
typedef os_mutex_t mbed_rtos_storage_mutex_t;
4647
typedef os_semaphore_t mbed_rtos_storage_semaphore_t;

rtos/rtos.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#ifndef RTOS_H
2626
#define RTOS_H
2727

28-
#include "mbed_rtx.h"
29-
#include "mbed_rtx_conf.h"
3028
#include "mbed_rtos_storage.h"
3129
#include "rtos/Thread.h"
3230
#include "rtos/Mutex.h"

rtos/rtx5/mbed_rtx_conf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#include "mbed_rtx.h"
2626

27+
/** Any access to RTX5 specific data structures used in common code should be wrapped in ifdef MBED_OS_BACKEND_RTX5 */
28+
#define MBED_OS_BACKEND_RTX5
29+
2730
/** The thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */
2831
#ifndef MBED_CONF_APP_THREAD_STACK_SIZE
2932
#define MBED_CONF_APP_THREAD_STACK_SIZE 4096

0 commit comments

Comments
 (0)