Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions Sming/Arch/Esp32/Components/esp32/src/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ void sming_task_loop(void*)
tcpip_callback_msg* callbackMessage;
volatile bool eventQueueFlag;

/**
* @brief Process all messages in the Sming event queue
* Called in the context of the tcpip message thread.
*/
void tcpip_message_handler(void*)
{
eventQueueFlag = false;
Expand All @@ -35,6 +39,22 @@ void tcpip_message_handler(void*)
}
}

/**
* @brief Kick the tcpip message handling thread so we get a callback
* @retval bool Woken flag, true if a message was queued, false for no action
*/
bool tcpip_kick_thread()
{
// If queue isn't empty and we haven't already asked for a tcpip callback, do that now
if(xQueueIsQueueEmptyFromISR(eventQueue) == pdFALSE && !eventQueueFlag) {
eventQueueFlag = true;
auto err = tcpip_callbackmsg_trycallback_fromisr(callbackMessage);
return (err == ERR_NEED_SCHED);
}

return false;
}

#endif

} // namespace
Expand Down Expand Up @@ -82,6 +102,9 @@ void start_sming_task_loop()

callbackMessage = tcpip_callbackmsg_new(tcpip_callback_fn(tcpip_message_handler), nullptr);

// There may be messages already queued
tcpip_kick_thread();

#endif
}

Expand All @@ -103,14 +126,7 @@ bool IRAM_ATTR system_os_post(uint8_t prio, os_signal_t sig, os_param_t par)
// Message loop not yet active
return true;
}
// If queue isn't empty and we haven't already asked for a tcpip callback, do that now
if(xQueueIsQueueEmptyFromISR(eventQueue) == pdFALSE && !eventQueueFlag) {
eventQueueFlag = true;
auto err = tcpip_callbackmsg_trycallback_fromisr(callbackMessage);
woken = (err == ERR_NEED_SCHED);
} else {
woken = false;
}
woken = tcpip_kick_thread();
#endif

portYIELD_FROM_ISR_ARG(woken);
Expand Down
Loading