
From FreeRTOS V3.1.1 the HCS12 port supports both the small and banked memory models. This page demonstrates the usage of the small memory model on an MC9S12C32 processor. See the MC9S12DP256B RTOS port page for an example that uses the banked memory model.
The port was developed on a PK-HCS12C32 starter kit from SofTec Microsystems (instructions are provided should you wish to use an alternative development board). It uses the CodeWarrior HC(S)12 Development Tools from Metrowerks. A generous 32KByte code size limited version of the CodeWarrior tools can be obtained from the Metrowerks WEB site.
As downloaded this demo application does not demonstrate the use of co-routines. See the co-routine documentation page for information on how co-routine functionality can be quickly added to this demonstration.
See also the FAQ My application does not run, what could be wrong?
The HCS12 CodeWarrior small memory model demo application project file is located in the FreeRTOS/Demo/HCS12_CodeWarrior_small directory and is called RTOSDemo.mcp.
The demo applications included with other FreeRTOS ports make use of the standard ComTest tasks. These use a loopback connector to transmit and receive RS232 characters between two tasks. The test is important for two reasons:
The 'Button Push' task blocks on a queue, waiting for data to arrive. A simple interrupt routine connected to the PP0 input on the starter kit board places data in the queue each time the PP0 button is pushed (this button is built onto the starter kit board). As the 'Button Push' task is created with a relatively high priority it will unblock and want to execute as soon as data arrives in the queue - resulting in a context switch within the PP0 input interrupt service routine. If the data retrieved from the queue is that expected the 'Button Push' task toggles LED PB5.
When executing correctly the demo application will behave as follows:
LED PB7 is under control of the 'Check' task. Every three seconds the 'Check' task examines all the tasks in the system to ensure they are executing without error. It then toggles LED PB7. If LED PB7 is toggling every three seconds then no errors have ever been detected. The toggle rate increasing to 500ms indicates that the 'Check' task has discovered at least one error.
The project was originally created using the UNIS Processor Expert configuration utility - resulting in a lot of automatically generated files and folders being included in the project. The FreeRTOS real time kernel source files are contained in the 'Source->Kernel Source' project folder, highlighted in red in the diagram below. The demo application source files are contained in the 'Source->RTOS Demo' project folder highlighted in green in the diagram below.

The demo application project contains two build configurations:
To simulate the RTOSDemo project first select the 'Simulator' configuration from the drop down list highlighted in blue within the diagram above. Following a successful build selecting Debug from the Project menu will automatically open the simulator and start a debug session.
The project can be executed and debugged directly on the HCS12 microcontroller using the USB BDM interface. To start a remote debugging session first select 'SofTec' from the drop down list highlighted in blue within the diagram above. Following a successful build selecting Debug from the Project menu will automatically load the program into the microcontroller flash memory and start a debug session (assuming you have the target board connected using the provided USB cable!).
Each port #defines 'portBASE_TYPE' to equal the most efficient data type for that processor. This port defines portBASE_TYPE to be of type char.
Note that vPortEndScheduler() has not been implemented.
An interrupt service routine that does not cause a context switch has no special requirements and can be written as per the normal CodeWarrior syntax.
Often you will require an interrupt service routine to cause a context switch. For example a serial port character being received may wake a high priority task that was blocked waiting for the character. If the ISR interrupted a lower priority task then it should return immediately to the woken task. A macro portTASK_SWITCH_FROM_ISR() is provided to permit this functionality. Note that portTASK_SWITCH_FROM_ISR() should only ever be used at the very end of an ISR and only when the ISR does not declare any non static local variables. If the ISR does use local variables then a call to portYIELD() can be used in place of the portTASK_SWITCH_FROM_ISR() macro.
As an
example here is the function vButtonPush() from the demo application:
/* ISR connected to PP0 button input. */
void interrupt vButtonPush( void )
{
static unsigned portBASE_TYPE uxValToSend = 0;
/* Send an incrementing value to the button push
task each time the button is pushed. */
uxValToSend++;
/* Clear the interrupt flag. */
PIFP = 1;
/* Send the incremented value down the queue. The
button push task is blocked waiting for the data.
As the button push task is high priority it will
wake and a context switch should be performed before
leaving the ISR. */
if( xQueueSendFromISR( xButtonQueue, &uxValToSend, pdFALSE ) )
{
/* Posting the message caused a higher priority
task to unblock. This is the end of the ISR so
we can perform the task switch here. This can be
used as the only local variable is static. */
portTASK_SWITCH_FROM_ISR();
}
}
See the interrupt function vCOM0_ISR() within FreeRTOS/Demo/HCS12_CodeWarrior_banked/serial/serial.c for a full example that uses local stack variables.
FreeRTOS/Source/Portable/MemMang/heap_1.c is included in the HCS12 demo application project to provide the memory allocation required by the real time kernel. Please refer to the Memory Management section of the API documentation for full information.
Any and all data, files, source code, html content and documentation included in the FreeRTOS.org distribution or available on this site are the exclusive property of Real Time Engineers Ltd..
See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd..