1 /*
2 * Copyright (c) 2021 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/init.h>
8 #include <zephyr/kernel.h>
9
10 /* Initialization chain of Thingy:53 board requires some delays before on board sensors
11 * could be accessed after power up. In particular bme680 and bmm150 sensors require,
12 * respectively 2ms and 1ms power on delay. In order to avoid delays sum, common delay is
13 * introduced in the board start up file. Below asserts ensure correct initialization order:
14 * on board regulators, board init (this), sensors init.
15 */
16 #if !defined(CONFIG_TRUSTED_EXECUTION_SECURE)
17 #if defined(CONFIG_REGULATOR_FIXED)
18 BUILD_ASSERT(CONFIG_THINGY53_INIT_PRIORITY > CONFIG_REGULATOR_FIXED_INIT_PRIORITY,
19 "CONFIG_THINGY53_INIT_PRIORITY must be higher than CONFIG_REGULATOR_FIXED_INIT_PRIORITY");
20 #endif /* CONFIG_REGULATOR_FIXED */
21 #if defined(CONFIG_IEEE802154_NRF5)
22 BUILD_ASSERT(CONFIG_THINGY53_INIT_PRIORITY < CONFIG_IEEE802154_NRF5_INIT_PRIO,
23 "CONFIG_THINGY53_INIT_PRIORITY must be less than CONFIG_IEEE802154_NRF5_INIT_PRIO");
24 #endif /* CONFIG_IEEE802154_NRF5 */
25 #endif /* !CONFIG_TRUSTED_EXECUTION_SECURE */
26
27 #if defined(CONFIG_SENSOR)
28 BUILD_ASSERT(CONFIG_THINGY53_INIT_PRIORITY < CONFIG_SENSOR_INIT_PRIORITY,
29 "CONFIG_THINGY53_INIT_PRIORITY must be less than CONFIG_SENSOR_INIT_PRIORITY");
30 #endif
31
32 #if !defined(CONFIG_TRUSTED_EXECUTION_SECURE) && defined(CONFIG_SENSOR)
setup(void)33 static int setup(void)
34 {
35 /* Initialization chain of Thingy:53 board requires some delays before on board
36 * sensors could be accessed after power up. In particular bme680 and bmm150
37 * sensors require, 2ms and 1ms power on delay respectively. In order not to sum
38 * delays, common delay is introduced in the board start up file. This code is
39 * executed after sensors are powered up and before their initialization.
40 * It's ensured by build asserts at the beginning of this file.
41 */
42 k_msleep(2);
43
44 return 0;
45 }
46
47 SYS_INIT(setup, POST_KERNEL, CONFIG_THINGY53_INIT_PRIORITY);
48 #endif /* !CONFIG_TRUSTED_EXECUTION_SECURE && CONFIG_SENSOR */
49