Tech Support > Computer Hardware > Microprocessors > Re: 68hc912b32 Interrupt Problems
Re: 68hc912b32 Interrupt Problems
Posted by Janvi on July 29th, 2003


On Sun, 27 Jul 2003 19:37:23 +0200, Ian wrote:

The reason is the location where your interrupt service routine is linked
to in the memory. This seems a problem from bank switching. Assume you
dont use banking with the B32 but the compiler cannot know if you have
connected megabytes of external flash to your target. Thats why you can
have conflicts with banking even if you do not use it.

If any function is located in a banked area, the CPU program flow can
branch to another function in the same bank with a pair of BSR/RTS or
JSR/RTS instructions. This saves the PC location to stack and the return
continues at this position after execution of the subroutine.

If a subroutine is located at another bank, at JSR to this is recognized
by the Cosmic Linker and creates a bank crossing error like you have. To
reach subroutines at diffrent banks, the Cosmic Compilers use the @far
modifier for such a function. This instructs the code generator to use a
pair of CALL/RTC instructions. The CALL instruction has 3 bytes of
arguments what are highbyte of next function address, lowbyte of next
function address and page number of next function address. The CALL pushs
return address to stack and after this the current bank number read from
PPAGE register is pushed to stack. Unlike the RTS instruction, the RTC
switches back to the old bank again. That also means, if a function is
@far, you have to invoke with CALL instruction. If you do with JSR or BSR
there will be a stack error and CPU returns to wrong bank. Of coarse, this
bank mechanism CALL will take more resources and compute time to execute
than beeing inside one bank only.

If you now have interrupt service functions with the @interrupt modifier
the code generator uses neither RTC nor RTS but a RTI instruction. This is
comparable to JSR/BSR but not to CALL instructions. With other words: The
HW interrupt does not take care on wich of the banks your program is in
that moment. Becouse the HW Interrupt cannot save the bank location and
the RTI instruction cannot restore the bank, all interrupt service
functions must be available in the common address area to be reachable
from any bank in the system.

Make shure your interrupt service function is in the common address range
0x4000 to 0x8000 what is equal to page 0x3e. Use page 0x3e even if this
page is not requiered for the B32. The address space is mirrored several
times and if you change to bigger chips like the DG128 or DP265 later you
can load the same S-Record without modifications. If you face further
problems, make shure that your interrupt service function does not access
constant data what is located at other bank locations.

hope this helps to check your LKF and arrange the +seg instructions and
sections for the linker.

its not a shame and it took me one or two weeks to understand what happens
with the HC12

Posted by Ian on July 30th, 2003


Many thanks for your detailed response.
I got round it in the end by using the -bs0 option with the linker which
disables bank switching but you have explained the reasoning behind it.
Many thanks again. Much appreciated






Similar Posts