Skip to content

Commit a1ee42c

Browse files
committed
nrf: Use common implementation of machine disable/enable IRQ.
This is a breaking change due to the signature change of `enable_irq()`. Previously the signature was: machine.enable_irq() Now the signature matches other ports, and the docs, and is: machine.enable_irq(state) Where `state` is the return value from `machine.disable_irq()`. Signed-off-by: Damien George <[email protected]>
1 parent cc7eb1a commit a1ee42c

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

ports/nrf/modules/machine/modmachine.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@
8585

8686
#define MICROPY_PY_MACHINE_EXTRA_GLOBALS \
8787
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&machine_info_obj) }, \
88-
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, \
89-
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, \
9088
{ MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) }, \
9189
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pin_type) }, \
9290
\
@@ -214,24 +212,3 @@ static mp_obj_t mp_machine_get_freq(void) {
214212
static void mp_machine_set_freq(size_t n_args, const mp_obj_t *args) {
215213
mp_raise_NotImplementedError(NULL);
216214
}
217-
218-
static mp_obj_t machine_enable_irq(void) {
219-
#ifndef BLUETOOTH_SD
220-
__enable_irq();
221-
#else
222-
223-
#endif
224-
return mp_const_none;
225-
}
226-
MP_DEFINE_CONST_FUN_OBJ_0(machine_enable_irq_obj, machine_enable_irq);
227-
228-
// Resets the board in a manner similar to pushing the external RESET button.
229-
static mp_obj_t machine_disable_irq(void) {
230-
#ifndef BLUETOOTH_SD
231-
__disable_irq();
232-
#else
233-
234-
#endif
235-
return mp_const_none;
236-
}
237-
MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq);

ports/nrf/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
#define MICROPY_PY_MACHINE_RESET (1)
182182
#define MICROPY_PY_MACHINE_BARE_METAL_FUNCS (1)
183183
#define MICROPY_PY_MACHINE_BOOTLOADER (1)
184+
#define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1)
184185
#define MICROPY_PY_MACHINE_PULSE (0)
185186
#define MICROPY_PY_MACHINE_SOFTI2C (MICROPY_PY_MACHINE_I2C)
186187

ports/nrf/mphalport.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
3535
#include "nrfx_config.h"
3636
#include "shared/runtime/interrupt_char.h"
3737

38+
// Entering a critical section.
39+
#ifndef BLUETOOTH_SD
40+
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
41+
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)
42+
#endif
43+
44+
static inline void enable_irq(mp_uint_t state) {
45+
__set_PRIMASK(state);
46+
}
47+
48+
static inline mp_uint_t disable_irq(void) {
49+
mp_uint_t state = __get_PRIMASK();
50+
__disable_irq();
51+
return state;
52+
}
53+
3854
typedef enum
3955
{
4056
HAL_OK = 0x00,

0 commit comments

Comments
 (0)