2. 4.1 Task notifications — signaux légers
Les task notifications sont 10x plus rapides que les sémaphores et n'allouent pas de RAM supplémentaire (chaque tâche a un compteur de notification intégré). Idéal pour remplacer un sémaphore binaire quand une seule tâche attend.
TaskHandle_t xTaskSensorHandle;
// Depuis n'importe quelle tâche ou ISR
xTaskNotify(xTaskSensorHandle, 0, eNoAction); // signal simple
xTaskNotifyFromISR(xTaskSensorHandle, 0, eNoAction, &xHPTW); // depuis ISR
// Dans la tâche qui attend
uint32_t ulNotificationValue;
xTaskNotifyWait(0, 0, &ulNotificationValue, portMAX_DELAY);
ESP_LOGI("SENSOR", "Notified — reading sensor");
Pour une sémantique counting simple (remplace sémaphore counting) :
// Producteur
xTaskNotifyGive(xTaskConsumerHandle);
// Consommateur
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // pdTRUE = décrémenter le compteur
Quand utiliser : - Une seule tâche attend le signal → task notification - Plusieurs tâches attendent → sémaphore / queue