1 /*
2  * Copyright (c) 2019 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/sys/printk.h>
9 #include <zephyr/sys/libc-hooks.h>
10 #include <zephyr/logging/log.h>
11 
12 #include "app_shared.h"
13 #include "app_a.h"
14 #include "app_b.h"
15 
16 #define APP_A_STACKSIZE	2048
17 #define APP_B_STACKSIZE	2048
18 
19 LOG_MODULE_REGISTER(app_main);
20 
21 /* Define a thread for the root of application A.
22  */
23 struct k_thread app_a_thread;
24 K_THREAD_STACK_DEFINE(app_a_stack, APP_A_STACKSIZE);
25 
26 /* Define a thread for the root of application B.
27  */
28 struct k_thread app_b_thread;
29 K_THREAD_STACK_DEFINE(app_b_stack, APP_B_STACKSIZE);
30 
main(void)31 int main(void)
32 {
33 	k_tid_t thread_a, thread_b;
34 
35 	LOG_INF("APP A partition: %p %zu", (void *)app_a_partition.start,
36 		(size_t)app_a_partition.size);
37 	LOG_INF("APP B partition: %p %zu", (void *)app_b_partition.start,
38 		(size_t)app_b_partition.size);
39 	LOG_INF("Shared partition: %p %zu", (void *)shared_partition.start,
40 		(size_t)shared_partition.size);
41 #ifdef Z_LIBC_PARTITION_EXISTS
42 	LOG_INF("libc partition: %p %zu", (void *)z_libc_partition.start,
43 		(size_t)z_libc_partition.size);
44 #endif
45 	sys_heap_init(&shared_pool, shared_pool_mem, HEAP_BYTES);
46 
47 	/* Spawn supervisor entry for application A */
48 	thread_a = k_thread_create(&app_a_thread, app_a_stack, APP_A_STACKSIZE,
49 				   app_a_entry, NULL, NULL, NULL,
50 				   -1, K_INHERIT_PERMS, K_NO_WAIT);
51 
52 	/* Spawn supervisor entry for application B */
53 	thread_b = k_thread_create(&app_b_thread, app_b_stack, APP_B_STACKSIZE,
54 				   app_b_entry, NULL, NULL, NULL,
55 				   -1, K_INHERIT_PERMS, K_NO_WAIT);
56 
57 	k_thread_join(thread_a, K_FOREVER);
58 	k_thread_join(thread_b, K_FOREVER);
59 	return 0;
60 }
61