summaryrefslogtreecommitdiff
path: root/ports/esp32s2/common-hal/microcontroller/Processor.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/esp32s2/common-hal/microcontroller/Processor.c')
-rw-r--r--ports/esp32s2/common-hal/microcontroller/Processor.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/ports/esp32s2/common-hal/microcontroller/Processor.c b/ports/esp32s2/common-hal/microcontroller/Processor.c
index b81521601..fffd1a1b1 100644
--- a/ports/esp32s2/common-hal/microcontroller/Processor.c
+++ b/ports/esp32s2/common-hal/microcontroller/Processor.c
@@ -28,10 +28,15 @@
#include <math.h>
#include <string.h>
-#include "common-hal/microcontroller/Processor.h"
#include "py/runtime.h"
+
+#include "common-hal/microcontroller/Processor.h"
+#include "shared-bindings/microcontroller/ResetReason.h"
#include "supervisor/shared/translate.h"
+#include "esp_sleep.h"
+#include "esp_system.h"
+
#include "soc/efuse_reg.h"
#include "components/driver/esp32s2/include/driver/temp_sensor.h"
@@ -74,3 +79,44 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
*ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
*ptr-- = swap_nibbles(mac_address_part & 0xff);
}
+
+mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
+ switch (esp_reset_reason()) {
+ case ESP_RST_POWERON:
+ return RESET_REASON_POWER_ON;
+
+ case ESP_RST_SW:
+ case ESP_RST_PANIC:
+ return RESET_REASON_SOFTWARE;
+
+ case ESP_RST_INT_WDT:
+ case ESP_RST_TASK_WDT:
+ case ESP_RST_WDT:
+ return RESET_REASON_WATCHDOG;
+
+ case ESP_RST_BROWNOUT:
+ return RESET_REASON_BROWNOUT;
+
+ case ESP_RST_SDIO:
+ case ESP_RST_EXT:
+ return RESET_REASON_RESET_PIN;
+
+ case ESP_RST_DEEPSLEEP:
+ switch (esp_sleep_get_wakeup_cause()) {
+ case ESP_SLEEP_WAKEUP_TIMER:
+ case ESP_SLEEP_WAKEUP_EXT0:
+ case ESP_SLEEP_WAKEUP_EXT1:
+ case ESP_SLEEP_WAKEUP_TOUCHPAD:
+ return RESET_REASON_DEEP_SLEEP_ALARM;
+
+ case ESP_SLEEP_WAKEUP_UNDEFINED:
+ default:
+ return RESET_REASON_UNKNOWN;
+ }
+
+ case ESP_RST_UNKNOWN:
+ default:
+ return RESET_REASON_UNKNOWN;
+
+ }
+}