I'm confused over the behavior of a select statement. I have two threads in my program. One listens for input, while the other processes pre-cached settings. My problem with the select statement is that even when there is no input for the listener to consume, the select statement behaves as though it has had input. The serial link seems to not always return to 1 when it's done sending data. In response to that, I have attempted to read the state of the serial link at the beginning of the loop, and then detect if that changes. This doesn't seem to work - if any value aside from 255 is sent over the serial link, this gets caught in the second case after going once through the process thread, as though input were received.
Can anyone guide me on where this is going wrong?
Code: Select all
void getSettings(chanend out_ch, chanend process_ch){
unsigned char nSettings;
timeset settings[255];
char pDone;
char STOP=1;
char GO=0;
char rxd_tmp;
while(1)
{
// The serial link seems to not always return to 1 when it's done sending data
rxd :> rxd_tmp;
select
{
// the process thread sends this signal when it finishes its round
case process_ch :> pDone: // process thread is ready for another round
{
// this is a signal to the process thread that it should start
// another loop with whatever cached settings it presently has.
out_ch <: GO;
break;
}
case rxd when pinsneq(rxd_tmp) :> void: // comm received, incoming data
{
(get settings functionality omitted for brevity)
}