This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Bank switching for CC2531?

Other Parts Discussed in Thread: CC2531, TIMAC

I'm using the CC2531 with 256kb and the TIMAC (Version 1.5.0, May 09, 2013) with the default "banked code model" and linker file "ti_51ew_cc2531b.xcl". In the latter, I defined a code segment where I want to place a struct variable which is used for default settings:


-Z(CODE)MY_VAR_LOCATION=0x7E000-0x7E7FF

and

#pragma location="MY_VAR_LOCATION"
const MyVar_t MyVar_std = {
...
/*default settings*/
...
}

Then, I have another variable of the same type in the RAM which holds the active settings called
MyVar_t MyVar;

Now, when I want to copy the default settings (MyVar_std) to the active settings (MyVar), I figured that I have to actively change the bank that is mapped to XBANK with the following code:

#define MYVAR_SEGMENT_BANK     7

//switch MEMCTR.XBANK (Bits 2:0)  to bank 7 
uint8 memctrBackup = MEMCTR;
MEMCTR = MYVAR_SEGMENT_BANK;

//now load the standard MyVar_std from code segment (XDATA) to active MyVar in RAM
osal_memcpy(&MyVar, &MyVar_std, sizeof(MyVar));

//restore previous bank setting
MEMCTR = memctrBackup;


My question: Is there any way that the IAR compiler can do this by itself? E.g. when I have another CONST variable, I have to change banks back to that location?

If I want to get the address of the variable with &MyVar_std, I do only get the address within the XBANK, i.e. 0x8000-0xFFFF, right? Thus, I have to know the bank and thus the absolute address to switch the banks by myself?

Best regards,
Timo