Multiple Inputs for Channels

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
Posts: 10
Joined: Sat May 29, 2010 6:06 am

Multiple Inputs for Channels

Postby mashc5 » Mon Jul 12, 2010 11:50 pm

My XC-1A is arriving tomorrow and I'm currently reading Programming XC for XMOS Devices. The literature seems to indicate that you can only establish channels between 2 threads. Using a UART as an example, what if I'd like to make a general interface from any thread to the UART Tx thread, a sort of global putchar() that can be called from any thread on any core. Is this possible?
User avatar
Active Member
Posts: 38
Joined: Wed Jun 09, 2010 3:20 am
Location: Maine, USA

Postby monk_is_batman » Tue Jul 13, 2010 3:01 am

It is my understanding from everything I have read (and people can correct me if I am wrong, never tried it), that you can definitely do what you were saying. I think what you would do is have a chanend in each thread that uses the putchar() and set the destination of every chanend (using setd) to the uart thread's chanend (I don't know of anyway to do this without at least a couple lines of inline assembly).

If you are on one core you can skip the setting destinations by duplicating one of the channel ends in c and making sure only one thread uses it at a time using a hardware lock (this I have done successfully). A quick work around to copy a resource that XC protects is to call a C function copy the resource into an array of that resource several times and then to call an XC function passing that array of resources, however if you are not careful you will get exceptions doing this.

I would not recommend either of these if you have not done any XC programming before. You could create a thread using a select statement to read form several other channels and take any characters it gets and send them to the UART TX thread, this is the simplest solution however it takes an extra thread and several channels.
Posts: 10
Joined: Sat May 29, 2010 6:06 am

Postby mashc5 » Tue Jul 13, 2010 4:52 am

That's disappointing :( I feel like this would be useful for utilizing hardware resources that might be used by several threads, such as uart, spi, etc. I'll probably have to do something similar to what you ended your post with. f

Another Question: Could I create an array of channels and then pass them as an array of chanends?

Something like this:

Code: Select all

channel myChan[2];

void myFunc(chanend c[])

void otherFunc0(chanend c0);

void otherFunc1(chanend c1);

int main(void)

User avatar
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Postby Berni » Tue Jul 13, 2010 8:22 am

Thats actually how its done. You define a channel array and pass the array to the uart thread. Then give any other thread each one of the channels inside the array. The uart thread then keeps checking all of the channels in the array for new data. Annoying part is that you still need to pass he chanend to the functions that use uart. Someone should really try writing a asm library for channel sharing to make these things cleaner.
User avatar
Experienced Member
Posts: 99
Joined: Mon Dec 14, 2009 1:01 pm

Postby Jamie » Tue Jul 13, 2010 10:22 am

Yeah, channels are a lot more flexible in the ISA than they appear in XC -- such as being able to set up many-to-one channels or reconfiguring connecitons at run time can be very useful.
User avatar
Posts: 30
Joined: Sat Dec 12, 2009 7:14 pm
Location: Silicon Valley

Postby Jerry » Tue Jul 13, 2010 7:24 pm

I've seen this question asked multiple times here and on Xlinkers.

This would be a good topic for XMOS to write a detailed application note, complete with code examples. Hint. Hint...

Who is online

Users browsing this forum: No registered users and 2 guests