Skip to content

Commit 064fbf4

Browse files
committed
Implement interrupts and noInterrupts
- Using irq_lock and irq_unlock zephyr apis. Signed-off-by: Ayush Singh <[email protected]>
1 parent 99ccf1a commit 064fbf4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cores/arduino/Arduino.h

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user),
9797

9898
#endif
9999

100+
void interrupts(void);
101+
void noInterrupts(void);
102+
100103
#include <variant.h>
101104
#ifdef __cplusplus
102105
#include <zephyrPrint.h>

cores/arduino/zephyrCommon.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ size_t analog_pin_index(pin_size_t pinNumber) {
175175

176176
#endif //CONFIG_ADC
177177

178+
static unsigned int irq_key;
179+
static bool interrupts_disabled = false;
180+
181+
void interrupts(void) {
182+
if (interrupts_disabled) {
183+
irq_unlock(irq_key);
184+
interrupts_disabled = false;
185+
}
186+
}
187+
188+
void noInterrupts(void) {
189+
if (!interrupts_disabled) {
190+
irq_key = irq_lock();
191+
interrupts_disabled = true;
192+
}
193+
}
178194
}
179195

180196
void yield(void) {

0 commit comments

Comments
 (0)