FreeRTOS for MSP430F148
Getting started with FreeRTOS on the MSP430F148
FreeRTOS is a open source real-time microkernel for ported to a variety of processors and microcontrollers. The scheduler uses the real-time abstraction and so it guarantees that high priority threads will be scheduled before those of a lower priority. Furthermore, low priority tasks will be suspended when a high priority needs to be resumed. If the programmed time constraints are realistic - then the microkernel of a real-time system will schedule the threads so as to meet the constraints. According to the FreeRTOS site, threads with equal priority are scheduled using the round-robin method.
I started with version 3.2.4 that contains a port to a MSP430F449 evaluation board using GCC. The ZIP file unpacks into a tree with a "demo" and "source" branches. The source branch contains the FreeRTOS micro-kernel for various architectures - and demo branch the example programs for each of the architectures.
demo program 1
Although the FreeRTOS demo programs are interesting, I find them to be too complex for someone new to the FreeRTOS distribution. I've created a simple generic MSP430 demo program that one can quickly customize to their own platform.
My experimental platform has LEDs on PORT5 bits 0-2, and UART1 on port3 bits 6-7. If your platform is different you will need to make minor and obvious edits to the makefile, main.c, and uart_isr.c. Users of the MSP430F12xx will need to make more serious changes to the uart.c #defines as the UART0 location is unique on this device.
After extracting the files - change to ./FreeRTOS/demo/msp430f148_gcc and edit the files if necessary.
To compile and create the a.out file - type "make".
To compile and download a.out on a parallel port jtag cable type "make download".
The demo spawns 4 tasks. Three of them toggle LEDs and output chars to the serial port. The 4th task operates at the idle priority and (when calibrated) outputs a number showing the percentage of the CPU that is free.
To keep things simple in my first demo - shared resources are NOT locked. For example, the LED ports are not modified with an atomic operation. The serial port output - due to being in an ISR - is effectively atomic, however a the ISR reads from a single queue filled from threads that don't lock it. Thus a printf output from one thread could be mixed with output from another thread.
The best way to understand the demo program is make good use of the FreeRTOS API. You can also access the API by going to FreeRTOS.org and expanding the "Information" node on the top-right frame. Then select "FreeRTOS API".
dIDEAS example 2
The 2nd demo adds resource locking.
MODs to the offical demo branch
Changing the target MSP430 from the MSP430F449 to the F148 required no changes to the source tree! However the example programs are both processor and platform dependant. I've not made any serious efforts to port those to my platform.
However there are some FreeRTOS distro changes that will be helpful:
First the file demo/msp430_gcc/FreeRTOSConfig.h could be made portable across all MSP430 devices:
Replace the line:
"io.h" contains macros that include the correct MSP430 portmap based on the processor type.
Also needed - modify the makefile (demo/msp430_gcc/makefile) and replace the line:
CFLAGS=-mmcu=msp430x449 $(OPT) ...
CFLAGS=-mmcu=msp430x148 $(OPT) ...
or to the appropriate value for your processor type.