EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

9S12DP256 codewarrior uCOS-II banked flash

Started by donpichol December 7, 2003
Hi,

At the moment, i got a uCOS-II-based-application running in "Flash
Application" target (Codewarrior). I want to run it in "Banked Flash"
mode.
As you can think, some problems occur with assembly routines. After a
while reading datasheets i resolve some problems (e.g. JSR-RTS
replaced by CALL-RTC instructions) but some stay.
Routine example :

OSStartHighRdy:
call OSTaskSwHook, PAGE(OSTaskSwHook) ;Invoke user defined context
switch hook
inc OSRunning ;Indicate that we are multitasking
ldx OSTCBHighRdy ;Point to TCB of highest priority task ready to run
lds 0,x ;Load SP into 68HC12
rti ;Run task

when i use this, the value of PC register in the task stack is wrong

;1) The stack frame is assumed to look as follows:
;
; OSTCBHighRdy->OSTCBStkPtr + 0 --> CCR
; + 1 B
; + 2 A
; + 3 X (H)
; + 4 X (L)
; + 5 Y (H)
; + 6 Y (L)
; + 7 PC(H)
; + 8 PC(L)

when i debug this, i obtain :
- at RTI instruction : SP = 0x10F2 where i can find the highest
priority task stack so no problem, so
SP + 0 --> 0x80
SP + 1 --> 0xBB
SP + 2 --> 0xAA
SP + 3 --> 0x11
SP + 4 --> 0x11
SP + 5 --> 0x22
SP + 6 --> 0x22
SP + 7 --> 0xA0
SP + 8 --> 0x00

so after the RTI, PC will point on 0xA000 and here there is an error,
there's nothing at this address and highest priority task is at
0xC4A0, so if i change it by edit mode in the memory window of hiwave
it works, the RTI returns good

maybe its a problem with OS initialization but init code is exactly
the same C code as my old "Flash Application" which works fine and C
compiler should make the change between the two target.

Please, help a young french student to get his OS working :)
Need more details ?

Thank you,
Don`
(sorry for my english)



Don,

When you run your code in paged mode, the address window $8000 - $BFFF is
used to access various pages of code. When your code manipulates the value
of the PPAGE register (using the CALL and RTC instructions) it places
different code chunks, each 16K of size, into the $8000 - $BFFF page. You
should therefore assume that for all any jump to code in this range (like
the attempt to change task to address $A000 for example in your case), you
will need to specify both the PC and PPAGE. Thus, before the RTI I think
you need to also set the PPAGE to the correct value and then your
task-switching code may work. Alternatively, you need to make sure the
tasks you call after the RTI are in non-paged Flash.

Please also note that all the interrupt routines are also usually placed in
non-paged Flash at $C000 - $FEFF or at $4000 - $7FFF. The reason is that an
interrupt can occur while executing code from any code-page. When an
interrupt occurs the PC registers are stored to the stack, but PPAGE is
not. Also the RTI instruction doesn't restore PPAGE from the stack.

Hope this helps,
Doron
Nohau Corporation
HC12 In-Circuit Emulators
www.nohau.com/emul12pc.html

At 14:51 07/12/2003 +0000, you wrote:
>Hi,
>
>At the moment, i got a uCOS-II-based-application running in "Flash
>Application" target (Codewarrior). I want to run it in "Banked Flash"
>mode.
>As you can think, some problems occur with assembly routines. After a
>while reading datasheets i resolve some problems (e.g. JSR-RTS
>replaced by CALL-RTC instructions) but some stay.
>Routine example :
>
>OSStartHighRdy:
> call OSTaskSwHook, PAGE(OSTaskSwHook) ;Invoke user defined context
> switch hook
> inc OSRunning ;Indicate that we are multitasking
> ldx OSTCBHighRdy ;Point to TCB of highest priority task ready to run
> lds 0,x ;Load SP into 68HC12
> rti ;Run task
>
>when i use this, the value of PC register in the task stack is wrong
>
>;1) The stack frame is assumed to look as follows:
>;
>; OSTCBHighRdy->OSTCBStkPtr + 0 --> CCR
>; + 1 B
>; + 2 A
>; + 3 X (H)
>; + 4 X (L)
>; + 5 Y (H)
>; + 6 Y (L)
>; + 7 PC(H)
>; + 8 PC(L)
>
>when i debug this, i obtain :
>- at RTI instruction : SP = 0x10F2 where i can find the highest
>priority task stack so no problem, so
>SP + 0 --> 0x80
>SP + 1 --> 0xBB
>SP + 2 --> 0xAA
>SP + 3 --> 0x11
>SP + 4 --> 0x11
>SP + 5 --> 0x22
>SP + 6 --> 0x22
>SP + 7 --> 0xA0
>SP + 8 --> 0x00
>
>so after the RTI, PC will point on 0xA000 and here there is an error,
>there's nothing at this address and highest priority task is at
>0xC4A0, so if i change it by edit mode in the memory window of hiwave
>it works, the RTI returns good
>
>maybe its a problem with OS initialization but init code is exactly
>the same C code as my old "Flash Application" which works fine and C
>compiler should make the change between the two target.
>
>Please, help a young french student to get his OS working :)
>Need more details ?
>
>Thank you,
>Don`
>(sorry for my english)





The 2024 Embedded Online Conference