Skip to content

Commit 09b02c0

Browse files
committed
Fix style
* Comments capitalization and punctuation. * Explicit use of stack sizes. * Minor fixes.
1 parent 1c234e6 commit 09b02c0

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

source/led.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,54 @@ static const UvisorBoxAclItem acl[] = {
2929

3030
static void my_box_main(const void *);
3131

32+
/* Box configuration
33+
* We need 1kB of stack both in the main and interrupt threads as both of them
34+
* use printf. */
3235
UVISOR_BOX_NAMESPACE(NULL);
3336
UVISOR_BOX_HEAPSIZE(3072);
34-
UVISOR_BOX_MAIN(my_box_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
35-
UVISOR_BOX_CONFIG(my_box, acl, UVISOR_BOX_STACK_SIZE, my_box_context);
37+
UVISOR_BOX_MAIN(my_box_main, osPriorityNormal, 1024);
38+
UVISOR_BOX_CONFIG(my_box, acl, 1024, my_box_context);
3639

3740
static void my_box_switch_irq(void)
3841
{
39-
/* flip LED state */
42+
/* Flip LED state. */
4043
*uvisor_ctx->led = !*uvisor_ctx->led;
4144

42-
/* print LED state on serial port */
43-
uvisor_ctx->pc->printf(
44-
"\nPressed SW2, printing from interrupt - LED changed to %i\n\n",
45-
(int)(*uvisor_ctx->led));
45+
/* Print LED state on serial port. */
46+
uvisor_ctx->pc->printf("\r\nPressed switch, printing from interrupt - LED changed to %i\r\n\r\n",
47+
(int) (*uvisor_ctx->led));
4648
}
4749

4850
static void my_box_main(const void *)
4951
{
50-
/* allocate serial port to ensure that code in this secure box
51-
* won't touch handle in the default security context when printing */
52-
RawSerial *pc;
53-
if(!(pc = new RawSerial(USBTX, USBRX)))
52+
/* Allocate the serial port to ensure that code in this secure box won't
53+
* touch handles in the default security context when printing. */
54+
RawSerial * pc;
55+
if (!(pc = new RawSerial(USBTX, USBRX))) {
5456
return;
55-
/* remember serial driver for IRQ routine */
57+
}
58+
59+
/* Remember serial driver for IRQ routine. */
5660
uvisor_ctx->pc = pc;
5761

58-
/* allocate a box-specific LED */
59-
if(!(uvisor_ctx->led = new DigitalOut(SECURE_LED)))
60-
pc->printf("ERROR: failed to allocate memories for LED\n");
61-
else
62-
{
63-
/* turn LED off by default */
62+
/* Allocate a box-specific LED. */
63+
if (!(uvisor_ctx->led = new DigitalOut(SECURE_LED))) {
64+
pc->printf("ERROR: failed to allocate memories for LED\r\n");
65+
} else {
66+
/* Turn LED off by default */
6467
*uvisor_ctx->led = LED_OFF;
6568

66-
/* allocate a box-specific switch handler */
67-
if(!(uvisor_ctx->sw = new InterruptIn(SECURE_SWITCH)))
68-
pc->printf("ERROR: failed to allocate memories for SW1\n");
69-
else
70-
{
71-
/* register handler for switch SW1 */
69+
/* Allocate a box-specific switch handler. */
70+
if (!(uvisor_ctx->sw = new InterruptIn(SECURE_SWITCH))) {
71+
pc->printf("ERROR: failed to allocate memories for switch\r\n");
72+
} else {
73+
/* Register handler for switch. */
7274
uvisor_ctx->sw->mode(SECURE_SWITCH_PULL);
7375
uvisor_ctx->sw->fall(my_box_switch_irq);
7476

75-
/* no problem to return here as everything is initialized */
77+
/* No problem to return here as everything is initialized. */
7678
return;
7779
}
78-
7980
delete uvisor_ctx->led;
8081
}
8182
delete pc;

source/main.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,21 @@ MAIN_ACL(g_main_acl);
2323

2424
/* Enable uVisor. */
2525
UVISOR_SET_MODE_ACL(UVISOR_ENABLED, g_main_acl);
26-
UVISOR_SET_PAGE_HEAP(8*1024, 5);
26+
UVISOR_SET_PAGE_HEAP(8 * 1024, 5);
2727

2828
int main(void)
2929
{
30-
DigitalOut led1(MAIN_LED);
30+
DigitalOut led(MAIN_LED);
3131

3232
printf("\r\n***** IRQ blinky uvisor-rtos example *****\r\n");
3333

3434
size_t count = 0;
3535

36-
while (1)
37-
{
36+
while (1) {
3837
printf("Main loop count: %d\r\n", count++);
39-
led1 = !led1;
38+
led = !led;
4039

41-
/* blink once per second */
40+
/* Blink once per second. */
4241
Thread::wait(500);
4342
}
4443

0 commit comments

Comments
 (0)