Ken Van Hoeylandt 42e843b463
C++ conversions (#111)
* Remove version from artifact name
* Target C++ 20 and higher
* Use cpp string
* Better crash implementation
* String utils in cpp style
* Replace parameter methods with start() method
* MutexType to Mutex::Type
* Kernel c to cpp style
* Cleanup event flag
* More cpp conversions
* Test fixes
* Updated ideas docs
2024-12-07 12:24:28 +01:00

43 lines
924 B
C++

#include "Critical.h"
#include "CoreDefines.h"
#include "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 {
TtCriticalInfo enter() {
TtCriticalInfo 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(TtCriticalInfo info) {
if (info.fromIsr) {
taskEXIT_CRITICAL_FROM_ISR(info.isrm);
} else if (info.kernelRunning) {
TT_ENTER_CRITICAL();
} else {
portENABLE_INTERRUPTS();
}
}
}