با فراخوانی تابع vTaskStartScheduler() در تابع main کنترل روند اجرای برنامه را به FreeRTOS می سپاریم.. خب! برنامه باید در حالت non-RTOS نیز عملکرد صحیحی داشته باشد... از این امر باید مطمئن شوید...
سیستم عامل ↔ زمانبندی
خب! برای زمانبدی به یک تایمر احتیاج داریم...
EVERY RTOS PORT USES A TIMER TO GENERATE A PERIODIC TICK INTERRUPT. MANY PORTS USE ADDITIONAL INTERRUPTS TO MANAGE CONTEXT SWITCHING...
FreeRTOS - Basic directory structure
The core RTOS code is contained in three files, which are called tasks.c, queue.c and list.c. These three files are in the FreeRTOS/Source directory. The same directory contains two optional files called timers.c and croutine.c which implement software timer and co-routine functionality respectively.
Core FreeRTOS Source Code (FreeRTOSV8.1.2/FreeRTOS/Source)
FreeRTOS/Source/tasks.c
FreeRTOS/Source/queue.c
FreeRTOS/Source/list.c.
FreeRTOS/Source/timers.c
FreeRTOS/Source/croutine.c
Each supported processor architecture requires a small amount of architecture specific RTOS code. This is the RTOS portable layer, and it is located in the FreeRTOS/Source/Portable/[compiler]/[architecture] subdirectories, where [compiler] and [architecture] are the compiler used to create the port, and the architecture on which the port runs, respectively.
RTOS Portable Layer (FreeRTOSV8.1.2/FreeRTOS/Source/portable/RVDS)
FreeRTOS/Source/portable/YOUR_PORT/port.c
Anatomy of a minimum FreeRTOS Project
Source Files
FreeRTOS/Source/tasks.c
FreeRTOS/Source/queue.c
FreeRTOS/Source/list.c
FreeRTOS/Source/portable/[compiler]/[architecture]/port.c
FreeRTOS/Source/portable/MemMang/heap_x.c // where 'x' is 1, 2, 3 or 4.
- If the directory that contains the port.c file also contains an assembly language file, then the assembly language file must also be used...
- If you need software timer functionality, then include FreeRTOS/Source/timers.c...
- If you need co-routine functionality, then include FreeRTOS/Source/croutine.c
Header Files
FreeRTOS/Source/include
FreeRTOS/Source/portable/[compiler]/[architecture]
Configuration File
Src/FreeRTOSConfig.h
configTOTAL_HEAP_SIZE // total amount of available heap space
configMINIMAL_STACK_SIZE // size of the stack used by the idle task
- It is advised to copy the settings from an official FreeRTOS demo provided for the same microcontroller architecture
Memory Management
The RTOS kernel allocates RAM each time a task, queue, mutex, software timer, semaphore or event group is created...
The standard C library malloc() and free() functions can sometimes be used for this purpose, but they are not safe, deterministic...
One embedded / real time system can have very different RAM and timing requirements to another - so a single RAM allocation algorithm will only ever be appropriate for a subset of applications...
Creating a New FreeRTOS Project
0- Import FreeRTOS folder to our project tree
1- Link following sources to your project
FreeRTOS/Source/list.c
FreeRTOS/Source/queue.c
FreeRTOS/Source/tasks.c
FreeRTOS/Source/portable/MemMang/heap_YOUR_HEAP.c
FreeRTOS/Source/portable/YOUR_PORT/port.c
FreeRTOS/Source/portable/YOUR_PORT/portASM.s
2- Copy FreeRTOSConfig.h from closest demo example to your include path
3- Add following directories to you include path
FreeRTOS\Source\include
4- You may need to change Startup.S to the one from closest demo example, if threads are not starting
5- Modify your main.c ...!!!