Protothread after C pre-processor

May 10, 2009 13:05

For those curious, here's what the protothread function in my previous post looks like after being passed through the C preprocessor and being indented using indent -linux:

char lights_thread(struct pt *pt)
{
{
char PT_YIELD_FLAG = 1;
switch ((pt)->lc) {
case 0:;
for (;;) {
printf("\n-> red");
resetTimer(0);
do {
((pt))->lc = 113;
case 113: ;
if (!(!(getTime(0) < 3))) {
return 0;
}
} while (0);

printf("\n-> green");
resetTimer(0);
do {
((pt))->lc = 117;
case 117: ;
if (!(!(getTime(0) < 5))) {
return 0;
}
} while (0);

printf("\n-> yellow");
resetTimer(0);
do {
((pt))->lc = 121;
case 121: ;
if (!(!(getTime(0) < 2))) {
return 0;
}
} while (0);
}
};
PT_YIELD_FLAG = 0;
(pt)->lc = 0;;
return 3;
};
}

It's not that different from the FSM implementation. The lc field is the analog of the cur_state variable.

A caveat when using the standard-C implementation of protothreads is that you cannot use a switch statement inside of a protothread because of the way the protothread uses a switch for the local continuation.

programming, embedded, protothreads, c

Previous post Next post
Up