I use for working out of program CodeWarrior 4.7 for HC12X.
The code such:
main:
#pragma DATA_SEG SHARED_DATA
volatile int shared_counter; /* volatile because both cores are accessing it. */
volatile unsigned char* p;
#pragma DATA_SEG DEFAULT
xgate:
#pragma DATA_SEG SHARED_DATA
volatile extern int shared_counter; /* volatile because both cores are accessing it. */
volatile extern unsigned char* p;
#pragma DATA_SEG DEFAULT
With variables all works remarkably but if it is necessary to use the pointer problems begin. In XGATE and in HC12 under the same pointer there is various data. I believe that the pointer specifies in various cells of memory in XGATE and in HC12.
Prompt as to be?
解決済! 解決策の投稿を見る。
I thought there are is a TN for this topic too, but I don't have the S12 tools installed here.
The sharing of non pointers is simple, one point to consider is that the XGATE needs alignment struct members (for ints,longs). So either allocate the structs so that all members are naturally aligned or there is also a pragma which enables the alignment for the S12X too.
For pointers the situation is more complex as the encoding of S12X and XGATE pointers is different.
There are some ways around that if you restrict the referenced objects. More specifically either allocate all of the referenced objects so they have a fixed offset in the S12X and the XGATE memory map.
e.g. Unbanked RAM in S12X at 0x2000'L which maps to 0xE000'X for the XGATE, so an offset of 0xC000.
A second way is to use __far pointers for the S12X and to use just the lower 16 bits of that pointer for the XGATE. If all the pointers point to only RAM (or to only flash accessible by both cores), then
this setup does not need any offset.
E.g. (just speudo code, did not try it our right now)
struct PointerShare {
#ifdef __HC12__
unsigned char align; // needed for XGATE alignment
unsigned char* __far ptr;
#else
// XGATE
unsigned char align;
unsigned char s12Bank; // fixed 0xF for RAM
unsigned char* ptr;
#endif
};
With this struct both the cores can use straight C code using the ptr member.
The only thing special is that if the XGATE sets the pointer first, then it has to set the s12Bank to 0xF too.
The S12 will automatically set it to 0xF (and if it ever is non 0xF, then it does not point into shared RAM).
Daniel
I thought there are is a TN for this topic too, but I don't have the S12 tools installed here.
The sharing of non pointers is simple, one point to consider is that the XGATE needs alignment struct members (for ints,longs). So either allocate the structs so that all members are naturally aligned or there is also a pragma which enables the alignment for the S12X too.
For pointers the situation is more complex as the encoding of S12X and XGATE pointers is different.
There are some ways around that if you restrict the referenced objects. More specifically either allocate all of the referenced objects so they have a fixed offset in the S12X and the XGATE memory map.
e.g. Unbanked RAM in S12X at 0x2000'L which maps to 0xE000'X for the XGATE, so an offset of 0xC000.
A second way is to use __far pointers for the S12X and to use just the lower 16 bits of that pointer for the XGATE. If all the pointers point to only RAM (or to only flash accessible by both cores), then
this setup does not need any offset.
E.g. (just speudo code, did not try it our right now)
struct PointerShare {
#ifdef __HC12__
unsigned char align; // needed for XGATE alignment
unsigned char* __far ptr;
#else
// XGATE
unsigned char align;
unsigned char s12Bank; // fixed 0xF for RAM
unsigned char* ptr;
#endif
};
With this struct both the cores can use straight C code using the ptr member.
The only thing special is that if the XGATE sets the pointer first, then it has to set the s12Bank to 0xF too.
The S12 will automatically set it to 0xF (and if it ever is non 0xF, then it does not point into shared RAM).
Daniel
Greetings, thanks for yours councils Daniel and Tom. Daniel, into the account of the first way I knew and to use this shift on 0xC000, but it worked not always and the code turned out too huge. The second way offered by you remarkably works and thus looks more correct and clear. I will try to use it in the program. Respectfully Konstantin.
I haven't programmed an XGATE, so bear with my shot-gun approach to an answer.
Application Note 3469, page 13, discusses how data is arranged for a context switch between the HCS12X and XGATE spaces. You may want to study that. It may not offer a solution, but might provide additional background to understand what's going one.
Tech Note 243 discusses sharing data between the cores. Although it's about an HC08 device, it should be applicable to the HCS12(X). I've attached it here.
---Tom