Waiting on channel

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

Waiting on channel

Post by dimitris »

I am trying to implement a two port ethernet module on an XMOS slicekit.
As so, I have two functions reading incoming packets on different cores and a demo application that checks both ports and acts accordingly.

My novice question is how can I use a select statement with these two channels carrying buffers to implement a "whichever comes first" situation.
My initial thought was to have something like the code below, however it turns out that xmos doesn't allow channels to be inputed to void. (error: input from channel with unspecified size)

Code: Select all

select{
      case rxCircle :> void:
			mac_rx(rxCircle, (rxbufCircle,char[]), nbytes, src_port);
			break;
		case rxTriangle :> void:
			mac_rx(rxTriangle, (rxbufTriangle,char[]), nbytes, src_port);
			break;
}
Regards,
Dimitris


User avatar
TSC
Experienced Member
Posts: 111
Joined: Sun Mar 06, 2011 11:39 pm

Post by TSC »

Are you sure you want to discard the first incoming token? With most channel communication routines, the first token contains useful data, such as the number of tokens that will follow, or some status data from the sender.

If you really want to discard it, just do:

Code: Select all

int tmp;  // or char, depending on type of tokens being sent.
select{
      case rxCircle :> tmp:
      //etc.
}
Edit: I think this would also do what you want, assuming an int token is sent:

Code: Select all

case rxCircle :> int _
dimitris
Active Member
Posts: 37
Joined: Tue Feb 19, 2013 5:07 pm

Post by dimitris »

Hi TSC,

I really do not want to discard it as it. I only need to be notified that a packet has arrived at one of the ports and handle it.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

That sounds like a job for

Code: Select all

#pragma select handler
dimitris
Active Member
Posts: 37
Joined: Tue Feb 19, 2013 5:07 pm

Post by dimitris »

That was a great piece of advice Segher!
Thank you!
Post Reply