Ken Van Hoeylandt c87200a80d
Project restructuring (fixes macOS builds) (#198)
- Create `Include/` folder for all main projects
- Fix some issues here and there (found while moving things)
- All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
2025-02-01 18:13:20 +01:00

44 lines
965 B
C++

#include "Tactility/kernel/critical/Critical.h"
#include "Tactility/CoreDefines.h"
#include "Tactility/RtosCompatTask.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 = TT_IS_ISR(),
.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();
}
}
}