Basic channel communication problem

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
dragonself
New User
Posts: 3
Joined: Tue Feb 09, 2010 10:05 am

Basic channel communication problem

Postby dragonself » Tue Feb 09, 2010 10:17 am

For a channel read in as below:
dataIn :> data ;

Can it be a non-block mode, which mean if there is no input to the channel, it can escape and run next line?
Or is there any function to detect the event for channel data input?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Postby richard » Tue Feb 09, 2010 10:51 am

You can use a select with a default case:

Code: Select all

select {
case dataIn :> data:
  // handle data
  break;
default:
  break;
}
If there is no data in the channel the default case will be taken.
dragonself
New User
Posts: 3
Joined: Tue Feb 09, 2010 10:05 am

Postby dragonself » Wed Feb 10, 2010 12:49 pm

Thanks for yr reply, I have one more question which should be simple. I write some code as below:
int TX(chanend c)
{
int i,j;
slave
{
for (i=0; i <10; i ++)
{
c <: i;
printf("finsih send out %d\n",i);
}
printf("finish all sending\n");
}
return 0;
}

int RX(chanend c)
{
int i,j;
master
{
while(1)
{
c:> i;
printf("finsih recieve %d\n",i);
for(j=0;j<2000;j++)
{
//delay
}

}
}
return 0;
}


int main() {
chan c;
par {
on stdcore [0] : TX (c) ; // Thread X
on stdcore [1] : RX (c) ; // Thread Y
}
return 0;
}
To test the transaction feature. But i got an error after the RX read the finish channel data like this:
finsih recieve 5
finsih recieve 6
finsih recieve 7
finsih recieve 8
finsih recieve 9
Unhandled exception: ILLEGAL_RESOURCE, data: 0x00010102
1) Is it I am using a wrong way to doing that or I need some more function to handle the exception.

2) I intentionally use master as Tx and slave as RX and seem it work, how should I define the master/slave in a transition?

3)One more conceptual question, from the XC mannual, both transation and streaming is for asyn, and streaming
In contrast to transactions,
multiple streams can be processed concurrently
, what does that mean? When will I use streaming over transition?

Thx very much for the help ^.^
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Postby richard » Wed Feb 10, 2010 2:21 pm

Transactions provide packetised communication. Under the hood end of message tokens are implicitly sent and received at the end of a transaction.

The communications on both sides of the channel must match up. In the slave transaction on the TX side you send 10 integers. In the master transaction on the RX side you try to continuously input integers. When trying to input the 11th integer it will receive the end of message token from the slave transaction instead. The unexpected end of message token will cause an exception.

If you swap the transactions so that TX uses a master transaction and RX uses a slave transaction then after sending the the last integer the slave transaction will pause expecting an end of message from the master transaction. This end of message will never be received because the master transaction still expects to receive more data.

In both cases the program is invalid. It happens to be that with the current ABI one way causes an exception and one causes deadlock. To fix the problem you should change your program so the number of outputs on one side of the transaction match the number of inputs on the other side.
3)One more conceptual question, from the XC mannual, both transation and streaming is for asyn, and streaming
In contrast to transactions,
multiple streams can be processed concurrently
, what does that mean? When will I use streaming over transition?
The XC language disallows nesting of transactions. i.e. On a single thread it is not possible to start a new transaction while in the middle of an existing transaction.

Streaming channels behave like infinite length transactions. The main disadvantage of streaming channels over transactions is that they reserve a dedicated path on the network between the two channel ends. This puts a limit on the number of streaming channels you can declare between cores. The more streaming channels between cores you declare then the less bandwidth there is for all other inter core channel communication.
dragonself
New User
Posts: 3
Joined: Tue Feb 09, 2010 10:05 am

Postby dragonself » Thu Feb 11, 2010 2:17 am

If you swap the transactions so that TX uses a master transaction and RX uses a slave transaction then after sending the the last integer the slave transaction will pause expecting an end of message from the master transaction. This end of message will never be received because the master transaction still expects to receive more data.
So there is no different to interchange the master and slave in my code?

Is it usually a TX will be a master and a RX will be a slave?

Then in what situation there will be different when master and slave is swapped?

Thanks!
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Postby richard » Thu Feb 11, 2010 9:27 am

You can select on the start of a slave transaction, you can't select on the start of a master transaction. If you don't use either end in a select there is no semantic difference if you swap the type of the two transactions.

With the current implementation of selects it is slightly more efficient if you make the transaction which starts with an output the slave, although the difference is minimal either way.

Who is online

Users browsing this forum: No registered users and 2 guests