Skip to content

Commit

Permalink
Add support for the DISCO_F429ZI target
Browse files Browse the repository at this point in the history
This commit includes:

* Reduce stack and heap size for all boxes, where necessary and
  possible (printf used in threads is a constraint).
* Use new Thread APIs.
* Add ACLs and configurations for the DISCO_F429ZI target.
  • Loading branch information
AlessandroA committed Dec 8, 2016
1 parent a5cd217 commit 07bbc93
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 29 deletions.
2 changes: 1 addition & 1 deletion mbed_app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"target_overrides": {
"K64F": {
"*": {
"target.features_add": ["UVISOR"],
"target.extra_labels_add": ["UVISOR_SUPPORTED"]
}
Expand Down
22 changes: 14 additions & 8 deletions source/client_a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ static const UvisorBoxAclItem acl[] = {

static void client_a_main(const void *);

/* Box configuration */
/* Box configuration
* This box has a smaller interrupt and main thread stack sizes as we do nothing
* special in them. */
UVISOR_BOX_NAMESPACE("client_a");
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(secure_number_client_a, acl, UVISOR_BOX_STACK_SIZE, box_context);
UVISOR_BOX_HEAPSIZE(3072);
UVISOR_BOX_MAIN(client_a_main, osPriorityNormal, 512);
UVISOR_BOX_CONFIG(secure_number_client_a, acl, 512, box_context);

static uint32_t get_a_number()
{
/* Such random. Many secure. Much bits. Wow. */
return (uvisor_ctx->number -= 500UL);
}

static void box_async_runner(const void *)
static void box_async_runner(void)
{
while (1) {
uvisor_rpc_result_t result;
Expand All @@ -67,7 +69,7 @@ static void box_async_runner(const void *)
}
}

static void box_sync_runner(const void *)
static void box_sync_runner(void)
{
while (1) {
/* Synchronous access to the number. */
Expand All @@ -87,7 +89,11 @@ static void client_a_main(const void *)
return;
}

/* Create new threads. */
/* Note: The stack must be at least 1kB since threads will use printf. */
srand(uvisor_box_id_self());
new Thread(box_sync_runner, NULL);
new Thread(box_async_runner, NULL);
Thread sync(osPriorityNormal, 1024, NULL);
sync.start(box_sync_runner);
Thread async(osPriorityNormal, 1024, NULL);
async.start(box_async_runner);
}
10 changes: 6 additions & 4 deletions source/client_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ static const UvisorBoxAclItem acl[] = {

static void client_b_main(const void *);

/* Box configuration */
/* Box configuration
* This box has a smaller interrupt stack size as we do nothing special in it.
* The main thread uses printf so it needs at least 1kB of stack. */
UVISOR_BOX_NAMESPACE("client_b");
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(secure_number_client_b, acl, UVISOR_BOX_STACK_SIZE, box_context);
UVISOR_BOX_HEAPSIZE(3072);
UVISOR_BOX_MAIN(client_b_main, osPriorityNormal, 1024);
UVISOR_BOX_CONFIG(secure_number_client_b, acl, 512, box_context);

static uint32_t get_a_number()
{
Expand Down
43 changes: 32 additions & 11 deletions source/main-hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@
#ifndef __UVISOR_HELLOWORLD_MAIN_HW_H__
#define __UVISOR_HELLOWORLD_MAIN_HW_H__

/* The vector containing the challenge is shared with the push-button ISR, so
* that it can attempt to access it from an IRQ context. */
extern DigitalOut led_red;
extern DigitalOut led_green;
extern DigitalOut led_blue;

#if defined(TARGET_K64F)

#define LED_ON false
#define LED_OFF true

#define MAIN_LED LED_BLUE
#define HALT_LED LED_RED

#define MAIN_BTN SW2
#define MAIN_BTN_PUPD PullUp

#define MAIN_ACL(acl_list_name) \
static const UvisorBoxAclItem acl_list_name[] = { \
{SIM, sizeof(*SIM), UVISOR_TACLDEF_PERIPH}, \
Expand All @@ -48,8 +45,32 @@
{SPI0, sizeof(*SPI0), UVISOR_TACLDEF_PERIPH}, \
}

extern DigitalOut led_red;
extern DigitalOut led_green;
extern DigitalOut led_blue;
#elif defined (TARGET_DISCO_F429ZI)

#define LED_ON true
#define LED_OFF false

#define MAIN_ACL(acl_list_name) \
static const UvisorBoxAclItem acl_list_name[] = { \
{GPIOA, sizeof(*GPIOA), UVISOR_TACLDEF_PERIPH}, \
{GPIOB, sizeof(*GPIOB), UVISOR_TACLDEF_PERIPH}, \
{GPIOC, sizeof(*GPIOC), UVISOR_TACLDEF_PERIPH}, \
{GPIOD, sizeof(*GPIOD), UVISOR_TACLDEF_PERIPH}, \
{GPIOE, sizeof(*GPIOE), UVISOR_TACLDEF_PERIPH}, \
{RTC, sizeof(*RTC), UVISOR_TACLDEF_PERIPH}, \
{TIM5, sizeof(*TIM5), UVISOR_TACLDEF_PERIPH}, \
{USART1, sizeof(*USART1), UVISOR_TACLDEF_PERIPH}, \
{I2C1, sizeof(*I2C1), UVISOR_TACLDEF_PERIPH}, \
{SPI1, sizeof(*SPI1), UVISOR_TACLDEF_PERIPH}, \
{RCC, sizeof(*RCC), UVISOR_TACLDEF_PERIPH}, \
{FLASH, sizeof(*FLASH), UVISOR_TACLDEF_PERIPH}, \
{PWR, sizeof(*PWR), UVISOR_TACLDEF_PERIPH}, \
{EXTI, sizeof(*EXTI), UVISOR_TACLDEF_PERIPH}, \
{GPIOG, sizeof(*GPIOG), UVISOR_TACLDEF_PERIPH}, \
{SYSCFG, sizeof(*SYSCFG), UVISOR_TACLDEF_PERIPH}, \
{(void *) 0x42000000, 0x01000000, UVISOR_TACLDEF_PERIPH}, /* FIXME */ \
}

#endif /* Target-specific settings */

#endif /* __UVISOR_HELLOWORLD_MAIN_HW_H__ */
11 changes: 7 additions & 4 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static uint32_t get_a_number()
return (number -= 400UL);
}

static void main_async_runner(const void *)
static void main_async_runner(void)
{
while (1) {
uvisor_rpc_result_t result;
Expand All @@ -71,7 +71,7 @@ static void main_async_runner(const void *)
}
}

static void main_sync_runner(const void *)
static void main_sync_runner(void)
{
while (1) {
/* Synchronous access to the number. */
Expand All @@ -90,8 +90,11 @@ int main(void)
led_green = LED_OFF;

/* Startup a few RPC runners. */
Thread sync(main_sync_runner, NULL);
Thread async(main_async_runner, NULL);
/* Note: The stack must be at least 1kB since threads will use printf. */
Thread sync(osPriorityNormal, 1024, NULL);
sync.start(main_sync_runner);
Thread async(osPriorityNormal, 1024, NULL);
async.start(main_async_runner);

size_t count = 0;

Expand Down
2 changes: 1 addition & 1 deletion source/secure_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int set_number(uint32_t number);

/* Box configuration */
UVISOR_BOX_NAMESPACE(NULL);
UVISOR_BOX_HEAPSIZE(8192);
UVISOR_BOX_HEAPSIZE(3072);
UVISOR_BOX_MAIN(number_store_main, osPriorityNormal, UVISOR_BOX_STACK_SIZE);
UVISOR_BOX_CONFIG(box_number_store, acl, UVISOR_BOX_STACK_SIZE, box_context);

Expand Down

0 comments on commit 07bbc93

Please sign in to comment.