In our previous articles, we discussed about microprocessor, ARM architecture, kernel of operating system, UNIX, Linux, Difference Between Real Time OS (RTOS) and Embedded Linux etc topics. Here is How To Set Up Real Time OS FreeRTOS on Arduino UNO. Although Sounds Challenging, it is Simple Dropping Directory and Including Via Code.
Arduino UNO has Atmel AVR. FreeRTOS officially support AVR. However, AArduino UNO’s AVR is just 8 bit. So do not expect more than you can actually used to get from BBC Micro Computers. Arduino DUE or other STM32 boards are far more practical for heavy load computing with a practically usable operating system for modern need.
Many n00bs think, operating system means uploading everything on processor. That is not exactly true. We actually almost never involve all HEX files of whole operating system.
In this case, at end, you’ll not feel huge difference in normal Arduino way (in case you are thinking some procedure like rooting of mobile phones by uploading custom OS). It is safe, easy work.
How To Set Up Real Time OS FreeRTOS on Arduino UNO
FreeRTOS configuration options can be specified from
FreeRTOSConfig.h file. AVR Watchdog Timer is used to generate 15ms time slices. More lower will offload to Scheduler. Time slices can be rom 15ms up to 500ms. Slower time slicing can allow the Arduino MCU to sleep for longer, without the complexity of a Tickless idle.
Interrupts come above the scheduler/Tasks as long as they are enabled. For Task overflows, there will be a slow LED blink, with 4 second cycle (Stack Overflow). There will be a fast LED blink, with 100 millisecond cycle in failure to allocate memory (Heap Overflow).
Go to Library directory of your Arduino. Download and keep the files from this repo :
Close Arduino IDE and again launch it. Go to Arduino IDE’s File > Examples > FreeRTOS >01-TaskSwitching. The code will load as sketch. Compile it on Arduino IDE and upload. Open the serial monitor of Arduino IDE to see the output as test example. It will clarify you that it is actually an operating system.
On official site of FreeRTOS, you’ll find useful configaration and other stuffs :
There are some important files :
Arduino_FreeRTOS.h : references other configuration files, and sets defaults.
FreeRTOSConfig.h :contains some API and environment configurations.
FreeRTOSVariant.h : contains AVR specific configurations.
heap_3.c : contains the heap allocation scheme based on malloc().
If, as example sensor value is read from UART, that specific interrupt can be enabled. When a new data will be received, then it will be copied to the buffers and signalled to the task using the semaphores. Whenever a new senor value will be received by interrupt, data will be copied to buffer and Semaphore will be released.