blob: ae4c7a8e560ae547f22e4b33d4cdcf298f631723 [file] [log] [blame]
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -07001
Javier B Perez Hernandezf7fffae2015-10-06 11:00:37 -05002/*
3 * Copyright (c) 2015 Intel Corporation.
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -07004 *
David B. Kinderac74d8b2017-01-18 17:01:01 -08005 * SPDX-License-Identifier: Apache-2.0
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -07006 */
7
Flavio Ceolin67ca1762018-09-14 10:43:44 -07008#ifndef ZEPHYR_INCLUDE_INIT_H_
9#define ZEPHYR_INCLUDE_INIT_H_
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -070010
11#include <device.h>
Andrew Boiea13fddb2015-08-04 16:37:35 -070012#include <toolchain.h>
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -070013
Peter Mitsisa0e45682016-01-22 12:38:49 -050014#ifdef __cplusplus
15extern "C" {
16#endif
17
Dirk Brandewie92d01352015-09-25 13:02:12 -070018/*
Andrew Boie0b474ee2016-11-08 11:06:55 -080019 * System initialization levels. The PRE_KERNEL_1 and PRE_KERNEL_2 levels are
Allan Stephensa860cb72015-10-14 11:17:20 -040020 * executed in the kernel's initialization context, which uses the interrupt
Andrew Boie0b474ee2016-11-08 11:06:55 -080021 * stack. The remaining levels are executed in the kernel's main task.
Dirk Brandewieac3fdf02015-06-24 08:22:56 -070022 */
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -070023
Andrew Boie0b474ee2016-11-08 11:06:55 -080024#define _SYS_INIT_LEVEL_PRE_KERNEL_1 0
25#define _SYS_INIT_LEVEL_PRE_KERNEL_2 1
26#define _SYS_INIT_LEVEL_POST_KERNEL 2
27#define _SYS_INIT_LEVEL_APPLICATION 3
28
Allan Stephensa860cb72015-10-14 11:17:20 -040029
Sebastian Bøef816c392018-03-26 15:31:06 +020030/* A counter is used to avoid issues when two or more system devices
31 * are declared in the same C file with the same init function.
Andrew Boiea5b26822016-09-22 11:14:59 -070032 */
33#define _SYS_NAME(init_fn) _CONCAT(_CONCAT(sys_init_, init_fn), __COUNTER__)
34
Andrew Boiea498d462016-09-07 14:51:32 -070035/**
36 * @def SYS_INIT
37 *
Anas Nashif70942732016-09-17 08:01:57 -040038 * @brief Run an initialization function at boot at specified priority
Andrew Boiea498d462016-09-07 14:51:32 -070039 *
40 * @details This macro lets you run a function at system boot.
41 *
42 * @param init_fn Pointer to the boot function to run
43 *
Varun Sharma77c643a2018-12-09 23:17:34 +053044 * @param level The initialization level, See DEVICE_AND_API_INIT for details.
Andrew Boiea498d462016-09-07 14:51:32 -070045 *
46 * @param prio Priority within the selected initialization level. See
Varun Sharma77c643a2018-12-09 23:17:34 +053047 * DEVICE_AND_API_INIT for details.
Andrew Boiea498d462016-09-07 14:51:32 -070048 */
Benjamin Walsh629e1dd2016-01-28 14:56:48 -050049#define SYS_INIT(init_fn, level, prio) \
Varun Sharma77c643a2018-12-09 23:17:34 +053050 DEVICE_AND_API_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level,\
51 prio, NULL)
Benjamin Walsh629e1dd2016-01-28 14:56:48 -050052
Andrew Boiea498d462016-09-07 14:51:32 -070053/**
Ramesh Thomas6249c562016-10-07 17:07:04 -070054 * @def SYS_DEVICE_DEFINE
55 *
56 * @brief Run an initialization function at boot at specified priority,
57 * and define device PM control function.
58 *
Anas Nashif11828bf2018-02-25 08:31:17 -060059 * @details This macro lets you run a function at system boot.
60 *
Ramesh Thomas6249c562016-10-07 17:07:04 -070061 * @param drv_name Name of this system device
Anas Nashif11828bf2018-02-25 08:31:17 -060062 * @param init_fn Pointer to the boot function to run
63 * @param pm_control_fn Pointer to device_pm_control function.
64 * Can be empty function (device_pm_control_nop) if not
65 * implemented.
66 * @param level The initialization level, See DEVICE_INIT for details.
67 * @param prio Priority within the selected initialization level. See
68 * DEVICE_INIT for details.
Ramesh Thomas6249c562016-10-07 17:07:04 -070069 */
70#define SYS_DEVICE_DEFINE(drv_name, init_fn, pm_control_fn, level, prio) \
71 DEVICE_DEFINE(_SYS_NAME(init_fn), drv_name, init_fn, pm_control_fn, \
amirkapld305da62016-09-01 09:01:10 +030072 NULL, NULL, level, prio, NULL)
73
Peter Mitsisa0e45682016-01-22 12:38:49 -050074#ifdef __cplusplus
75}
76#endif
77
Flavio Ceolin67ca1762018-09-14 10:43:44 -070078#endif /* ZEPHYR_INCLUDE_INIT_H_ */