Share data between XGATE and S12X

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Share data between XGATE and S12X

ソリューションへジャンプ
3,759件の閲覧回数
admin
Specialist II

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?

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,424件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee

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

元の投稿で解決策を見る

0 件の賞賛
返信
5 返答(返信)
1,425件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee

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
0 件の賞賛
返信
1,424件の閲覧回数
admin
Specialist II
There was still a problem how to be with functors? I in S12 fill a array of pointer on function, at occurrence of interruption processed XGATE should be caused from a array functions functors, depending on conditions at present. How it is impossible to solve this problem, prompt there can be who that faced the such?
0 件の賞賛
返信
1,424件の閲覧回数
J2MEJediMaster
Specialist I
Please check this forum thread on how to call XGATE functions.
0 件の賞賛
返信
1,424件の閲覧回数
admin
Specialist II

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.

0 件の賞賛
返信
1,424件の閲覧回数
J2MEJediMaster
Specialist I

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

 

TN243.PDF

Message Edited by t.dowe on 2009-09-22 12:35 PM