Zephyr API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
System Initialization

Zephyr offers an infrastructure to call initialization code before main. More...

Data Structures

struct  init_entry
 Structure to store initialization entry information. More...
 

Macros

#define INIT_LEVEL_ORD(level)
 Obtain the ordinal for an init level.
 
#define SYS_INIT(init_fn, level, prio)
 Register an initialization function.
 
#define SYS_INIT_NAMED(name, init_fn_, level, prio)
 Register an initialization function (named).
 

Detailed Description

Zephyr offers an infrastructure to call initialization code before main.

Such initialization calls can be registered using SYS_INIT() or SYS_INIT_NAMED() macros. By using a combination of initialization levels and priorities init sequence can be adjusted as needed. The available initialization levels are described, in order, below:

Initialization priority can take a value in the range of 0 to 999.

Note
The same infrastructure is used by devices.

Macro Definition Documentation

◆ INIT_LEVEL_ORD

#define INIT_LEVEL_ORD ( level)

#include <zephyr/init.h>

Value:
COND_CASE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY), \
Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1), \
Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2), \
Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL), \
Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION), \
Z_INIT_SMP_##level, (Z_INIT_ORD_SMP), \
#define COND_CASE_1(...)
Evaluate a list of COND_CODE_1-style cases.
Definition util_macro.h:250
#define ZERO_OR_COMPILE_ERROR(cond)
0 if cond is true-ish; causes a compile error otherwise.
Definition util.h:89

Obtain the ordinal for an init level.

Parameters
levelInit level (EARLY, PRE_KERNEL_1, PRE_KERNEL_2, POST_KERNEL, APPLICATION, SMP).
Returns
Init level ordinal.

◆ SYS_INIT

#define SYS_INIT ( init_fn,
level,
prio )

#include <zephyr/init.h>

Value:
SYS_INIT_NAMED(init_fn, init_fn, level, prio)
#define SYS_INIT_NAMED(name, init_fn_, level, prio)
Register an initialization function (named).
Definition init.h:170

Register an initialization function.

The function will be called during system initialization according to the given level and priority.

Note
The return value of the initialization function is ignored.
Parameters
init_fnInitialization function.
levelInitialization level. Allowed tokens: EARLY, PRE_KERNEL_1, PRE_KERNEL_2, POST_KERNEL, APPLICATION and SMP if
CONFIG_SMP 
is enabled.
prioInitialization priority within _level. Note that it must be a decimal integer literal without leading zeroes or sign (e.g. 32), or an equivalent symbolic name (e.g. #define MY_INIT_PRIO 32); symbolic expressions are not permitted (e.g. CONFIG_KERNEL_INIT_PRIORITY_DEFAULT + 5).

◆ SYS_INIT_NAMED

#define SYS_INIT_NAMED ( name,
init_fn_,
level,
prio )

#include <zephyr/init.h>

Value:
static const Z_DECL_ALIGN(struct init_entry) \
Z_INIT_ENTRY_SECTION(level, prio, 0) __used __noasan \
Z_INIT_ENTRY_NAME(name) = {.init_fn = (init_fn_), .dev = NULL} \
Structure to store initialization entry information.
Definition init.h:66

Register an initialization function (named).

Note
This macro can be used for cases where the multiple init calls use the same init function.
The return value of the initialization function is ignored.
Parameters
nameUnique name for SYS_INIT entry.
init_fn_See SYS_INIT().
levelSee SYS_INIT().
prioSee SYS_INIT().
See also
SYS_INIT()