Maxim Integrated 71M6534 Energy Meter IC Family Software User Manual
Page 38

71M653X Software User’s Guide
Keil’s linkers minimize the size of the page table. A subroutine has an entry in the page table only if:
1. The subroutine is in a bank, and
2. The subroutine is called from outside its bank.
Most problems with banking code occur because the linker omits a function from the page table. The result is that the
call to a function in a different bank goes to code in the current bank, causing unexpected code in the current bank to
be executed.
One major cause of this is a callback subroutine called via a function pointer. Another is an interrupt defined in banked
assembly language file (fortunately, Keil detects and flags banked interrupts in C code).
To solve problems stemming from callback routines, all subroutines called from other banks should be made global, so
that the linker can use their data.
Next, overlay commands should be used to inform the Keil linker that a banked function is called from a caller in a
different bank. This forces the linker to put the callee function into the page table. To use the overlay command in the
linker, see the discussion of “overlay” in the Keil linker’s documentation. Here’s an example of the overlay commands
from the demo code. They map the callback routines that are called from the software timer, and hardware timer
interrupt 0.
Figure 4-3, Setting Keil’s Linker for Bank-switched Code
However, if there should be other problems, there is a way to isolate them:
1. Remove code from the project until all code fits in common and bank 1.
2. Move modules individually each to a bank until the problem occurs.
3. At some point, the problem is likely to show up as an unexpected reset. What is happening is that the call to
code in bank 1 is probably going to uninitialized code memory in another bank. It will execute until the
program counter wraps around to zero and begins executing the reset vector.
4. Place a break point near the end of the other bank, to catch the erroneous execution.
5. After trapping the error, set the program counter to the address of a RET instruction, and single-step. The
code will return to the code that called the wrong bank.
6. Fix the calling routine, and all similar problems!
v1.1v1.1
TERIDIAN Proprietary
38 of 116
© Copyright 2005-2008 TERIDIAN Semiconductor Corporation