From 73d9d83a2f7f4979696b5efdce9b7e10e4bee37b Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Mon, 31 Oct 2022 18:00:52 +0100 Subject: [PATCH] feat(freertos): make num of task notifications configurable Closes https://github.com/espressif/esp-idf/issues/9349 --- .../include/freertos/FreeRTOSConfig_smp.h | 2 +- .../include/freertos/FreeRTOSConfig_smp.h | 2 +- components/freertos/Kconfig | 10 +++++ .../include/freertos/FreeRTOSConfig.h | 2 +- .../kernel/tasks/test_freertos_task_notify.c | 41 +++++++++++++++++++ .../test_apps/freertos/pytest_freertos.py | 22 ++++++++++ .../freertos/sdkconfig.ci.freertos_options | 1 + tools/mocks/freertos/Kconfig | 10 +++++ 8 files changed, 87 insertions(+), 3 deletions(-) diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/FreeRTOSConfig_smp.h b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/FreeRTOSConfig_smp.h index 1f3c459c20..4c1b735e9f 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/FreeRTOSConfig_smp.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/riscv/include/freertos/FreeRTOSConfig_smp.h @@ -129,7 +129,7 @@ This file get's pulled into assembly sources. Therefore, some includes need to b #define configUSE_QUEUE_SETS 1 #define configQUEUE_REGISTRY_SIZE CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE #define configUSE_TASK_NOTIFICATIONS 1 -#define configTASK_NOTIFICATION_ARRAY_ENTRIES 1 +#define configTASK_NOTIFICATION_ARRAY_ENTRIES CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES // ----------------------- System -------------------------- diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/FreeRTOSConfig_smp.h b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/FreeRTOSConfig_smp.h index 10ab6c91ba..9fe4e78000 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/FreeRTOSConfig_smp.h +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/include/freertos/FreeRTOSConfig_smp.h @@ -158,7 +158,7 @@ This file get's pulled into assembly sources. Therefore, some includes need to b #define configUSE_QUEUE_SETS 1 #define configQUEUE_REGISTRY_SIZE CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE #define configUSE_TASK_NOTIFICATIONS 1 -#define configTASK_NOTIFICATION_ARRAY_ENTRIES 1 +#define configTASK_NOTIFICATION_ARRAY_ENTRIES CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES // ----------------------- System -------------------------- diff --git a/components/freertos/Kconfig b/components/freertos/Kconfig index 3cf3644456..23281f6e52 100644 --- a/components/freertos/Kconfig +++ b/components/freertos/Kconfig @@ -190,6 +190,16 @@ menu "FreeRTOS" Note: A value of 0 will disable queue registry functionality + config FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES + int "configTASK_NOTIFICATION_ARRAY_ENTRIES" + range 1 32 + default 1 + help + Set the size of the task notification array of each task. When increasing this value, keep in + mind that this means additional memory for each and every task on the system. + However, task notifications in general are more light weight compared to alternatives + such as semaphores. + config FREERTOS_USE_TRACE_FACILITY bool "configUSE_TRACE_FACILITY" default n diff --git a/components/freertos/esp_additions/include/freertos/FreeRTOSConfig.h b/components/freertos/esp_additions/include/freertos/FreeRTOSConfig.h index 0c6df70c6f..4239d4bb1e 100644 --- a/components/freertos/esp_additions/include/freertos/FreeRTOSConfig.h +++ b/components/freertos/esp_additions/include/freertos/FreeRTOSConfig.h @@ -126,7 +126,7 @@ This file get's pulled into assembly sources. Therefore, some includes need to b #define configUSE_QUEUE_SETS 1 #define configQUEUE_REGISTRY_SIZE CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE #define configUSE_TASK_NOTIFICATIONS 1 -#define configTASK_NOTIFICATION_ARRAY_ENTRIES 1 +#define configTASK_NOTIFICATION_ARRAY_ENTRIES CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES // ----------------------- System -------------------------- diff --git a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_task_notify.c b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_task_notify.c index 1ab6556de5..c0c61c7ac2 100644 --- a/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_task_notify.c +++ b/components/freertos/test_apps/freertos/kernel/tasks/test_freertos_task_notify.c @@ -196,3 +196,44 @@ TEST_CASE("Test Task_Notify", "[freertos]") TEST_ESP_OK(gptimer_del_timer(gptimers[i])); } } + +TEST_CASE("Notify too high index fails", "[ignore]") +{ + uint32_t notification_value = 47; + xTaskNotifyIndexed(xTaskGetCurrentTaskHandle(), 2, notification_value, eNoAction); +} + +TEST_CASE("Notify Wait too high index fails", "[ignore]") +{ + uint32_t notification_value; + xTaskNotifyWaitIndexed(2, 0, 0, ¬ification_value, pdMS_TO_TICKS(10)); +} + +#if CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES > 1 +const uint32_t NOTIFICATION_VALUE_0 = 47; +const uint32_t NOTIFICATION_VALUE_1 = 48; + +void notify(void *arg) +{ + TaskHandle_t main_task = (TaskHandle_t) arg; + xTaskNotifyIndexed(main_task, 0, NOTIFICATION_VALUE_0, eSetValueWithOverwrite); + xTaskNotifyIndexed(main_task, 1, NOTIFICATION_VALUE_1, eSetValueWithOverwrite); + vTaskDelete(NULL); +} +static TaskHandle_t notificator_task; + +TEST_CASE("Notify to different indexes works", "[freertos]") +{ + uint32_t notification_value_0 = 0; + uint32_t notification_value_1 = 0; + + TaskHandle_t main_task = xTaskGetCurrentTaskHandle(); + xTaskCreate(notify, "notificator", 2048, main_task, 2, ¬ificator_task); + + xTaskNotifyWaitIndexed(0, 0, 0xFFFFFFFF, ¬ification_value_0, pdMS_TO_TICKS(10)); + xTaskNotifyWaitIndexed(1, 0, 0xFFFFFFFF, ¬ification_value_1, pdMS_TO_TICKS(10)); + + TEST_ASSERT_EQUAL(notification_value_0, NOTIFICATION_VALUE_0); + TEST_ASSERT_EQUAL(notification_value_1, NOTIFICATION_VALUE_1); +} +#endif diff --git a/components/freertos/test_apps/freertos/pytest_freertos.py b/components/freertos/test_apps/freertos/pytest_freertos.py index 6da2ef98d7..7298a48f7a 100644 --- a/components/freertos/test_apps/freertos/pytest_freertos.py +++ b/components/freertos/test_apps/freertos/pytest_freertos.py @@ -21,3 +21,25 @@ def test_freertos(dut: Dut) -> None: dut.write('![ignore]') # All of the FreeRTOS tests combined take > 60s to run. So we use a 120s timeout dut.expect_unity_test_output(timeout=120) + + +@pytest.mark.supported_targets +@pytest.mark.generic +@pytest.mark.parametrize('config', ['freertos_options'], indirect=True) +def test_task_notify_too_high_index_fails(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests.') + dut.write('\"Notify too high index fails\"') + dut.expect('assert failed: xTaskGenericNotify', timeout=5) + dut.expect('uxIndexToNotify < [0-9]+') + dut.expect_exact('Rebooting...') + + +@pytest.mark.supported_targets +@pytest.mark.generic +@pytest.mark.parametrize('config', ['freertos_options'], indirect=True) +def test_task_notify_wait_too_high_index_fails(dut: Dut) -> None: + dut.expect_exact('Press ENTER to see the list of tests.') + dut.write('\"Notify Wait too high index fails\"') + dut.expect('assert failed: xTaskGenericNotifyWait', timeout=5) + dut.expect('uxIndexToWait < [0-9]+', timeout=5) + dut.expect_exact('Rebooting...') diff --git a/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options b/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options index 15a026cfe6..65e9cff7e9 100644 --- a/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options +++ b/components/freertos/test_apps/freertos/sdkconfig.ci.freertos_options @@ -16,3 +16,4 @@ CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y CONFIG_FREERTOS_FPU_IN_ISR=y +CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 diff --git a/tools/mocks/freertos/Kconfig b/tools/mocks/freertos/Kconfig index 3a2d4786a7..0863a1be23 100644 --- a/tools/mocks/freertos/Kconfig +++ b/tools/mocks/freertos/Kconfig @@ -18,5 +18,15 @@ menu "FreeRTOS" more details). Note: For most uses, the default of 16 characters is sufficient. + + config FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES + int "configTASK_NOTIFICATION_ARRAY_ENTRIES" + range 1 32 + default 1 + help + Set the size of the task notification array of each task. When increasing this value, keep in + mind that this means additional memory for each and every task on the system. + However, task notifications in general are more light weight compared to alternatives + such as semaphores. endmenu endmenu