Page 1 of 1
Easy access to RGB led from several cores
Posted: Wed Aug 25, 2010 9:18 pm
by rihorle
I was wondering how one could implement an easy interface to a RGB diode connected via 3xpins to eg. core[0]. My plan is to do a Pwm function in a thread on core 0 with a channel to communicate. My question now is how does one easy send data to this thread from ANY location Core 0,1,2,3 via a simple function call eg. SetRGBled(red,green,blue); I was thinking about a Client/server via channels solution but i get stuck (channels being only point to point etc.) .. think im completely off track and need some fresh inspiration - this i prob. very trivial but multicore multithread programming is a completely new expericence to me :-)
Re: Easy access to RGB led from several cores
Posted: Wed Aug 25, 2010 9:49 pm
by boeserbaer
The inelegant brute force solution:
connect all the cores with channels
within the led thread select on receiving from each channel
update the leds accordingly.
Mike
Re: Easy access to RGB led from several cores
Posted: Thu Aug 26, 2010 7:40 am
by rihorle
Thanks for the reply:-)
... i got it so far - but how do you do this... i allways run into the fact that channels are point to point how do you from multiple places send info to a channel?
/a
Re: Easy access to RGB led from several cores
Posted: Thu Aug 26, 2010 8:48 am
by Berni
You can use a for loop cycle trough an array of channels that go to separate locations, you must use that select statement trick to make a channel not block when it has no data. This is used in the new ethernet example on the XC-2.
There should be something about this in the documentation but well it aint.
Re: Easy access to RGB led from several cores
Posted: Fri Aug 27, 2010 10:37 am
by Andy
Something like this should do the trick...
Code: Select all
int consumer(chanend c_chan[], int num_chans)
{
int i;
while (1)
{
for (i=0; i < num_chans; i++)
{
select
{
case c_chan[i] :> int _ :
{
// Call some function
break;
}
default :
{
// Do some default action
break;
}
}
}
}
return 0;
}
int foo(chanend c_chan)
{
// Do stuff here
// ..
c_chan <: 1;
return 0;
}
int main(void)
{
chan c_chan[3];
par
{
on stdcore[0] : foo(c_chan[0]);
on stdcore[1] : foo(c_chan[1]);
on stdcore[2] : foo(c_chan[2]);
on stdcore[3] : consumer(c_chan, 3);
}
return 0;
}