1 /*
2  * Copyright (c) 2017 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _POSIX_SOC_INF_CLOCK_POSIX_NATIVE_TASK_H
8 #define _POSIX_SOC_INF_CLOCK_POSIX_NATIVE_TASK_H
9 
10 #include <zephyr/toolchain.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  * NATIVE_TASK
18  *
19  * For native_posix, register a function to be called at particular moments
20  * during the native_posix execution.
21  *
22  * There is 5 choices for when the function will be called (level):
23  * * PRE_BOOT_1: Will be called before the command line parameters are parsed,
24  *   or the HW models are initialized
25  *
26  * * PRE_BOOT_2: Will be called after the command line parameters are parsed,
27  *   but before the HW models are initialized
28  *
29  * * PRE_BOOT_3: Will be called after the HW models initialization, right before
30  *   the "CPU is booted" and Zephyr is started.
31  *
32  * * FIRST_SLEEP: Will be called the 1st time the CPU is sent to sleep
33  *
34  * * ON_EXIT: Will be called during termination of the native application
35  * execution.
36  *
37  * The function must take no parameters and return nothing.
38  * Note that for the PRE and ON_EXIT levels neither the Zephyr kernel or
39  * any Zephyr thread are running.
40  */
41 #define NATIVE_TASK(fn, level, prio)	\
42 	static void (* const _CONCAT(__native_task_, fn))() __used __noasan \
43 	__attribute__((__section__(".native_" #level STRINGIFY(prio) "_task")))\
44 	= fn
45 
46 
47 #define _NATIVE_PRE_BOOT_1_LEVEL	0
48 #define _NATIVE_PRE_BOOT_2_LEVEL	1
49 #define _NATIVE_PRE_BOOT_3_LEVEL	2
50 #define _NATIVE_FIRST_SLEEP_LEVEL	3
51 #define _NATIVE_ON_EXIT_LEVEL		4
52 
53 /**
54  * @brief Run the set of special native tasks corresponding to the given level
55  *
56  * @param level One of _NATIVE_*_LEVEL as defined in soc.h
57  */
58 void run_native_tasks(int level);
59 
60 #ifdef __cplusplus
61 }
62 #endif
63 
64 #endif /* _POSIX_SOC_INF_CLOCK_POSIX_NATIVE_TASK_H */
65