Sharing data between XGATE and main core

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sharing data between XGATE and main core

Jump to solution
1,985 Views
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.
 

 

 

 


 
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
545 Views
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

View solution in original post

0 Kudos
Reply
1 Reply
546 Views
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 Kudos
Reply