Study of an operating system: FreeRTOS
Nicolas Melot
Operating systems for embedded devices

Sommaire
Introduction
........................................................................................................................................................................
4
1 Tasks
.................................................................................................................................................................................
5
1.1 A task in FreeRTOS
..................................................................................................................................................
5
1.1.1 Life cycle of a task
............................................................................................................................................
5
1.2 Creating and deleting a task
......................................................................................................................................
6
2 Scheduling
........................................................................................................................................................................
8
2.1 Priorities
....................................................................................................................................................................
8
2.2 Priority-equally tasks
................................................................................................................................................
9
2.3 Starvation
..................................................................................................................................................................
9
3 Queue management
.........................................................................................................................................................
9
3.1 Reading in a queue
..................................................................................................................................................
10
3.2 Writing to a queue
...................................................................................................................................................
10
3.3 Creating a queue
......................................................................................................................................................
11
4 Resources management
.................................................................................................................................................
12
4.1 Binary semaphores
..................................................................................................................................................
12
4.1.1 Handle binary semaphores
..............................................................................................................................
13
4.1.1.1 Creation of a semaphore
.........................................................................................................................
13
4.1.1.2 Taking a semaphore
................................................................................................................................
13
4.1.1.3 Giving a semaphore
................................................................................................................................
13
4.2 Mutexes
...................................................................................................................................................................
15
4.2.1 Priority inheritance
.........................................................................................................................................
15
4.3 Counting semaphores
..............................................................................................................................................
15
4.3.1 Counting semaphore routines
.........................................................................................................................
15
4.3.1.1 Creation
..................................................................................................................................................
15
4.3.1.2 Take & give operations
...........................................................................................................................
16
5 Handling interrupts
.......................................................................................................................................................
16
5.1 Manage interrupts using a binary semaphore
..........................................................................................................
17
5.2 Critical sections
.......................................................................................................................................................
18
5.2.1 Suspend interrupts
..........................................................................................................................................
18
5.2.2 Stop the scheduler
...........................................................................................................................................
19
6 Memory management
....................................................................................................................................................
19
6.1 Prototypes
................................................................................................................................................................
19
6.2 Memory allocated once for all
................................................................................................................................
20
6.3 Constant sized and numbered memory
...................................................................................................................
20
6.4 Free memory allocation and deallocation
...............................................................................................................
21
Conclusion
........................................................................................................................................................................
23
References
.........................................................................................................................................................................
24

7 Illustrations
....................................................................................................................................................................
25
8 Appendix
.........................................................................................................................................................................
26
8.1 An example of FreeRTOSConfig.h
.........................................................................................................................
27
8.2 heap_1.c
..................................................................................................................................................................
29
8.3 heap_2.c
...................................................................................................................................................................
31
8.4 heap_3.c
..................................................................................................................................................................
37

Nicolas Melot
Study of an operating system: FreeRTOS
Introduction
FreeRTOS is an free and open-source Real-Time Operating system developed by Real Time Engineers Ltd. Its
design has been developed to fit on very small embedded systems and implements only a very minimalist set of
functions: very basic handle of tasks and memory management, just sufficient API concerning synchronization, and
absolutely nothing is provided for network communication, drivers for external hardware, or access to a filesystem.
However, among its features are the following characteristics: preemptive tasks, a support for 23 micro-controller
architectures
1
by its developers, a small footprint
2
(4.3Kbytes on an ARM7 after compilation
3
), written in C and
compiled with various C compiler (some ports are compiled with gcc, others with openwatcom or borland c++). It also
allows an unlimited number of tasks to run at the same time and no limitation about their priorities as long as used
hardware can afford it. Finally, it implements queues, binary and counting semaphores and mutexes.
1
2
3
4

Nicolas Melot
Study of an operating system: FreeRTOS
Tasks
1
Tasks
1.1
A task in FreeRTOS
FreeRTOS allows an unlimited number of tasks to be run as long as hardware and memory can handle it. As a
real time operating system, FreeRTOS is able to handle both cyclic and acyclic tasks. In RTOS, a task is defined by a
simple C function, taking a void* parameter and returning nothing (void).


You've reached the end of your free preview.
Want to read all 39 pages?
- Spring '17
- Tuan
- Interrupt, Value added, Interrupt handler, Semaphore line