Zephyr Project API  3.3.0
A Scalable Open Source RTOS
System Initialization

Data Structures

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

Macros

#define SYS_INIT(init_fn, level, prio)    SYS_INIT_NAMED(init_fn, init_fn, level, prio)
 Register an initialization function. More...
 
#define SYS_INIT_NAMED(name, init_fn, level, prio)    Z_INIT_ENTRY_DEFINE(name, init_fn, NULL, level, prio)
 Register an initialization function (named). More...
 

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

◆ 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 
)     Z_INIT_ENTRY_DEFINE(name, init_fn, NULL, level, prio)

#include <include/zephyr/init.h>

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_fnSee SYS_INIT().
levelSee SYS_INIT().
prioSee SYS_INIT().
See also
SYS_INIT()