I've noticed a problem when using vTaskDelete(NULL). This is the last statement in task function and I expect it to delete task itself and release resources allocated for task. But unfortunately I see that task state changes from eBlocked/eRunning state to eReady state.
Here is a little snippet of code, illustrating this problem:
Code: Select all
#define SLEEP(ms) vTaskDelay(ms / portTICK_PERIOD_MS)
...
TaskHandle_t handle = NULL;
xTaskCreate(&testTask, "TestTask", 4096, NULL, 10, &handle);
ESP_LOGE(TAG, "Test task handle is 0x%.8X", handle);
while (1)
{
volatile eTaskState state = eTaskGetState(handle);
ESP_LOGI(TAG, "Task 0x%.8X state is %u", handle, state); // State is 2 when task is running (that's expected,
// cause task is sleeping most of time
// But when task is completed, state is changed to 1
// and remains 1 forever
SLEEP(500);
}
...
void testTask(void *pvParameters)
{
ESP_LOGW(TAG, "Test task started");
for (uint8_t i = 0; i < 60; i++)
{
SLEEP(1000);
ESP_LOGW(TAG, "Test task iteration %u", i);
}
ESP_LOGW(TAG, "Test task ended");
vTaskDelete(NULL);
}