Passing resources from XC to C to XC

New to XMOS and XCore? Get started here.
Post Reply
dimitris
Active Member
Posts: 37
Joined: Tue Feb 19, 2013 5:07 pm

Passing resources from XC to C to XC

Post by dimitris »

Hi there,
I have a main.xc routine that needs to start a c application. The c application needs to put things on an xc channel.

Code: Select all

int main(){
	chan ch1,ch2;
	par{
		on tile[1]: xc1(ch1);
		on tile[1]: xc2(ch2);
		on tile[1]: c(ch1,ch2);
	}
}
I have read about xccompat.h support but the info is rather vague. Is there a solid example somewhere?

Thanx in advance.


User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

The following should build:

main.xc:

Code: Select all

#include <xs1.h>
#include <platform.h>

unsigned channel_input(chanend c)
{
    unsigned x;
    c :> x;
    return x;
}

void xc1(chanend c)
{
   c <: (unsigned) 1;
}

void xc2(chanend c)
{
   c <: (unsigned) 2;
}

void c(chanend c1, chanend c2);

int main(){
   chan ch1,ch2;
   par{
      on tile[1]: xc1(ch1);
      on tile[1]: xc2(ch2);
      on tile[1]: c(ch1,ch2);
   }
}
cee.c:

Code: Select all

#include <xccompat.h>
#include <print.h>
#include <xs1.h>

unsigned channel_input(chanend c);

void c(chanend c1, chanend c2)
{
    unsigned x;
 
    x = channel_input(c1);
    printintln(x);
    x = channel_input(c2);
    printintln(x);
}

build with: xcc main.xc cee.c -target=SLICEKIT-L16

run in the simulator with:

xsim a.xe

Gives the output:

Code: Select all

$ xsim a.xe 
1
2
dimitris
Active Member
Posts: 37
Joined: Tue Feb 19, 2013 5:07 pm

Post by dimitris »

Quick and solid! Thanx!
User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

dimitris wrote:Quick and solid! Thanx!
:)

I got slightly distracted before I got to completely the example - I've now updated the example above to include how to use the channels (via calls to XC helper functions from C)
Post Reply