Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Uses a binary semaphore to synchronize two tasks.
#include <FreeRTOS.h>
#include <task.h>
#include <semphr.h>
#include <stdio.h>
SemaphoreHandle_t xBinarySem;
void vTaskProducer(void* pvParameters) {
printf("Producer giving semaphore\n");
xSemaphoreGive(xBinarySem);
vTaskDelete(NULL);
}
void vTaskConsumer(void* pvParameters) {
xSemaphoreTake(xBinarySem, portMAX_DELAY);
printf("Consumer received semaphore\n");
vTaskDelete(NULL);
}
int main() {
xBinarySem = xSemaphoreCreateBinary();
xTaskCreate(vTaskProducer, "Producer", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(vTaskConsumer, "Consumer", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
return 0;
}FreeRTOS is a lightweight, open-source real-time operating system (RTOS) kernel for embedded devices. It provides multitasking, scheduling, and inter-task communication for microcontrollers and small processors.
Origin & Creator
Created by Richard Barry in 2003, now maintained and extended by Amazon Web Services as Amazon FreeRTOS and FreeRTOS Kernel.
Industrial Note
Essential in embedded systems requiring predictable real-time behavior, small footprint, and multitasking support-commonly used in IoT sensors, motor control, and safety-related microcontroller applications.