UDP packet injection/generation on XC-3

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
mynameisdev
Junior Member
Posts: 7
Joined: Thu Aug 04, 2011 5:36 pm

UDP packet injection/generation on XC-3

Post by mynameisdev »

Morning forum, could I get some pointers from you on something...

I have an XC-3 sitting on my bench running a slightly modified version of the stock LED display tile driver firmware.

I wanted to add some further functionality to the network side of things but I am truly lost as to how I should go about it.

Before we get going I will say that I spent some time reading the XC-3 source code and trawling through the Ethernet documentation. Alas - I am none the wiser as to how the thing is really working. In fact - I'm not sure if the sc_ethernet stuff applies to the XC-3. For one - the XC-3 is not mentioned in the hardware notes. Further - I can't find some of the most basic sc_ethernet components for example ethernet_conf.h is nowhere to be found...

In the first instance, I want to take a single byte of data (let's say ASCII "X") and destination IP/port and release it on to the network as a UDP packet.

I was somewhat hoping there would be a nice method I could use for this e.g.

Code: Select all

byte[] send_buffer = Encoding.ASCII.GetBytes("X");
UDPClient.senddata(send_buffer,IP,Port); 
No such luck.

Ultimately want to send packets on a button press event.

For demo purposes I knocked up this:

Code: Select all

in port button = XS1_PORT_4E;
out port LED = XS1_PORT_4F;

int main(void) {

	int x;
	while (1) {
		button		:> x;
		if (x == 8)
			LED <: 2;
		else
			LED <: 1;
	}
	return 0;
}
But what I would like to do is something like this:

Code: Select all

in port button = XS1_PORT_4E;
out port LED = XS1_PORT_4F;
#define DELAY 5000000 //half a second at 100MHz

int main(void) {

	int x;
        unsigned state = 1, time;
	timer t;
        t :> time;
         while (1) {
                time += DELAY;
                t when timerafter(time) :> void;
                state = !state;
                if (state == 1)
                	button   :> x;
					if (x == 8) //Button pressed
                                              //Generate UDP packet (content,destination,port)
                                               //Insert packet into ethernet output buffer
					else
						//Do nothing
	}
	return 0;
}

Which - would transmit a UDP packet every half a second while the button is depressed.

Now I understand that I'll probably have to write the helper functions to generate my packets and so on but I have no idea where to start.

Further - my little routine (above) is all good and well as a standalone piece of code, but the XC-3 firmware is already a complex ecosystem of interrelated functions. Where would you advise this code is run (i.e. which core).

Any advice much appreciated,
Best
D


User avatar
Interactive_Matter
XCore Addict
Posts: 216
Joined: Wed Feb 10, 2010 10:26 am

Post by Interactive_Matter »

Hi D/mynameisdev,

I am actively working on the 'new' software version of the XC-3 kit. I am currently working on a XC-3 based solution myself (or at least based on the same software). You can find the 'new' versionhere at github https://github.com/xcore/sw_led_tile_controller

The new version is not yet really new. I have for starters just added some comments in the code to understand it better. But as you can see I am working on a new version. Especially it is imoprtant for me to incorporate the sc_ethernet stuff. From the code analysis I have seen that the sc_ethernet and XC-3 ethernet stuff are more or less the same - or at least have the same code as origin. But the sc_ethernet on github is better since it has evolved since it got incorporated into the XC-3. So I really want to replace the ethernet stuff in the sw_led_tile with the stuff from sc_ethernet. But it is possible that I have to adapt the sc_ethrnet stuff a bit. Since some changes for XC-3 may not have been incorporated into sc_ethernet. Unfortunateely I have to finish my display driver for my LED matrix first to ensure that and how the current stuff is working.

So it would be great if you can fork the sw_led_tile on github and incoroporate your changes there - if this is possible for you - since then we can collaborativly work on our solutions and by that improve the ap_led_tile software.

I have also seen that you have posted some other xc3 related questions in the forum and I will incorporate the answers in thr documentation stub on the github wiki https://github.com/xcore/sw_led_tile_controller/wiki

But reagardin your question where to put your code for sending UDP packages. in main.xc you can see that ethernetSwitch3Port is handling all the ethernet traffic coming in from both ethernet ports, either passing through or going to the local server in localServer/ethServer.xc

Since you want to change the behaviour of handling (i.e. sending and receiving) packages you have to add you package sending routines to localServer/ethServer.xc. And since you add a new source of information you have to add a new channel to the signature of ethServer.xc.

To realize the function you want to realize I would try to create a new thread watching the button and if the button is pressed sending every half a second the data of the package over the new channel to ethServer.xc. There you have to transform this package into an udp package and send it out to the ethernet.

I hope you can work with my rough sketch of what has to be done.

Marcus
User avatar
rubenc
Active Member
Posts: 40
Joined: Fri Jul 22, 2011 2:31 pm

Post by rubenc »

I am also working on the XC-3, It seems that this is the new board right?
because there are no tutorials nor templates for this one so far.

I had modified some projects from the git to make them run on this board. by changing the TARGET to XC-3
and the port names of Ethernet by adding _0 and _1 respectively.

I would like to know. ( and I am sure that Mathias knows :-P ) how would it be an ortodox way of porting this projects? or am I doing it right?

I have also seen that some of the newly generated projects include a XC-?.xn file with the pin asignments among other information. But on most of the projects on the github. I can not see this .xn file. so my question is how is this handled? where can I see the association between
XS1_PORT_1I to PORT_LED_3_0
if it is not in the .xn file?


Thankyou
User avatar
Interactive_Matter
XCore Addict
Posts: 216
Joined: Wed Feb 10, 2010 10:26 am

Post by Interactive_Matter »

rubenc wrote:I am also working on the XC-3, It seems that this is the new board right?
because there are no tutorials nor templates for this one so far.
Hi, I do not know either. But the XC-3 has been araound some time. Perhaps it has been a board created especially for a (potential) client. Yes it is very lightly documented - something I would really like to change sicne the XXC-3 is quite a cool board with dual ethernet and lots of 1-bit ports brouth out to the connectors.
rubenc wrote:I had modified some projects from the git to make them run on this board. by changing the TARGET to XC-3
and the port names of Ethernet by adding _0 and _1 respectively.

I would like to know. ( and I am sure that Mathias knows :-P ) how would it be an ortodox way of porting this projects? or am I doing it right?
The best way to change the project is to use the fork button in github - since then your project is hosted on github and either I can see what you are doing and thinking about integrating the changes - or you can create pull request to aks to get certain changes incorporated into the main project.

rubenc wrote: I have also seen that some of the newly generated projects include a XC-?.xn file with the pin asignments among other information. But on most of the projects on the github. I can not see this .xn file. so my question is how is this handled? where can I see the association between
XS1_PORT_1I to PORT_LED_3_0
if it is not in the .xn file?


Thankyou
The project currently does not contain a .xn file. Due to the configuration in the makefile it uses the XC-3 bundled with the XDE tools. It is really quite unhelpful to have no .xn file. I have simply added the stock .xn file to the project, but it is not active yet (I think). Will check that on the weekend.

Hope it helps

Marcus
mynameisdev
Junior Member
Posts: 7
Joined: Thu Aug 04, 2011 5:36 pm

Post by mynameisdev »

Hey guys, sorry for my late response - had a busy week and I often get the chance to sit down and read/respond to forums/email etc. Thanks for all your responses.

@Marcus - thanks for your post, some useful stuff in there. The outline you gave of what needs to be done makes sense to me and I had a look at your code in git; the comments and so on are very useful, thank you!

I'm currently bouncing between projects at the moment but when I get back to this little XMOS quandary I will as you suggested fork a copy of your course from github. I will invariably have some more questions once I get my teeth in to it properly.

More news as I get it

D