Follow+Star Public Account Number, don’t miss wonderful content
Author | strongerHuang
WeChat Public Account | Embedded Column
Embedded Column
1
However, in most cases, they communicate using “intermediary objects” rather than “direct task messages“.
Communicating through “intermediary objects” allocates a segment of memory (message buffer and stream buffer) for each set of queues or semaphores. The problem is that if there are many queues or semaphores, it will inevitably lead to greater memory expenditure.
However, if communication is done through the “direct messages” described in this article, a lot of memory can be saved.
Embedded Column
2
QueueHandle_t xQueue;
xQueue = xQueueCreate(10, sizeof( /* length */ ) );
Can you calculate how much RAM space this “intermediary object” will occupy?
Understand intermediary object communication through a code diagram:
Since FreeRTOS V10.4.0, each task has a series of notifications. Each notification contains a 32-bit value and a boolean status, consuming only5 bytesof RAM.
Just as a task can block a binary semaphore waiting for that semaphore to become “available”, a task can block a notification waiting for the notification’s status to become “pending”. Similarly, just as a task can block a counting semaphore waiting for the count of that semaphore to become non-zero, a task can block a notification waiting for the value of that notification to become non-zero. The first example below demonstrates this situation.
Notifications can convey not only events but also data in various ways.
Embedded Column
3
https://www.freertos.org/RTOS-task-notification-API.html
Embedded Column
4
-
RTOS task notifications can only be used when only one task can act as the receiver of the event. However, this condition can be met in most practical use cases, such as when an interrupt interrupts the task processing, and that task will handle the data received from the interrupt.
-
Only when using RTOS task notifications instead of queues: the receiving task can wait for a notification in a “blocked” state (thus not consuming any CPU time), while the sending task cannot wait for a message in a “blocked” state. If the sending cannot be completed immediately, the sending completes.
Embedded Column
5
/* Prototype of the two tasks created by main() */static void prvTask1( void *pvParameters );static void prvTask2( void *pvParameters );
/* Handles for tasks created by main() */static TaskHandle_t xTask1 = NULL, xTask2 = NULL;
/* Create two tasks to send notifications back and forth, then start the RTOS scheduler */void main( void ){ xTaskCreate( prvTask1, "Task1", 200, NULL, tskIDLE_PRIORITY, &xTask1 ); xTaskCreate( prvTask2, "Task2", 200, NULL, tskIDLE_PRIORITY, &xTask2 ); vTaskStartScheduler();}/*———————————————————–*/
/* prvTask1() uses the "indexed" version of the API */static void prvTask1( void *pvParameters ){ for( ;; ) { /* Send notification to prvTask2() to unblock it.*/ xTaskNotifyGiveIndexed( xTask2, 0 );
/* Block waiting for prvTask2() to notify this task */ ulTaskNotifyTakeIndexed( 0, pdTRUE, portMAX_DELAY ); }}/*———————————————————–*/
/* prvTask2() uses the original version of the API (without "index") */static void prvTask2( void *pvParameters ){ for( ;; ) { /* Wait for prvTask1() to notify this task */ ulTaskNotifyTake( pdTRUE, portMAX_DELAY );
/* Send notification to prvTask1() to unblock it */ xTaskNotifyGive( xTask1 ); }}
https://www.freertos.org/2020/09/decrease-ram-footprint-and-accelerate-execution-with-freertos-notifications.html
Reply in the background with 『RTOS』『FreeRTOS』『Microcontroller』 to read more related articles.
Click “Read the original” to see more shares, and welcome to share, collect, like, and view.