2015-06-02 02:11:39 +08:00
|
|
|
|
2015-10-07 00:00:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
2015-06-02 02:11:39 +08:00
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-06-02 02:11:39 +08:00
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_INCLUDE_INIT_H_
|
|
|
|
#define ZEPHYR_INCLUDE_INIT_H_
|
2015-06-02 02:11:39 +08:00
|
|
|
|
|
|
|
#include <device.h>
|
2015-08-05 07:37:35 +08:00
|
|
|
#include <toolchain.h>
|
2015-06-02 02:11:39 +08:00
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-10-14 23:17:20 +08:00
|
|
|
/*
|
2016-11-09 03:06:55 +08:00
|
|
|
* System initialization levels. The PRE_KERNEL_1 and PRE_KERNEL_2 levels are
|
2015-10-14 23:17:20 +08:00
|
|
|
* executed in the kernel's initialization context, which uses the interrupt
|
2016-11-09 03:06:55 +08:00
|
|
|
* stack. The remaining levels are executed in the kernel's main task.
|
2015-10-14 23:17:20 +08:00
|
|
|
*/
|
2015-07-11 02:52:53 +08:00
|
|
|
|
2016-11-09 03:06:55 +08: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 23:17:20 +08:00
|
|
|
|
2018-03-26 21:31:06 +08: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-23 02:14:59 +08:00
|
|
|
*/
|
|
|
|
#define _SYS_NAME(init_fn) _CONCAT(_CONCAT(sys_init_, init_fn), __COUNTER__)
|
|
|
|
|
2016-09-08 05:51:32 +08:00
|
|
|
/**
|
|
|
|
* @def SYS_INIT
|
|
|
|
*
|
2016-09-17 20:01:57 +08:00
|
|
|
* @brief Run an initialization function at boot at specified priority
|
2016-09-08 05:51:32 +08:00
|
|
|
*
|
|
|
|
* @details This macro lets you run a function at system boot.
|
|
|
|
*
|
|
|
|
* @param init_fn Pointer to the boot function to run
|
|
|
|
*
|
|
|
|
* @param level The initialization level, See DEVICE_INIT for details.
|
|
|
|
*
|
|
|
|
* @param prio Priority within the selected initialization level. See
|
|
|
|
* DEVICE_INIT for details.
|
|
|
|
*/
|
2016-01-29 03:56:48 +08:00
|
|
|
#define SYS_INIT(init_fn, level, prio) \
|
2016-09-23 02:14:59 +08:00
|
|
|
DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio)
|
2016-01-29 03:56:48 +08:00
|
|
|
|
2016-10-08 08:07:04 +08:00
|
|
|
/**
|
|
|
|
* @def SYS_DEVICE_DEFINE
|
|
|
|
*
|
|
|
|
* @brief Run an initialization function at boot at specified priority,
|
|
|
|
* and define device PM control function.
|
|
|
|
*
|
2018-02-25 22:31:17 +08:00
|
|
|
* @details This macro lets you run a function at system boot.
|
|
|
|
*
|
2016-10-08 08:07:04 +08:00
|
|
|
* @param drv_name Name of this system device
|
2018-02-25 22:31:17 +08: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 08:07:04 +08:00
|
|
|
*/
|
|
|
|
#define SYS_DEVICE_DEFINE(drv_name, init_fn, pm_control_fn, level, prio) \
|
|
|
|
DEVICE_DEFINE(_SYS_NAME(init_fn), drv_name, init_fn, pm_control_fn, \
|
2016-09-01 14:01:10 +08:00
|
|
|
NULL, NULL, level, prio, NULL)
|
|
|
|
|
2016-01-23 01:38:49 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /* ZEPHYR_INCLUDE_INIT_H_ */
|