Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
init.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_INIT_H_
8#define ZEPHYR_INCLUDE_INIT_H_
9
10#include <stdint.h>
11#include <stddef.h>
12
13#include <zephyr/sys/util.h>
14#include <zephyr/toolchain.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
51
52struct device;
53
68struct init_entry {
73 int (*init_fn)(void);
78 const struct device *dev;
79};
80
82
83/* Helper definitions to evaluate level equality */
84#define Z_INIT_EARLY_EARLY 1
85#define Z_INIT_PRE_KERNEL_1_PRE_KERNEL_1 1
86#define Z_INIT_PRE_KERNEL_2_PRE_KERNEL_2 1
87#define Z_INIT_POST_KERNEL_POST_KERNEL 1
88#define Z_INIT_APPLICATION_APPLICATION 1
89#define Z_INIT_SMP_SMP 1
90
91/* Init level ordinals */
92#define Z_INIT_ORD_EARLY 0
93#define Z_INIT_ORD_PRE_KERNEL_1 1
94#define Z_INIT_ORD_PRE_KERNEL_2 2
95#define Z_INIT_ORD_POST_KERNEL 3
96#define Z_INIT_ORD_APPLICATION 4
97#define Z_INIT_ORD_SMP 5
98
104#define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
105
113#define Z_INIT_ENTRY_SECTION(level, prio, sub_prio) \
114 __attribute__((__section__( \
115 ".z_init_" #level "_P_" STRINGIFY(prio) "_SUB_" STRINGIFY(sub_prio)"_")))
116
118
127#define INIT_LEVEL_ORD(level) \
128 COND_CASE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY), \
129 Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1), \
130 Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2), \
131 Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL), \
132 Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION), \
133 Z_INIT_SMP_##level, (Z_INIT_ORD_SMP), \
134 (ZERO_OR_COMPILE_ERROR(0)))
135
154#define SYS_INIT(init_fn, level, prio) \
155 SYS_INIT_NAMED(init_fn, init_fn, level, prio)
156
172#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
173 static const Z_DECL_ALIGN(struct init_entry) \
174 Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
175 Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_), .dev = NULL} \
176
177
178
179#ifdef __cplusplus
180}
181#endif
182
183#endif /* ZEPHYR_INCLUDE_INIT_H_ */
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Structure to store initialization entry information.
Definition init.h:68
int(* init_fn)(void)
If the init function belongs to a SYS_INIT, this field stored the initialization function,...
Definition init.h:73
const struct device * dev
If the init entry belongs to a device, this fields stores a reference to it, otherwise it is set to N...
Definition init.h:78
Misc utilities.
Macros to abstract toolchain specific capabilities.