- Cleanup unused code and move ISR/IRQ checks to `Kernel.h` - Improve clang-format - Fix for LVGL lock transfer: ensure lock isn't activate when changing the lock - Implement SPI HAL - Remove `initHardware` HAL configuration entry - Fix `I2cScanner`: don't scan when port isn't started
44 lines
971 B
C++
44 lines
971 B
C++
#include "Tactility/kernel/critical/Critical.h"
|
|
|
|
#include "Tactility/RtosCompatTask.h"
|
|
#include "Tactility/kernel/Kernel.h"
|
|
|
|
#ifdef ESP_PLATFORM
|
|
static portMUX_TYPE critical_mutex;
|
|
#define TT_ENTER_CRITICAL() taskENTER_CRITICAL(&critical_mutex)
|
|
#else
|
|
#define TT_ENTER_CRITICAL() taskENTER_CRITICAL()
|
|
#endif
|
|
|
|
namespace tt::kernel::critical {
|
|
|
|
CriticalInfo enter() {
|
|
CriticalInfo info = {
|
|
.isrm = 0,
|
|
.fromIsr = kernel::isIsr(),
|
|
.kernelRunning = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING)
|
|
};
|
|
|
|
if (info.fromIsr) {
|
|
info.isrm = taskENTER_CRITICAL_FROM_ISR();
|
|
} else if (info.kernelRunning) {
|
|
TT_ENTER_CRITICAL();
|
|
} else {
|
|
portDISABLE_INTERRUPTS();
|
|
}
|
|
|
|
return info;
|
|
}
|
|
|
|
void exit(CriticalInfo info) {
|
|
if (info.fromIsr) {
|
|
taskEXIT_CRITICAL_FROM_ISR(info.isrm);
|
|
} else if (info.kernelRunning) {
|
|
TT_ENTER_CRITICAL();
|
|
} else {
|
|
portENABLE_INTERRUPTS();
|
|
}
|
|
}
|
|
|
|
}
|