InterruptLock per core for rp2040

This commit is contained in:
Jesse Hills 2023-03-21 14:13:25 +13:00
parent cd57469e06
commit b6e765daaa
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
2 changed files with 22 additions and 3 deletions

View File

@ -415,8 +415,23 @@ IRAM_ATTR InterruptLock::~InterruptLock() { xt_wsr_ps(state_); }
IRAM_ATTR InterruptLock::InterruptLock() { portDISABLE_INTERRUPTS(); }
IRAM_ATTR InterruptLock::~InterruptLock() { portENABLE_INTERRUPTS(); }
#elif defined(USE_RP2040)
IRAM_ATTR InterruptLock::InterruptLock() { state_ = save_and_disable_interrupts(); }
IRAM_ATTR InterruptLock::~InterruptLock() { restore_interrupts(state_); }
IRAM_ATTR InterruptLock::InterruptLock() {
auto core = get_core_num();
if (this->stack_top_[core] == STACK_SIZE) {
panic("InterruptLock stack overflow");
}
uint8_t stack_top = this->stack_top_[core]++;
state_stack_[core][stack_top] = save_and_disable_interrupts();
}
IRAM_ATTR InterruptLock::~InterruptLock() {
auto core = get_core_num();
if (!this->stack_top_[core]) {
return; // No state to restore
}
uint8_t stack_top = --this->stack_top_[core];
uint32_t state = this->state_stack_[core][stack_top];
restore_interrupts(state);
}
#endif
uint8_t HighFrequencyLoopRequester::num_requests = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

View File

@ -583,8 +583,12 @@ class InterruptLock {
~InterruptLock();
protected:
#if defined(USE_ESP8266) || defined(USE_RP2040)
#if defined(USE_ESP8266)
uint32_t state_;
#elif defined(USE_RP2040)
static const uint8_t STACK_SIZE = 15;
uint8_t stack_top_[2] = {0, 0};
uint32_t state_stack_[2][STACK_SIZE];
#endif
};