Skip to content

Implement interrupts and noInterrupts #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user),

#endif

void interrupts(void);
void noInterrupts(void);

#include <variant.h>
#ifdef __cplusplus
#include <zephyrPrint.h>
Expand Down
16 changes: 16 additions & 0 deletions cores/arduino/zephyrCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading