Skip to content

Commit 75559f3

Browse files
committed
wip: ResetReason to microcontroller.cpu
1 parent e4c6699 commit 75559f3

File tree

33 files changed

+220
-206
lines changed

33 files changed

+220
-206
lines changed

locale/circuitpython.pot

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-11-19 00:28-0500\n"
11+
"POT-Creation-Date: 2020-11-21 12:36-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -990,7 +990,7 @@ msgstr ""
990990
msgid "I2SOut not available"
991991
msgstr ""
992992

993-
#: ports/esp32s2/common-hal/alarm_io/__init__.c
993+
#: ports/esp32s2/common-hal/alarm/pin/__init__.c
994994
msgid "IOs 0, 2 & 4 do not support internal pullup in sleep"
995995
msgstr ""
996996

@@ -2449,6 +2449,10 @@ msgstr ""
24492449
msgid "division by zero"
24502450
msgstr ""
24512451

2452+
#: ports/esp32s2/common-hal/alarm/time/DurationAlarm.c
2453+
msgid "duration out of range"
2454+
msgstr ""
2455+
24522456
#: py/objdeque.c
24532457
msgid "empty"
24542458
msgstr ""
@@ -2809,7 +2813,7 @@ msgstr ""
28092813
msgid "invalid syntax for number"
28102814
msgstr ""
28112815

2812-
#: ports/esp32s2/common-hal/alarm_io/__init__.c
2816+
#: ports/esp32s2/common-hal/alarm/pin/__init__.c
28132817
msgid "io must be rtc io"
28142818
msgstr ""
28152819

@@ -3434,10 +3438,6 @@ msgstr ""
34343438
msgid "threshold must be in the range 0-65536"
34353439
msgstr ""
34363440

3437-
#: ports/esp32s2/common-hal/alarm_time/__init__.c
3438-
msgid "time out of range"
3439-
msgstr ""
3440-
34413441
#: shared-bindings/time/__init__.c
34423442
msgid "time.struct_time() takes a 9-sequence"
34433443
msgstr ""
@@ -3484,7 +3484,7 @@ msgstr ""
34843484
msgid "trapz is defined for 1D arrays of equal length"
34853485
msgstr ""
34863486

3487-
#: ports/esp32s2/common-hal/alarm_io/__init__.c
3487+
#: ports/esp32s2/common-hal/alarm/pin/__init__.c
34883488
msgid "trigger level must be 0 or 1"
34893489
msgstr ""
34903490

@@ -3630,7 +3630,7 @@ msgstr ""
36303630
msgid "vectors must have same lengths"
36313631
msgstr ""
36323632

3633-
#: ports/esp32s2/common-hal/alarm_io/__init__.c
3633+
#: ports/esp32s2/common-hal/alarm/pin/__init__.c
36343634
msgid "wakeup conflict"
36353635
msgstr ""
36363636

main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ bool run_code_py(safe_mode_t safe_mode) {
330330
#if CIRCUITPY_ALARM
331331
// If USB isn't enumerated then deep sleep.
332332
if (ok && !supervisor_workflow_active() && supervisor_ticks_ms64() > CIRCUITPY_USB_ENUMERATION_DELAY * 1024) {
333-
common_hal_mcu_deep_sleep();
333+
common_hal_alarm_restart_on_alarm(0, NULL);
334334
}
335335
#endif
336336
// Show the animation every N seconds.
@@ -430,14 +430,9 @@ void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
430430
if (!skip_boot_output) {
431431
// Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
432432
// in case power is momentary or will fail shortly due to, say a low, battery.
433-
#if CIRCUITPY_ALARM
434-
if (common_hal_alarm_get_reset_reason() == RESET_REASON_POWER_ON) {
435-
#endif
433+
if (common_hal_mcu_processor_get_reset_reason() == RESET_REASON_POWER_ON) {
436434
mp_hal_delay_ms(1500);
437-
#if CIRCUITPY_ALARM
438435
}
439-
#endif
440-
441436
// USB isn't up, so we can write the file.
442437
filesystem_set_internal_writable_by_usb(false);
443438
f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS);

ports/atmel-samd/common-hal/microcontroller/Processor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
#include "py/mphal.h"
6767
#include "common-hal/microcontroller/Processor.h"
68+
#include "shared-bindings/microcontroller/ResetReason.h"
6869

6970
#include "samd/adc.h"
7071

@@ -349,3 +350,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
349350
}
350351
}
351352
}
353+
354+
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
355+
return RESET_REASON_POWER_ON;
356+
}

ports/atmel-samd/common-hal/microcontroller/__init__.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ void common_hal_mcu_reset(void) {
8484
reset();
8585
}
8686

87-
void common_hal_mcu_deep_sleep(void) {
88-
//deep sleep call here
89-
}
90-
9187
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
9288
// It currently only has properties, and no state.
9389
const mcu_processor_obj_t common_hal_mcu_processor_obj = {

ports/cxd56/common-hal/microcontroller/Processor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
// For NAN: remove when not needed.
3232
#include <math.h>
3333
#include "py/mphal.h"
34+
#include "shared-bindings/microcontroller/ResetReason.h"
3435

3536
uint32_t common_hal_mcu_processor_get_frequency(void) {
3637
return cxd56_get_cpu_baseclk();
@@ -47,3 +48,7 @@ float common_hal_mcu_processor_get_voltage(void) {
4748
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
4849
boardctl(BOARDIOC_UNIQUEID, (uintptr_t) raw_id);
4950
}
51+
52+
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
53+
return RESET_REASON_POWER_ON;
54+
}

ports/cxd56/common-hal/microcontroller/__init__.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ void common_hal_mcu_reset(void) {
8181
boardctl(BOARDIOC_RESET, 0);
8282
}
8383

84-
void common_hal_mcu_deep_sleep(void) {
85-
//deep sleep call here
86-
}
87-
8884
STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
8985
{ MP_ROM_QSTR(MP_QSTR_UART2_RXD), MP_ROM_PTR(&pin_UART2_RXD) },
9086
{ MP_ROM_QSTR(MP_QSTR_UART2_TXD), MP_ROM_PTR(&pin_UART2_TXD) },

ports/esp32s2/common-hal/alarm/__init__.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,6 @@ void common_hal_alarm_disable_all(void) {
3535
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
3636
}
3737

38-
alarm_reset_reason_t common_hal_alarm_get_reset_reason(void) {
39-
switch (esp_sleep_get_wakeup_cause()) {
40-
case ESP_SLEEP_WAKEUP_TIMER:
41-
return RESET_REASON_DEEP_SLEEP_ALARM;
42-
43-
case ESP_SLEEP_WAKEUP_EXT0:
44-
return RESET_REASON_DEEP_SLEEP_ALARM;
45-
46-
case ESP_SLEEP_WAKEUP_TOUCHPAD:
47-
//TODO: implement TouchIO
48-
case ESP_SLEEP_WAKEUP_UNDEFINED:
49-
default:
50-
return RESET_REASON_INVALID;
51-
}
52-
}
53-
54-
5538
mp_obj_t common_hal_alarm_get_wake_alarm(void) {
5639
switch (esp_sleep_get_wakeup_cause()) {
5740
case ESP_SLEEP_WAKEUP_TIMER: {

ports/esp32s2/common-hal/microcontroller/Processor.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
#include <math.h>
2929
#include <string.h>
3030

31-
#include "common-hal/microcontroller/Processor.h"
3231
#include "py/runtime.h"
32+
33+
#include "common-hal/microcontroller/Processor.h"
3334
#include "supervisor/shared/translate.h"
3435

3536
#include "soc/efuse_reg.h"
@@ -74,3 +75,23 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
7475
*ptr-- = swap_nibbles(mac_address_part & 0xff); mac_address_part >>= 8;
7576
*ptr-- = swap_nibbles(mac_address_part & 0xff);
7677
}
78+
79+
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
80+
switch (esp_sleep_get_wakeup_cause()) {
81+
case ESP_SLEEP_WAKEUP_TIMER:
82+
return RESET_REASON_DEEP_SLEEP_ALARM;
83+
84+
case ESP_SLEEP_WAKEUP_EXT0:
85+
return RESET_REASON_DEEP_SLEEP_ALARM;
86+
87+
case ESP_SLEEP_WAKEUP_TOUCHPAD:
88+
//TODO: implement TouchIO
89+
case ESP_SLEEP_WAKEUP_UNDEFINED:
90+
default:
91+
return RESET_REASON_POWER_APPLIED;
92+
}
93+
}
94+
95+
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
96+
return RESET_REASON_POWER_ON;
97+
}

ports/esp32s2/common-hal/microcontroller/__init__.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ void common_hal_mcu_reset(void) {
7979
while(1);
8080
}
8181

82-
void common_hal_mcu_deep_sleep(void) {
83-
esp_deep_sleep_start();
84-
}
85-
8682
// The singleton microcontroller.Processor object, bound to microcontroller.cpu
8783
// It currently only has properties, and no state.
8884
const mcu_processor_obj_t common_hal_mcu_processor_obj = {

ports/litex/common-hal/microcontroller/Processor.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
*/
2727

2828
#include <math.h>
29-
#include "common-hal/microcontroller/Processor.h"
3029
#include "py/runtime.h"
30+
31+
#include "common-hal/microcontroller/Processor.h"
32+
#include "shared-bindings/microcontroller/ResetReason.h"
3133
#include "supervisor/shared/translate.h"
3234

3335
#include "csr.h"
@@ -62,3 +64,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
6264
raw_id[13] = csr_readl(CSR_VERSION_SEED_ADDR + 8);
6365
raw_id[14] = csr_readl(CSR_VERSION_SEED_ADDR + 12);
6466
}
67+
68+
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
69+
return RESET_REASON_POWER_ON;
70+
}

0 commit comments

Comments
 (0)