mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-19 03:13:14 +00:00
- 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`)
44 lines
965 B
C++
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();
|
|
}
|
|
}
|
|
|
|
}
|