Hi,
the issue can be addressing mode, pointer and compiler approach.
You use a global address but logical address must be used.
I prepared prepared following example under CodeWarrior. Valid for s12XD..., S12XE...
I suggest to step the code and look into assembler instructions and CPU register what is set in reality.
//==============================================================================
// Banked Memory Model
// I suppose the return code from the function is RTC so the function
// The functio xx() with known address will be called by CALL
//==============================================================================
#include <hidef.h> /* common defines and macros */
#include <mc9s12xdp512.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"
//==============================================================================
// Local types definitions
//==============================================================================
#define UBYTE unsigned char
#define SBYTE char
#define UWORD unsigned int
#define UDWORD unsigned long int
//==============================================================================
// Function definitions
//==============================================================================
#pragma CODE_SEG __FAR_SEG MY_SEG // the segment is located in the PPAGE 0xF5
void far xx(void);
#pragma CODE_SEG DEFAULT
//==============================================================================
void (*far p_fcnt_XX)(void); // pointer to a function
//==============================================================================
#pragma CODE_SEG __FAR_SEG MY_SEG
void far xx(void) // the function is located at global address 0xF58000 (GPAGE_OFFSET)
{ // it is logical address 0x7D4000 (PPSGE_Offset)
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
}
#pragma CODE_SEG DEFAULT
//==============================================================================
//void main(void)
//==============================================================================
void main(void)
{
volatile UDWORD addr,addr0, addr1;
for(;;)
{
// 1)
((void(*far)()) 0xF58000)(); // logical address of the function xx()
// 2)
p_fcnt_XX = (void(*far)()) (0x8000F5);
p_fcnt_XX();
// 3)
addr = 0xF58000; // a logical address PPAGE_OFFSET
addr = ((addr>>16) & 0x000000FFUL) + ((addr <<8) & 0x00FFFF00UL);
p_fcnt_XX = (void(*far)()) (addr);
p_fcnt_XX();
// 4)
addr = 0x7D4000; // a global address GPAGE_OFFSET
// convert it to ppage_offset and pointer to function accepted by CW
addr0= addr/0x4000; /// convert it to ppage_offset
addr1= addr - (addr0 * 0x4000);
addr = (addr0 & 0x000000FF) | ((addr1 | 0x8000)<<8);
p_fcnt_XX = (void(*far)()) (addr);
p_fcnt_XX();
// or in one line
addr = 0x7D4000; // a global address GPAGE_OFFSET
// convert it to ppage_offset and pointer to function accepted by CW
addr = ((addr/0x4000) & 0x000000FF) | (((addr - ((addr/0x4000) * 0x4000)) | 0x8000)<<8);
p_fcnt_XX = (void(*far)()) (addr);
p_fcnt_XX();
//---------------
xx();
}
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Best regards,
Ladislav