1 /*
2 * Copyright (c) 2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/llext/symbol.h>
9
10 #include <app_api.h>
11
12 #define STACKSIZE 512
13 #define PRIORITY 2
14
15 static struct k_sem *my_sem;
16
tick_sub(void * p1,void * p2,void * p3)17 static void tick_sub(void *p1, void *p2, void *p3)
18 {
19 struct k_event *tick_evt = k_object_alloc(K_OBJ_EVENT);
20
21 k_event_init(tick_evt);
22
23 register_subscriber(CHAN_TICK, tick_evt);
24
25 while (true) {
26 printk("[ext3]Waiting event\n");
27 k_event_wait(tick_evt, CHAN_TICK, true, K_FOREVER);
28 printk("[ext3]Got event, giving sem\n");
29
30 k_sem_give(my_sem);
31 }
32 }
33
start(void)34 int start(void)
35 {
36 k_thread_stack_t *sub_stack;
37 struct k_thread *sub_thread;
38
39 /* Currently, any kobjects need to be dynamic on extensions,
40 * so the semaphore, thread stack and thread objects are created
41 * dynamically.
42 */
43 my_sem = k_object_alloc(K_OBJ_SEM);
44 k_sem_init(my_sem, 0, 1);
45
46 sub_stack = k_thread_stack_alloc(STACKSIZE, K_USER);
47 sub_thread = k_object_alloc(K_OBJ_THREAD);
48 printk("[ext3]%p - %p\n", sub_stack, sub_thread);
49 k_thread_create(sub_thread, sub_stack, STACKSIZE, tick_sub, NULL, NULL,
50 NULL, PRIORITY, K_INHERIT_PERMS | K_USER, K_NO_WAIT);
51
52 while (true) {
53 long l;
54
55 printk("[ext3]Waiting sem\n");
56 k_sem_take(my_sem, K_FOREVER);
57
58 printk("[ext3]Got sem, reading channel\n");
59 receive(CHAN_TICK, &l, sizeof(l));
60 printk("[ext3]Read val: %ld\n", l);
61 }
62
63 return 0;
64 }
65 LL_EXTENSION_SYMBOL(start);
66