⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chipcon_banked_code_support.s51

📁 CC2430多功能调试程序
💻 S51
字号:
/******************************************************************************
*                                                                             *
*        **********                                                           *
*       ************                                                          *
*      ***        ***                                                         *
*     ***    ++    ***                                                        *
*     ***   +  +   ***                      CHIPCON                           *
*     ***   +                                                                 *
*     ***   +  +   ***                                                        *
*     ***    ++    ***                                                        *
*      ***        ***                                                         *
*       ************                                                          *
*        **********                                                           *
*                                                                             *
*******************************************************************************

Filename:     chipcon_banked_code_support.s51
Target:       cc2430
Author:       KJA
Revised:      16/12-2005
Revision:     1.0

Description:
Functions to make banked CALL and RET.

The routines will store the bank number on the stack (which is read 
back by the tools for return address) and then load MEMCTL with the new bank 
or-ed with MEMCTL bits. The "same" thing is done on return. 

Add $TOOLKIT_DIR$\SRC\LIB\ to the assembler include path.

Under General Options set Code model to Banked and under tab "Code Bank" 
set "Register address" to 0xC7 (only valid if code model == banked) 


The register holding current code bank:
?CBANK

Should be defined to IAR XLINK Linker with:
-D?CBANK=xx

Copyright 2004-2005 IAR Systems. All rights reserved.

******************************************************************************/



        MODULE  ?BANKED_CODE_SUPPORT

#include "iar_common.h"

        EXTERN  ?CBANK
        EXTERN  ?RESET_CODE_BANK
        REQUIRE ?RESET_CODE_BANK
        RSEG    CSTART



;-----------------------------------------------------------------------------
;
;       Function: ?BCALL
;
;       Description: Saves the caller bank on stack, Switches to bank defined
;                    by A register and jumps to the banked function A:DPTR.
;
;       Register input:
;               DPTR:  16-bit function address
;               A:     8-bit page address
;
;       Stack:
;
;           +--------+
;           | ?CBANK | <-- SP end
;           + - - - -+
;           |  retH  | <-- SP begin
;           + - - - -+
;           |  retL  |
;           + - - - -+
;   CFA --> | xxxxxx |
;           +--------+
;
;               16-bit return address
;
;       Register output:
;               DPTR:  16-bit function-address
;               A  = 0
;
;       Stack usage: 1
;-----------------------------------------------------------------------------
   PUBLIC  ?BCALL

   cfi BLOCK ?BCALL USING cfi_common
   cfi NOFUNCTION
   cfi A undefined
   cfi CFA_MACHINE MACHINE_SP - 2

?BCALL:
   SWAP  A
   MOV   B, A
   MOV   A, ?CBANK   ; read current MEMCTR
   ANL   A, #0x30    ; mask bank bits
   SWAP  A
   PUSH  A           ; store return bank (bank number only)

   cfi CFA_MACHINE MACHINE_SP - 3

   MOV   A, ?CBANK   ; read current MEMCTR
   ANL   A, #0xCF    ; mask bank bits
   ORL   A, B        ; add new bank number to MEMCTR
   MOV   ?CBANK, A

   CLR   A
   JMP   @A+DPTR


;-----------------------------------------------------------------------------
;
;       Function: ?BRET
;
;       Description: Return from banked function.
;                    Leaves current function, Switched bank and returns to
;                    function that called ?BCALL.
;
;                    NOTE: This function will be jumped to.
;
;       Register input:
;               None
;
;       Stack input:
;
;               +------------+ <-- SP
;               |  RET bank  |
;               + - - - - - -+
;               |  RET High  |
;               + - - - - - -+
;               |  RET Low   |
;               +------------+
;
;               24-bit return address
;
;       Register output:
;               DPTR:  16-bit function-address
;               A  = 0
;
;       Stack usage: 3
;               Stack: 16-bit return address
;-----------------------------------------------------------------------------
   PUBLIC  ?BRET

?BRET:
   cfi CFA_MACHINE MACHINE_SP - 3

   MOV   B, ?CBANK   ; get current bank
   ANL   B, #0xCF    ; mask bank bits

   POP   A           ; pop bank number
   SWAP  A
   ORL   A, B        ; add the MEMCTR bits
   MOV   ?CBANK, A   ; set new bank
   cfi   CFA_MACHINE MACHINE_SP - 2

   RET

   cfi ENDBLOCK ?BCALL

   END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -