Skip to content

Commit 5493f55

Browse files
committed
Make example build with mbed OS feature_cmsis5
Add support for building with RTX2, without breaking compatibility with the previous version of RTX.
1 parent 6b507c3 commit 5493f55

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

source/led3.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ static void run_3(void)
3636
}
3737
}
3838

39+
#if (osCMSIS >= 0x20000U)
40+
/* A thin wrapper around run_3 that accepts and ignores a context. This avoid a
41+
* cast, as mbed's Thread and RTX's osThreadContextNew operate on differently
42+
* typed thread functions. */
43+
static void run_3_context(void *)
44+
{
45+
run_3();
46+
}
47+
#endif
48+
3949
static void led3_main(const void *)
4050
{
4151
osStatus status;
@@ -60,6 +70,22 @@ static void led3_main(const void *)
6070
const uint32_t kB = 1024;
6171
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
6272
/* Prepare the thread definition structure. */
73+
/* FIXME: Remove the dependency on the CMSIS OS version after mbed OS has
74+
* completed its migration to CMSIS 5 RTX 2. We only need to keep both
75+
* around so that the example will work both before and after the
76+
* migration. */
77+
#if (osCMSIS >= 0x20000U)
78+
osThreadAttr_t thread_attr = {0};
79+
os_thread_t thread_def = {0};
80+
thread_def.stack_size = 512;
81+
/* Allocate the stack inside the page allocator! */
82+
thread_attr.stack_mem = (uint32_t *) secure_malloc(alloc, 512);
83+
thread_def.priority = osPriorityNormal;
84+
thread_attr.cb_size = sizeof(thread_def);
85+
thread_attr.cb_mem = &thread_def;
86+
/* Create a thread with the page allocator as heap. */
87+
osThreadContextNew(run_3_context, NULL, &thread_attr, alloc);
88+
#else
6389
osThreadDef_t thread_def;
6490
thread_def.stacksize = 512;
6591
/* Allocate the stack inside the page allocator! */
@@ -68,6 +94,7 @@ static void led3_main(const void *)
6894
thread_def.pthread = (void (*)(const void *)) &run_3;
6995
/* Create a thread with the page allocator as heap. */
7096
osThreadContextCreate(&thread_def, NULL, alloc);
97+
#endif
7198

7299
while (1) {
73100
static const size_t size = 20;

0 commit comments

Comments
 (0)