2019-01-07 17:18:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Alexander Wachter
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <soc.h>
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/drivers/hwinfo.h>
|
2019-01-07 17:18:35 +01:00
|
|
|
#include <string.h>
|
2019-12-16 13:23:44 +01:00
|
|
|
#include <hal/nrf_ficr.h>
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/sys/byteorder.h>
|
2020-04-30 22:32:52 -04:00
|
|
|
#ifndef CONFIG_BOARD_QEMU_CORTEX_M0
|
|
|
|
#include <helpers/nrfx_reset_reason.h>
|
|
|
|
#endif
|
2022-03-18 15:06:00 +01:00
|
|
|
#include <soc_secure.h>
|
2019-01-07 17:18:35 +01:00
|
|
|
struct nrf_uid {
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t id[2];
|
2019-01-07 17:18:35 +01:00
|
|
|
};
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
2019-01-07 17:18:35 +01:00
|
|
|
{
|
|
|
|
struct nrf_uid dev_id;
|
2022-03-18 15:06:00 +01:00
|
|
|
uint32_t deviceid[2];
|
|
|
|
|
|
|
|
soc_secure_read_deviceid(deviceid);
|
2019-01-07 17:18:35 +01:00
|
|
|
|
2022-03-18 15:06:00 +01:00
|
|
|
dev_id.id[0] = sys_cpu_to_be32(deviceid[1]);
|
|
|
|
dev_id.id[1] = sys_cpu_to_be32(deviceid[0]);
|
2019-01-07 17:18:35 +01:00
|
|
|
|
|
|
|
if (length > sizeof(dev_id.id)) {
|
|
|
|
length = sizeof(dev_id.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buffer, dev_id.id, length);
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2020-04-30 22:32:52 -04:00
|
|
|
|
|
|
|
#ifndef CONFIG_BOARD_QEMU_CORTEX_M0
|
|
|
|
int z_impl_hwinfo_get_reset_cause(uint32_t *cause)
|
|
|
|
{
|
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
uint32_t reason = nrfx_reset_reason_get();
|
|
|
|
|
|
|
|
if (reason & NRFX_RESET_REASON_RESETPIN_MASK) {
|
|
|
|
flags |= RESET_PIN;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_DOG_MASK) {
|
|
|
|
flags |= RESET_WATCHDOG;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_LOCKUP_MASK) {
|
|
|
|
flags |= RESET_CPU_LOCKUP;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_OFF_MASK) {
|
|
|
|
flags |= RESET_LOW_POWER_WAKE;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_DIF_MASK) {
|
|
|
|
flags |= RESET_DEBUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !NRF_POWER_HAS_RESETREAS
|
|
|
|
if (reason & NRFX_RESET_REASON_CTRLAP_MASK) {
|
|
|
|
flags |= RESET_DEBUG;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_DOG0_MASK) {
|
|
|
|
flags |= RESET_WATCHDOG;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_DOG1_MASK) {
|
|
|
|
flags |= RESET_WATCHDOG;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESETREAS_SREQ_MASK) {
|
|
|
|
flags |= RESET_SOFTWARE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NRF_RESET_HAS_NETWORK
|
|
|
|
if (reason & NRFX_RESET_REASON_LSREQ_MASK) {
|
|
|
|
flags |= RESET_SOFTWARE;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_LLOCKUP_MASK) {
|
|
|
|
flags |= RESET_CPU_LOCKUP;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_LDOG_MASK) {
|
|
|
|
flags |= RESET_WATCHDOG;
|
|
|
|
}
|
|
|
|
if (reason & NRFX_RESET_REASON_LCTRLAP_MASK) {
|
|
|
|
flags |= RESET_DEBUG;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
if (reason & NRFX_RESET_REASON_SREQ_MASK) {
|
|
|
|
flags |= RESET_SOFTWARE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*cause = flags;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int z_impl_hwinfo_clear_reset_cause(void)
|
|
|
|
{
|
|
|
|
uint32_t reason = -1;
|
|
|
|
|
|
|
|
nrfx_reset_reason_clear(reason);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported)
|
|
|
|
{
|
|
|
|
*supported = (RESET_PIN
|
|
|
|
| RESET_WATCHDOG
|
|
|
|
| RESET_SOFTWARE
|
|
|
|
| RESET_CPU_LOCKUP
|
|
|
|
| RESET_LOW_POWER_WAKE
|
|
|
|
| RESET_DEBUG);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|