About porting FreeRTOS to general 80C51 MCU

nobody wrote on Tuesday, March 15, 2005:

As the first task when the Schedular started should be loading the stack with the format the same as defined in the function *pxPortInitialiseStack(), I should expected that the pxCurrentTCB is pointing to the tcb of the task I created. and the first byte pointer stored inside the pxCurrentTCB, should be the top stack address of  the task stack. This pointer should contants : 17(20),(0x11,0x12,0x13),LSB of PC , MSB of PC , 0xaa… right?

It seems to me that the pxCurrentTCB is not pointing to the TCB of the task I created (when schedular first started), any idea for such … happend… I believe that Cygnal 8051’s context switching is basically the same as the other 8051s right?

Sorry for so many questions and trouble all a lot.

nobody wrote on Tuesday, March 15, 2005:

This is getting confusing -

pxCurrentTCB points to the TCB.
The first pointer in the TCB points to the stack.

Therefore -

*pxCurrentTCB = TCB of your task.

and

( portSTACK_TYPE * ) TCB = the address of the task stack.

*(( portSTACK_TYPE * ) TCB) = the first item on the stack.

Just to add more confusion, effectively:

**( ( portSTACK_TYPE **) pxCurrentTCB ) is where the stack is at.

This is simpler than it looks here.

nobody wrote on Tuesday, March 15, 2005:

I have tried to enforce the pxCurrentTCB to point to the first task, it would run the task for 1 tick ( I guess).

From the tasks.c , I found that the PC never loops the following code:
    if( usCurrentNumberOfTasks == 1 )
            {
                /* As this is the first task it must also be the current task. */
                pxCurrentTCB = ( volatile tskTCB * volatile ) pxNewTCB;               
                P1_5=0;
                /* This is the first task to be created so do the preliminary
                initialisation required.  We will not recover if this call
                fails, but we will report the failure. */
                sReturn = prvInitialiseTaskLists();
               
            }

rtel wrote on Tuesday, March 15, 2005:

I think you need to find the reason the static variables have the wrong values first - otherwise everything else will also be odd also.

Are you using the --no-xinit-opt compiler option.  This would seem to be a possible cause of the symptoms you are finding?

nobody wrote on Wednesday, March 16, 2005:

Thank you~ I also believe that there are some problems for my SDCC(maybe setting,maybe something else)…

I tried to make a static unsigned char in the main.c and initialize it with a value, however, I checked inside the main() function but it fails too…

I did not use such optimized options. I straightly follow the makefile… with just the xram-size option changed.

I am now wondoring if there are any other reasons which caused the error…

nobody wrote on Wednesday, March 16, 2005:

Just have a trial, with no object files built with the main.c by SDCC with the same flags, the main.c will works fine(static variable initialization) .It seems that the linker is not working correctly with the makefile…

when the main.c links with the object files(rel), all static variables initialization failed.

nobody wrote on Thursday, March 17, 2005:

Thank you all for your kindly help.

I had solved the problem by reinitialize all the static variable before creating first task.
  0C:4FE3    Fmain$__xinit_sLatchedError$0$0
  0C:4FE5    F______Source_tasks$__xinit_pxCurrentTCB$0$0
  0C:4FE8    F______Source_tasks$__xinit_sUsingPreemption$0$0
  0C:4FEA    F______Source_tasks$__xinit_usCurrentNumberOfTasks$0$0
  0C:4FEC    F______Source_tasks$__xinit_xTickCount$0$0
  0C:4FEE    F______Source_tasks$__xinit_ucTopUsedPriority$0$0
  0C:4FEF    F______Source_tasks$__xinit_ucTopReadyPriority$0$0
  0C:4FF0    F______Source_tasks$__xinit_cSchedulerRunning$0$0
  0C:4FF1    F______Source_tasks$__xinit_ucSchedulerSuspended$0$0
  0C:4FF2    F______Source_tasks$__xinit_ucMissedTicks$0$0
  0C:4FF3    F______Source_portable_MemMang_heap_1$__xinit_usNextFreeByte$0$0
  0C:4FF5    F___Common_Minimal_integer$__xinit_cTaskCheck$0$0
  0C:4FF6    F___Common_Minimal_PollQ$__xinit_cPollingConsumerCount$0$0
  0C:4FF7    F___Common_Minimal_PollQ$__xinit_cPollingProducerCount$0$0

And reduced the size of the following
#define portMINIMAL_STACK_SIZE        ( ( unsigned portSHORT ) 100 - ( unsigned portSHORT ) portSTACK_START )

The RTOS is working fine on my Atmel 89C51SND1 @ 16Mhz X2 mode(32Mhz) @ 1000Hz timer tick running for 12task + 1 idle task

Dunno why have such to happen, but anyway thanks to all~