Hi,
I hope I will not confuse you a lot because the topic is "a little bit" complex.
If I understand you well then I am not sure you correctly understand pointer (memory addressing) possibilities. C language is high level and it is good to step short test codes via asm instructions to see what the compiler uses and how the accesses are processed.
The RAM memory can by addressed by:
- Near pointer (no page is necessary, direct space, 16 bit address is used)
- Far pointer in global memory space (GLD,GST,…global asm instructions are used with 24bit global address from global address space )
- Far pointer in RPAGE paged memory space(local space) (The address from window 1000-1FFF is used together with RPAGE register setup )
Some of the spaces are addressable with all three options, see attached file for XEP100 or XDP512 device.
So, it is not possible to use pointer of different types as a parameter of the function. Each address space has its own principle of an access.
Of course, there is a possibility to combine near space with local space when we create 24bit pointer and use common addressing as to local space.
0x004000 is the same as 0x4000 and will be processed as a near address access (RPAGE has no meaning because internal mechanizm recognizes access to near space)
0xFC1000 will set RPAGE=0xFC because access to a RAM memory window is recognized.
(both lines access the same address as you can see in the attached memory map)
But,….the same address in a global address space is 0x0FC000 and global address access instructions are used by compiler.
Because of this, if you create some code with other programmers then you have to define joint point. Or, there is possibility to set agreement that all shared data will be placed in near memory space (2000~5FFF) or the same space but linearly ordered to 4000~7FFF if RAMHM=1 and ROMHM=1. (16kB should be enough if you also reorder data from access and importance point of view)
There is also another solution where you can pass the pointer as a number and then inside the function process it on the basis of used address or convert incoming address to suitable (one of them selected for addressing) for next data processing.
(In order to avoid redundant issues I suggest to use near space as described above.)
Moreover; If you use far data then do not forget to add to compiler command line command “-D__FAR_DATA” (Alt F7-> Compiler for HCS12) because of possible issues described in the file start12.c on the top.
A simple example code is also attached.
Best regards,
Ladislav