1 /*
2  * Copyright (c) 2016 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief System/hardware module for Nordic Semiconductor nRF52 family processor
10  *
11  * This module provides routines to initialize and support board-level hardware
12  * for the Nordic Semiconductor nRF52 family processor.
13  */
14 
15 #include <zephyr/kernel.h>
16 #include <zephyr/init.h>
17 #include <hal/nrf_power.h>
18 #include <soc/nrfx_coredep.h>
19 #include <zephyr/logging/log.h>
20 
21 #include <cmsis_core.h>
22 
23 #define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
24 LOG_MODULE_REGISTER(soc);
25 
26 #ifdef CONFIG_NRF_STORE_REBOOT_TYPE_GPREGRET
27 /* Overrides the weak ARM implementation:
28  * Set general purpose retention register and reboot
29  * This is deprecated and has been replaced with the boot mode retention
30  * subsystem
31  */
sys_arch_reboot(int type)32 void sys_arch_reboot(int type)
33 {
34 	nrf_power_gpregret_set(NRF_POWER, (uint8_t)type);
35 	NVIC_SystemReset();
36 }
37 #endif
38 
nordicsemi_nrf52_init(void)39 static int nordicsemi_nrf52_init(void)
40 {
41 #ifdef CONFIG_NRF_ENABLE_ICACHE
42 	/* Enable the instruction cache */
43 	NRF_NVMC->ICACHECNF = NVMC_ICACHECNF_CACHEEN_Msk;
44 #endif
45 
46 #if defined(CONFIG_SOC_DCDC_NRF52X)
47 	nrf_power_dcdcen_set(NRF_POWER, true);
48 #endif
49 #if NRF_POWER_HAS_DCDCEN_VDDH && defined(CONFIG_SOC_DCDC_NRF52X_HV)
50 	nrf_power_dcdcen_vddh_set(NRF_POWER, true);
51 #endif
52 
53 	return 0;
54 }
55 
arch_busy_wait(uint32_t time_us)56 void arch_busy_wait(uint32_t time_us)
57 {
58 	nrfx_coredep_delay_us(time_us);
59 }
60 
61 SYS_INIT(nordicsemi_nrf52_init, PRE_KERNEL_1, 0);
62