generate an exception if writing in a channel blocks

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
scrusson
Member
Posts: 9
Joined: Wed Mar 21, 2012 10:33 am

generate an exception if writing in a channel blocks

Post by scrusson »

Hi,

Here is a major problem i'm facing with xmos :
I'm trying to create a bidirectional communication between two xs1 cores with one streaming channel. If, for any reason, a thread t0 on core0 sends more than 4 words of 32 bits and a thread t1 on core1 doesn't read them, the thread t0 will block. In this case, is there a way not to block the thread t0 (thanks to an exception or a timout) ?

Thanks


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

Post by segher »

The proper way to avoid t0 blocking is of course to not send more
data than t1 can swallow up; so let's assume this is for recovering
from some bad situation, data loss is unavoidable.

When a thread is blocked on some I/O instruction, event or interrupt
requests will still be honoured. I don't think you can set things up
in XC for this, so you'll need some little asm or C code. Your idea
of using a timer is probably the easiest way to go.
User avatar
lilltroll
XCore Expert
Posts: 956
Joined: Fri Dec 11, 2009 3:53 am
Location: Sweden, Eskilstuna

Post by lilltroll »

The ideá is not not loose any data with samples.

If you need a longer buffer, there is code-package for that from XMOS.
You may also use a select() on the RX side. This way you can read in the channeldata when it exists, and choose if you want to discard it on the RX side instead, not stalling the TX side.
scrusson
Member
Posts: 9
Joined: Wed Mar 21, 2012 10:33 am

Post by scrusson »

Hi guys, thanks for your replies.

I may need to give you a bit more information of what i'm trying to do. I want to use 4 xs1 cores, each of them must communicate with the other ones. My idea is to create a specific exchange thread for each core which will be dedicated to the communications and will share a streaming channel with each other exchange thread. So, communications should be bidirectional and asynchronous. Imagine that an exchange thread writes some data in the channel and the one who should read them doesn't swallow them. The thread blocks and my whole system is down, which is something i can't afford. My question is : isn't there a way to know that a channel is full and then not write in it or, if a thread fills the entire channel, get out properly without blocking. In another way, implement "a sort of select" on the TX side.

Thank you per advance
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

Take a look at the thread communication examples on Github. There's a bidirectional buffered example that might suit your needs:

https://github.com/xcore/sw_thread_comm ... rc/main.xc

It works by posting a control token on the channel and waiting for a reply before sending the data. The consumer thread only replies when it is ready to send the data.
Post Reply