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("[k-ext1]Waiting event\n");
27 k_event_wait(tick_evt, CHAN_TICK, true, K_FOREVER);
28 printk("[k-ext1]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, 0);
47 sub_thread = k_object_alloc(K_OBJ_THREAD);
48 k_thread_create(sub_thread, sub_stack, STACKSIZE, tick_sub, NULL, NULL,
49 NULL, PRIORITY, K_INHERIT_PERMS, K_NO_WAIT);
50
51 while (true) {
52 long l;
53
54 printk("[k-ext1]Waiting sem\n");
55 k_sem_take(my_sem, K_FOREVER);
56
57 printk("[k-ext1]Got sem, reading channel\n");
58 receive(CHAN_TICK, &l, sizeof(l));
59 printk("[k-ext1]Read val: %ld\n", l);
60 }
61
62 return 0;
63 }
64 EXPORT_SYMBOL(start);
65