Created
February 21, 2021 13:05
-
-
Save shakram02/a33e2b4358435b439e506b26290b744a to your computer and use it in GitHub Desktop.
Control passing using FreeRTOS notifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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