Zephyr API Documentation 4.2.0-rc1
A Scalable Open Source RTOS
 4.2.0-rc1
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#include <zephyr/service.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
52struct device;
53
68struct init_entry {
73 union {
74 const void *_init_object;
75 const struct device *dev;
76 const struct service *srv;
77 };
78};
79
82/* Helper definitions to evaluate level equality */
83#define Z_INIT_EARLY_EARLY 1
84#define Z_INIT_PRE_KERNEL_1_PRE_KERNEL_1 1
85#define Z_INIT_PRE_KERNEL_2_PRE_KERNEL_2 1
86#define Z_INIT_POST_KERNEL_POST_KERNEL 1
87#define Z_INIT_APPLICATION_APPLICATION 1
88#define Z_INIT_SMP_SMP 1
89
90/* Init level ordinals */
91#define Z_INIT_ORD_EARLY 0
92#define Z_INIT_ORD_PRE_KERNEL_1 1
93#define Z_INIT_ORD_PRE_KERNEL_2 2
94#define Z_INIT_ORD_POST_KERNEL 3
95#define Z_INIT_ORD_APPLICATION 4
96#define Z_INIT_ORD_SMP 5
97
103#define Z_INIT_ENTRY_NAME(init_id) _CONCAT(__init_, init_id)
104
112#define Z_INIT_ENTRY_SECTION(level, prio, sub_prio) \
113 __attribute__((__section__( \
114 ".z_init_" #level "_P_" STRINGIFY(prio) "_SUB_" STRINGIFY(sub_prio)"_")))
115
126#define INIT_LEVEL_ORD(level) \
127 COND_CODE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY), \
128 (COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1), \
129 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2), \
130 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL), \
131 (COND_CODE_1(Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION), \
132 (COND_CODE_1(Z_INIT_SMP_##level, (Z_INIT_ORD_SMP), \
133 (ZERO_OR_COMPILE_ERROR(0)))))))))))))
134
151#define SYS_INIT(init_fn, level, prio) \
152 SYS_INIT_NAMED(init_fn, init_fn, level, prio)
153
167#define SYS_INIT_NAMED(name, init_fn_, level, prio) \
168 Z_SERVICE_DEFINE(name, init_fn_, level, prio); \
169 static const Z_DECL_ALIGN(struct init_entry) \
170 Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
171 Z_INIT_ENTRY_NAME(name) = { \
172 .srv = (const struct service *)&Z_SERVICE_NAME_GET(name) \
173 }
174
177#ifdef __cplusplus
178}
179#endif
180
181#endif /* ZEPHYR_INCLUDE_INIT_H_ */
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Structure to store initialization entry information.
Definition init.h:68
const struct service * srv
Definition init.h:76
const struct device * dev
Definition init.h:75
Structure to store service instance.
Definition service.h:31
Misc utilities.
Macros to abstract toolchain specific capabilities.