Hi,
Here are the function which you can use to convert addresses to global and back to logical:
//==============================================================================
// Convert data address format from 0xPPAGE~offset to the global address format 0xGPAGE~offset
// Conversion flow:
// Addr - function: 0000 0000 pppp pppp ffff ffff ffff ffff
// 1111 1198 7654 3210 7654 3210
// || 5432 10
// \/
// Global addr : 1 PPAGE Register [7:0] Address [13:0]
//
// : 0000 0000 01pp pppp ppff ffff ffff ffff
// 76 5432 1011 1198 7654 3210
// 32 10
//==============================================================================
unsigned long int ConvertPPageOff2Global(unsigned ling int Addr)
{
Addr = ((Addr>>2) & 0x003FC000UL) | (Addr & 0x00003FFFUL) | 0x00400000;
return(Addr);
}
//==============================================================================
// Convert data address format from global address format 0xGPAGE~offset to the
// format 0xPPAGE~offset
// It is made because compiler uses global addressing (GLY, GLAB) for far data access.
// Conversion flow:
// Global addr : 1 PPAGE Register [7:0] Address [13:0]
//
// || : 0000 0000 01pp pppp ppff ffff ffff ffff
// \/ 76 5432 1011 1198 7654 3210
// 32 10
// Addr - function: 0000 0000 pppp pppp ffff ffff ffff ffff
// 1111 1198 7654 3210 7654 3210
// 5432 10
//==============================================================================
unsigned long int ConvertGlobal2PPageOff(unsigned long int Addr)
{
Addr = ((Addr<<2) & 0x00FF0000UL) | (Addr & 0x00003FFFUL);
return(Addr);
}
//==============================================================================
Moreover, you might want to read an appnote about S12X memory scheme - AN3784:
http://cache.freescale.com/files/soft_dev_tools/doc/app_note/AN3784.pdf
Also, in the CodeWarrior installation folder on your PC, find Help PDFs. There are some Technical Notes (TNxxx) you might like to read.