0% found this document useful (0 votes)
4 views

Operating Systme

This case study examines FreeRTOS, focusing on its architecture, scheduling mechanisms, memory management, and inter-task communication features, along with implemented modifications for performance optimization. The study highlights significant improvements in system performance while maintaining FreeRTOS's lightweight nature, providing insights for developers in embedded systems. Key findings include the importance of FreeRTOS in real-time applications and its adaptability through targeted enhancements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Operating Systme

This case study examines FreeRTOS, focusing on its architecture, scheduling mechanisms, memory management, and inter-task communication features, along with implemented modifications for performance optimization. The study highlights significant improvements in system performance while maintaining FreeRTOS's lightweight nature, providing insights for developers in embedded systems. Key findings include the importance of FreeRTOS in real-time applications and its adaptability through targeted enhancements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

TRIBHUVAN UNIVERSITY

INSTITUTE OF ENGINEERING
Pulchowk Campus

Free RTOS(Real Time Operating System)

Submitted By:
Sakshyam Luitel (078BCT073)
Sijan Khadka (078BCT088)
Sudip Basnet (078BCT092)
Sujan Thapaliya (078BCT094)

Submitted To:
Department of Electronics and Computer Engineering
Pulchowk Campus, Lalitpur, Nepal
ACKNOWLEDGEMENT
We would like to express our sincere gratitude to all those who contributed to the suc-
cessful completion of this case study. First and foremost, we extend our heartfelt thanks
to our professor, Mr. Bikal Adhikari, for their invaluable guidance, continuous support,
and insightful feedback throughout the case study. His expertise and encouragement were
instrumental in shaping the direction of this work.
We are also deeply thankful to the Department of Electronics and Computer Engineer-
ing Pulchowk Campus for providing us with the necessary resources and infrastructure to
carry out this case study. Special thanks to our friends for their constructive suggestions
and moral support during challenging phases of the case study.
Lastly, we would like to acknowledge the contributions of various open-source com-
munities and researchers whose work served as a foundation for our case study. Their
efforts in advancing the fields of operating system have been a source of inspiration.
This case study would not have been possible without the collective efforts and support
of everyone involved. We are truly grateful for their contributions.

i
ABSTRACT
This case study explores the architecture, scheduling mechanisms, memory manage-
ment, and inter-task communication features of FreeRTOS. Additionally, a set of mod-
ifications has been implemented to optimize its performance, including [brief mention
of modifications, e.g., improving task scheduling, reducing memory overhead, enhancing
inter-task communication]. These modifications aim to enhance system efficiency, reduce
execution time, and improve reliability in real-time applications.
A comparative evaluation is performed to analyze the impact of these modifications
on task execution, CPU utilization, and memory management. The results demonstrate
notable improvements in system performance while maintaining FreeRTOS’s lightweight
and scalable nature. The study concludes with key findings, challenges, and future direc-
tions for further enhancements in FreeRTOS.
This case study provides valuable insights for developers and researchers working with
embedded systems, highlighting the potential of FreeRTOS in real-world applications and
its adaptability through targeted optimizations.

ii
Contents

ACKNOWLEDGEMENT i

ABSTRACT ii

1 INTRODUCTION 1
1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Importance of Free Real Time Operating System in Embedded Systems . . . 1
1.3 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 OVERVIEW OF FREE Real Time Operating System 3


2.1 History and Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Features and Functionalities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 TECHNICAL ANALYSIS 6

4 File Architecture 8
4.1 Key Directories and Files in FreeRTOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.1 /Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.2 /Include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.3 /Portable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.1.4 /Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2 Extensions for Enhanced Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2.1 SCM Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2.2 TCZ Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.2.3 TCE Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5 Modes of Operation 10
5.1 Default Mode (Bare-Metal / No OS Environment) . . . . . . . . . . . . . . . . . . . . . . . . 10
5.2 Static Allocation Mode (Preconfigured Tasks and Memory) . . . . . . . . . . . . . . . 10
5.3 Dynamic Allocation Mode (Heap-based Memory Management). . . . . . . . . . . . 10
5.4 Tickless Mode (Low-Power Operation) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5.5 Symmetric Multiprocessing (SMP) Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

iii
6 Coding in FreeRTOS 11
6.1 Setting Up the Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

7 Modifications Implemented in FreeRTOS 12


7.1 Description of Modification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.2 Justification for Modifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.3 Performance Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

8 Package Management 14
8.1 Kernel and Middleware Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
8.2 Source Code Management. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
8.3 Third-Party Libraries and Build Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
8.4 Configuration and Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

9 Process Scheduling and Memory Management 15


9.1 Process Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
9.2 Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

10 Use Cases 16
10.1 Industrial Automation and Control Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
10.2 Consumer Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
10.3 Automotive Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
10.4 Networking and Communication Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

11 Case Study Findings and Discussion 17


11.1 Key Takeaways . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
11.2 Real-World Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
11.3 Security and Reliability Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
11.4 Potential for Further Enhancements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

12 Conclusion 18

iv
1 INTRODUCTION
1.1 Background
FreeRTOS is a free, open-source real-time operating system (RTOS) designed for
microcontrollers and small microprocessors. Developed over an 18-year period in collabo-
ration with leading chip manufacturers, it has become one of the most widely used RTOS
solutions in embedded systems. It is distributed under the MIT open-source license,
making it accessible for both academic and commercial use.
The FreeRTOS kernel provides essential multitasking capabilities, allowing multiple
tasks to execute concurrently. It is designed to be lightweight, reliable, and easy to use,
making it suitable for resource-constrained environments such as IoT devices, automotive
systems, medical equipment, and industrial automation. FreeRTOS supports over 40
architectures, ensuring broad compatibility across different hardware platforms.
In 2017, Amazon Web Services (AWS) acquired FreeRTOS, further enhancing its
features and cloud connectivity. This led to the introduction of Amazon FreeRTOS,
which includes additional IoT libraries for secure cloud integration.

1.2 Importance of Free Real Time Operating System in Em-


bedded Systems
1. Efficient Task Scheduling: Uses preemptive and cooperative scheduling to man-
age multiple tasks efficiently.

2. Minimal Memory Footprint:Designed to run on low-power, memory-constrained


microcontrollers.

3. Portability:Supports 40+ hardware architectures, including ARM, RISC-V, and


AVR.

4. Inter-Task Communication:Offers queues, semaphores, mutexes, and event groups


for effective communication between tasks.

5. Reliability and Deterministic Behavior:Ensures real-time performance with


predictable execution times.

6. Cloud Integration:Amazon FreeRTOS enhances IoT capabilities by enabling se-


cure cloud connectivity.

7. Extensive Community and Industry Support:Maintained by AWS and lead-


ing semiconductor companies, ensuring continuous updates and improvements.

1
1.3 Objective
The main objective of this setup is to:

• Build and modify FreeRTOS using Windows, MingW and GCC.

• Provide an efficient method to compile on Windows without relying on physical


hardware.

• Showcase the Demo WIN32-MingW for compiling FreeRTOS applications directly


within a Windows environment.

• Modify the source code of FreeRTOS .

• Integrate easily with VSCode, using the GCC toolchain to manage and compile the
code.

2
2 OVERVIEW OF FREE Real Time Operating Sys-
tem
2.1 History and Development
FreeRTOS was originally developed by Richard Barry in the early 2000s as a lightweight
and efficient real-time operating system (RTOS) for microcontrollers. Over time, it gained
widespread adoption due to its portability, reliability, and simplicity. The system was
designed to provide preemptive multitasking capabilities in resource-constrained environ-
ments, making it a preferred choice for embedded systems, IoT devices, and industrial
automation.
In 2017, Amazon Web Services (AWS) acquired FreeRTOS, integrating it with AWS
IoT services to enhance its cloud capabilities. This led to the development of Amazon
FreeRTOS, which includes additional security and connectivity features tailored for mod-
ern IoT applications. Despite AWS ownership, FreeRTOS remains open-source under the
MIT license, allowing developers worldwide to use and modify it freely.
Today, FreeRTOS supports over 40 different architectures, including ARM Cortex-M,
RISC-V, AVR, and ESP32, making it one of the most versatile and widely used RTOS
platforms in the embedded systems industry.

2.2 System Architecture


1. Hardware Abstraction Layer (HAL)
The Hardware Abstraction Layer (HAL) serves as an intermediary between the
hardware and the FreeRTOS kernel. It provides a set of device drivers, interrupt
handlers, and hardware-specific functions that abstract the underlying hardware
complexity. By using the HAL, FreeRTOS can be easily ported to different mi-
crocontrollers and hardware platforms without needing significant changes to the
kernel or application code. This abstraction makes the system portable and ensures
that the same kernel code can run on different hardware configurations.

2. Kernel
The kernel is the core component of FreeRTOS, responsible for managing multitask-
ing, memory, synchronization, and interrupt handling. The kernel implements task
scheduling, ensuring that tasks are executed based on their priority levels and time
constraints. It provides essential functionalities such as task management, inter-
task communication, and synchronization mechanisms (e.g., semaphores, mutexes,
and queues). The kernel also handles interrupts, ensuring that high-priority tasks
can be executed promptly in real-time environments. It is lightweight and designed
to meet the strict resource constraints of embedded systems.

3
3. Application Programming Interface (API)
The API layer provides a high-level interface that allows application developers
to interact with the FreeRTOS kernel and system resources. Through the API,
developers can create, delete, and manage tasks, as well as allocate and synchronize
resources like semaphores, mutexes, and message queues. The API abstracts the
complexity of the kernel and provides a set of easy-to-use functions that enable
application developers to implement their logic without needing to deal directly
with the kernel’s inner workings.

4. Application Code
The application code layer contains the user-written application code that runs
on top of the FreeRTOS operating system. This code can be written in standard
programming languages such as C and C++, leveraging the API to interact with
the kernel and other system components. The application code is responsible for
defining the behavior of the embedded system and can include multiple tasks that
the kernel schedules and manages. It can also handle input and output operations,
communication between tasks, and other high-level functionality that the embedded
system needs to perform.

Figure 2.1: System Architecture of FreeRTOS

4
2.3 Features and Functionalities
1. Multitasking
FreeRTOS enables multitasking with task prioritization, allowing tasks to execute
based on their priority. It supports preemptive and cooperative multitasking.

2. Inter-Task Communication
The system provides message queues, semaphores, mutexes, and event groups for
safe and efficient communication and synchronization between tasks.

3. Memory Management
It supports both static and dynamic memory allocation, with multiple heap man-
agement schemes to optimize memory usage and reduce fragmentation.

4. Portability
The hardware abstraction layer (HAL) provides a platform-independent interface,
making FreeRTOS portable across various architectures, including ARM Cortex-M
and RISC-V.

5. Low Power Management


FreeRTOS supports power-efficient designs, with features like tickless idle mode,
which reduces system power consumption by halting the tick timer during idle
periods.

6. Timer Services
FreeRTOS provides software timers that allow tasks to execute after a specified
time, aiding in time-sensitive task execution and resource management.

5
3 TECHNICAL ANALYSIS
Task Management and Scheduling
Task management and scheduling are fundamental aspects of FreeRTOS, designed to
ensure efficient and effective execution of concurrent tasks in real-time systems. FreeR-
TOS supports both preemptive and cooperative scheduling mechanisms, with a default
preemptive priority-based scheduling approach. Each task in FreeRTOS is assigned a
priority, and the scheduler ensures that tasks with higher priority are executed first. If
two tasks have the same priority, the scheduler employs time-slicing to give each task a
fair share of CPU time.
Task management involves the creation, suspension, and deletion of tasks dynamically
during runtime. The task control block (TCB) holds important information about each
task, including its priority, state, and stack pointer. The FreeRTOS kernel ensures that
tasks can be scheduled based on their priorities and their interaction with other tasks.
Task scheduling is optimized to minimize context-switching overhead while providing
real-time guarantees, making FreeRTOS well-suited for embedded systems where time-
sensitive tasks must execute with minimal delay.
Memory Management
Memory management in FreeRTOS is designed to optimize memory usage while min-
imizing fragmentation and maintaining predictable performance. FreeRTOS offers both
static and dynamic memory allocation schemes. Static allocation occurs at compile-time,
where memory is reserved for tasks, queues, and other system objects, making it pre-
dictable and reducing memory fragmentation. Dynamic memory allocation is handled
during runtime, where memory can be allocated as needed, providing greater flexibility.
FreeRTOS provides different heap management options (heap1 , heap2 , heap3 ), eachdesignedtohandlemem
Heap1 isthesimplestandhasnof ragmentation, butdoesnotallowmemorytobef reedonceallocated.Hea
Inter-Task Communication
Inter-task communication is critical in FreeRTOS for managing interactions between
tasks in a real-time environment. FreeRTOS provides a range of synchronization and
communication mechanisms, including message queues, semaphores, mutexes, and event
groups, each serving different purposes.
Message queues allow tasks to communicate asynchronously by sending and receiving
messages. This is particularly useful for producer-consumer scenarios, where one task
produces data and another task consumes it. Semaphores and mutexes are used for
synchronization and resource management. A semaphore is used for signaling between
tasks, while a mutex ensures that only one task can access a shared resource at any given
time, preventing race conditions.

6
Event groups allow multiple tasks to wait for one or more events to occur, syn-
chronizing the tasks. These communication tools allow FreeRTOS to support complex
interactions and ensure that tasks can work together efficiently, without conflicts, while
maintaining data integrity.
Timers and Interrupt Handling
Timers and interrupt handling are essential in FreeRTOS for ensuring that time-
sensitive tasks are executed promptly and efficiently. FreeRTOS includes both software
timers and hardware interrupt management. Software timers provide a mechanism for
scheduling tasks to execute after a specific time interval. These timers are particularly
useful for creating timeouts, periodic tasks, and event-driven behavior.
Interrupt handling in FreeRTOS ensures that high-priority tasks can preempt lower-
priority tasks when needed. The interrupt handling mechanism is tightly integrated with
the kernel, allowing interrupt service routines (ISRs) to notify tasks or trigger actions
without causing race conditions or conflicts. FreeRTOS provides a safe method for inter-
acting with ISRs, ensuring that interrupts can be managed with minimal impact on task
execution.
The system’s interrupt handling mechanism is optimized for minimal latency and
quick response times, making FreeRTOS ideal for embedded systems where handling
real-time events is critical. The ability to set up and manage hardware and software
timers ensures that time-based events and task scheduling are synchronized efficiently.

7
4 File Architecture
The file structure of FreeRTOS follows a modular and organized approach, ensur-
ing efficiency, maintainability, and ease of use for embedded system development. This
structure includes core components for task management, inter-task communication, and
system configuration, while also supporting extensibility for different microcontroller ar-
chitectures.

4.1 Key Directories and Files in FreeRTOS


4.1.1 /Source
Contains the core FreeRTOS source files that implement the fundamental features of
the operating system, such as task scheduling, queues, timers, and event groups. Impor-
tant files include:

• tasks.c: Handles task creation, management, and scheduling.

• queue.c: Manages inter-task communication through message queues.

• timers.c: Implements software timer functionality.

• croutine.c: Supports lightweight co-routines, which are smaller tasks with specific
use cases.

• event groups.c: Manages event groups for synchronizing tasks.

4.1.2 /Include
This directory contains the header files needed to configure and interact with FreeR-
TOS from application code. Key headers include:

• FreeRTOS.h: The primary header file that includes all necessary FreeRTOS header
files.

• task.h: Provides task management functions.

• queue.h: Contains function declarations for working with message queues.

• timers.h: Provides declarations for software timer functions.

• event groups.h: Includes function declarations for managing event groups.

4.1.3 /Portable
This directory is critical for ensuring FreeRTOS works on different hardware plat-
forms. It contains architecture-specific code that provides hardware abstraction, such as
interrupt handling and context switching. For example:

8
• GCC: Contains architecture-specific code for platforms using the GCC compiler.

– port.c: Defines low-level operations like interrupt handling and task switch-
ing.
– portmacro.h: Contains macros and settings specific to the target architecture.

• ARM CM4: Contains code for ARM Cortex-M4 platforms, including:

– port.c: Platform-specific code for task switching and interrupt management.


– portmacro.h: Architecture-specific macros.

4.1.4 /Demo
The demo directory contains example projects designed to showcase FreeRTOS capa-
bilities. These examples are usually platform-specific and provide practical insights into
task management, inter-task communication, and system configuration. Example files
include:

• blinky.c: A simple demo program to blink an LED, demonstrating basic task


creation and scheduling.

• task create.c: A sample showing task creation and management.

• main.c: The entry point for demo applications, configuring the FreeRTOS kernel
and starting tasks.

4.2 Extensions for Enhanced Functionality


4.2.1 SCM Modules
These are optional kernel components that provide low-level features like hardware
abstraction layers, memory management, and system initialization, depending on the
target platform.
4.2.2 TCZ Files
These compressed packages contain FreeRTOS extensions or application code that
can be easily included in the project for additional features.
4.2.3 TCE Directories
Allow the dynamic inclusion of modules or functionality at runtime, facilitating easy
expansion and customization of the system without modifying core components.

9
5 Modes of Operation
5.1 Default Mode (Bare-Metal / No OS Environment)
• FreeRTOS runs directly on hardware without an underlying operating system.

• Tasks are created dynamically and scheduled using the FreeRTOS kernel.

• Memory allocation is managed by FreeRTOS heap implementations.

• Peripheral drivers and hardware interfaces are controlled directly by the application.

5.2 Static Allocation Mode (Preconfigured Tasks and Memory)


• Tasks, queues, semaphores, and other kernel objects are allocated statically.

• No dynamic memory allocation, reducing fragmentation and ensuring deterministic


behavior.

• Best suited for safety-critical applications, such as automotive and medical systems.

• Provides better predictability and real-time performance.

5.3 Dynamic Allocation Mode (Heap-based Memory Manage-


ment)
• Tasks and kernel objects are dynamically allocated using heap memory.

• Supports multiple heap management strategies (heap 1 to heap 5) for flexibility.

• Allows runtime creation and destruction of tasks, queues, and semaphores.

• Suitable for applications requiring dynamic behavior, such as IoT and cloud-connected
devices.

5.4 Tickless Mode (Low-Power Operation)


• Reduces CPU power consumption by disabling the system tick timer when idle.

• The kernel enters a low-power sleep mode when no tasks need execution.

• Ideal for battery-powered and energy-efficient embedded systems.

5.5 Symmetric Multiprocessing (SMP) Mode


• Extends FreeRTOS to utilize multiple processor cores.

• Tasks are scheduled dynamically across available cores.

• Suitable for high-performance applications requiring parallel execution.

10
6 Coding in FreeRTOS
For developers working on embedded systems, managing multitasking and real-time
operations efficiently is crucial, especially in resource-constrained environments. FreeR-
TOS provides a lightweight framework that simplifies task management, inter-task com-
munication, and synchronization. With its minimal overhead, FreeRTOS enables the
creation of time-sensitive applications with precise control over task scheduling and sys-
tem behavior. This guide will walk through essential features of FreeRTOS, showcasing
how to implement and test real-time applications effectively, even when physical hardware
is not available.

6.1 Setting Up the Development Environment


To set up the development environment for FreeRTOS in VSCode on a Windows
device, you first need to install Visual Studio Code and the necessary extensions, primarily
the C/C++ extension by Microsoft, which enables features like IntelliSense, debugging,
and code navigation. Next, you must install the GCC toolchain, which is required to
compile your FreeRTOS application. On Windows, this can be done by installing MinGW
or using the MSYS2 package manager, both of which provide a GCC compiler. Once GCC
is installed, ensure that the compiler’s binary path is added to your system’s environment
variables so that it can be accessed from the terminal. With VSCode and GCC in place,
you can create or open a FreeRTOS project, typically organized with source files in the
‘src‘ folder, FreeRTOS kernel files in the ‘FreeRTOS‘ folder, and a ‘Makefile‘ or other
build configuration for compiling the project. In VSCode, you’ll need to configure a
build task in the ‘tasks.json‘ file, which defines how to invoke the GCC compiler from
within the editor, including specifying the necessary include paths for the FreeRTOS
headers and your project’s source files. Once configured, you can run the build task from
the terminal in VSCode, and the output will be displayed in the terminal, allowing you
to identify any compilation errors or warnings. This setup enables a smooth workflow
for developing and testing FreeRTOS applications on Windows, even without physical
hardware, by leveraging the VSCode terminal for compiling and simple debugging.

11
7 Modifications Implemented in FreeRTOS
7.1 Description of Modification
The tick rate in FreeRTOS is controlled using configTICK RATE HZ in the FreeRTOSConfig.h
file. Initially, the tick rate was set to 500 Hz, and it has now been increased to 1000 Hz.
This modification changes the system tick period from 2ms to 1ms, increasing the sched-
uler’s update frequency.

7.2 Justification for Modifications


Increasing the tick rate provides the following benefits:

• Finer Task Scheduling: Tasks execute more frequently, leading to better respon-
siveness.

• Improved Timer Accuracy: Delay functions such as vTaskDelay() provide


more precise timing.

• Reduced Jitter: Periodic tasks experience less variation in execution timing.

However, higher tick rates also come with trade-offs:

• Increased CPU Load: More frequent tick interrupts may lead to higher CPU
utilization.

• Potential Overhead: Unnecessary tick processing for tasks that do not require
high precision.

7.3 Performance Considerations


The performance impact of increasing the tick rate is summarized in the table below:

Metric 500 Hz (Before) 1000 Hz (After) Impact


Tick Period 2ms 1ms Faster scheduler updates
Task Responsiveness Moderate Improved More frequent execution
CPU Load Lower Slightly Higher Increased tick interrupts
Delay Accuracy ±2ms ±1ms More precise timing

The console output before and after the modification confirms the change:
This verifies that the scheduler is now running at the updated tick rate, enhancing
real-time performance.

12
Figure 7.1: Performance comparison before modifying the tick rate.

Figure 7.2: Performance comparison after modifying the tick rate.

13
8 Package Management
In FreeRTOS, package management refers to the process of managing the kernel, mid-
dleware, third-party libraries, and other dependencies used within an embedded system.
While FreeRTOS itself doesn’t have a built-in package management system like desktop
operating systems, it offers a flexible and modular approach for managing its components
and third-party software.

8.1 Kernel and Middleware Packages


FreeRTOS provides a modular kernel with additional middleware packages, such as
FreeRTOS+TCP (for networking) and FreeRTOS+FAT (for file systems). Developers
can choose which components to include based on application requirements, ensuring
minimal memory usage and optimal system performance. These packages can be easily
added or excluded from the project as needed.

8.2 Source Code Management


FreeRTOS is open-source and hosted on GitHub, allowing developers to clone the
repository, modify the kernel, and track updates through version control. The FreeRTOS
repository contains both the kernel and additional packages, making it easy to maintain
and update the code.
FreeRTOS GitHub Repository: https://github.com/FreeRTOS/FreeRTOS

8.3 Third-Party Libraries and Build Systems


FreeRTOS applications often rely on third-party libraries for additional features, such
as device drivers or communication protocols. While FreeRTOS doesn’t have a dedicated
package manager, developers can use build systems like Make or CMake to manage these
external libraries and automate the build process. These tools simplify compiling and
linking the FreeRTOS kernel with additional components or third-party code.

8.4 Configuration and Dependencies


The configuration of FreeRTOS is managed through the FreeRTOSConfig.h file, where
developers can specify which features of the kernel to include. Dependencies like hardware
drivers, middleware, or external libraries can be managed manually or using version
control tools, such as Git submodules.

14
9 Process Scheduling and Memory Management
In the context of building a kernel and executing applications on FreeRTOS, process
scheduling and memory management are crucial aspects that ensure the efficient execution
and resource allocation for various tasks.

9.1 Process Scheduling


FreeRTOS uses a preemptive, priority-based scheduling algorithm to manage tasks.
Tasks in FreeRTOS are assigned priorities, and the scheduler ensures that the highest-
priority ready task runs first. The scheduling process happens in a round-robin manner
for tasks with the same priority, ensuring fair CPU time allocation.
In an application, tasks such as handling sensor input, controlling actuators, or updat-
ing displays can be defined with specific priorities, and the scheduler will allocate CPU
time to these tasks based on their priority levels. This mechanism ensures that critical
tasks (e.g., real-time sensor reading) can preempt lower-priority tasks (e.g., user interface
updates), achieving efficient multitasking.

9.2 Memory Management


FreeRTOS provides dynamic memory management features through heap manage-
ment schemes, such as heap 1, heap 2, and heap 3, which are optimized for embedded
systems. Applications may require dynamically allocated memory for task stacks, queues,
or buffers, and FreeRTOS allows developers to choose the most suitable memory alloca-
tion scheme based on the application’s needs.
The memory management system in FreeRTOS is designed to minimize overhead and
optimize memory usage, particularly in resource-constrained environments. By config-
uring the memory allocation settings in FreeRTOSConfig.h, developers can control the
heap size and memory allocation behavior, ensuring that the application runs efficiently
without wasting memory.

15
10 Use Cases
FreeRTOS is a versatile real-time operating system widely used in embedded systems
across various industries. Below are some of the diverse use cases that demonstrate its
flexibility and capabilities:

10.1 Industrial Automation and Control Systems


In industrial applications, FreeRTOS is often used to manage control systems in ma-
chinery, robotics, and production lines. The OS’s ability to prioritize tasks and handle
multiple real-time operations simultaneously makes it ideal for controlling motors, sen-
sors, and actuators. For example, in a conveyor belt system, FreeRTOS could manage
tasks such as speed regulation, sensor monitoring, and error handling, all while maintain-
ing precise timing to ensure efficient operation.

10.2 Consumer Electronics


FreeRTOS is used in consumer electronics like smart home devices, wearables, and
IoT products. These devices often require real-time task scheduling for handling multiple
inputs from sensors, displays, and connectivity modules. In a smart thermostat, for
instance, FreeRTOS could manage tasks such as reading temperature sensors, controlling
heating elements, and managing communication with a smartphone app, all with minimal
latency and resource usage.

10.3 Automotive Systems


In the automotive industry, FreeRTOS is commonly used in systems that require real-
time processing, such as in-vehicle control systems, infotainment systems, and advanced
driver-assistance systems (ADAS). For example, in an ADAS system, FreeRTOS could be
used to manage the processing of data from cameras, radar, and lidar sensors, ensuring
that safety-critical tasks such as collision detection and lane-keeping assist are executed
in real-time and with low latency.

10.4 Networking and Communication Devices


FreeRTOS is ideal for networking and communication devices like routers, modems,
and gateways, where real-time data transmission is essential. In a wireless sensor network,
FreeRTOS can be used to schedule tasks related to data collection, packet transmission,
and communication with base stations, ensuring that data is sent on time without delays,
even in low-power or constrained environments.

16
11 Case Study Findings and Discussion
11.1 Key Takeaways
FreeRTOS offers a lightweight, real-time operating system optimized for embedded
systems with limited resources. Its efficient scheduling and task management allow for
precise control over execution, making it ideal for applications requiring real-time per-
formance. However, it demands careful configuration of system parameters, such as task
priorities and memory allocation, to ensure stable operation. Despite its power and flexi-
bility, FreeRTOS’s sparse documentation can pose challenges, particularly for newcomers
to real-time systems.

11.2 Real-World Application


FreeRTOS is widely used across industries. In industrial automation, it controls ma-
chinery and sensor networks, managing tasks like speed regulation and monitoring with
precise timing. In automotive systems, it supports safety-critical applications such as
advanced driver-assistance systems (ADAS), handling real-time data from sensors like
cameras and radar. Additionally, FreeRTOS is integral to smart home devices and med-
ical equipment, ensuring real-time operation for tasks like monitoring patient data or
managing IoT devices.

11.3 Security and Reliability Considerations


Security and reliability are vital for embedded systems. While FreeRTOS provides
basic memory protection and fault detection, developers must integrate additional secu-
rity features, like encryption and secure boot, for sensitive applications. Reliability can
be ensured through proper task management, watchdog timers, and redundancy. It is
essential to address resource contention and system failures proactively to maintain high
reliability, especially in safety-critical applications.

11.4 Potential for Further Enhancements


FreeRTOS can be further enhanced with improved debugging tools and more compre-
hensive documentation to assist developers. Expanding security features, such as secure
communication protocols, would strengthen its applicability in secure environments. Ad-
ditionally, better support for multicore processors and optimized task scheduling could
improve performance in more complex systems. These improvements would help FreeR-
TOS cater to a broader range of modern embedded system applications.

17
12 Conclusion
This case study aimed to familiarize us with FreeRTOS by directly engaging with the
system and applying the knowledge we acquired to modify its core functionalities. FreeR-
TOS is a real-time operating system designed for embedded systems, offering minimal
overhead and precise control over task execution, which is crucial for real-time applica-
tions. Through our exploration, we learned that FreeRTOS manages tasks, queues, and
semaphores in a way that ensures time-critical operations can be executed with deter-
ministic timing, providing an efficient and reliable solution for embedded systems.
A key takeaway from our experience was the necessity of configuring the system
for specific hardware and resource requirements. FreeRTOS operates in a memory-
constrained environment, and developers need to adjust task stack sizes, priorities, and
other system parameters to ensure optimal performance. Task management and memory
allocation must be handled carefully, as improper configuration can lead to issues such as
stack overflow or resource contention. This hands-on experience emphasized the need for
a solid understanding of the underlying system architecture and resource management to
maximize the benefits of FreeRTOS.
While FreeRTOS offers extensive control and flexibility, its documentation can be
sparse, particularly for those new to embedded systems or real-time operating systems.
While the core concepts like task scheduling, inter-task communication, and interrupt
handling were relatively straightforward, understanding the finer details required fur-
ther exploration through community resources and additional reading. Despite these
challenges, FreeRTOS remains an excellent choice for developers working with resource-
constrained devices who need precise control over their system’s timing and behavior.

18
Bibliography
[1] FreeRTOS: Real-Time Operating System for Embedded Devices. FreeRTOS.org, 2023.
Available at: https://www.freertos.org/

[2] FreeRTOS Source Code: GitHub Repository. GitHub, 2023. Available at:
https://github.com/FreeRTOS/FreeRTOS

[3] FreeRTOS Documentation. FreeRTOS.org, 2023. Available at:


https://www.freertos.org/FreeRTOS-Plus/FreeRTOS-Plus.html

19

You might also like