Zephyr Project API  3.2.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 <zephyr/toolchain.h>
11#include <zephyr/kernel.h>
12#include <zephyr/types.h>
13
14#ifdef __cplusplus
15extern "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#ifdef CONFIG_SMP
30#define _SYS_INIT_LEVEL_SMP 4
31#endif
32
33struct device;
34
43struct init_entry {
47 int (*init)(const struct device *dev);
51 const struct device *dev;
52};
53
54void z_sys_init_run_level(int32_t level);
55
61#define Z_SYS_NAME(_name) _CONCAT(sys_init_, _name)
62
68#define Z_INIT_ENTRY_NAME(_entry_name) _CONCAT(__init_, _entry_name)
69
92#define Z_INIT_ENTRY_DEFINE(_entry_name, _init_fn, _device, _level, _prio) \
93 static const Z_DECL_ALIGN(struct init_entry) \
94 Z_INIT_ENTRY_NAME(_entry_name) __used __noasan \
95 __attribute__((__section__(".z_init_" #_level STRINGIFY(_prio)"_"))) = { \
96 .init = (_init_fn), \
97 .dev = (_device), \
98 }
99
140#define SYS_INIT(_init_fn, _level, _prio) \
141 SYS_INIT_NAMED(_init_fn, _init_fn, _level, _prio)
142
159#define SYS_INIT_NAMED(_name, _init_fn, _level, _prio) \
160 Z_INIT_ENTRY_DEFINE(Z_SYS_NAME(_name), _init_fn, NULL, _level, _prio)
161
162#ifdef __cplusplus
163}
164#endif
165
166#endif /* ZEPHYR_INCLUDE_INIT_H_ */
Public kernel APIs.
__INT32_TYPE__ int32_t
Definition: stdint.h:74
Runtime device structure (in ROM) per driver instance.
Definition: device.h:435
Static init entry structure for each device driver or services.
Definition: init.h:43
int(* init)(const struct device *dev)
Definition: init.h:47
const struct device * dev
Definition: init.h:51
Macros to abstract toolchain specific capabilities.