FreeRTOS is free open source RTOS that supports several architectures. You can get its source code here. This post is my port for my ATMega128 board. It may run on your board (or may not).My version is not much different from the original ATMega323 port. The things that I’ve changed are:
- Makefile: User can include it, rather than built their own Makefile.
- GCC flags: I added new CFLAGS and LDFLAGS to remove dead codes/unused functions. It’ll make your binaries smaller (and still works, I hope)
- Using RTC osc as RTOS’ tick interrupt: I need precise resolution for timing. Therefore, I moved the interrupt from OCR1A to asynchronous OCR0.
Here’s some explanation about the Makefile. I’ve added main Makefile in the FreeRTOS source code, so user that’s needed to build new code just need simple Makefile, like this:
SRC = leds.c include $(FREERTOS_DIR)/Makefile
You can compile, program, generate COFF, SREC, IHEX as usual (because I’m using the standard AVR Makefile from mfile) as long as you define the FREERTOS_DIR, like this:
$ make FREERTOS_DIR=../FreeRTOS_ATMega128 program
Take a look at the main Makefile to know which Makefile variables that you can override.
The RTOS’ tick is changed to OCR0 interrupt. My board has RTC xtal (32.768kHz) attached on it. So, I’m expecting better timing precision than the original port. Anyway, this also means that you cannot use my FreeRTOS port without RTC xtal in your board.
The settings of the OCR0 enables the RTOS running with max 512Hz tick rate. Don’t try to use it more than 512Hz. It won’t tick (it will hang on OCR0 interrupt handler).