Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
 4.1.99
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
50struct device;
51
66struct init_entry {
71 int (*init_fn)(void);
76 const struct device *dev;
77};
78
81/* Helper definitions to evaluate level equality */
82#define Z_INIT_EARLY_EARLY 1
83#define Z_INIT_PRE_KERNEL_1_PRE_KERNEL_1 1
84#define Z_INIT_PRE_KERNEL_2_PRE_KERNEL_2 1
85#define Z_INIT_POST_KERNEL_POST_KERNEL 1
86#define Z_INIT_APPLICATION_APPLICATION 1
87#define Z_INIT_SMP_SMP 1
88
89/* Init level ordinals */
90#define Z_INIT_ORD_EARLY 0
91#define Z_INIT_ORD_PRE_KERNEL_1 1
92#define Z_INIT_ORD_PRE_KERNEL_2 2
93#define Z_INIT_ORD_POST_KERNEL 3
94#define Z_INIT_ORD_APPLICATION 4
95#define Z_INIT_ORD_SMP 5
96
102#define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
103
111#define Z_INIT_ENTRY_SECTION(level, prio, sub_prio) \
112 __attribute__((__section__( \
113 ".z_init_" #level "_P_" STRINGIFY(prio) "_SUB_" STRINGIFY(sub_prio)"_")))
114
125#define INIT_LEVEL_ORD(level) \
126 COND_CODE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY), \
127 (COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1), \
128 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2), \
129 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL), \
130 (COND_CODE_1(Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION), \
131 (COND_CODE_1(Z_INIT_SMP_##level, (Z_INIT_ORD_SMP), \
132 (ZERO_OR_COMPILE_ERROR(0)))))))))))))
133
150#define SYS_INIT(init_fn, level, prio) \
151 SYS_INIT_NAMED(init_fn, init_fn, level, prio)
152
166#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
167 static const Z_DECL_ALIGN(struct init_entry) \
168 Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
169 Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_), .dev = NULL} \
170
173#ifdef __cplusplus
174}
175#endif
176
177#endif /* ZEPHYR_INCLUDE_INIT_H_ */
Runtime device structure (in ROM) per driver instance.
Definition device.h:504
Structure to store initialization entry information.
Definition init.h:66
int(* init_fn)(void)
If the init function belongs to a SYS_INIT, this field stored the initialization function,...
Definition init.h:71
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:76
Misc utilities.
Macros to abstract toolchain specific capabilities.