Zephyr Project API  3.4.0
A Scalable Open Source RTOS
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
66 int (*sys)(void);
75 int (*dev)(const struct device *dev);
76};
77
92struct init_entry {
99 const struct device *dev;
100};
101
104/* Helper definitions to evaluate level equality */
105#define Z_INIT_EARLY_EARLY 1
106#define Z_INIT_PRE_KERNEL_1_PRE_KERNEL_1 1
107#define Z_INIT_PRE_KERNEL_2_PRE_KERNEL_2 1
108#define Z_INIT_POST_KERNEL_POST_KERNEL 1
109#define Z_INIT_APPLICATION_APPLICATION 1
110#define Z_INIT_SMP_SMP 1
111
112/* Init level ordinals */
113#define Z_INIT_ORD_EARLY 0
114#define Z_INIT_ORD_PRE_KERNEL_1 1
115#define Z_INIT_ORD_PRE_KERNEL_2 2
116#define Z_INIT_ORD_POST_KERNEL 3
117#define Z_INIT_ORD_APPLICATION 4
118#define Z_INIT_ORD_SMP 5
119
125#define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
126
133#define Z_INIT_ENTRY_SECTION(level, prio) \
134 __attribute__((__section__(".z_init_" #level STRINGIFY(prio)"_")))
135
146#define INIT_LEVEL_ORD(level) \
147 COND_CODE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY), \
148 (COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1), \
149 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2), \
150 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL), \
151 (COND_CODE_1(Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION), \
152 (COND_CODE_1(Z_INIT_SMP_##level, (Z_INIT_ORD_SMP), \
153 (ZERO_OR_COMPILE_ERROR(0)))))))))))))
154
171#define SYS_INIT(init_fn, level, prio) \
172 SYS_INIT_NAMED(init_fn, init_fn, level, prio)
173
187#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
188 static const Z_DECL_ALIGN(struct init_entry) \
189 Z_INIT_ENTRY_SECTION(level, prio) __used __noasan \
190 Z_INIT_ENTRY_NAME(name) = { \
191 .init_fn = {.sys = (init_fn_)}, \
192 .dev = NULL, \
193 }
194
197#ifdef __cplusplus
198}
199#endif
200
201#endif /* ZEPHYR_INCLUDE_INIT_H_ */
Runtime device structure (in ROM) per driver instance.
Definition: device.h:380
Structure to store initialization entry information.
Definition: init.h:92
union init_function init_fn
Definition: init.h:94
const struct device * dev
Definition: init.h:99
Macros to abstract toolchain specific capabilities.
Initialization function for init entries.
Definition: init.h:59
int(* dev)(const struct device *dev)
Definition: init.h:75
int(* sys)(void)
Definition: init.h:66
Misc utilities.