rtel wrote on Saturday, July 15, 2006:
I am not familiar with the 2560, but if the program counter is 3 bytes then this will definitely prevent the standard code from executing. I think this should be simple to fix.
Going into and out of interrupts the hardware will handle the three bytes. This area can therefore probably remain the same.
A change will definitely be required where the initial stack of the task is set up. Take a look in the function pxPortInitialiseStack() within Source/Portable/IAR/ATMega323. Here you will see the following code (I have taken out the casting to make it more readable):
///////////////////////////////////////////////////////////
The first part of the stack is the hardware stack. Place the start
address of the task on the hardware stack. */
usAddress = pxCode;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack–;
usAddress >>= 8;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack–;
/* Leave enough space for the hardware stack before starting the software
stack. The ‘- 2’ is because we have already used two spaces for the
address of the start of the task. */
pxTopOfStack -= ( configCALL_STACK_SIZE - 2 );
///////////////////////////////////////////////////////////
This only places two bytes at the stop of the stack for the return address (in this case the start of the task). You will need to modify this to something like:
///////////////////////////////////////////////////////////
The first part of the stack is the hardware stack. Place the start
address of the task on the hardware stack. */
usAddress = pxCode;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack–;
usAddress >>= 8;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack–;
/* AND THE THIRD BYTE! */
usAddress >>= 8;
*pxTopOfStack = ( usAddress & 0x00ff );
pxTopOfStack–;
/* Leave enough space for the hardware stack before starting the software
stack. The ‘- 3’ is because we have already used two spaces for the
address of the start of the task. */
pxTopOfStack -= ( configCALL_STACK_SIZE - 3 );
///////////////////////////////////////////////////////////
The size required by the hardware stack is going to be larger as each time the program counter is saved you will require an extra byte. It is likely therefore that you will want to increase the value of configCALL_STACK_SIZE.
Regards.