summaryrefslogtreecommitdiff
path: root/extmod/modmachine.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-11-27 11:43:15 +1100
committerDamien George <damien@micropython.org>2023-11-30 16:11:11 +1100
commitf523b86541440cc756aa0b2379538ee5e7864803 (patch)
tree1020c8b0335d6825537afd266c1acd5165f9b2c9 /extmod/modmachine.c
parente1ec6af654b1c5c4a973b6c6b029ee68bb92eb89 (diff)
extmod/modmachine: Provide common implementation of disable/enable_irq.
The ports esp32, mimxrt, rp2 and samd all shared exactly the same implementation of machine.disable_irq() and machine.enable_irq(), implemented in terms of MICROPY_{BEGIN,END}_ATOMIC_SECTION. This commit factors these implementations into extmod/modmachine.c. The cc3200, esp8266, nrf, renesas-ra and stm32 ports do not yet use this common implementation. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/modmachine.c')
-rw-r--r--extmod/modmachine.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/extmod/modmachine.c b/extmod/modmachine.c
index d56b938bb..a64b8ba79 100644
--- a/extmod/modmachine.c
+++ b/extmod/modmachine.c
@@ -117,6 +117,23 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsle
#endif
+#if MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ
+
+STATIC mp_obj_t machine_disable_irq(void) {
+ uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION();
+ return mp_obj_new_int(state);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);
+
+STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) {
+ uint32_t state = mp_obj_get_int(state_in);
+ MICROPY_END_ATOMIC_SECTION(state);
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq);
+
+#endif
+
STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) },
@@ -148,6 +165,12 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
#endif
+ // Interrupt related functions.
+ #if MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ
+ { 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) },
+ #endif
+
// Functions for bit protocols.
#if MICROPY_PY_MACHINE_BITSTREAM
{ MP_ROM_QSTR(MP_QSTR_bitstream), MP_ROM_PTR(&machine_bitstream_obj) },