Skip to content

Commit

Permalink
Merge branch 'feature/freertos_task_notification_configurable' into '…
Browse files Browse the repository at this point in the history
…master'

freertos: make num of task notifications configurable

Closes IDFGH-7819

See merge request espressif/esp-idf!20880
  • Loading branch information
0xjakob committed Nov 16, 2022
2 parents 4c1ff60 + 73d9d83 commit cce1f9d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------

Expand Down
10 changes: 10 additions & 0 deletions components/freertos/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, &notification_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, &notificator_task);

xTaskNotifyWaitIndexed(0, 0, 0xFFFFFFFF, &notification_value_0, pdMS_TO_TICKS(10));
xTaskNotifyWaitIndexed(1, 0, 0xFFFFFFFF, &notification_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
22 changes: 22 additions & 0 deletions components/freertos/test_apps/freertos/pytest_freertos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions tools/mocks/freertos/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cce1f9d

Please sign in to comment.