This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can I switch code bank as I wish in runtime.

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.

Parents
  • 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.

Reply
  • 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.

Children
No data