switch to Recursive Mutex and non-blocking

This commit is contained in:
2024-12-13 22:29:48 +01:00
parent 8205253b5a
commit 1af962190e
6 changed files with 88 additions and 36 deletions

View File

@ -33,12 +33,12 @@ void initOutputs(void)
gpio_config(&ioConfCirculationPump);
gpio_config(&ioConfBurner);
xMutexAccessOutputs = xSemaphoreCreateBinary();
xMutexAccessOutputs = xSemaphoreCreateRecursiveMutex();
if (xMutexAccessOutputs == NULL)
{
ESP_LOGE(TAG, "Unable to create mutex");
}
xSemaphoreGive(xMutexAccessOutputs);
xSemaphoreGiveRecursive(xMutexAccessOutputs);
}
eOutput getCirculationPumpState(void)
@ -48,7 +48,7 @@ eOutput getCirculationPumpState(void)
void setCirculationPumpState(eOutput in)
{
if (xSemaphoreTake(xMutexAccessOutputs, portMAX_DELAY) == pdTRUE)
if (xSemaphoreTakeRecursive(xMutexAccessOutputs, pdMS_TO_TICKS(5000)) == pdTRUE)
{
sCirculationPumpState = in;
switch (sCirculationPumpState)
@ -61,24 +61,32 @@ void setCirculationPumpState(eOutput in)
default:
break;
}
xSemaphoreGive(xMutexAccessOutputs);
xSemaphoreGiveRecursive(xMutexAccessOutputs);
}
else
{
ESP_LOGE(TAG, "Unable to take mutex: setCirculationPumpState()");
}
}
eOutput getBurnerState(void)
{
eOutput ret = ENABLED;
if (xSemaphoreTake(xMutexAccessOutputs, portMAX_DELAY) == pdTRUE)
if (xSemaphoreTakeRecursive(xMutexAccessOutputs, pdMS_TO_TICKS(5000)) == pdTRUE)
{
ret = sBurnerState;
xSemaphoreGive(xMutexAccessOutputs);
xSemaphoreGiveRecursive(xMutexAccessOutputs);
}
else
{
ESP_LOGE(TAG, "Unable to take mutex: getBurnerState()");
}
return ret;
}
void setBurnerState(eOutput in)
{
if (xSemaphoreTake(xMutexAccessOutputs, portMAX_DELAY) == pdTRUE)
if (xSemaphoreTakeRecursive(xMutexAccessOutputs, pdMS_TO_TICKS(5000)) == pdTRUE)
{
sBurnerState = in;
switch (sBurnerState)
@ -91,6 +99,10 @@ void setBurnerState(eOutput in)
default:
break;
}
xSemaphoreGive(xMutexAccessOutputs);
xSemaphoreGiveRecursive(xMutexAccessOutputs);
}
else
{
ESP_LOGE(TAG, "Unable to take mutex: setBurnerState()");
}
}