@@ -29,53 +29,54 @@ static const UvisorBoxAclItem acl[] = {
29
29
30
30
static void my_box_main (const void *);
31
31
32
+ /* Box configuration
33
+ * We need 1kB of stack both in the main and interrupt threads as both of them
34
+ * use printf. */
32
35
UVISOR_BOX_NAMESPACE (NULL );
33
36
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);
36
39
37
40
static void my_box_switch_irq (void )
38
41
{
39
- /* flip LED state */
42
+ /* Flip LED state. */
40
43
*uvisor_ctx->led = !*uvisor_ctx->led ;
41
44
42
- /* print LED state on serial port */
43
- uvisor_ctx->pc ->printf (
44
- " \n Pressed 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\n Pressed switch, printing from interrupt - LED changed to %i\r\n\r\n " ,
47
+ (int ) (*uvisor_ctx->led ));
46
48
}
47
49
48
50
static void my_box_main (const void *)
49
51
{
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))) {
54
56
return ;
55
- /* remember serial driver for IRQ routine */
57
+ }
58
+
59
+ /* Remember serial driver for IRQ routine. */
56
60
uvisor_ctx->pc = pc;
57
61
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 */
64
67
*uvisor_ctx->led = LED_OFF;
65
68
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. */
72
74
uvisor_ctx->sw ->mode (SECURE_SWITCH_PULL);
73
75
uvisor_ctx->sw ->fall (my_box_switch_irq);
74
76
75
- /* no problem to return here as everything is initialized */
77
+ /* No problem to return here as everything is initialized. */
76
78
return ;
77
79
}
78
-
79
80
delete uvisor_ctx->led ;
80
81
}
81
82
delete pc;
0 commit comments