esp32: Make machine.soft_reset() work in main.py and reset_cause().

This commit fixes two issues on the esp32:
- it enables machine.soft_reset() to be called in main.py;
- it enables machine.reset_cause() to correctly identify a soft reset.

The former is useful in that it enables soft resets in applications that
are started at boot time.  The support is patterned after the stm32 port.
pull/6929/head
Thorsten von Eicken 2020-06-03 22:42:37 -07:00 zatwierdzone przez Damien George
rodzic c10d431819
commit d28dbcd6c7
3 zmienionych plików z 24 dodań i 1 usunięć

Wyświetl plik

@ -73,6 +73,7 @@ void mp_task(void *pvParameter) {
mp_thread_init(pxTaskGetStackStart(NULL), MP_TASK_STACK_SIZE / sizeof(uintptr_t));
#endif
uart_init();
machine_init();
// TODO: CONFIG_SPIRAM_SUPPORT is for 3.3 compatibility, remove after move to 4.0.
#if CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_SPIRAM_SUPPORT
@ -118,7 +119,10 @@ soft_reset:
pyexec_frozen_module("_boot.py");
pyexec_file_if_exists("boot.py");
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
pyexec_file_if_exists("main.py");
int ret = pyexec_file_if_exists("main.py");
if (ret & PYEXEC_FORCED_EXIT) {
goto soft_reset_exit;
}
}
for (;;) {
@ -135,6 +139,8 @@ soft_reset:
}
}
soft_reset_exit:
#if MICROPY_BLUETOOTH_NIMBLE
mp_bluetooth_deinit();
#endif
@ -151,6 +157,7 @@ soft_reset:
// deinitialise peripherals
machine_pins_deinit();
machine_deinit();
usocket_events_deinit();
mp_deinit();

Wyświetl plik

@ -59,6 +59,8 @@ typedef enum {
MP_SOFT_RESET
} reset_reason_t;
STATIC bool is_soft_reset = 0;
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
// get
@ -140,6 +142,9 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_ma
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_deepsleep_obj, 0, machine_deepsleep);
STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
if (is_soft_reset) {
return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET);
}
switch (esp_reset_reason()) {
case ESP_RST_POWERON:
case ESP_RST_BROWNOUT:
@ -171,6 +176,15 @@ STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_reset_cause_obj, 0, machine_reset_cause);
void machine_init(void) {
is_soft_reset = 0;
}
void machine_deinit(void) {
// we are doing a soft-reset so change the reset_cause
is_soft_reset = 1;
}
STATIC mp_obj_t machine_wake_reason(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
return MP_OBJ_NEW_SMALL_INT(esp_sleep_get_wakeup_cause());
}

Wyświetl plik

@ -22,6 +22,8 @@ extern const mp_obj_type_t machine_uart_type;
extern const mp_obj_type_t machine_rtc_type;
extern const mp_obj_type_t machine_sdcard_type;
void machine_init(void);
void machine_deinit(void);
void machine_pins_init(void);
void machine_pins_deinit(void);
void machine_timer_deinit_all(void);