2019-02-04 02:22:01 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Leandro A. F. Pereira
|
2020-04-11 00:23:25 +08:00
|
|
|
* Copyright (c) 2020 Nordic Semiconductor ASA
|
2019-02-04 02:22:01 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <soc/efuse_reg.h>
|
2023-02-25 03:45:04 +08:00
|
|
|
#include <soc/reset_reasons.h>
|
|
|
|
#include "esp_system.h"
|
|
|
|
#include "rtc.h"
|
2019-02-04 02:22:01 +08:00
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/hwinfo.h>
|
2019-02-04 02:22:01 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
2019-02-04 02:22:01 +08:00
|
|
|
{
|
2023-02-25 03:45:04 +08:00
|
|
|
#ifndef CONFIG_SOC_ESP32
|
2022-11-30 08:06:01 +08:00
|
|
|
uint32_t rdata1 = sys_read32(EFUSE_RD_MAC_SPI_SYS_0_REG);
|
|
|
|
uint32_t rdata2 = sys_read32(EFUSE_RD_MAC_SPI_SYS_1_REG);
|
|
|
|
#else
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t rdata1 = sys_read32(EFUSE_BLK0_RDATA1_REG);
|
|
|
|
uint32_t rdata2 = sys_read32(EFUSE_BLK0_RDATA2_REG);
|
2022-11-30 08:06:01 +08:00
|
|
|
#endif
|
2020-05-28 00:26:57 +08:00
|
|
|
uint8_t id[6];
|
2019-02-04 02:22:01 +08:00
|
|
|
|
2020-04-11 00:23:25 +08:00
|
|
|
/* The first word provides the lower 32 bits of the MAC
|
|
|
|
* address; the low 16 bits of the second word provide the
|
|
|
|
* upper 16 bytes of the MAC address. The upper 16 bits are
|
|
|
|
* (apparently) a checksum, and reserved. See ESP32 Technical
|
|
|
|
* Reference Manual V4.1 section 20.5.
|
|
|
|
*/
|
2020-05-28 00:26:57 +08:00
|
|
|
id[0] = (uint8_t)(rdata2 >> 8);
|
|
|
|
id[1] = (uint8_t)(rdata2 >> 0);
|
|
|
|
id[2] = (uint8_t)(rdata1 >> 24);
|
|
|
|
id[3] = (uint8_t)(rdata1 >> 16);
|
|
|
|
id[4] = (uint8_t)(rdata1 >> 8);
|
|
|
|
id[5] = (uint8_t)(rdata1 >> 0);
|
2019-02-04 02:22:01 +08:00
|
|
|
|
2020-04-11 00:23:25 +08:00
|
|
|
if (length > sizeof(id)) {
|
|
|
|
length = sizeof(id);
|
|
|
|
}
|
|
|
|
memcpy(buffer, id, length);
|
2019-02-04 02:22:01 +08:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2023-02-25 03:45:04 +08:00
|
|
|
|
|
|
|
int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported)
|
|
|
|
{
|
|
|
|
*supported = (RESET_POR
|
|
|
|
| RESET_PIN
|
|
|
|
| RESET_SOFTWARE
|
|
|
|
| RESET_WATCHDOG
|
|
|
|
| RESET_LOW_POWER_WAKE
|
|
|
|
| RESET_CPU_LOCKUP
|
|
|
|
| RESET_BROWNOUT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int z_impl_hwinfo_get_reset_cause(uint32_t *cause)
|
|
|
|
{
|
|
|
|
uint32_t reason = esp_reset_reason();
|
|
|
|
|
|
|
|
switch (reason) {
|
|
|
|
case ESP_RST_POWERON:
|
|
|
|
*cause = RESET_POR;
|
|
|
|
break;
|
|
|
|
case ESP_RST_EXT:
|
|
|
|
*cause = RESET_PIN;
|
|
|
|
break;
|
|
|
|
case ESP_RST_SW:
|
|
|
|
*cause = RESET_SOFTWARE;
|
|
|
|
break;
|
|
|
|
case ESP_RST_INT_WDT:
|
|
|
|
case ESP_RST_TASK_WDT:
|
|
|
|
case ESP_RST_WDT:
|
|
|
|
*cause = RESET_WATCHDOG;
|
|
|
|
break;
|
|
|
|
case ESP_RST_DEEPSLEEP:
|
|
|
|
*cause = RESET_LOW_POWER_WAKE;
|
|
|
|
break;
|
|
|
|
case ESP_RST_PANIC:
|
|
|
|
*cause = RESET_CPU_LOCKUP;
|
|
|
|
case ESP_RST_BROWNOUT:
|
|
|
|
*cause = RESET_BROWNOUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*cause = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|