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

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

Data Structures

union  init_function
 Initialization function for init entries. More...
 
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)    SYS_INIT_NAMED(init_fn, 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 99.

Note
The same infrastructure is used by devices.

Macro Definition Documentation

◆ INIT_LEVEL_ORD

#define INIT_LEVEL_ORD (   level)

#include <include/zephyr/init.h>

Value:
COND_CODE_1(Z_INIT_EARLY_##level, (Z_INIT_ORD_EARLY), \
(COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (Z_INIT_ORD_PRE_KERNEL_1), \
(COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (Z_INIT_ORD_PRE_KERNEL_2), \
(COND_CODE_1(Z_INIT_POST_KERNEL_##level, (Z_INIT_ORD_POST_KERNEL), \
(COND_CODE_1(Z_INIT_APPLICATION_##level, (Z_INIT_ORD_APPLICATION), \
(COND_CODE_1(Z_INIT_SMP_##level, (Z_INIT_ORD_SMP), \
(ZERO_OR_COMPILE_ERROR(0)))))))))))))
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195
#define ZERO_OR_COMPILE_ERROR(cond)
0 if cond is true-ish; causes a compile error otherwise.
Definition util.h:90

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 
)     SYS_INIT_NAMED(init_fn, init_fn, level, prio)

#include <include/zephyr/init.h>

Register an initialization function.

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

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 <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 = {.sys = (init_fn_)}, \
Z_INIT_SYS_INIT_DEV_NULL}
Structure to store initialization entry information.
Definition init.h:103

Register an initialization function (named).

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