Skip to content

Commit

Permalink
feat: fixes for esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Jan 29, 2025
1 parent 79cf88e commit 21842cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
7 changes: 2 additions & 5 deletions main/platform/esp/MDNSBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,13 @@ class implMDNSBrowser : public mdns::Browser {
}

void processEvents(int timeoutMs) override {
// Start Avahi thread poll
mdns_result_t* results = nullptr;
esp_err_t err = mdns_query_ptr(serviceType.c_str(), proto.c_str(),
timeoutMs, maxResults, &results);
if (err) {
BELL_LOG(
error, "MDNSBrowser",
"Failed to query mdns services. Service type: {}, proto: {}, err: {}",
serviceType, proto, static_cast<int>(err));
throw std::runtime_error("Could not query mdns services");
} else {
parseResults(results);
}

mdns_query_results_free(results);
Expand Down
19 changes: 13 additions & 6 deletions main/platform/esp/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ class Task::Impl {
espPriority(espPriority),
taskName(std::move(taskName)) {

if (espStackOnPsram) {
xStack = static_cast<StackType_t*>(
heap_caps_malloc(stackSize, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
if (this->espStackOnPsram) {
xStack = static_cast<StackType_t*>(heap_caps_malloc(
this->stackSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));

xTaskBuffer = static_cast<StaticTask_t*>(heap_caps_malloc(
sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
}
}
~Impl() {
if (taskPtr) {
taskPtr->stopTask();
}

if (xStack) {
BELL_LOG(info, "Task", "Freeing PSRAM stack");
heap_caps_free(xStack);

// Create a cleanup timer for PSRAM task TCB
auto* timerHandle =
xTimerCreate("TaskCleanupTimer", pdMS_TO_TICKS(5000), pdFALSE,
xTaskBuffer, [](TimerHandle_t timer) {
BELL_LOG(info, "Task", "Freeing up TCB");
heap_caps_free(pvTimerGetTimerID(timer));
xTimerDelete(timer, portMAX_DELAY);
});
Expand All @@ -59,6 +65,9 @@ class Task::Impl {
static void taskEntryPointShim(void* task) {
Task::Impl* taskPtr = static_cast<Task::Impl*>(task);
taskPtr->taskEntryPoint();

printf("Task ended\n");
vTaskDelete(NULL);
}

bool startTask(Task* task) {
Expand Down Expand Up @@ -115,9 +124,7 @@ Task::Task(const std::string& taskName, int stackSize, int espPriority,
: pImpl(std::make_unique<Impl>(taskName, stackSize, espPriority,
espTaskCore, espStackOnPsram)) {}

Task::~Task() {
stopTask();
}
Task::~Task() {}

bool Task::startTask() {
return pImpl->startTask(this);
Expand Down

0 comments on commit 21842cc

Please sign in to comment.