Rahul,
Code in your Daubt*.zip is wrong. Placing data in paged RAM, you have to tell CPU12X compiler how does it need to care about page switching. It is not enough to use
#pragma DATA_SEG PAGED_RAM
^^ this line only contains information for linker that you want it to place data under this pragma in PAGED_RAM. And compiler (CPU12X) is still unaware that it needs to switch RPAGE or use global addressing to access your data. To make CPU12X compiler aware, you need to insert __GPAGE_SEG or __RPAGE_SEG like this
#pragma DATA_SEG __GPAGE_SEG PAGED_RAM
far keyword is kind of replacing __?PAGE_SEG in pragma, but IMO it's much worse than __?PAGE_SEG.
Since __?PAGE_SEG tells CPU12X compiler how data should be accessed, you need to use the same pragma in header files when sharing data among CPU12X source files. XGATE uses its own addressing mode and XGATE compiler should ignore __?PAGE_SEG pragmas.
- 1.I am sharing some data (RAM) between s12x and xgate i know there should be data alignment between S12x and Xgate. I am not sure whether my project follows data alignment. How to know this?
Shared data segment in your PRM file should haver ALIGN 2 or ALIGN 2[1:1] like this:
RAM = READ_WRITE DATA_NEAR 0x2000 TO 0x3FFF ALIGN 2[1:1]; /* word align for XGATE accesses */
This should make linker placing object with sizeof(object)>=2 at even addresses.
Also sharing struct's between XGATE and CPU12X, you should use
#pragma align on
in CPU12X to ask compiler to word align struct members. The same like with #pragma DATA_SEG pragmas, #pragma align on for shared data should be visible in all CPU12X source files, which are making access to "#pragma align on"'ed structs.
- 2.Should the shared data be always located in non banked RAM memory or it can be in Banked memory?I have shared the data in banked memory. Any extra care need to be taken in case of sharing data in paged memory.
Yes, shared data can be banked. There should be no problems with this, unless you try to share pointers. Data pointers are not compatible between XGATE and CPU12X. Some tricks are possible, but you should not share any pointers between cores. Use indexes instead.
- 3.If the alignment is not proper between xgate and s12x, what will be the behaviour of the code. Is the data retrieved will always be wrong or sometimes we get the expected value and sometimes unexpected value.
Sometimes good, sometimes not. XGATE can't read word from odd address, it must be even. If you are not sure about alignment, make XGATE reading upper and lower bytes of word and then glue them into word. Just use ALIGN in PRM and #pragma align on.
- 4.Can I copy the data from one paged memory to another paged memory? Am I correct that data can be copied from any paged memory to the non paged memory.
No problems with correct -PSegXXX compiler switch.
Hope this helps
Edward