2015-06-01 20:11:39 +02:00
|
|
|
|
2015-10-06 18:00:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
2015-06-01 20:11:39 +02:00
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-06-01 20:11:39 +02:00
|
|
|
*/
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_INIT_H_
|
|
|
|
#define ZEPHYR_INCLUDE_INIT_H_
|
2015-06-01 20:11:39 +02:00
|
|
|
|
|
|
|
#include <device.h>
|
2015-08-05 01:37:35 +02:00
|
|
|
#include <toolchain.h>
|
2015-06-01 20:11:39 +02:00
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-10-14 17:17:20 +02:00
|
|
|
/*
|
2016-11-08 20:06:55 +01:00
|
|
|
* System initialization levels. The PRE_KERNEL_1 and PRE_KERNEL_2 levels are
|
2015-10-14 17:17:20 +02:00
|
|
|
* executed in the kernel's initialization context, which uses the interrupt
|
2016-11-08 20:06:55 +01:00
|
|
|
* stack. The remaining levels are executed in the kernel's main task.
|
2015-10-14 17:17:20 +02:00
|
|
|
*/
|
2015-07-10 20:52:53 +02:00
|
|
|
|
2016-11-08 20:06:55 +01:00
|
|
|
#define _SYS_INIT_LEVEL_PRE_KERNEL_1 0
|
|
|
|
#define _SYS_INIT_LEVEL_PRE_KERNEL_2 1
|
|
|
|
#define _SYS_INIT_LEVEL_POST_KERNEL 2
|
|
|
|
#define _SYS_INIT_LEVEL_APPLICATION 3
|
|
|
|
|
2015-10-14 17:17:20 +02:00
|
|
|
|
2018-03-26 15:31:06 +02:00
|
|
|
/* A counter is used to avoid issues when two or more system devices
|
|
|
|
* are declared in the same C file with the same init function.
|
2016-09-22 20:14:59 +02:00
|
|
|
*/
|
2019-03-08 22:19:05 +01:00
|
|
|
#define Z_SYS_NAME(init_fn) _CONCAT(_CONCAT(sys_init_, init_fn), __COUNTER__)
|
2016-09-22 20:14:59 +02:00
|
|
|
|
2016-09-07 23:51:32 +02:00
|
|
|
/**
|
|
|
|
* @def SYS_INIT
|
|
|
|
*
|
2016-09-17 14:01:57 +02:00
|
|
|
* @brief Run an initialization function at boot at specified priority
|
2016-09-07 23:51:32 +02:00
|
|
|
*
|
|
|
|
* @details This macro lets you run a function at system boot.
|
|
|
|
*
|
|
|
|
* @param init_fn Pointer to the boot function to run
|
|
|
|
*
|
2018-12-09 18:47:34 +01:00
|
|
|
* @param level The initialization level, See DEVICE_AND_API_INIT for details.
|
2016-09-07 23:51:32 +02:00
|
|
|
*
|
|
|
|
* @param prio Priority within the selected initialization level. See
|
2018-12-09 18:47:34 +01:00
|
|
|
* DEVICE_AND_API_INIT for details.
|
2016-09-07 23:51:32 +02:00
|
|
|
*/
|
2016-01-28 20:56:48 +01:00
|
|
|
#define SYS_INIT(init_fn, level, prio) \
|
2019-03-08 22:19:05 +01:00
|
|
|
DEVICE_AND_API_INIT(Z_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level,\
|
2018-12-09 18:47:34 +01:00
|
|
|
prio, NULL)
|
2016-01-28 20:56:48 +01:00
|
|
|
|
2016-10-08 02:07:04 +02:00
|
|
|
/**
|
|
|
|
* @def SYS_DEVICE_DEFINE
|
|
|
|
*
|
|
|
|
* @brief Run an initialization function at boot at specified priority,
|
|
|
|
* and define device PM control function.
|
|
|
|
*
|
2018-02-25 15:31:17 +01:00
|
|
|
* @details This macro lets you run a function at system boot.
|
|
|
|
*
|
2016-10-08 02:07:04 +02:00
|
|
|
* @param drv_name Name of this system device
|
2018-02-25 15:31:17 +01:00
|
|
|
* @param init_fn Pointer to the boot function to run
|
|
|
|
* @param pm_control_fn Pointer to device_pm_control function.
|
|
|
|
* Can be empty function (device_pm_control_nop) if not
|
|
|
|
* implemented.
|
|
|
|
* @param level The initialization level, See DEVICE_INIT for details.
|
|
|
|
* @param prio Priority within the selected initialization level. See
|
|
|
|
* DEVICE_INIT for details.
|
2016-10-08 02:07:04 +02:00
|
|
|
*/
|
|
|
|
#define SYS_DEVICE_DEFINE(drv_name, init_fn, pm_control_fn, level, prio) \
|
2019-03-08 22:19:05 +01:00
|
|
|
DEVICE_DEFINE(Z_SYS_NAME(init_fn), drv_name, init_fn, pm_control_fn, \
|
2016-09-01 08:01:10 +02:00
|
|
|
NULL, NULL, level, prio, NULL)
|
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_INIT_H_ */
|