The most frequent appointment made by users that used leOS was the incompatibility between my little scheduler and other libraries that used the same timer used by leOS. So I decided to follow another way to get a scheduler running and chose to use the WatchDog. The WatchDog is a circuit usually used to reset the microcontroller in case the CPU freezes in an infinite loop. The WatchDog has a timer that, once it’s has been set, is incremented by a 128 kHz oscillator, that is integrated into the Atmel microcontrollers, through a prescaler. When the timer expires, the WDT (WatchDog Timer) resets the microcontroller.
But the WDT can also be used to raise an interrupt. Using this mode, the WDT can be used as a timer to recall the scheduler every a fixed interval. The WDT is not as configurable as a timer so the minimum interval that we can set is ~16 ms but this is enough for our scopes.
leOS2 can also set the WDT to run in a particular mode called “interrupt then system reset” that first raises an interrupt, then, if a specific flag isn’t set again to “1”, resets the microcontroller. Thanks to this trick I was able to write a scheduler that can reset the microcontroller if it finds that a task has freezed during execution. The timeout period before the scheduler resets the microcontroller is selectable by the user.