mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-03 00:21:44 +01:00
freertos: Remove legacy hooks
This commit refactors the legacy hooks as follows:
- Removed CONFIG_FREERTOS_LEGACY_HOOKS
- FreeRTOS hooks are now enabled via:
- CONFIG_FREERTOS_USE_IDLE_HOOK
- CONFIG_FREERTOS_USE_TICK_HOOK
- Update IDF hooks documentation
This commit is contained in:
86
components/freertos/test/test_freertos_hooks.c
Normal file
86
components/freertos/test/test_freertos_hooks.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include <freertos/semphr.h>
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
/*
|
||||
Test FreeRTOS idle hook. Only compiled in if FreeRTOS idle hooks are enabled.
|
||||
*/
|
||||
#if ( configUSE_IDLE_HOOK == 1 )
|
||||
|
||||
static volatile unsigned idle_count;
|
||||
|
||||
void vApplicationIdleHook(void)
|
||||
{
|
||||
idle_count++;
|
||||
}
|
||||
|
||||
TEST_CASE("FreeRTOS idle hook", "[freertos]")
|
||||
{
|
||||
idle_count = 0;
|
||||
vTaskDelay(10);
|
||||
TEST_ASSERT_NOT_EQUAL(0, idle_count); // The legacy idle hook should be called at least once
|
||||
}
|
||||
|
||||
#endif // configUSE_IDLE_HOOK
|
||||
|
||||
/*
|
||||
Test the FreeRTOS tick hook. Only compiled in if FreeRTOS tick hooks are enabled.
|
||||
*/
|
||||
#if ( configUSE_TICK_HOOK == 1 )
|
||||
|
||||
static volatile unsigned tick_count;
|
||||
|
||||
void vApplicationTickHook(void)
|
||||
{
|
||||
tick_count++;
|
||||
}
|
||||
|
||||
TEST_CASE("FreeRTOS tick hook", "[freertos]")
|
||||
{
|
||||
unsigned before = xTaskGetTickCount();
|
||||
const unsigned SLEEP_FOR = 20;
|
||||
tick_count = before;
|
||||
vTaskDelay(SLEEP_FOR);
|
||||
TEST_ASSERT_UINT32_WITHIN_MESSAGE(3 * portNUM_PROCESSORS, before + SLEEP_FOR * portNUM_PROCESSORS, tick_count,
|
||||
"The FreeRTOS tick hook should have been called approx 1 time per tick per CPU");
|
||||
}
|
||||
|
||||
#endif // configUSE_TICK_HOOK
|
||||
|
||||
#if CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
|
||||
|
||||
static volatile void *deleted_tcb;
|
||||
|
||||
static void taskDeletesItself(void *ignored)
|
||||
{
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void vPortCleanUpTCB(void *pxTCB)
|
||||
{
|
||||
deleted_tcb = pxTCB;
|
||||
}
|
||||
|
||||
TEST_CASE("static task cleanup hook is called based on config", "[freertos]")
|
||||
{
|
||||
for(int i = 0; i < portNUM_PROCESSORS; i++) {
|
||||
printf("Creating task CPU %d\n", i);
|
||||
TaskHandle_t new_task = NULL;
|
||||
deleted_tcb = NULL;
|
||||
xTaskCreatePinnedToCore(taskDeletesItself, "delete", 2048, NULL, UNITY_FREERTOS_PRIORITY, &new_task, i);
|
||||
vTaskDelay(5);
|
||||
TEST_ASSERT_EQUAL_PTR(deleted_tcb, new_task); // TCB & TaskHandle are the same in FreeRTOS
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
|
||||
Reference in New Issue
Block a user