======High Level overview of FreeRTOS====== [[http://www.freertos.org|FreeRTOS]] is a very popular embedded real-time OS for small microcontrollers. It has been ported to almost all the major microcontroller architectures. =====What does the OS actually do?===== Remember, we are not dealing with the source code of the Linux kernel - an OS like //FreeRTOS// typically runs on processors which have a few kilobytes of RAM/Flash. We don't have to deal with millions of lines of code; let's look at the line count of a few crucial source files in the FreeRTOS 4.6.1 kernel: * tasks.c 2036 lines * queue.c 1061 lines * list.c 205 lines * port.c 324 lines * portmacro.h 142 lines That is a grand total of 3768 lines! The processor dependent code is found only in two source files //port.c// and //portmacro.h// - just 466 lines. What does the OS actually do, with so few lines of code? No file systems. No complex memory management. No networking. No complex device drivers. The OS let's you create //tasks// (usually C functions), assign priorities to them and //schedules// them //pre-emptively//. The OS provides mechansisms for the tasks to //communicate// with each other and modify shared data items safely. That's about it! =====Source code layout===== Let's look at a part of the source layout of FreeRTOS v5.1.2 (names in brackets represent directories). *[FreeRTOS] *[Source] *[include] *list.c *queue.c *tasks.c *[portable] *[MemMang] *heap_1.c *heap_2.c *heap_3.c *[GCC] *[ARM_CM3] *portmacro.h *port.c *[Demo] *[CORTEX_STM32F103_Primer_GCC] *FreeRTOSConfig.h //portmacro.h// and //port.c// are the processor-dependent parts of the OS. The core files //list.c//, //queue.c// and //tasks.c// are processor independent. The file //FreeRTOSConfig.h// contains parameters (like total heap size, cpu clock hz) which can be changed to suit the particular board and application. The //MemMang// directory holds 3 files, //heap_1.c//, //heap_2.c// and //heap_3.c//. The first one, //heap_1.c//, defines a very simple //malloc// routine without any support for freeing allocated blocks. //heap_2.c// allows allocated blocks to be freed, but does not combine adjacent free blocks. //heap_3.c// uses the native //malloc// implementation defined by the toolchain.