1 /*
2 * Copyright (c) 2017-2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <ksched.h>
9
10 #include "footprint.h"
11
12 #define STACK_SIZE 512
13
14 K_SEM_DEFINE(semaphore0, 0, 1);
15
thread_fn(void * p1,void * p2,void * p3)16 void thread_fn(void *p1, void *p2, void *p3)
17 {
18 k_sem_give(&semaphore0);
19
20 k_sem_take(&semaphore0, K_FOREVER);
21 }
22
run_semaphore(void)23 void run_semaphore(void)
24 {
25 k_tid_t sem0_tid;
26 struct k_sem sem0;
27
28 k_sem_init(&sem0, 0, 1);
29
30 k_sem_give(&sem0);
31
32 k_sem_take(&sem0, K_FOREVER);
33
34 sem0_tid = k_thread_create(&my_thread, my_stack_area,
35 STACK_SIZE, thread_fn,
36 NULL, NULL, NULL,
37 0, 0, K_NO_WAIT);
38
39 k_thread_join(sem0_tid, K_FOREVER);
40
41 #ifdef CONFIG_USERSPACE
42 sem0_tid = k_thread_create(&my_thread, my_stack_area,
43 STACK_SIZE, thread_fn,
44 NULL, NULL, NULL,
45 0, K_USER, K_FOREVER);
46
47 k_object_access_grant(&semaphore0, sem0_tid);
48
49 k_thread_start(sem0_tid);
50 k_thread_join(sem0_tid, K_FOREVER);
51 #endif
52 }
53