Skip to content

Commit dfae9c5

Browse files
committed
Fix style
* Correct spacing around operators. * Spell out stack sizes explicitly. * Minor fixes.
1 parent b76224b commit dfae9c5

File tree

4 files changed

+37
-30
lines changed

4 files changed

+37
-30
lines changed

source/led1.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ 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) {
3134
static const size_t size = 500;
@@ -34,6 +37,6 @@ static void led1_main(const void *)
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: 11 additions & 8 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(8 * 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,13 +36,13 @@ 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

@@ -52,9 +55,9 @@ static void led2_main(const void *)
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: 11 additions & 9 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(8 * 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,23 +40,23 @@ 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;
5962
thread_def.stacksize = DEFAULT_STACK_SIZE;
@@ -64,7 +67,6 @@ static void led3_main(const void *)
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.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@
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) {
3637
alloc_fill_wait_verify_free(500, seed, 577);
37-
specific_alloc_fill_wait_verify_free(alloc, 5*kB, seed, 97);
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);
@@ -53,8 +53,7 @@ int main(void)
5353

5454
size_t count = 0;
5555

56-
while (1)
57-
{
56+
while (1) {
5857
printf("Main loop count: %d\r\n", count++);
5958
}
6059

0 commit comments

Comments
 (0)