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