huzhiping wrote on Friday, December 13, 2013:
I am trying to port FreeRTOS to v850 Fx4 based on Fx3, but using GreenHills compiler.
Sereval issues found:
-
From FreeRTOS offical website, it is said “6.If the stack on the microcontroller being ported to grows downward from high memory to low memory then set portSTACK_GROWTH in portmacro.h to -1, otherwise set portSTACK_GROWTH to 0.” --> in here, http://www.freertos.org/FreeRTOS-porting-guide.html…, if you set “portSTACK_GROWTH to 0”, then you got a compiler error, “pxEndOfStack” is undefined, you have to set “portSTACK_GROWTH to be greater than 0”, which in Tasks.c, the condition is “portSTACK_GROWTH > 0”.
-
I created 2 simple tasks with function by setting a different LED ON in each task, When I using debugger, 2 tasks (priority is different, task 2 is 2, task1 is 1) and the idle task all created successfully, but in function "xPortStartScheduler()–>vPortStart() -> portRESTORE_CONTEXT (assembly macro), it can NOT get the right address of “_pxCurrentTCB” that is for task2. my vPortStart() function is:
_vPortStart:
portRESTORE_CONTEXT – Restore the context of whichever task the …
ld.w 0[sp],lp
ldsr lp,5 – restore PSW
DI
ld.w 4[sp],lp – restore LP
ld.w 8[sp],lp – restore LP
ADD 0x0C,sp – set SP to right position
EI
jmp [lp]
- I tried different heap_x.c, I found each time after call vPortStat()->portRESTORE_CONTEXT
the stack pointer of “_pxCurrentTCB” is different. I double checked the “portRESTORE_CONTEXT” and “portSAVE_CONTEXT”, it looks like correct.
I attched these assembly macro below:
.macro portSAVE_CONTEXT
prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},18,sp – save general purpose registers
sst.w r19,68[ep]
sst.w r18,64[ep]
sst.w r17,60[ep]
sst.w r16,56[ep]
sst.w r15,52[ep]
sst.w r14,48[ep]
sst.w r13,44[ep]
sst.w r12,40[ep]
sst.w r11,36[ep]
sst.w r10,32[ep]
sst.w r9,28[ep]
sst.w r8,24[ep]
sst.w r7,20[ep]
sst.w r6,16[ep]
sst.w r5,12[ep]
sst.w r2,8[ep]
sst.w r1,4[ep]
MOVHI hi(_usCriticalNesting),r0,r1 – save usCriticalNesting value to stack
ld.w lo(_usCriticalNesting)[r1],r2
sst.w r2,0[ep]
MOVHI hi(_pxCurrentTCB),r0,r1 – save SP to top of current TCB
ld.w lo(_pxCurrentTCB)[r1],r2
st.w sp,0[r2]
.endm
.macro portRESTORE_CONTEXT
MOVHI hi(_pxCurrentTCB),r0,r1 – get Stackpointer address
ld.w lo(_pxCurrentTCB)[r1],sp
MOV sp,r1
ld.w 0[r1],sp – load stackpointer
MOV sp,ep – set stack pointer to element pointer
sld.w 0[ep],r1 – load usCriticalNesting value from stack
MOVHI hi(_usCriticalNesting),r0,r2
st.w r1,lo(_usCriticalNesting)[r2]
sld.w 4[ep],r1 – restore general purpose registers
sld.w 8[ep],r2
sld.w 12[ep],r5
sld.w 16[ep],r6
sld.w 20[ep],r7
sld.w 24[ep],r8
sld.w 28[ep],r9
sld.w 32[ep],r10
sld.w 36[ep],r11
sld.w 40[ep],r12
sld.w 44[ep],r13
sld.w 48[ep],r14
sld.w 52[ep],r15
sld.w 56[ep],r16
sld.w 60[ep],r17
sld.w 64[ep],r18
sld.w 68[ep],r19
dispose 18,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
.endm
I don’t know how to do it next, hopefully I can get help from you.
Thanks in advance!
Albert