Skip to content

Commit 0aa2743

Browse files
committed
Make example build with mbed OS feature_cmsis5
Add support for building with RTX2, breaking compatibility with the previous version of RTX.
1 parent 67e9a0b commit 0aa2743

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

source/led1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct box_context {
1212
static const UvisorBoxAclItem acl[] = {
1313
};
1414

15-
static void led1_main(const void *);
15+
static void led1_main(void *);
1616

1717
/* Box configuration
1818
* We do not need large stacks in either the main nor the interrupt thread, as
@@ -24,7 +24,7 @@ UVISOR_BOX_CONFIG(box_led1, acl, 512, box_context);
2424

2525
#define uvisor_ctx ((box_context *) __uvisor_ctx)
2626

27-
static void led1_main(const void *)
27+
static void led1_main(void *)
2828
{
2929
DigitalOut led1(LED1);
3030
led1 = LED_OFF;

source/led2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct box_context {
1212
static const UvisorBoxAclItem acl[] = {
1313
};
1414

15-
static void led2_main(const void *);
15+
static void led2_main(void *);
1616

1717
/* Box configuration
1818
* We do not need large stacks in either the main nor the interrupt thread, as
@@ -24,7 +24,7 @@ UVISOR_BOX_CONFIG(box_led2, acl, 512, box_context);
2424

2525
#define uvisor_ctx ((box_context *) __uvisor_ctx)
2626

27-
static void led2_main(const void *)
27+
static void led2_main(void *)
2828
{
2929
DigitalOut led2(LED2);
3030
led2 = LED_OFF;

source/led3.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct box_context {
1212
static const UvisorBoxAclItem acl[] = {
1313
};
1414

15-
static void led3_main(const void *);
15+
static void led3_main(void *);
1616

1717
/* Box configuration
1818
* We need at least 1kB in the main thread as we use printf in it. The interrupt
@@ -36,9 +36,17 @@ static void run_3(void)
3636
}
3737
}
3838

39-
static void led3_main(const void *)
39+
/* A thin wrapper around run_3 that accepts and ignores a context. This avoid a
40+
* cast, as mbed's Thread and RTX's osThreadContextNew operate on differently
41+
* typed thread functions. */
42+
static void run_3_context(void *)
4043
{
41-
osStatus status;
44+
run_3();
45+
}
46+
47+
static void led3_main(void *)
48+
{
49+
osStatus_t status;
4250
DigitalOut led3(LED3);
4351
led3 = LED_OFF;
4452

@@ -60,14 +68,16 @@ static void led3_main(const void *)
6068
const uint32_t kB = 1024;
6169
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
6270
/* Prepare the thread definition structure. */
63-
osThreadDef_t thread_def;
64-
thread_def.stacksize = 512;
71+
osThreadAttr_t thread_attr = {0};
72+
os_thread_t thread_def = {0};
73+
thread_def.stack_size = 512;
6574
/* Allocate the stack inside the page allocator! */
66-
thread_def.stack_pointer = (uint32_t *) secure_malloc(alloc, DEFAULT_STACK_SIZE);
67-
thread_def.tpriority = osPriorityNormal;
68-
thread_def.pthread = (void (*)(const void *)) &run_3;
75+
thread_attr.stack_mem = (uint32_t *) secure_malloc(alloc, 512);
76+
thread_def.priority = osPriorityNormal;
77+
thread_attr.cb_size = sizeof(thread_def);
78+
thread_attr.cb_mem = &thread_def;
6979
/* Create a thread with the page allocator as heap. */
70-
osThreadContextCreate(&thread_def, NULL, alloc);
80+
osThreadContextNew(run_3_context, NULL, &thread_attr, alloc);
7181

7282
while (1) {
7383
static const size_t size = 20;

source/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static void main_alloc(void)
4343
int main(void)
4444
{
4545
Thread thread(osPriorityNormal, 512, NULL);
46-
osStatus status = thread.start(main_alloc);
46+
osStatus_t status = thread.start(main_alloc);
4747
if (status != osOK) {
4848
printf("Could not start main thread.\r\n");
4949
uvisor_error(USER_NOT_ALLOWED);

0 commit comments

Comments
 (0)