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 | |
| 8 | #ifndef _INIT_H_ |
| 9 | #define _INIT_H_ |
| 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 | |
Andrew Boie | a5b2682 | 2016-09-22 11:14:59 -0700 | [diff] [blame] | 30 | /* 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 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 | * |
| 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 Walsh | 629e1dd | 2016-01-28 14:56:48 -0500 | [diff] [blame] | 49 | #define SYS_INIT(init_fn, level, prio) \ |
Andrew Boie | a5b2682 | 2016-09-22 11:14:59 -0700 | [diff] [blame] | 50 | DEVICE_INIT(_SYS_NAME(init_fn), "", init_fn, NULL, NULL, level, prio) |
Benjamin Walsh | 629e1dd | 2016-01-28 14:56:48 -0500 | [diff] [blame] | 51 | |
Andrew Boie | a498d46 | 2016-09-07 14:51:32 -0700 | [diff] [blame] | 52 | /** |
Ramesh Thomas | 6249c56 | 2016-10-07 17:07:04 -0700 | [diff] [blame] | 53 | * @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, \ |
amirkapl | d305da6 | 2016-09-01 09:01:10 +0300 | [diff] [blame] | 65 | NULL, NULL, level, prio, NULL) |
| 66 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
| 70 | |
Dirk Brandewie | c9ac95a | 2015-06-01 11:11:39 -0700 | [diff] [blame] | 71 | #endif /* _INIT_H_ */ |