Addressing the C167CR xram using the Keil and Tasking C166 compilers |
Many current C167 derivatives have what is called the "XRAM" at around 0xE000-0xE7FF in the memory space. Whilst there are special keywords to force data into the idata and bdata areas (system and bitword in Tasking C166), there are no specific ones to force data into the XRAM. This application note looks at how to do this on the two leading C166/ST10 compilers.
1. Keil C166The sdata keyword is used to create a variable that could go anywhere between 0xC000 and 0xFDFF. This variable goes into the SDATA0 class. Ideally all variables destined for the XRAM should be placed in the same file - here called "XRAM.C". If the NOINIT control is active, any variable after this is placed into the SDATA class. The #pragma RENAMECLASS control renames these default class names into something more appropriate like "XRAM0". The linker control file then places the new class at the 0xE000 address of the physical XRAM.
One peculiarity is that when the XRAM variables are accessed from another module, the extern declaration must include the original sdata keyword so that the compiler knows how to address them. The MAIN.C below illustrates this.
Keil Example
XRAM.C
#pragma RENAMECLASS(SDATA0=XRAM0) /* Put SDATA0 variables into a new class */ #pragma RENAMECLASS(SDATA=XRAM) /* Put SDATA variables into a new class */ // Create an sdata variable. This will go // into the SDATA0 class. unsigned short sdata xramvar1 ; #pragma NOINIT unsigned short sdata xram
XRAM.LIN
CLASSES (ICODE (0x0-0x3FFF), NCODE (0x0-0x3FFF),
FCONST (0x0-0x3FFF), HCONST (0x0-0x3FFF),
XCONST (0x0-0x3FFF), NCONST (0x0-0x3FFF),
NDATA (0x4000-0x7FFF), NDATA0 (0x4000-0x7FFF),
XRAM (0xE000-0xE7FF), XRAM0 (0xE000-0xE7FF), //
Put new class into XRAM
SDATA (0xE000-0xE7FF, 0xF600-0xFDFF), SDATA0 (0xE000-0xE7FF, 0xF600-0xFDFF),
IDATA (0xF600-0xFDFF), IDATA0 (0xF600-0xFDFF),
FDATA (0x4000-0x7FFF), FDATA0 (0x4000-0x7FFF),
HDATA (0x4000-0x7FFF), HDATA0 (0x4000-0x7FFF),
XDATA (0x4000-0x7FFF), XDATA0 (0x4000-0x7FFF))
CINITTAB (0x0-0x3FFF)
MAIN.C
//
// Example of how to put variables into the XRAM on a C167CR
//
extern unsigned short sdata xramvar1 ;
extern unsigned short sdata xramvar2 ;
// Test Loop
void main (void) {
while(1) {
xramvar1++ ;
xramvar2++ ;
}
}
2. Tasking C166
The system keyword is used to create a variable that could
go anywhere between 0xC000 and 0xFDFF. This variable goes into the "SB" class. Ideally all variables destined for
the XRAM should be placed in the same file - here called "XRAM.C".
. The #pragma class
control renames the default class name "SB" into something more appropriate like "XRAM".
The linker control file then places the new class at the 0xE000 address of the
physical XRAM. One peculiarity is that when the XRAM variables are accessed
from another module, the extern declaration must include the original system
keyword so that the compiler knows how to address them. The MAIN.C below illustrates
this.
XRAM.C
#pragma class SB=XRAM
// Create an system variable. This will
go
// into the SB class.
unsigned short system xramvar1 ;
unsigned short system xram_buffer[0x100] ;
XRAM.ILO
;========================================================================
; Class Location Control
;========================
CLASSES (CPROGRAM,
C_INIT,
CINITROM,
CPLIBRARY,
CLIBRARY,
SHAREDRTLIB (00200h-00DFFFh,010000h-03ffffh)) ; Far ROM classes
CLASSES (XRAM(0E000H-0E7FFH))
CLASSES (CUSTACK, ?CHEAP, CINITIRAM,CNEAR(040000h-047FFFh)) ; Near RAM classe
plus unused FAR and HUGE
MAIN.C
//
// Example of how to put variables into the XRAM on a C167CR
//
extern unsigned short system xramvar1 ;
// Test Loop
void main (void) {
while(1) {
xramvar1++ ;
}
}
Getting Help!
Example programs that demonstrate these techniques are included in our example programs disk that can be requested from Hitex.