Easy access to RGB led from several cores
-
- New User
- Posts: 2
- Joined: Wed Aug 25, 2010 9:07 pm
Easy access to RGB led from several cores
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 :-)
-
- Active Member
- Posts: 51
- Joined: Fri Jan 29, 2010 4:36 pm
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
connect all the cores with channels
within the led thread select on receiving from each channel
update the leds accordingly.
Mike
-
- New User
- Posts: 2
- Joined: Wed Aug 25, 2010 9:07 pm
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
... 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
-
- Respected Member
- Posts: 363
- Joined: Thu Dec 10, 2009 10:17 pm
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.
There should be something about this in the documentation but well it aint.
-
- Respected Member
- Posts: 279
- Joined: Fri Dec 11, 2009 1:34 pm
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;
}