blob: 337d1b5f2518bc714af393d9a2734c939b1a2d8f [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
8#ifndef _INIT_H_
9#define _INIT_H_
10
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
Andrew Boiea5b26822016-09-22 11:14:59 -070030/* Counter use to avoid issues if two or more system devices are declared
31 * in the same C file with the same init function
32 */
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 *
44 * @param level The initialization level, See DEVICE_INIT for details.
45 *
46 * @param prio Priority within the selected initialization level. See
47 * DEVICE_INIT for details.
48 */
Benjamin Walsh629e1dd2016-01-28 14:56:48 -050049#define SYS_INIT(init_fn, level, prio) \
Andrew Boiea5b26822016-09-22 11:14:59 -070050 DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio)
Benjamin Walsh629e1dd2016-01-28 14:56:48 -050051
Andrew Boiea498d462016-09-07 14:51:32 -070052/**
Ramesh Thomas6249c562016-10-07 17:07:04 -070053 * @def SYS_DEVICE_DEFINE
54 *
55 * @brief Run an initialization function at boot at specified priority,
56 * and define device PM control function.
57 *
58 * @copydetails SYS_INIT
59 * @param pm_control_fn Pointer to device_pm_control function.
60 * Can be empty function (device_pm_control_nop) if not implemented.
61 * @param drv_name Name of this system device
62 */
63#define SYS_DEVICE_DEFINE(drv_name, init_fn, pm_control_fn, level, prio) \
64 DEVICE_DEFINE(_SYS_NAME(init_fn), drv_name, init_fn, pm_control_fn, \
amirkapld305da62016-09-01 09:01:10 +030065 NULL, NULL, level, prio, NULL)
66
Peter Mitsisa0e45682016-01-22 12:38:49 -050067#ifdef __cplusplus
68}
69#endif
70
Dirk Brandewiec9ac95a2015-06-01 11:11:39 -070071#endif /* _INIT_H_ */