24#include "boards/board.h"
25#include "boards/board_traits.h"
26#include <avr/interrupt.h>
36#define REGISTER_WATCHDOG_CLOCK_ISR(EVENT) \
39 watchdog::isr_handler::watchdog_clock<EVENT>(); \
47#define REGISTER_WATCHDOG_RTT_ISR() \
50 watchdog::isr_handler::watchdog_rtt(); \
61#define REGISTER_WATCHDOG_ISR_METHOD(HANDLER, CALLBACK) \
64 watchdog::isr_handler::watchdog_method<HANDLER, CALLBACK>(); \
74#define REGISTER_WATCHDOG_ISR_FUNCTION(CALLBACK) \
77 watchdog::isr_handler::watchdog_function<CALLBACK>() : \
85#define REGISTER_WATCHDOG_ISR_EMPTY() EMPTY_INTERRUPT(WDT_vect)
93#define DECL_WATCHDOG_ISR_HANDLERS_FRIEND \
94 friend struct watchdog::isr_handler; \
95 friend void ::WDT_vect();
161 uint8_t config =
bits::BV8(WDIE) | (uint8_t(timeout) & MASK_WDP012) |
162 ((uint8_t(timeout) & MASK_WDP3) ?
bits::BV8(WDP3) : 0);
163 synchronized begin_with_config(config);
180 void begin_with_config(uint8_t config)
INLINE
182 __asm__ __volatile__(
"wdr");
188 static constexpr const uint8_t MASK_WDP012 =
bits::BV8(WDP0, WDP1, WDP2);
189 static constexpr const uint8_t MASK_WDP3 = 0x08U;
193 using REG8 = board_traits::REG8;
194 static constexpr const REG8 MCUSR_{MCUSR};
195 static constexpr const REG8 WDTCSR_{WDTCSR};
224 uint16_t ms_per_tick =
bits::BV16(uint8_t(timeout) + 4);
225 uint8_t config =
bits::BV8(WDIE) | (uint8_t(timeout) & MASK_WDP012) |
226 ((uint8_t(timeout) & MASK_WDP3) ?
bits::BV8(WDP3) : 0);
230 begin_with_config(config);
231 millis_per_tick_ = ms_per_tick;
244 synchronized return millis_;
253 synchronized millis_ = 0;
270 uint32_t limit =
millis() + ms;
284 millis_ += millis_per_tick_;
289 volatile uint32_t millis_ = 0UL;
290 uint16_t millis_per_tick_ = 0U;
292 friend struct isr_handler;
303 static_assert(events::Event_trait<EVENT>::IS_EVENT,
"EVENT type must be an events::Event<T>");
324 WatchdogRTT::on_tick();
330 friend struct isr_handler;
336 template<
typename EVENT>
static void watchdog_clock()
338 interrupt::HandlerHolder<watchdog::Watchdog<EVENT>>::handler()->on_tick();
341 static void watchdog_rtt()
343 interrupt::HandlerHolder<watchdog::WatchdogRTT>::handler()->on_tick();
346 template<
typename HANDLER,
void (HANDLER::*CALLBACK)()>
static void watchdog_method()
348 interrupt::CallbackHandler<void (HANDLER::*)(), CALLBACK>::call();
351 template<
void (*CALLBACK)()>
static void watchdog_function()
353 interrupt::CallbackHandler<void (*)(), CALLBACK>::call();
bool push_(TREF item)
Push item to the end of this queue, provided there is still available space in its ring buffer.
Simple API to use watchdog timer as a clock for events generation.
Watchdog(containers::Queue< EVENT > &event_queue)
Construct a new watchdog-based clock that will, for each watchdog timeout, add an event to the given ...
Simple API to use watchdog timer as a real-time clock.
uint32_t millis() const
Get the number of milliseconds that elapsed since begin() was called.
void reset()
Reset current counter to 0.
WatchdogRTT()
Construct a new watchdog-based clock that will count elapsed milliseconds since it was started with b...
void delay(uint32_t ms)
Delay program execution for the given amount of milliseconds.
void begin(TimeOut timeout=TimeOut::TO_16ms)
Start the watchdog clock with the given timeout period.
Simple API to handle watchdog signals.
void end()
Stop this watchdog timer.
void begin(TimeOut timeout=TimeOut::TO_16ms)
Start the watchdog timer with the given timeout period.
#define INLINE
Specific GCC attribute to force the compiler to always inline code of a given function.
#define UNUSED
Specific GCC attribute to declare an argument or variable unused, so that the compiler does not emit ...
Support for events management.
General API for handling AVR interrupt vectors.
static constexpr uint8_t BV8(uint8_t bit)
Create a uint8_t bitmask for the given bit number.
static constexpr uint16_t BV16(uint8_t bit)
Create a uint16_t bitmask for the given bit number.
const uint8_t WDT_TIMER
Type of events generated by watchdog::Watchdog for each watchdog timeout interrupt.
void register_handler(Handler &handler)
Register a class instance containing methods that shall be called back by an ISR.
void yield()
Utility method used by many FastArduino API in order to "yield" some processor time; concretely it ju...
Defines the simple API for Watchdog timer management.
TimeOut
Defines the watchdog timeout period; watchdog interrupts will be triggered at the selected period.
@ TO_8s
Watchdog timeout 8 seconds.
@ TO_16ms
Watchdog timeout 16 ms.
@ TO_32ms
Watchdog timeout 32 ms.
@ TO_64ms
Watchdog timeout 64 ms.
@ TO_1s
Watchdog timeout 1 second.
@ TO_125ms
Watchdog timeout 125 ms.
@ TO_2s
Watchdog timeout 2 seconds.
@ TO_250ms
Watchdog timeout 250 ms.
@ TO_4s
Watchdog timeout 4 seconds.
@ TO_500ms
Watchdog timeout 500 ms.