Select Page

FreeRTOS – Task Notifications Examples

Example 1

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h
 
TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
 
void myTask1(void *p)
{
    while(1) {
        xTaskNotifyGive(myTask2Handle);
        vTaskDelay( pdMS_TO_TICKS(100) );
    }
}
 
void myTask2(void *p)
{
    uint32_t notificationValue;
 
    while(1) {
        notificationValue = ulTaskNotifyTake( pdTRUE, (TickType_t)portMAX_DELAY );
        if( notificationValue > 0 ) {
            printf("Notification Received: %d\n\r", notificationValue);
        }
    }
}

Example 2

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h
 
TaskHandle_t myTask1Handle = NULL;
TaskHandle_t myTask2Handle = NULL;
 
void myTask1(void *p)
{
    while(1) {
        xTaskNotify(myTask2Handle, 0, eNoAction);
        vTaskDelay( pdMS_TO_TICKS(1000) );
    }
}
 
void myTask2(void *p)
{
    uint32_t ulNotifiedValue;
 
    while(1) {
        if( xTaskNotifyWait(0, 0, &ulNotifiedValue, portMAX_DELAY ) == pdTRUE ) {
            printf("Notification Received: %d\n\r", ulNotifiedValue);
        }
    }
}