From fd926ed5aed7831b16558a621b95caa7335026ef Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Fri, 16 Aug 2024 14:39:13 +0530 Subject: [PATCH] Implement interrupts and noInterrupts - Using irq_lock and irq_unlock zephyr apis. Signed-off-by: Ayush Singh --- cores/arduino/zephyrCommon.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 13611ca..cdaadf7 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -464,3 +464,18 @@ void disableInterrupt(pin_size_t pinNumber) { pcb->handlers[BIT(arduino_pins[pinNumber].pin)].enabled = false; } } + +static unsigned int irq_key = UINT_MAX; + +void interrupts(void) { + if (irq_key != UINT_MAX) { + irq_unlock(irq_key); + irq_key = UINT_MAX; + } +} + +void noInterrupts(void) { + if (irq_key == UINT_MAX) { + irq_key = irq_lock(); + } +}