For example
Code: Select all
void f(streaming chanend ch, in port CLK, in port DATA) {
unsigned cmd;
unsigned clkState, dataState;
unsigned tmp, counter;
clkState = peek(CLK);
dataState = peek(DATA);
counter = 5;
while(counter) {
#pragma ordered
select {
case ch :> cmd:
...do something with cmd
break;
case CLK when pinsneq(clkState) :> clkState:
DATA :> tmp;
counter--;
... do something more
break;
case DATA when pinsneq(dataState) :> dataState:
DATA :> cmd;
ch <: cmd;
...other actions
break;
}
}
So, if both CLK and DATA changes simultaneously both event handlers will be executed, right? First the part that handles the CLK change and then, in the next while cycle, the DATA handler.
it's possible to use some guard flags for that in the "DATA handler" but I'm wondering if the pending events on a resource can be "cleared"? I know the event handler for the resource could be "cleared" but that would break the select (the handler should be manually set again - to the correct place!)
I also saw a construct in few places like this one lilltroll showed here
Code: Select all
case t when timerafter(time) :> int _: //Do not run another event
t when timerafter(time+TIMERESERVE) :> int _; //if more than TIMERESERVE CPU cycles are available
...
regards,
mculibrk