AVR Threads Library
The AVR Threads Library provides basic preemptive multitasking/multi-threading to the Atmel AVR family of microcontrollers. It is written mostly in C with some assembly language. It implements a simple round-robin style task switcher.
This library provides basic thread start and stop functions, a couple of flavors of mutual exclusion semaphore, and events to help synchronize threads.
The library builds for three AVR families which include the ATmega128, the ATmega103, and the AT90S8515 and AT90S8535. It should be relatively easy to modify the make files and source to build the libraries for other AVR microcontrollers.
I have released this code under the GNU Lesser General Public License with the hope that others might find it useful.
Patches and Enhancements
Others have kindly provided changes and enhancements to this library. Unfortunately, I'm not actively developing for AVR microcontrollers at this time and can't try out their changes. I'm providing them here, as is, so others can benefit.
Dr. Rainer Müller
Dr. Rainer Müller provided changes he described as follows:
Since I didn't find a method to block a thread until some data will be written to an rs232 port, I made a small extension to your version 1.3. Perhaps you find it useful and want to keep it.
See the avr-threads-1.3-Rainer.Mueller-2009-05-27.patch patch file from the downloads tab.
Dr. Rainer Müller has also provided an implementation of counting semaphores. From the header file:
Counting semaphores are described at many places. They are ideal to synchronize buffer access between threads. The basic operations as described by Dijkstra are P (here: request) and V (here: release).
See counting-semaphores-Rainer.Mueller-2012-05-25.patch from the downloads tab.
Giuseppe Magnotta provided a change he described as follows:
I've replaced the avr_thread_idle() function in avr-thread.c... Instead of using the "nop" instruction i put to sleep the processor.
See the avr-threads-1.3-Giuseppe.Magnotta-2012-04-01.patch patch file from the downloads tab.