Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 1 | |
Javier B Perez Hernandez | f7fffae | 2015-10-06 11:00:37 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Intel Corporation. |
Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 4 | * |
David B. Kinder | ac74d8b | 2017-01-18 17:01:01 -0800 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 |
Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 8 | #ifndef ZEPHYR_INCLUDE_INIT_H_ |
| 9 | #define ZEPHYR_INCLUDE_INIT_H_ |
Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 10 | |
| 11 | #include <device.h> |
Andrew Boie | a13fddb | 2015-08-04 16:37:35 -0700 | [diff] [blame] | 12 | #include <toolchain.h> |
Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 13 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 14 | #ifdef __cplusplus |
| 15 | extern "C" { |
| 16 | #endif |
| 17 | |
Dirk Brandewie | 92d0135 | 2015-09-25 13:02:12 -0700 | [diff] [blame] | 18 | /* |
Andrew Boie | 0b474ee | 2016-11-08 11:06:55 -0800 | [diff] [blame] | 19 | * System initialization levels. The PRE_KERNEL_1 and PRE_KERNEL_2 levels are |
Allan Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 20 | * executed in the kernel's initialization context, which uses the interrupt |
Andrew Boie | 0b474ee | 2016-11-08 11:06:55 -0800 | [diff] [blame] | 21 | * stack. The remaining levels are executed in the kernel's main task. |
Dirk Brandewie | ac3fdf0 | 2015-06-24 08:22:56 -0700 | [diff] [blame] | 22 | */ |
Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 23 | |
Andrew Boie | 0b474ee | 2016-11-08 11:06:55 -0800 | [diff] [blame] | 24 | #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 Stephens | a860cb7 | 2015-10-14 11:17:20 -0400 | [diff] [blame] | 29 | |
Sebastian Bøe | f816c39 | 2018-03-26 15:31:06 +0200 | [diff] [blame] | 30 | /* 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 Boie | a5b2682 | 2016-09-22 11:14:59 -0700 | [diff] [blame] | 32 | */ |
| 33 | #define _SYS_NAME(init_fn) _CONCAT(_CONCAT(sys_init_, init_fn), __COUNTER__) |
| 34 | |
Andrew Boie | a498d46 | 2016-09-07 14:51:32 -0700 | [diff] [blame] | 35 | /** |
| 36 | * @def SYS_INIT |
| 37 | * |
Anas Nashif | 7094273 | 2016-09-17 08:01:57 -0400 | [diff] [blame] | 38 | * @brief Run an initialization function at boot at specified priority |
Andrew Boie | a498d46 | 2016-09-07 14:51:32 -0700 | [diff] [blame] | 39 | * |
| 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 Sharma | 77c643a | 2018-12-09 23:17:34 +0530 | [diff] [blame] | 44 | * @param level The initialization level, See DEVICE_AND_API_INIT for details. |
Andrew Boie | a498d46 | 2016-09-07 14:51:32 -0700 | [diff] [blame] | 45 | * |
| 46 | * @param prio Priority within the selected initialization level. See |
Varun Sharma | 77c643a | 2018-12-09 23:17:34 +0530 | [diff] [blame] | 47 | * DEVICE_AND_API_INIT for details. |
Andrew Boie | a498d46 | 2016-09-07 14:51:32 -0700 | [diff] [blame] | 48 | */ |
Benjamin Walsh | 629e1dd | 2016-01-28 14:56:48 -0500 | [diff] [blame] | 49 | #define SYS_INIT(init_fn, level, prio) \ |
Varun Sharma | 77c643a | 2018-12-09 23:17:34 +0530 | [diff] [blame] | 50 | DEVICE_AND_API_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level,\ |
| 51 | prio, NULL) |
Benjamin Walsh | 629e1dd | 2016-01-28 14:56:48 -0500 | [diff] [blame] | 52 | |
Andrew Boie | a498d46 | 2016-09-07 14:51:32 -0700 | [diff] [blame] | 53 | /** |
Ramesh Thomas | 6249c56 | 2016-10-07 17:07:04 -0700 | [diff] [blame] | 54 | * @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 Nashif | 11828bf | 2018-02-25 08:31:17 -0600 | [diff] [blame] | 59 | * @details This macro lets you run a function at system boot. |
| 60 | * |
Ramesh Thomas | 6249c56 | 2016-10-07 17:07:04 -0700 | [diff] [blame] | 61 | * @param drv_name Name of this system device |
Anas Nashif | 11828bf | 2018-02-25 08:31:17 -0600 | [diff] [blame] | 62 | * @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 Thomas | 6249c56 | 2016-10-07 17:07:04 -0700 | [diff] [blame] | 69 | */ |
| 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, \ |
amirkapl | d305da6 | 2016-09-01 09:01:10 +0300 | [diff] [blame] | 72 | NULL, NULL, level, prio, NULL) |
| 73 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 74 | #ifdef __cplusplus |
| 75 | } |
| 76 | #endif |
| 77 | |
Flavio Ceolin | 67ca176 | 2018-09-14 10:43:44 -0700 | [diff] [blame] | 78 | #endif /* ZEPHYR_INCLUDE_INIT_H_ */ |