Sharing data between XGATE and main core

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Sharing data between XGATE and main core

跳至解决方案
1,988 次查看
sfb
Contributor I
Hello,
I want to use shared datas in both cores (XGate and main core). But there is a problem for data structures.
 
For an int variable I insert following lines into main.c file
Code:
#pragma DATA_SEG SHARED_DATAvolatile int shared_counter; /* volatile because both cores are accessing it. */#pragma DATA_SEG DEFAULT

 
 And for this variable inserted the followings into xgate.h file
Code:
#pragma DATA_SEG SHARED_DATA /* allocate the following variables in the segment SHARED_DATA */volatile extern int shared_counter; /* volatile because both cores are accessing it. */#pragma pop

 

after above insertings there is no problem for using sharing_counter in xgate core or main core. But when I want to use a data structure like below failed the compile operation:

 

For example, Inserted the followings into main.c

Code:
#pragma DATA_SEG SHARED_DATAvolatile int shared_counter; /* volatile because both cores are accessing it. */typedef struct {  unsigned char Member1;  unsigned char Member2;} MyStr;volatile MyStr Str1;#pragma DATA_SEG DEFAULT

 

And inserted into xgate.h:

Code:
#pragma DATA_SEG SHARED_DATA /* allocate the following variables in the segment SHARED_DATA */volatile extern int shared_counter; /* volatile because both cores are accessing it. */volatile extern MyStr Str1;#pragma pop

 

When I compiled there is "Error : C2450 Expected:   ;=,"  error message. I think that I make a mistake for about syntax but don't know what. May anybody explain me how to use same data structure in both cores.
 

 

 

 


 
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
548 次查看
CompilerGuru
NXP Employee
NXP Employee
Hi Sfb,

You have to move the definition (the typedef) of the struct into the header file,
so that it can be included and used by both cores. Basically this is not different to share a global structure in between 2 C files for any C compiler.

Sharing data in between the XGATE and the S12X works fine with the following 2 things to lookout for.
First, pointers are different for the S12X and the XGATE, arrays are fine though. So sharing pointers in between the cores is more advanced. Note that pointers may also be different in size, so be careful with pointers in general, even if not used by both cores.
Second, the XGATE core needs to align all 16 bit (and larger) objects, the S12X does not. The best and most straight forward approach is to always even align all 16 bit fields in all structs, so the compilers do not need to align anything.
(If this is not done, then the S12X compiler needs to be told (I think with a pragma) to insert the same alignment bytes as the XGATE needs.

Daniel

在原帖中查看解决方案

0 项奖励
回复
1 回复
549 次查看
CompilerGuru
NXP Employee
NXP Employee
Hi Sfb,

You have to move the definition (the typedef) of the struct into the header file,
so that it can be included and used by both cores. Basically this is not different to share a global structure in between 2 C files for any C compiler.

Sharing data in between the XGATE and the S12X works fine with the following 2 things to lookout for.
First, pointers are different for the S12X and the XGATE, arrays are fine though. So sharing pointers in between the cores is more advanced. Note that pointers may also be different in size, so be careful with pointers in general, even if not used by both cores.
Second, the XGATE core needs to align all 16 bit (and larger) objects, the S12X does not. The best and most straight forward approach is to always even align all 16 bit fields in all structs, so the compilers do not need to align anything.
(If this is not done, then the S12X compiler needs to be told (I think with a pragma) to insert the same alignment bytes as the XGATE needs.

Daniel

0 项奖励
回复