I am trying to solve a generic issues with channels and think I'm being stupid here but, I would like to take input from a channel but do not wish to block the thread as it has more important stuff to be getting on with. My first thought is to use a select statement of some sort. The channel is receiving integers in and asynchronous manner, I don't know when they are coming and I need to keep the channel open through the life of the thread. I also need to make decisions based on the value of the int received over the channel which effects how this thread operate. In the XC prog manual I only found one select statement combined with a channel which was based around a master slave but this channel use is not transaction like (not fixed number of transfers) so that is not suitable. Any ideas, any references to channels used in selects or some other method that doesn't block the thread?
Hers the kind of thing I'm talking about (pseudo code):
Code: Select all
int RESET;
int START;
int STOP;
void gatherdata(chanend control,int data[], int size) {
...
while(1){
select {
case control :> x when x == RESET :
reset();
break;
case control :> x when x == START :
start();
break;
case control :> x when x == STOP :
return 0;
case p pinusneg(0) :> void :
collect_data(data,size);
break;
... other case statements..
}
}
}