Store constant data in the banks of a banked application
Technical Note 27661
IAR C/C++ Compiler for 8051 only supports banking of code generated from C source, i.e. segment CODE and bank switching will only be done when calling C functions, not at data accesses. However, if you're confident in the tools and feel you can manage it, you can see to that no bank switching is necessary when accessing data. That is done by putting the code and the constant data it accesses in the same bank.
Follow these steps:
- Declare the constants in the same C source module that has functions that makes accesses to it.
- Use #pragma memory=constseg(CONST1) to place your const vars in a user named segment CONST1. Note. Constant strings cannot be placed with #pragma. Instead, use XLIB after compiling to rename CSTR segment in current module to CSTR1.
- Compile the source with option -RCODE1 to give the code segment name CODE1.
- Repeat step 2-3 for each module where you need const data accesses but increase CONST1, CODE1 to CONST2, CODE2 and so on.
- Link your application as normal but change the banking option so that every CONSTn will be in the same bank as its correspondent CODEn. You can do that by using -b(CODE)CONST1,CODE1:CONST2,CODE2: ... : CODE = ......
The : is used to switch bank, see the IAR Linker and Library Tools Reference Guide. Of course, several pairs of CONSTn, CODEn may fit in the same bank but you have to check the map file to see that there's space enough in the bank and that you efficiently make use of the banks.
This Technical Note was written in 2005, at the time when IAR Embedded Workbench for 8051 version 7.20 was released. Some of the implementation details above may have changed since then.
All product names are trademarks or registered trademarks of their respective owners.