resource exception for simple port forwarder

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Gravis
Experienced Member
Posts: 75
Joined: Thu Feb 02, 2012 3:32 pm

resource exception for simple port forwarder

Post by Gravis »

all i'm trying to do is forward rx/tx data on ports X/Y from core 0 to core 3. it seems like a simple task but i keep getting resource exception upon running the code.

in short it does this:
point1 rx -> point2 tx
point2 rx -> point1 tx


here's my simple code:

Code: Select all

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

on stdcore[3] : in  port point1_rx  = XS1_PORT_1D;
on stdcore[3] : out port point1_tx = XS1_PORT_1E;

on stdcore[0] : in  port point2_rx  = XS1_PORT_1D;
on stdcore[0] : out port point2_tx = XS1_PORT_1E;

void point1(chanend relay)
{
	char data;
	while (1)
	{
		select
		{
			case point1_rx :> data :
				relay <: data;
			break;

			case relay :> data :
				point1_tx <: data;
			break;
		}
	}
}

void point2(chanend relay)
{
	char data;
	while (1)
	{
		select
		{
			case point2_rx :> data :
				relay <: data;
			break;

			case relay :> data :
				point2_tx <: data;
			break;
		}
	}
}

void main(void)
{
	chan relay;
	par
	{
		on stdcore[0] : point2(relay);
		on stdcore[3] : point1(relay);
	}
}
any idea why?


yzoer
XCore Addict
Posts: 133
Joined: Tue Dec 15, 2009 10:23 pm

Post by yzoer »

Don't have any docs / data here but are the same ports available on both cores? Depending on the hardware you use some ports don't exist / have been reserved.

-Yvo
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Gravis I think you need relay_tx and relay_rx chanends for it to work the way you are expecting.

regards
Al
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

Both "relay" threads write to the channel before they read from it.
But XC channels are synchronous, they require the other side to
ACK before and after the data (this is automatically generated
code, not something you have control over): nothing can be buffered
that way.

So you should change the order of operations in one of the threads,
make it first read and then write. Or perhaps better for your application:
put the two independent actions (port->chan and chan->port) in each
thread inside a select. Or do that in only one thread, so that the threads
stay rate matched. What is best depends on what you *really* want :-)