1 /*
2  * Copyright (c) 2020 BayLibre, SAS
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <stdio.h>
9 #define USER_STACKSIZE	2048
10 
11 #ifndef CONFIG_USERSPACE
12 #error This sample requires CONFIG_USERSPACE.
13 #endif
14 
15 struct k_thread user_thread;
16 K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);
17 
user_function(void * p1,void * p2,void * p3)18 static void user_function(void *p1, void *p2, void *p3)
19 {
20 	printf("Hello World from %s (%s)\n",
21 	       k_is_user_context() ? "UserSpace!" : "privileged mode.",
22 	       CONFIG_BOARD);
23 	__ASSERT(k_is_user_context(), "User mode execution was expected");
24 }
25 
26 
main(void)27 int main(void)
28 {
29 	k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
30 			user_function, NULL, NULL, NULL,
31 			-1, K_USER, K_MSEC(0));
32 	return 0;
33 }
34