Skip to content

Instantly share code, notes, and snippets.

@shakram02
Created February 21, 2021 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakram02/a33e2b4358435b439e506b26290b744a to your computer and use it in GitHub Desktop.
Save shakram02/a33e2b4358435b439e506b26290b744a to your computer and use it in GitHub Desktop.
Control passing using FreeRTOS notifications.
/**
* Adapted from: https://www.freertos.org/RTOS_Task_Notification_As_Binary_Semaphore.html
*/
#include <stdio.h>
#include <pthread.h>
#include "FreeRTOS.h"
#include "semphr.h"
#define TASK_LOOP_DELAY 30
TaskHandle_t passcontrol_h_task1 = NULL;
TaskHandle_t passcontrol_h_task2 = NULL;
void passcontrol_task1(void *_)
{
uint16_t c1 = 0;
while (1)
{
xTaskNotifyGive(passcontrol_h_task2);
printf("[1] C1:%hu\r\n", c1);
c1++;
ulTaskNotifyTake(0, portMAX_DELAY);
vTaskDelay(pdMS_TO_TICKS(TASK_LOOP_DELAY));
}
}
void passcontrol_task2(void *_)
{
uint16_t c2 = 0;
while (1)
{
ulTaskNotifyTake(0, portMAX_DELAY);
printf("[2] C2:%hu\r\n", c2);
c2++;
xTaskNotifyGive(passcontrol_h_task1);
vTaskDelay(pdMS_TO_TICKS(TASK_LOOP_DELAY));
}
}
void main_passcontrol()
{
xTaskCreate(passcontrol_task1, "T1", configMINIMAL_STACK_SIZE, NULL, 1, &passcontrol_h_task1);
xTaskCreate(passcontrol_task2, "T2", configMINIMAL_STACK_SIZE, NULL, 1, &passcontrol_h_task2);
vTaskStartScheduler();
for (;;)
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment