Passing structures between XC and C code by reference?

New to XMOS and XCore? Get started here.
IanH
Junior Member
Posts: 7
Joined: Wed Jun 02, 2010 1:47 pm

Passing structures between XC and C code by reference?

Postby IanH » Sun Jun 13, 2010 9:15 pm

Could anyone point me toward some code to study that passes structures between XC and C code by reference?.

I have been pushing common data too and fro, but am told that using common is considered bad form.
(If anyone is curious, you need to declare the shared C common variables with __attribute__((common)) to appease the GCC gods.

edit. Sorted

in the header file something like:

Code: Select all

[size=85]
[color=#BF0000]struct PulseParameters {unsigned int NoFillBlocks,FillBits;
unsigned int NoClearBlocks,ClearBits1,ClearBits2;};//define structure
#ifdef __XC__
int PrepareCounts(unsigned int FillFloatIn,unsigned int ClearFloatIn,struct PulseParameters &);//seen by XC
#else
int PrepareCounts(unsigned int FillFloatIn,unsigned int ClearFloatIn,struct PulseParameters *);//seen by c
#endif[/color]

in the XC code:

[color=#4000FF]struct PulseParameters Param;//create instanc eof structure
............
Dummy=PrepareCounts(FillT,ClearT,Param);//call c routine
...........[/color]
[color=#BF0000][/color]
In the c code:
[color=#FF00FF]
int PrepareCounts(unsigned int FillFloatIn,unsigned int ClearFloatIn,struct PulseParameters *Param)// pass structure as pointer
{
........
Param->FillBits=Param->FillBits | (1 << j);// do stuff with structure elements
........
}[/color]

[/size]

Who is online

Users browsing this forum: No registered users and 3 guests