Skip to content

Commit eea5db5

Browse files
authored
Merge pull request #30 from AlessandroA/minor_fixes
Minor improvements to the app
2 parents 0fd174e + 4d138d6 commit eea5db5

File tree

9 files changed

+186
-1653
lines changed

9 files changed

+186
-1653
lines changed

.gitignore

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
# Misc hidden files
12
.DS_Store
2-
.build
3-
gdb.script
43
*.sw*
4+
5+
# mbed files and folders
6+
.build
7+
BUILD
8+
mbed-os
9+
mbed-os/*
510
mbed_settings.py*
6-
/mbed-os/
7-
/firmware.*
8-
/debug.elf
11+
.mbed
12+
13+
# Custom Makefile temp files
14+
gdb.script
15+
firmware.*
16+
debug.elf

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $ screen /dev/tty.usbmodem1422 9600
3131
You will see an output similar to the following one:
3232

3333
```
34-
***** threaded blinky uvisor-rtos example *****
34+
***** Threaded blinky uVisor example *****
3535
Main loop count: 0
3636
Main loop count: 1
3737
Main loop count: 2

mbed_app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"target_overrides": {
3-
"K64F": {
3+
"*": {
44
"target.features_add": ["UVISOR"],
55
"target.extra_labels_add": ["UVISOR_SUPPORTED"]
66
}

source/led1.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,29 @@ static const UvisorBoxAclItem acl[] = {
1414

1515
static void led1_main(const void *);
1616

17+
/* Box configuration
18+
* We do not need large stacks in either the main nor the interrupt thread, as
19+
* we do not do anything special in them. */
1720
UVISOR_BOX_NAMESPACE(NULL);
18-
UVISOR_BOX_HEAPSIZE(8192);
19-
UVISOR_BOX_MAIN(led1_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
20-
UVISOR_BOX_CONFIG(box_led1, acl, UVISOR_BOX_STACK_SIZE, box_context);
21+
UVISOR_BOX_HEAPSIZE(3 * 1024);
22+
UVISOR_BOX_MAIN(led1_main, osPriorityNormal, 512);
23+
UVISOR_BOX_CONFIG(box_led1, acl, 512, box_context);
2124

2225
static void led1_main(const void *)
2326
{
2427
DigitalOut led1(LED1);
2528
led1 = LED_OFF;
2629
const uint32_t kB = 1024;
2730

28-
SecureAllocator alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
31+
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
2932

3033
while (1) {
31-
static const size_t size = 500;
34+
static const size_t size = 50;
3235
uint16_t seed = (size << 8) | (uvisor_ctx->heartbeat & 0xFF);
3336

3437
led1 = !led1;
3538
++uvisor_ctx->heartbeat;
3639
alloc_fill_wait_verify_free(size, seed, 211);
37-
specific_alloc_fill_wait_verify_free(alloc, 5*kB, seed, 107);
40+
specific_alloc_fill_wait_verify_free(alloc, 5 * kB, seed, 107);
3841
}
3942
}

source/led2.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ static const UvisorBoxAclItem acl[] = {
1414

1515
static void led2_main(const void *);
1616

17+
/* Box configuration
18+
* We do not need large stacks in either the main nor the interrupt thread, as
19+
* we do not do anything special in them. */
1720
UVISOR_BOX_NAMESPACE(NULL);
18-
UVISOR_BOX_HEAPSIZE(8192);
19-
UVISOR_BOX_MAIN(led2_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
20-
UVISOR_BOX_CONFIG(box_led2, acl, UVISOR_BOX_STACK_SIZE, box_context);
21+
UVISOR_BOX_HEAPSIZE(3 * 1024);
22+
UVISOR_BOX_MAIN(led2_main, osPriorityNormal, 512);
23+
UVISOR_BOX_CONFIG(box_led2, acl, 512, box_context);
2124

2225
static void led2_main(const void *)
2326
{
@@ -33,28 +36,28 @@ static void led2_main(const void *)
3336
* page heap!
3437
*/
3538
/* Allocate one page. */
36-
alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
39+
alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
3740
/* Allocate another page. */
38-
SecureAllocator alloc2 = secure_allocator_create_with_pages(4*kB, 1*kB);
41+
SecureAllocator alloc2 = secure_allocator_create_with_pages(4 * kB, 1 * kB);
3942
/* Deallocate alloc1 page, creating a hole. */
4043
secure_allocator_destroy(alloc);
4144
/* Allocate two pages. */
42-
alloc = secure_allocator_create_with_pages(uvisor_get_page_size() + 3*kB, 6*kB);
45+
alloc = secure_allocator_create_with_pages(uvisor_get_page_size() + 3 * kB, 6 * kB);
4346
/* Deallocate alloc2 page, creating another hole. */
4447
secure_allocator_destroy(alloc2);
4548

4649
while (1) {
47-
static const size_t size = 300;
50+
static const size_t size = 30;
4851
uint16_t seed = (size << 8) | (uvisor_ctx->heartbeat & 0xFF);
4952

5053
led2 = !led2;
5154
++uvisor_ctx->heartbeat;
5255
alloc_fill_wait_verify_free(size, seed, 311);
5356

5457
/* Allocate in first page */
55-
specific_alloc_fill_wait_verify_free(alloc, 6*kB, seed, 0);
58+
specific_alloc_fill_wait_verify_free(alloc, 6 * kB, seed, 0);
5659

5760
/* Allocate in second page */
58-
specific_alloc_fill_wait_verify_free(alloc, 6*kB, seed, 101);
61+
specific_alloc_fill_wait_verify_free(alloc, 6 * kB, seed, 101);
5962
}
6063
}

source/led3.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ static const UvisorBoxAclItem acl[] = {
1414

1515
static void led3_main(const void *);
1616

17+
/* Box configuration
18+
* We need at least 1kB in the main thread as we use printf in it. The interrupt
19+
* stack size can be smaller as we do not do anything special in them. */
1720
UVISOR_BOX_NAMESPACE(NULL);
18-
UVISOR_BOX_HEAPSIZE(8192);
19-
UVISOR_BOX_MAIN(led3_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
20-
UVISOR_BOX_CONFIG(box_led3, acl, UVISOR_BOX_STACK_SIZE, box_context);
21+
UVISOR_BOX_HEAPSIZE(3 * 1024);
22+
UVISOR_BOX_MAIN(led3_main, osPriorityNormal, 1024);
23+
UVISOR_BOX_CONFIG(box_led3, acl, 512, box_context);
2124

2225
static void run_3(void)
2326
{
@@ -37,34 +40,33 @@ static void led3_main(const void *)
3740
DigitalOut led3(LED3);
3841
led3 = LED_OFF;
3942

40-
Thread * thread1 = new Thread();
41-
status = thread1->start(run_3);
43+
Thread thread1(osPriorityNormal, 512, NULL);
44+
status = thread1.start(run_3);
4245
if (status != osOK) {
4346
printf("Could not start box_led3 thread1.\r\n");
4447
uvisor_error(USER_NOT_ALLOWED);
4548
}
4649

47-
Thread * thread2 = new Thread();
48-
status = thread2->start(run_3);
50+
Thread thread2(osPriorityNormal, 512, NULL);
51+
status = thread2.start(run_3);
4952
if (status != osOK) {
5053
printf("Could not start box_led3 thread2.\r\n");
5154
uvisor_error(USER_NOT_ALLOWED);
5255
}
5356

5457
/* Create page-backed allocator. */
5558
const uint32_t kB = 1024;
56-
SecureAllocator alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
59+
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
5760
/* Prepare the thread definition structure. */
5861
osThreadDef_t thread_def;
59-
thread_def.stacksize = DEFAULT_STACK_SIZE;
62+
thread_def.stacksize = 512;
6063
/* Allocate the stack inside the page allocator! */
6164
thread_def.stack_pointer = (uint32_t *) secure_malloc(alloc, DEFAULT_STACK_SIZE);
6265
thread_def.tpriority = osPriorityNormal;
6366
thread_def.pthread = (void (*)(const void *)) &run_3;
6467
/* Create a thread with the page allocator as heap. */
6568
osThreadContextCreate(&thread_def, NULL, alloc);
6669

67-
6870
while (1) {
6971
static const size_t size = 20;
7072
uint16_t seed = (size << 8) | (uvisor_ctx->heartbeat & 0xFF);

source/main-hw.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@
1717
#ifndef __UVISOR_HELLOWORLD_MAIN_HW_H__
1818
#define __UVISOR_HELLOWORLD_MAIN_HW_H__
1919

20-
/* The vector containing the challenge is shared with the push-button ISR, so
21-
* that it can attempt to access it from an IRQ context. */
20+
#if defined(TARGET_K64F)
2221

23-
#define LED_ON true
24-
#define LED_OFF false
25-
26-
#define MAIN_LED LED_BLUE
27-
#define HALT_LED LED_RED
28-
29-
#define MAIN_BTN SW2
30-
#define MAIN_BTN_PUPD PullUp
22+
#define MAIN_LED LED1
23+
#define SECURE_LED LED2
24+
#define LED_ON false
25+
#define LED_OFF true
26+
#define SECURE_SWITCH SW2
27+
#define SECURE_SWITCH_PULL PullUp
3128

3229
#define MAIN_ACL(acl_list_name) \
3330
static const UvisorBoxAclItem acl_list_name[] = { \
@@ -48,4 +45,10 @@
4845
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
4946
}
5047

48+
#else /* Target-specific settings */
49+
50+
#error "Unsupported target. Checkout the README.md file for the list of supported targets for this app."
51+
52+
#endif /* Target-specific settings */
53+
5154
#endif /* __UVISOR_HELLOWORLD_MAIN_HW_H__ */

source/main.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,40 @@
2222

2323
/* Create ACLs for main box. */
2424
MAIN_ACL(g_main_acl);
25+
2526
/* Enable uVisor. */
2627
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_main_acl);
27-
UVISOR_SET_PAGE_HEAP(8*1024, 5);
28+
UVISOR_SET_PAGE_HEAP(8 * 1024, 5);
2829

2930
static void main_alloc(void)
3031
{
3132
const uint32_t kB = 1024;
3233
uint16_t seed = 0x10;
33-
SecureAllocator alloc = secure_allocator_create_with_pages(4*kB, 1*kB);
34+
SecureAllocator alloc = secure_allocator_create_with_pages(4 * kB, 1 * kB);
3435

3536
while (1) {
36-
alloc_fill_wait_verify_free(500, seed, 577);
37-
specific_alloc_fill_wait_verify_free(alloc, 5*kB, seed, 97);
37+
alloc_fill_wait_verify_free(50, seed, 577);
38+
specific_alloc_fill_wait_verify_free(alloc, 5 * kB, seed, 97);
3839
seed++;
3940
}
4041
}
4142

4243
int main(void)
4344
{
44-
osStatus status;
45-
Thread * thread = new Thread();
46-
status = thread->start(main_alloc);
45+
Thread thread(osPriorityNormal, 512, NULL);
46+
osStatus status = thread.start(main_alloc);
4747
if (status != osOK) {
4848
printf("Could not start main thread.\r\n");
4949
uvisor_error(USER_NOT_ALLOWED);
5050
}
5151

52-
printf("\r\n***** threaded blinky uvisor-rtos example *****\r\n");
52+
printf("\r\n***** Threaded blinky uVisor example *****\r\n");
5353

5454
size_t count = 0;
5555

56-
while (1)
57-
{
56+
while (1) {
5857
printf("Main loop count: %d\r\n", count++);
58+
Thread::wait(500);
5959
}
6060

6161
return 0;

0 commit comments

Comments
 (0)