XK-1A board cuncurrent threads ???

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
cicga
Active Member
Posts: 51
Joined: Tue Oct 11, 2011 4:48 pm

XK-1A board cuncurrent threads ???

Post by cicga »

Hi all,
I am new in XMOS and just get the XK-1A kit. I start to play with concurrent threads and find something that I dont understand.

My code is simple:

#include <xs1.h>

out port outA = XS1_PORT_1A;
out port outB = XS1_PORT_1B;
clock clk = XS1_CLKBLK_1;

void L_L(){
for(int x = 0;x<5;x++){
outA<:1;
outA<:0;
}
}

void R_L(){
outB<:1;
outB<:0;
}

int main(void)
{

while(1) {

par{
L_L();
R_L();
}

}
}

I am creating two independent threads and running them at them in parallel. What I was expecting is that L_L and R_L functions will toggle port 1a and 1b at the same time. What I see in logic analyzer is that threads working one after other and not in parallel. I attached picture of LA traces.

what i am doing wrong?

cicga
Attachments
XK-1AccTHr.jpg
LA traces of two threads
(209.39 KiB) Not downloaded yet
XK-1AccTHr.jpg
LA traces of two threads
(209.39 KiB) Not downloaded yet


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

Post by Folknology »

The shorter thread R_L() has to wait until the longer thread L_L() finishes before the while loop can continue as both threads default to synchronise. This is thread Join synchronisation in practice. They do both run at the same time its just one has to in effect wait for the other before running again.

Having the while loop wrapping the 'par' maybe not achieving what you think it does. what are you actually trying to do?

regards
Al
Last edited by Folknology on Tue Oct 11, 2011 5:59 pm, edited 1 time in total.
User avatar
Andy
Respected Member
Posts: 279
Joined: Fri Dec 11, 2009 1:34 pm

Post by Andy »

The operation of the program you describe is correct. The threads are running in parallel, however, the ports outA and outB are not synchronised. The for loop in L_L() is causing a delay before outA <: 1. There is no such delay in R_L(), therefore outB <: 1 is happening slightly earlier.

I assume you expected outA and outB to toggle 1 at the same time?
cicga
Active Member
Posts: 51
Joined: Tue Oct 11, 2011 4:48 pm

Post by cicga »

thanks Folknology, Andy

what I found that actually was nothing wrong - the delay on LA was delay for thread to start.
I put inside L_L and R_L while(1) and on both lines I saw independent action - like it should be in hardware independent threads...

do u know if it's possible to control individual lines inside port ?

something like:

#defiine a as XS1_PORT_4A0;
#defiine b as XS1_PORT_4A1;

while(1){
b<:1;
a<:1;
bla bla bla.....
}

regards
cicga
Post Reply