From 064fbf41cbc94d21e14bad755df4cd1d3e83263a 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/Arduino.h | 3 +++ cores/arduino/zephyrCommon.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 673968ef..69390481 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -97,6 +97,9 @@ enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), #endif +void interrupts(void); +void noInterrupts(void); + #include #ifdef __cplusplus #include diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 13611ca2..9eb84dca 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -175,6 +175,22 @@ size_t analog_pin_index(pin_size_t pinNumber) { #endif //CONFIG_ADC +static unsigned int irq_key; +static bool interrupts_disabled = false; + +void interrupts(void) { + if (interrupts_disabled) { + irq_unlock(irq_key); + interrupts_disabled = false; + } +} + +void noInterrupts(void) { + if (!interrupts_disabled) { + irq_key = irq_lock(); + interrupts_disabled = true; + } +} } void yield(void) {