2016-08-26 02:38:53 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Nordic Semiconductor ASA
|
|
|
|
* Copyright (c) 2016 Linaro Limited
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-08-26 02:38:53 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief System/hardware module for Nordic Semiconductor nRF51 family processor
|
|
|
|
*
|
|
|
|
* This module provides routines to initialize and support board-level hardware
|
|
|
|
* for the Nordic Semiconductor nRF51 family processor.
|
|
|
|
*/
|
|
|
|
|
2016-12-23 21:35:34 +08:00
|
|
|
#include <kernel.h>
|
2016-08-26 02:38:53 +08:00
|
|
|
#include <init.h>
|
2019-09-19 19:25:18 +08:00
|
|
|
#include <hal/nrf_power.h>
|
2018-11-24 00:40:29 +08:00
|
|
|
#include <soc/nrfx_coredep.h>
|
2019-01-18 22:53:06 +08:00
|
|
|
#include <logging/log.h>
|
2016-08-26 02:38:53 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_RUNTIME_NMI
|
2019-10-01 03:31:07 +08:00
|
|
|
extern void z_arm_nmi_init(void);
|
|
|
|
#define NMI_INIT() z_arm_nmi_init()
|
2016-08-26 02:38:53 +08:00
|
|
|
#else
|
|
|
|
#define NMI_INIT()
|
|
|
|
#endif
|
|
|
|
|
2018-06-18 16:35:43 +08:00
|
|
|
#include <system_nrf51.h>
|
2018-09-17 23:39:56 +08:00
|
|
|
#define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
|
|
|
|
LOG_MODULE_REGISTER(soc);
|
2016-08-26 02:38:53 +08:00
|
|
|
|
2019-01-09 20:51:36 +08:00
|
|
|
/* Overrides the weak ARM implementation:
|
|
|
|
Set general purpose retention register and reboot */
|
|
|
|
void sys_arch_reboot(int type)
|
|
|
|
{
|
2019-11-08 06:13:34 +08:00
|
|
|
nrf_power_gpregret_set(NRF_POWER, (uint8_t)type);
|
2019-01-09 20:51:36 +08:00
|
|
|
NVIC_SystemReset();
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int nordicsemi_nrf51_init(const struct device *arg)
|
2016-08-26 02:38:53 +08:00
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t key;
|
2016-08-26 02:38:53 +08:00
|
|
|
|
|
|
|
ARG_UNUSED(arg);
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
|
|
|
/* Install default handler that simply resets the CPU
|
|
|
|
* if configured in the kernel, NOP otherwise
|
|
|
|
*/
|
|
|
|
NMI_INIT();
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-27 08:07:43 +08:00
|
|
|
#define DELAY_CALL_OVERHEAD_US 2
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
void arch_busy_wait(uint32_t time_us)
|
2019-04-27 08:07:43 +08:00
|
|
|
{
|
|
|
|
if (time_us <= DELAY_CALL_OVERHEAD_US) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
time_us -= DELAY_CALL_OVERHEAD_US;
|
|
|
|
nrfx_coredep_delay_us(time_us);
|
|
|
|
}
|
|
|
|
|
2019-05-22 22:18:18 +08:00
|
|
|
void z_platform_init(void)
|
|
|
|
{
|
|
|
|
SystemInit();
|
|
|
|
}
|
|
|
|
|
2016-11-09 03:06:55 +08:00
|
|
|
SYS_INIT(nordicsemi_nrf51_init, PRE_KERNEL_1, 0);
|