switch to Recursive Mutex and non-blocking
This commit is contained in:
@ -45,12 +45,12 @@ void initInputs(void)
|
||||
|
||||
gpio_config(&ioConfBurnerFault);
|
||||
|
||||
xMutexAccessInputs = xSemaphoreCreateBinary();
|
||||
xMutexAccessInputs = xSemaphoreCreateRecursiveMutex();
|
||||
if (xMutexAccessInputs == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to create mutex");
|
||||
}
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
|
||||
BaseType_t taskCreated = xTaskCreate(
|
||||
taskInput, // Function to implement the task
|
||||
@ -122,7 +122,7 @@ void taskInput(void *pvParameters)
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(PERIODIC_INTERVAL * 1000U / portTICK_PERIOD_MS);
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTakeRecursive(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
{
|
||||
sChamperTemperature.state = MEASUREMENT_FAULT;
|
||||
sOutdoorTemperature.state = MEASUREMENT_FAULT;
|
||||
@ -196,7 +196,16 @@ void taskInput(void *pvParameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
sChamperTemperature.state = MEASUREMENT_FAULT;
|
||||
sOutdoorTemperature.state = MEASUREMENT_FAULT;
|
||||
sInletFlowTemperature.state = MEASUREMENT_FAULT;
|
||||
sReturnFlowTemperature.state = MEASUREMENT_FAULT;
|
||||
|
||||
ESP_LOGE(TAG, "Unable to take mutex: taskInput()");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,10 +214,14 @@ sMeasurement getChamberTemperature(void)
|
||||
{
|
||||
sMeasurement ret;
|
||||
ret.state = MEASUREMENT_FAULT;
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTakeRecursive(xMutexAccessInputs, pdMS_TO_TICKS(5000)) == pdTRUE)
|
||||
{
|
||||
ret = sChamperTemperature;
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to take mutex: getChamberTemperature()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -217,10 +230,14 @@ sMeasurement getOutdoorTemperature(void)
|
||||
{
|
||||
sMeasurement ret;
|
||||
ret.state = MEASUREMENT_FAULT;
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTakeRecursive(xMutexAccessInputs, pdMS_TO_TICKS(5000)) == pdTRUE)
|
||||
{
|
||||
ret = sOutdoorTemperature;
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to take mutex: getOutdoorTemperature()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -229,10 +246,14 @@ sMeasurement getInletFlowTemperature(void)
|
||||
{
|
||||
sMeasurement ret;
|
||||
ret.state = MEASUREMENT_FAULT;
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTakeRecursive(xMutexAccessInputs, pdMS_TO_TICKS(5000)) == pdTRUE)
|
||||
{
|
||||
ret = sInletFlowTemperature;
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to take mutex: getInletFlowTemperature()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -241,10 +262,14 @@ sMeasurement getReturnFlowTemperature(void)
|
||||
{
|
||||
sMeasurement ret;
|
||||
ret.state = MEASUREMENT_FAULT;
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTakeRecursive(xMutexAccessInputs, pdMS_TO_TICKS(5000)) == pdTRUE)
|
||||
{
|
||||
ret = sReturnFlowTemperature;
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to take mutex: getReturnFlowTemperature()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -252,10 +277,14 @@ sMeasurement getReturnFlowTemperature(void)
|
||||
eBurnerErrorState getBurnerError(void)
|
||||
{
|
||||
eBurnerErrorState ret = FAULT;
|
||||
if (xSemaphoreTake(xMutexAccessInputs, portMAX_DELAY) == pdTRUE)
|
||||
if (xSemaphoreTakeRecursive(xMutexAccessInputs, pdMS_TO_TICKS(5000)) == pdTRUE)
|
||||
{
|
||||
ret = sBurnerErrorState;
|
||||
xSemaphoreGive(xMutexAccessInputs);
|
||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "Unable to take mutex: getBurnerError()");
|
||||
}
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user