First, my background: I am an "old hand" at software development and microcontroller-chip programming, but I am BRAND NEW to AVR chip, and Arduino programming, as of this past weekend. This is my first Arduino forum post.
Note: If these questions have been discussed before, or if there is documentation showing how to do what I ask, could you please provide URLs that link specifically to the answers?
My two questions, in a "nut-shell":
- Does the Arduino's internal "Operating Sytem" (or "OS") provide a "hook" or API to add a library method/function call to the internal, hidden main loop (i.e. to call a method/function from the same entity that makes the call to a sketch's loop() function)?
- Is there a software API or system call to reset the Arduino board?
Further Details:
I have in mind to write a software Watchdog library that does two things:
- Set up a watchdog timer and reset it every time through the main loop (and reset the Arduino board if the watchdog timer times out);
- Flash the (usually) provided Arduino on-board LED, as a "heartbeat" monitor.
The watchdog timeout value (0 for off, to disable the watchdog) and the LED flash on/off times, are to be provided as parameters to the class constructor, something like this (e.g. before the void setup() definition):
// Setup a watchdog timer of 5 seconds, and flash a heartbeat
// with on/off times of 50 ms and 950 ms, respectively
Watchdog wd(5000, 50, 950);
And that is ALL that should be required to set it up and to start it running when the main loop starts.
Both the LED flashing and watchdog reset should be managed as part of the main loop, and NOT from any timer interrupt service routine (ISR), since, in many cases, interrupts can continue to function even if the main loop has "died" or "gone off to la-la land", for any reason
It would be nice to have the class library automatically add the required function calls to the main loop, without requiring the sketch programmer to add any libary calls in the sketch's loop() function.
Is there any way to do this?
Thanks and best regards
The "Duinonator"