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

Code Banking

Hello all,
We have here with us, a atmel at89c51ed2 board.

i was trying a small code banking application.
Settings are as follows.....
?B_NBANKS EQU 8
?B_MODE EQU 4

one of the switch case is as follows...

SWITCH0 MACRO ;Switch to Mem Bank0
CLR P1.1 ;Clear P1 Bit 5
CLR P1.2 ;Clear P3 Bit 3
CLR P1.3
ENDM

there are 7 more similar switch macros, with setting and clearing different bits.

I have 4 functions in Bank1, Bank2, Bank3 and Bank4. These function just print the current bank and blink some led's.

To get the current bank, i have modified the L51_BANK.a51. I got the solution for this from one of the discussion threads.

The modifications is as below
; get the current bank in which you are running


PUBLIC get_bank
get_bank:

MOV A, ?B_CURRENTBANK
ANL A, #?B_MASK

REPT ?B_FIRSTBIT
RR A
ENDM

MOV R7, A
;pachu
;MOV R7, ?B_CURRENTBANK
;end pachu
RET

;end of get_bank function


The problem is as follows, when in main, the current bank is 2,
bank1 it prints 6,
Bank2 it prints 2
bank3 it prints 6
bank4 it prints 2

so it prints only two values, 2 and 6....am i doing something wrong. is it possible to get the correct bank number i mean like 1 2 3 and 4 for 4 banks i am using...

regards
pachu

  • When you use mode 4, you take all responsibility for the code banking.

    The example code you have to get the bank number WILL NOT WORK for mode 4.

    My suggestion is that you use the following getbank function as a starting point.

              PUBLIC  getbank
    getbank:  MOV  R7, ?B_CURRENTBANK
              RET
    

    In mode 4, ?B_CURRENTBANK actually contains the LOW byte of the B_SWITCH routine address for that bank. To convert this to a bank number, you must subtract an offset (?B_CURRENTBANK for bank 0) and then divide by 18 (the distance between B_SWITCH routines).

    But, start with my getbank example and see what this gives you.

    Jon

  • Thank you so much Mr.Jon Ward
    I will give it a try right away...

    I had also posted a question on the RTX code banking.

    Does RTX support B_MODE 4 ???
    How does RTX know in which bank a particular task exists...

    I mean when the os_create_task is called, rtx must start the task, he must stop the current task, save the context of the current task, save the bank for the current and then switch to the next task, and switch the bank....

    To do this, rtx must know in which bank each task exists...how does rtx resolve this.

    thanks and regards
    pachu

  • Why does the task care. the compiler knows wich back each function is in. It will switch banks the same way with or with out RTX