Ken Van Hoeylandt 43c78c69d8
Thread, Timer and flash.sh improvements (#165)
- Various improvements to Thread and Timer:
  - Remove "mark as static" option as it is unused
  - Implemented core pinning for ESP32 platforms
  - Use `TickType_t` consistently (instead of `uint32_t`)
  - Use `enum class` instead of `enum`
- Fix for `flash.sh` not working when using `pip` to install `esptool`
2025-01-13 20:20:43 +01:00

63 lines
1.4 KiB
C++

#include "Main.h"
#include "TactilityCore.h"
#include "Thread.h"
#include "FreeRTOS.h"
#include "task.h"
#define TAG "freertos"
namespace simulator {
MainFunction mainFunction = nullptr;
void setMain(MainFunction newMainFunction) {
mainFunction = newMainFunction;
}
static void freertosMainTask(TT_UNUSED void* parameter) {
TT_LOG_I(TAG, "starting app_main()");
assert(simulator::mainFunction);
mainFunction();
TT_LOG_I(TAG, "returned from app_main()");
vTaskDelete(nullptr);
}
void freertosMain() {
BaseType_t task_result = xTaskCreate(
freertosMainTask,
"main",
8192,
nullptr,
static_cast<UBaseType_t>(tt::Thread::Priority::Normal),
nullptr
);
tt_assert(task_result == pdTRUE);
// Blocks forever
vTaskStartScheduler();
}
} // namespace
/**
* Assert implementation as defined in the FreeRTOSConfig.h
* It allows you to set breakpoints and debug asserts.
*/
void vAssertCalled(unsigned long line, const char* const file) {
static portBASE_TYPE xPrinted = pdFALSE;
volatile uint32_t set_to_nonzero_in_debugger_to_continue = 0;
TT_LOG_E(TAG, "assert triggered at %s:%d", file, line);
taskENTER_CRITICAL();
{
// Step out by attaching a debugger and setting set_to_nonzero_in_debugger_to_continue
while (set_to_nonzero_in_debugger_to_continue == 0) {
// NO-OP
}
}
taskEXIT_CRITICAL();
}