We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a problem in using code bank. Suppose I use 4 code banks, bank 0 as common area, and have a function A in code bank 2 at first. But at runtime, I wish get new version function A, but it couldn't be writen to code bank 2, so I put funtion A into code bank 3, and set a bit to tell which bank should be use when A is called. Can it be done by software?
It's the example code of BANK_EX1. I guess I should modify the code. How to do it.
?B_SWITCH&N: MOV R0,A MOV A,#BANK&N MOV DPTR,#?B_XDATAPORT MOV ?B_CURRENTBANK,A MOVX @DPTR,A MOV A,R0 RET ENDM
Thanks.
The ?B_SWITCH&N macro is a routine you fill in to set your hardware appropriately for the given bank number. You may have an SFR, a latch in external data space, or who knows what hardware to provide the upper bits of the address. The example code you posted is written for hardware that happens to have a one-byte register at address B_XDATAPORT in xdata space. So, it writes the constant value BANK&N to that register.
The Keil tools, when configured for code banking, automatically generate code to do the bank switching, calling these functions as need be. With linker directives (or uVision) you assign C modules to particular banks. The compiler and linker take care of the details.
The actual calls from one non-common bank to another are performed by jumping to a stub (a "thunk") in the common area. This stub switches banks, and then calls back up into the function proper. You can't jump directly from one code bank to another because they don't exist in the address space at the same time.