fkln wrote on Sunday, December 30, 2007:
I’m working on a FreeRTOS port for Lattice MICO32 Processor (FPGA).
As a sample, I take the documentation about the Coldfire Implementation.
My actual problem is in Example Program 2 which prints out the two different Task-ID’s.
The first two printfs are correct, the remaining printfs are wrong, because the Task-ID’s have changed,
probable because the Context Switching is wrong.
I am wondering about the vPortYield Funktion.
void vPortYield( void )
{
portSAVE_CONTEXT();
vTaskSwitchContext();
portRESTORE_CONTEXT();
}
The following code is a disassembly from the final code
void vPortYield( void )
{
// The following 3 lines are automatically generated from the gcc Compiler
addi sp,sp,-4 Decrement Stack
sw (sp+4),ra Store Return Address on Stack
sw (sp+0),sp Store content of Stack on Stack
// macro portSAVE_CONTEXT();
addi sp,sp,-120 Decrement Stack by size of registers which are stored on the stack
sw (sp+116),r1 Store content of first register on Stack
… Store remaining registers on Stack
sw (sp+4),ra Store Return Address on Stack
and r1,r0,r0 Clear register R1
mvhi r1,hi(pxCurrentTCB) Load High-Halfword of CurrentTCB
ori r1,r1,lo(pxCurrentTCB) Load Low-Halfword of CurrentTCB
lw r1,(r1+0) Load Pointer from CurrentTCB
sw (r1+0), sp Store actual StackPointer into current CurrentTCB - TopOfStack
calli vTaskSwitchContext Call vTaskSwitchContext() Function
// macro portRESTORE_CONTEXT();
and sp,r0,r0 Clear StackPointer
mvhi sp,hi(pxCurrentTCB) Load High-Halfword of CurrentTCB
ori sp,sp,lo(pxCurrentTCB) Load Low-Halfword of CurrentTCB
lw sp,(sp+0) Load Pointer to CurrentTCB
lw sp,(sp+0) Load content from CurrentTCB - TopOfStack
lw ra,(sp+4) Load Return Address from Stack
… Load remaining registers on Stack
lw r1,(sp+116) Load content of first register from Stack
// The following 3 lines are automatically generated from the gcc Compiler
lw ra,(sp+4) Load Return Address from Stack
addi sp,sp,4 Increment Stack
ret Return from Subroutine
}
Any idea what is going wrong ?
Anyway, I have also tried the use the "naked" attribute, but the code for this fuction is always the same.
Thanks,
Klaus