Logging: avoid blocking in timer context
This commit is contained in:
parent
4195d7c2ee
commit
9024cd38ec
2 changed files with 19 additions and 5 deletions
|
@ -289,6 +289,7 @@ extern void vPortCleanUpTCB ( void *pxTCB );
|
||||||
#define configTIMER_TASK_STACK_DEPTH CONFIG_TIMER_TASK_STACK_DEPTH
|
#define configTIMER_TASK_STACK_DEPTH CONFIG_TIMER_TASK_STACK_DEPTH
|
||||||
|
|
||||||
#define INCLUDE_xTimerPendFunctionCall 1
|
#define INCLUDE_xTimerPendFunctionCall 1
|
||||||
|
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
|
||||||
#define INCLUDE_eTaskGetState 1
|
#define INCLUDE_eTaskGetState 1
|
||||||
#define configUSE_QUEUE_SETS 1
|
#define configUSE_QUEUE_SETS 1
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/FreeRTOSConfig.h>
|
#include <freertos/FreeRTOSConfig.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
|
#include <freertos/timers.h>
|
||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -191,6 +192,18 @@ void IRAM_ATTR esp_log_write(esp_log_level_t level,
|
||||||
if (!s_log_mutex) {
|
if (!s_log_mutex) {
|
||||||
s_log_mutex = xSemaphoreCreateMutex();
|
s_log_mutex = xSemaphoreCreateMutex();
|
||||||
}
|
}
|
||||||
|
#if ( configUSE_TIMERS == 1 ) && ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 0 )
|
||||||
|
#warning "Logging from timer context may block, consider enabling INCLUDE_xTimerGetTimerDaemonTaskHandle"
|
||||||
|
#elif ( configUSE_TIMERS == 1 ) && ( INCLUDE_xTimerGetTimerDaemonTaskHandle == 1 )
|
||||||
|
// Avoid blocking in timer context:
|
||||||
|
if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING
|
||||||
|
|| xTaskGetCurrentTaskHandle() == xTimerGetTimerDaemonTaskHandle()) {
|
||||||
|
if (xSemaphoreTake(s_log_mutex, 0) == pdFALSE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
if (xSemaphoreTake(s_log_mutex, MAX_MUTEX_WAIT_TICKS) == pdFALSE) {
|
if (xSemaphoreTake(s_log_mutex, MAX_MUTEX_WAIT_TICKS) == pdFALSE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue