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




Loading

Cygnal port optimisation.

Posted by Nobody/Anonymous on September 18, 2006
On the Cygnal port page:"Currently the task context is pushed onto the stack and the stack then copied to XRAM before checking to see if a higher priority task is ready to run. This could be modified so the context is pushed onto the stack, but the stack only copied to XRAM if necessary. If no context switch is required the original task would just pop its context off the stack and continue. This change would make the code very 8051 specific (which is why I have not done it)."

Can anyone give me some suggestion how to do it?
Thanks,

RE: Cygnal port optimisation.

Posted by David Hawks on September 18, 2006
I don't agree with the argument made on the Cygnal port page. I have performed the suggested optimization on the Keil Cygnal port that I am working on and it works quite nicely. I don't agree with the 8051-specific argument because the modification only affects the port files. My port of vPortYield() is in assembly because Keil's C51 does not support the _naked attribute, but I can give you the gist of my change in this untested back-port to C:

/* A place to remember the task running before vTaskSwitchContext(). */
static tskTCB * pxOldTCB;

void vPortYield( void ) _naked
{
/* Save the execution context onto the stack. */
portSAVE_CONTEXT();

/* Remember what task was running before calling vTaskSwitchContext(). */
pxOldTCB = pxCurrentTCB;

/* Call the standard scheduler context switch function. */
vTaskSwitchContext();

/* Only peform stack copy if a new task will be running. */
if( pxOldTCB != pxCurrentTCB )
{
/* Copy the entire stack to XRAM. This is necessary as the internal
RAM is only large enough to hold one stack, and we want one per task. */
portCOPY_STACK_TO_XRAM( pxOldTCB );

/* Copy the stack of the task about to execute from XRAM into RAM. */
portCOPY_XRAM_TO_STACK( pxCurrentTCB );
}

/* Restore the context of the task from the stack. */
portRESTORE_CONTEXT();
}

The idea here is to compare the value of pxCurrentTCB before you execute vTaskSwitchContext() with the value of pxCurrentTCB after you execute vTaskSwitchContext(). You only have to perform the stack copy if these values are different. You must perform the same modification to vTimer2ISR() as well.

The major modification outside of these functions is to change the macros that copy the stack to and from XRAM to accept as a parameter, the address of the TCB to use for the copy. Alternatively, you could modify portCOPY_STACK_TO_XRAM() to always work with pxOldTCB and portCOPY_XRAM_TO_STACK() to always work with pxCurrentTCB. My assembly port does the former because it makes the macros more generic.

Regards,
David Hawks

RE: Cygnal port optimisation.

Posted by David Hawks on September 18, 2006
Please note that my above post does have reentrancy problems. The use of statically-allocated memory (for pxOldTCB) makes vPortYield() non-reentrant. As I said, this was an untested back-port to C of my assembly modification. The value of pxCurrentTCB should be pushed on the stack before calling vTaskSwitchContext() and then popped off the stack into registers for the comparison after the call to vTaskSwitchContext(). This is easily done is assembly, but perhaps not so easily done in C.

Regards,
David

RE: Cygnal port optimisation.

Posted by Nobody/Anonymous on September 19, 2006
Thanks alot.

RE: Cygnal port optimisation.

Posted by Nobody/Anonymous on September 20, 2006
Can either of you tell me what version of SDCC you are using?

If I use SDCC V2.5.0 the demo program runs on my F124 (with mods for the slower max clock rate) but if I compile with SDCC V2.6.0 the program craters.

And yes, I did notice that the stack pointer needed to be moved.

RE: Cygnal port optimisation.

Posted by David Hawks on September 20, 2006
I am currently using Keil, not SDCC. I did get the demo to work using SDCC v2.5.0 before I started my port to Keil, though. I never tried v2.6.0.

Regards,
David


[ 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