1. Home
  2. /
  3. Freertos
  4. /
  5. Queue Set Example (FreeRTOS)

Queue Set Example (FreeRTOS) - Freertos Typing CST Test

Loading…

Queue Set Example (FreeRTOS) — Freertos Code

Demonstrates using a FreeRTOS queue set to manage multiple queues.

#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <stdio.h>

QueueHandle_t xQueue1, xQueue2;
QueueSetHandle_t xQueueSet;

int main() {
	xQueue1 = xQueueCreate(1, sizeof(int));
	xQueue2 = xQueueCreate(1, sizeof(int));
	xQueueSet = xQueueCreateSet(2);
	xQueueAddToSet(xQueue1, xQueueSet);
	xQueueAddToSet(xQueue2, xQueueSet);
	vTaskStartScheduler();
	return 0;
}

Freertos Language Guide

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.

Primary Use Cases

  • ▸Task scheduling for embedded systems
  • ▸IoT and sensor node software
  • ▸Industrial automation control
  • ▸Real-time motor and sensor management
  • ▸Edge devices and microcontroller applications

Notable Features

  • ▸Preemptive and cooperative multitasking
  • ▸Task priorities and time slicing
  • ▸Inter-task communication (queues, semaphores, mutexes)
  • ▸Software timers and tickless idle mode
  • ▸Memory management and dynamic allocation support

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.

Quick Explain

  • ▸FreeRTOS allows multiple tasks (threads) to run seemingly simultaneously on microcontrollers.
  • ▸Provides task scheduling with priorities, preemption, and time slicing.
  • ▸Supports inter-task communication using queues, semaphores, and mutexes.
  • ▸Highly portable across 8/16/32-bit MCUs and architectures like ARM, AVR, PIC, and RISC-V.
  • ▸Used widely in industrial, IoT, automotive, and consumer embedded systems.

Core Features

  • ▸Tasks (threads)
  • ▸Queues for message passing
  • ▸Semaphores and mutexes
  • ▸Event groups for synchronization
  • ▸Tick-based software timers

Learning Path

  • ▸Understand task creation and scheduling
  • ▸Learn inter-task communication mechanisms
  • ▸Practice ISR and task interactions
  • ▸Explore timers and software hooks
  • ▸Integrate with peripherals and connectivity stacks

Practical Examples

  • ▸Blink LED with periodic task
  • ▸UART communication using queues
  • ▸Sensor data acquisition with mutex protection
  • ▸Motor control with priority tasks
  • ▸Low-power IoT node using tickless idle

Comparisons

  • ▸FreeRTOS vs Zephyr: FreeRTOS simpler, Zephyr more full-featured
  • ▸FreeRTOS vs ChibiOS: FreeRTOS more widely used, ChibiOS faster kernel
  • ▸FreeRTOS vs bare-metal: RTOS adds multitasking & scheduling
  • ▸FreeRTOS vs Linux RT: FreeRTOS lighter, Linux richer OS
  • ▸FreeRTOS vs ThreadX: FreeRTOS open-source, ThreadX commercial with safety certifications

Strengths

  • ▸Very lightweight (few KB footprint)
  • ▸Highly portable across MCUs
  • ▸Open-source with active community
  • ▸Predictable real-time behavior
  • ▸Easy integration with peripheral drivers

Limitations

  • ▸Not a full-featured OS (no file system, GUI)
  • ▸Limited memory protection features
  • ▸Requires careful design for hard real-time tasks
  • ▸Debugging complex task interactions can be tricky
  • ▸No native networking stack (requires integration)

When NOT to Use

  • ▸High-level OS features required (GUI, filesystem)
  • ▸Very large memory embedded applications
  • ▸Desktop-class multi-threading needs
  • ▸Heavy network stacks without FreeRTOS+TCP
  • ▸Applications needing full memory protection by default

Cheat Sheet

  • ▸xTaskCreate() -> create task
  • ▸vTaskDelay() -> delay task
  • ▸xQueueSend()/xQueueReceive() -> send/receive data
  • ▸xSemaphoreTake()/Give() -> mutex/semaphore
  • ▸vTaskStartScheduler() -> start RTOS

FAQ

  • ▸Is FreeRTOS free? -> Yes, open-source MIT license.
  • ▸Is it suitable for low-power MCUs? -> Yes, supports tickless idle.
  • ▸Does it support networking? -> Yes, via FreeRTOS+TCP and LWIP.
  • ▸Can I use it on 8-bit MCUs? -> Yes, portable kernel supports 8/16/32-bit devices.
  • ▸Does it support C++? -> Yes, via wrapper classes and C++ tasks.

30-Day Skill Plan

  • ▸Week 1: Task basics and delays
  • ▸Week 2: Queues, semaphores, mutexes
  • ▸Week 3: ISR-safe coding and priorities
  • ▸Week 4: Tickless idle and power management
  • ▸Week 5: Integrate networking/IoT functionality

Final Summary

  • ▸FreeRTOS is a lightweight, open-source RTOS for embedded devices.
  • ▸Supports multitasking, inter-task communication, and real-time scheduling.
  • ▸Highly portable across MCUs and architectures.
  • ▸Widely used in IoT, industrial, automotive, and consumer applications.
  • ▸Ideal for projects needing predictable real-time behavior on resource-constrained devices.

Project Structure

  • ▸FreeRTOS source folder (tasks, queue, timers)
  • ▸Application C source files
  • ▸Board support package (BSP) and driver files
  • ▸FreeRTOSConfig.h
  • ▸Makefile or IDE project configuration

Monetization

  • ▸Embedded IoT device development
  • ▸Industrial automation solutions
  • ▸Consumer electronics RTOS deployment
  • ▸Edge AI embedded systems
  • ▸FreeRTOS training and consulting

Productivity Tips

  • ▸Use templates for tasks and queues
  • ▸Keep tasks short and modular
  • ▸Enable kernel-aware debugging
  • ▸Profile using tracing tools
  • ▸Regularly check stack and heap usage

Basic Concepts

  • ▸Task - independent unit of execution
  • ▸Queue - thread-safe message passing
  • ▸Semaphore - signaling between tasks
  • ▸Mutex - mutual exclusion for shared resources
  • ▸Tick - periodic timer driving scheduling

Official Docs

  • ▸https://www.freertos.org/
  • ▸FreeRTOS Kernel API Reference

More Freertos Typing Exercises

Hello World Task (FreeRTOS)Blink LED Task (FreeRTOS)Queue Example (FreeRTOS)Mutex Example (FreeRTOS)Timer Callback (FreeRTOS)Semaphore Synchronization (FreeRTOS)Task Delay Example (FreeRTOS)Priority Task Example (FreeRTOS)Event Group Example (FreeRTOS)

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher