Synchronization threads

Technical discussions related to any XMOS development kit or reference design. Eg XK-1A, sliceKIT, etc.
fdaniii
Member
Posts: 9
Joined: Tue Nov 22, 2011 3:20 pm

Synchronization threads

Post by fdaniii »

Hi guys,
i'm new ... and i'm starting now with xc programming. I have an XC-1A development kit ... i want to depth understand how threads work. In particular i wrote a code that rises up three pins: X1D0, X2D0, X036 and X038 with separate threads. The code is the follows:

Code: Select all


#include <platform.h>

void riseUp( out port pp1);

on stdcore[0] : out port p3 = XS1_PORT_1O; //PIN 38
on stdcore[0] : out port p1 = XS1_PORT_1M; //PIN 36
on stdcore[1] : out port p4 = XS1_PORT_1A; // X1D0, PIN 1  X1portA 
on stdcore[2] : out port p6 = XS1_PORT_1A; // X2D0, PIN 1 X2portA


int main(void) {
	par{
		on stdcore[0] : riseUp(p3);
		on stdcore[0] : riseUp(p1);
		on stdcore[1] : riseUp(p4);
		on stdcore[2] : riseUp( p6);
	}
	return 0;
}

void riseUp( out port pp1){
     pp1<:1;
}

My question is: why the three pins are not raised up simultaneously as reported in the following figure?
https://picasaweb.google.com/lh/photo/H ... directlink

The three separate threads should not start at the same time?
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

The threads are not truly concurrent, but executed in a round-robin fashion. If you want the ports to be synchronized, you can clock them to clock blocks with the same frequency (I think).

Read 5.1 from: https://www.xmos.com/download/public/Th ... 1.0%29.pdf

"Each thread has a 64-bit instruction buffer which is able to hold four short instructions
or two long ones. Instructions are issued from the runnable threads in a round-robin
manner, ignoring threads which are not in use or are paused waiting for a synchronisation
or input-output operation."
User avatar
paul
XCore Addict
Posts: 169
Joined: Fri Jan 08, 2010 12:13 am

Post by paul »

rp181 wrote:The threads are not truly concurrent, but executed in a round-robin fashion. If you want the ports to be synchronized, you can clock them to clock blocks with the same frequency (I think).
This is true, but you can't do that form of synchronisation across cores (the example above uses more than one core). IO synchronisation across cores is a bit of a hard problem to solve... You could feed the same external clock to each core, but then synchronising the pins so that they come are synchronised to the same T0 datum is quite tricky as the only communication you have between devices is via channels & xmos links.
Paul

On two occasions I have been asked, 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Ali
Member++
Posts: 22
Joined: Mon Jun 07, 2010 12:50 pm

Post by Ali »

In your example you have 4 cores, each of which truely executes in parallel. The problem is that you have no synchronisation between the 4 threads. As suggested, you can use an IO to synchronise the 4 cores, or more simply you can use channels.

If your thread on core0 sends a message through a channel to the other 3 threads telling them when to change the pin, that will synchronise the threads and cause the outputs to happen at the same time, within a few 10s of ns.
fdaniii
Member
Posts: 9
Joined: Tue Nov 22, 2011 3:20 pm

Post by fdaniii »

Thanks to all for your answers.... i'm trying to use channels... but the results is the same... the code i used is the follows:

Code: Select all

#include <print.h>
#include <platform.h>

void riseUp( out port pp1, chanend ch);
void startUp(chanend ch1,chanend ch2,chanend ch3);

on stdcore[0] : out port p3 = XS1_PORT_1O;
on stdcore[0] : out port p2 = XS1_PORT_1N;
on stdcore[0] : out port p1 = XS1_PORT_1M; 
on stdcore[1] : out port p4 = XS1_PORT_1A; 
on stdcore[2] : out port p6 = XS1_PORT_1A; 
on stdcore[3] : out port p7 = XS1_PORT_1A; 

int main(void) {
	chan c1, c2, c3;

	par{	
				                          on stdcore[0] : startUp(c1,c2,c3);
								//on stdcore[0] : riseUp(p1,c1);
								on stdcore[1] : riseUp(p4,c2);
								on stdcore[2] : riseUp( p6,c3);
								on stdcore[3] : riseUp( p7,c1);

	}
	return 0;
}
void startUp(chanend ch1,chanend ch2,chanend ch3)
{

	ch1<:1;
	ch2<:1;
	ch3<:1;
}



void riseUp( out port pp1, chanend ch){
  
   ch:>int;
    pp1<:1;

}

In my opinion the problem is on the fact that in the function SturtUp the three channels are not changed simultaneously. It is right?

Now i will try to cloking ports... Any other suggestions?

Thanks
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

The only way to achieve better timing is to use an external signal that will be driven by a master and all slaves will wait on this signal. This can be simulated with the pin loopback plugin in the XDE (I hope a 4-bit port can connect to 4 1-bit ports).

In the end, if you need multiple signals synchronized at a high resolution, it is better to keep them on the same core and ty the ports to the same clock block to decouple the instruction rate from the actual port operations.
User avatar
Ross
Verified
XCore Legend
Posts: 1163
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

If all on the same core you could use timed output (if all ports are clocked off the same clock)
Technical Director @ XMOS. Opinions expressed are my own
fdaniii
Member
Posts: 9
Joined: Tue Nov 22, 2011 3:20 pm

Post by fdaniii »

Hi guys,
i resolved by clocking ports with an external clock (generated by the device...)

I have another question to clarify:

When a port is clocked we have 2 situations:

1) the clocked port is an input port. In this case the value is sampled at the rising edge of the clock.
2) the clocked port is an output port. In this case, the value is transferred to the output at the falling edge of the clock.

Are right the two sentence above?

Thanks
User avatar
Ross
Verified
XCore Legend
Posts: 1163
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Yes, by default these statements are correct
Technical Director @ XMOS. Opinions expressed are my own
fdaniii
Member
Posts: 9
Joined: Tue Nov 22, 2011 3:20 pm

Post by fdaniii »

Hi, guys,
I want to expand them with a ULPI transceiver such as the SMSC USB33XX as reported in the "XMOS USB Device (XUD) Library" pag 2. The ports/Pins to be used for this configuration, reported on page 4 of the same document, are from XD12 to XD24. My questions are:

1) It is possible to use the ports of the core sdcore[3] (X3PortB)?
2) If it is feasible, how to specify the new hardware configuration? It is necessary to reconfigure the ports? i have to remap the ports?

thanks