@@ -36,6 +36,16 @@ static void run_3(void)
36
36
}
37
37
}
38
38
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
+
39
49
static void led3_main (const void *)
40
50
{
41
51
osStatus status;
@@ -60,6 +70,22 @@ static void led3_main(const void *)
60
70
const uint32_t kB = 1024 ;
61
71
SecureAllocator alloc = secure_allocator_create_with_pages (4 * kB , 1 * kB );
62
72
/* 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
63
89
osThreadDef_t thread_def;
64
90
thread_def.stacksize = 512 ;
65
91
/* Allocate the stack inside the page allocator! */
@@ -68,6 +94,7 @@ static void led3_main(const void *)
68
94
thread_def.pthread = (void (*)(const void *)) &run_3;
69
95
/* Create a thread with the page allocator as heap. */
70
96
osThreadContextCreate (&thread_def, NULL , alloc);
97
+ #endif
71
98
72
99
while (1 ) {
73
100
static const size_t size = 20 ;
0 commit comments