I'm trying to count the bursts I read from a pin and the number of cycles between those bursts.
Without a default case I can count the pulses of a burst but if I add a default case that increases a variable my program doesn't recognize the pulses anymore. I don't understand why The channel end still works though..
The code below is the thread containing the select statement.
Code: Select all
void receiver(chanend c){
unsigned dataIn = 0;
int channelData = 0;
unsigned pulseCounter = 0;
unsigned counter = 0;
while(1){
select {
/* Pin for bursts */
case inP when pinsneq(dataIn) :> dataIn:
pulseCounter++;
break;
/* Channel end for frequent reset */
case c :> channelData:
if (channelData == 0){
printf("ctr: %u; plsCtr: %u\n",counter,pulseCounter);
counter = 0;
pulseCounter = 0;
}
break;
default:
counter++;
break;
}
//counter++;
}
}
with default:
ctr: 7142857; plsCtr: 0
ctr: 7088387; plsCtr: 0
ctr: 7109786; plsCtr: 0
without default:
ctr: 0; plsCtr: 744
ctr: 0; plsCtr: 672
ctr: 0; plsCtr: 672
counter outside switch:
ctr: 744; plsCtr: 744
ctr: 669; plsCtr: 668
ctr: 673; plsCtr: 672
What is the reason for that behavior?