1 
2 /*
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef _INIT_H_
9 #define _INIT_H_
10 
11 #include <bt_device.h>
12 // #include <toolchain.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /*
19  * System initialization levels. The PRE_KERNEL_1 and PRE_KERNEL_2 levels are
20  * executed in the kernel's initialization context, which uses the interrupt
21  * stack. The remaining levels are executed in the kernel's main task.
22  */
23 
24 #define _SYS_INIT_LEVEL_PRE_KERNEL_1    0
25 #define _SYS_INIT_LEVEL_PRE_KERNEL_2    1
26 #define _SYS_INIT_LEVEL_POST_KERNEL 2
27 #define _SYS_INIT_LEVEL_APPLICATION 3
28 
29 
30 /* Counter use to avoid issues if two or more system devices are declared
31  * in the same C file with the same init function
32  */
33 #define _SYS_NAME(init_fn) _CONCAT(_CONCAT(sys_init_, init_fn), __COUNTER__)
34 
35 /**
36  * @def SYS_INIT
37  *
38  * @brief Run an initialization function at boot at specified priority
39  *
40  * @details This macro lets you run a function at system boot.
41  *
42  * @param init_fn Pointer to the boot function to run
43  *
44  * @param level The initialization level, See DEVICE_INIT for details.
45  *
46  * @param prio Priority within the selected initialization level. See
47  * DEVICE_INIT for details.
48  */
49 #define SYS_INIT(init_fn, level, prio) \
50     DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio)
51 
52 /**
53  * @def SYS_DEVICE_DEFINE
54  *
55  * @brief Run an initialization function at boot at specified priority,
56  * and define device PM control function.
57  *
58  * @copydetails SYS_INIT
59  * @param pm_control_fn Pointer to device_pm_control function.
60  * Can be empty function (device_pm_control_nop) if not implemented.
61  * @param drv_name Name of this system device
62  */
63 #define SYS_DEVICE_DEFINE(drv_name, init_fn, pm_control_fn, level, prio) \
64     DEVICE_DEFINE(_SYS_NAME(init_fn), drv_name, init_fn, pm_control_fn, \
65                   NULL, NULL, level, prio, NULL)
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif /* _INIT_H_ */
72