Operating Systme
Operating Systme
INSTITUTE OF ENGINEERING
Pulchowk Campus
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
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
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
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
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
1.3 Objective
The main objective of this setup is to:
• 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. 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.
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.
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.
• croutine.c: Supports lightweight co-routines, which are smaller tasks with specific
use cases.
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.
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.
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:
• main.c: The entry point for demo applications, configuring the FreeRTOS kernel
and starting tasks.
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.
• Peripheral drivers and hardware interfaces are controlled directly by the application.
• Best suited for safety-critical applications, such as automotive and medical systems.
• Suitable for applications requiring dynamic behavior, such as IoT and cloud-connected
devices.
• The kernel enters a low-power sleep mode when no tasks need 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.
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.
• Finer Task Scheduling: Tasks execute more frequently, leading to better respon-
siveness.
• 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.
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.
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.
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.
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:
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.
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
19