Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Problem Starting Scheduler in HCS12XDP512

Posted by Nobody/Anonymous on February 22, 2006
I am trying implement the FLASH task using the RTOS Demo for the HCS12 (banked) as a starting point (I removed all the other tasks, since I'm going for simplicity first time around). I had to make some changes since ProcessorExpert is not yet supported with the HCS12X. The changes I basically made were to setup the Periodic Interrupt Timer 0 as the RTOS Tick interrupt, hardcoding it for 1000 Hz (just like the demo). I changed the prvSetupTimerInterrupt() in port.c to simply start the PIT0 timer. The interrupt vector table is also updated so that the Tick ISR is serviced with the PIT0.

My problem is that in xBankedStartScheduler(), the application quits with an unknown event (quitting at the XIRQ interrupt for some reason). If I comment out the portRESTORE_CONTEXT(); and __asm( "rti" ); lines, it runs through (but obviously just sits in the loop in vMain()). I think its somewhere not correctly restoring the context so that the rti instruction goes to the correct Task, but I've been hung up for a while trying to track down what's going on.

Does anyone have any suggestions on what may be causing the problem? I'm thinking theres still something I need to change so that RTOS is correctly ported to the HCS12X and its memory map in regards to storing a task's context.

Anyway, any suggestion/help is greatly appreciated!

- Mike

RE: Problem Starting Scheduler in HCS12XDP512

Posted by Nobody/Anonymous on February 22, 2006
Not familiar with the HCS12X but some things come to mind reading your post.

1) The processor expert can be a pain wrt interrupts. The FreeRTOS demo requires that the interrupt table be populated manually after the expert has run. Also there was something I recall about having a file read only so the expert does not overwrite it. You might one to check that out.

2) Have you checked your timer without FreeRTOS? Simply setting up a timer and toggling a bit every 1000 ticks or something. Once you can guarantee that the interrupts are correct you can add the FreeRTOS code in.

3) You could try not turning on the interrupt (so it does not get in the way) and stepping through the starting of the first task to see exactly what it does. Obviously it will not run without the interrupt but it is easier to debug.

RE: Problem Starting Scheduler in HCS12XDP512

Posted by Nobody/Anonymous on February 23, 2006
The Tick interrupt works just fine and is very accurate to 1000 Hz.

I've stepped through the code a bit, and found something interesting. When the function xTaskCreate is called, the first parameter if the address of the function that has the task code (for me, that is located at memory location FE86CA). However, when debugging, it passes the address 86CAFE (the page is appended to the end for some reason?). It does this with the address-of operator as well. I'm thinking that something is not storing correctly in the stack, and so when RTI is called from the StartScheduler, it goes to a memory location for the XIRQ ISR (my vector table is setup so that each interrupt channel has its own ISR, then all the ISRs that are not used are simply blank).

RE: Problem Starting Scheduler in HCS12XDP512

Posted by NightEye on February 24, 2006
I fixed the issue. It has to do with the HCS12X having a larger CCR register (2 bytes instead of one). The first 5 bits are unused for future use, then comes IPL[2:0], and than the other 8 bytes. The two high bytes of the actual CCR register (S and X) need to be set to 1, or else the application ceases (clearing 0 or X causes an interrupt; which is why I was getting the XIRQ interrupt due to the X flag being cleared).

So here's what needs to be added to port.c in the function *pxPortInitialiseStack

Where the CCR is save to the stack, simply add stack the extra byte 0xC0 (C to set the S and X flags).

/* CCR: Note that when the task starts interrupts will be enabled since I" bit of CCR is cleared */
*pxTopOfStack = ( portSTACK_TYPE ) 0xC0;
*pxTopOfStack = ( portSTACK_TYPE ) 0x00;

So far I've gotten the Flash task to work correctly. If there are any other locations in the code where the CCR register is stacked, or unstacked, then that will need to be edited too (I have just now started to actually write my application since finding this issue).

I hope this helps future users who are trying to implement FreeRTOS on an HCS12X (XGate).



RE: Problem Starting Scheduler in HCS12XDP512

Posted by Richard on February 24, 2006
Thanks for reporting back - very useful information.


RE: Problem Starting Scheduler in HCS12XDP512

Posted by Jeff Smith on February 24, 2006
I had to trace the stack very carefully too, for my HCS12 port. With a new compiler and new MCU, you have to carefully count the bytes on the stack to see what address it will return to with the rti.

One more thing, I don't know if anyone mentioned the reason the memory bank (0xfe) is in the LSB instead of first in the "far" address. It's a new standard address type with 9S12X, I believe.

[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM 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.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists