summaryrefslogtreecommitdiff
path: root/ports/esp8266/modmachine.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-11-24 18:25:30 +1100
committerDamien George <damien@micropython.org>2023-11-30 16:11:11 +1100
commite1ec6af654b1c5c4a973b6c6b029ee68bb92eb89 (patch)
treebe9ca3b41d2fa993a7af4c3694ebbb63a05d4713 /ports/esp8266/modmachine.c
parent48b5a7b06079f0d0aa4780016f015ff023875680 (diff)
extmod/modmachine: Provide common bindings for 6 bare-metal functions.
Minor changes for consistency are: - nrf gains: unique_id(), freq() [they do nothing] - samd: deepsleep() now resets after calling lightsleep() - esp32: lightsleep()/deepsleep() no longer take kw arg "sleep", instead it's positional to match others. also, passing 0 here will now do a 0ms sleep instead of acting like nothing was passed. reset_cause() no longer takes any args (before it would just ignore them) - mimxrt: freq() with an argument and lightsleep() both raise NotImplementedError Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/esp8266/modmachine.c')
-rw-r--r--ports/esp8266/modmachine.c54
1 files changed, 20 insertions, 34 deletions
diff --git a/ports/esp8266/modmachine.c b/ports/esp8266/modmachine.c
index cce6b01ce..d55a656ce 100644
--- a/ports/esp8266/modmachine.c
+++ b/ports/esp8266/modmachine.c
@@ -41,13 +41,7 @@
#define MACHINE_WAKE_DEEPSLEEP (0x04)
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
- { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, \
- { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, \
- { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, \
- { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
- { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
- { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, \
\
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
@@ -68,45 +62,42 @@
{ MP_ROM_QSTR(MP_QSTR_WDT_RESET), MP_ROM_INT(REASON_WDT_RST) }, \
{ MP_ROM_QSTR(MP_QSTR_SOFT_RESET), MP_ROM_INT(REASON_SOFT_RESTART) }, \
-STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
- if (n_args == 0) {
- // get
- return mp_obj_new_int(system_get_cpu_freq() * 1000000);
- } else {
- // set
- mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
- if (freq != 80 && freq != 160) {
- mp_raise_ValueError(MP_ERROR_TEXT("frequency can only be either 80Mhz or 160MHz"));
- }
- system_update_cpu_freq(freq);
- return mp_const_none;
+STATIC mp_obj_t mp_machine_get_freq(void) {
+ return mp_obj_new_int(system_get_cpu_freq() * 1000000);
+}
+
+STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
+ mp_int_t freq = mp_obj_get_int(args[0]) / 1000000;
+ if (freq != 80 && freq != 160) {
+ mp_raise_ValueError(MP_ERROR_TEXT("frequency can only be either 80Mhz or 160MHz"));
}
+ system_update_cpu_freq(freq);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq);
-STATIC mp_obj_t machine_reset(void) {
+NORETURN STATIC void mp_machine_reset(void) {
system_restart();
- return mp_const_none;
+
+ // we must not return
+ for (;;) {
+ ets_loop_iter();
+ }
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset);
-STATIC mp_obj_t machine_reset_cause(void) {
- return MP_OBJ_NEW_SMALL_INT(system_get_rst_info()->reason);
+STATIC mp_int_t mp_machine_reset_cause(void) {
+ return system_get_rst_info()->reason;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause);
-STATIC mp_obj_t machine_unique_id(void) {
+STATIC mp_obj_t mp_machine_unique_id(void) {
uint32_t id = system_get_chip_id();
return mp_obj_new_bytes((byte *)&id, sizeof(id));
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id);
STATIC void mp_machine_idle(void) {
asm ("waiti 0");
ets_event_poll(); // handle any events after possibly a long wait (eg feed WDT)
}
-STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
+STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
uint32_t max_us = 0xffffffff;
if (n_args == 1) {
mp_int_t max_ms = mp_obj_get_int(args[0]);
@@ -124,11 +115,9 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
asm ("waiti 0");
}
}
- return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep);
-STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
+NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
// default to sleep forever
uint32_t sleep_us = 0;
@@ -171,10 +160,7 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
// we must not return
ets_loop_iter();
}
-
- return mp_const_none;
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
// These values are from the datasheet
#define ESP_TIMER_US_MIN (100)