Grant Edwards wrote:
On 2007-11-14, Grant Edwards <[email protected]> wrote:

Is anybody aware of a lightweight coroutine implementation for
mspgcc?  The yield operation would need to be implemented
without disabling interrupts...

Protothreads looks promising:

 http://www.sics.se/~adam/pt/


Yes, protothreads do not require any interrupt-disabling code (or any other low-level code for that matter - no assembler, no stack manipulation, etc - protothreads are pure C). The memory overhead is very low: only two bytes per protothread. Beware, however, that because protothreads are stackless, local variables are not stored across a blocking wait. Either use static local variables or pass around a state struct like event-driven programming.

The overhead or protothreads compared to an explicit switch()-based state machine is a few cycles so protothreads can even be used in time-critical code such as interrupts [1]. We're using them in Contiki [2] for a bunch of different purposes ranging from low-level radio framing protocol parsers (inside an interrupt handler) to the high-level process structure of Contiki.

/adam

[1] Adam Dunkels, Oliver Schmidt, Thiemo Voigt, and Muneeb Ali. Protothreads: Simplifying event-driven programming of memory-constrained embedded systems. In Proceedings of the Fourth ACM Conference on Embedded Networked Sensor Systems (SenSys 2006), Boulder, Colorado, USA, November 2006.
http://www.sics.se/~adam/dunkels06protothreads.pdf
http://www.sics.se/~adam/dunkels06protothreads.ppt

[2] http://www.sics.se/contiki/
--
Adam Dunkels <[email protected]>
http://www.sics.se/~adam/


Reply via email to