New Programming Guide

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

I am just starting to program xmos. The programming guide is good as a general overview but I would like to see a complete syntax reference.

For example, I am starting with the low level ethernet demo.

In the programming guide the chan statement is used as such:

chan c ;

In the demo code it is used like this:

chan rx[1], tx[1];

What does the parameter inside the brackets refer to?


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

Post by Folknology »

Please ignore this response it's a mistake, kept here purely to keep the thread flow

Code: Select all

chan c ;  // A single channel
chan rx[1], tx[1]; // two arrays of 2 channels each
This declares 5 channels c,rx[0],rx[1],tx[0],tx[1]
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

chan rx[1] declares an array of 1 channel, in the same way int a[1] declares an array of 1 int in C.
This declares 5 channels c,rx[0],rx[1],tx[0],tx[1]
I think you mean this declares 3 channels, c,rx[0],tx[0]. The number in brackets is the number of elements, not the index of the last element. If you try to access rx[1] it will error as the array only has one element.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Oops my bad, I presume it's so you can pass the channel into the task rather than have it's ends auto allocated?
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

Exactly my point, I cannot find information about this in the documentation.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

Or allow for more than one Ethernet I guess

BTW which Ethernet demo are you referring to?
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

It is the one referred to in the attached document.
You do not have the required permissions to view the files attached to this post.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

OK looking at the code it is supporting multiple receiver and transmitter clients, hence the use of chan arrays rather than single channels. The full implementation is capable of using multiple TX/RX clients but the Light version uses single Rx,Tx not quite sure why it's organised this way, perhaps a common setup interface was desired.

You can take a look at the code underneath on github to see the differences between them (although there isn't a 'full' demo you can peruse the full implementation)

P.S. the AVB demo uses full implementation and multiple tx/rx clients although this is likely to add complexity (AVB) in understanding the ethernet stack.

regards
Al
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

gerrykurz wrote:Exactly my point, I cannot find information about this in the documentation.
Its the same as C, int x[1] declares an array of integers, length 1. Nothing whacky about channel-ends etc. Its just an array.

They code probably uses an array (over a singular chan var) as some API it uses is expecting an array.
User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Folknology wrote:

Code: Select all

chan rx[1], tx[1]; // two arrays of 2 channels each
The comment in the code (wherever it came from) is wrong.