PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
watchdog.h
Go to the documentation of this file.
1 
26 #pragma once
27 
29 #include <PropWare/PropWare.h>
31 
32 namespace PropWare {
33 
37 class WatchDog : public Runnable {
38  public:
47  template<size_t N>
48  WatchDog (const uint32_t (&stack)[N], const unsigned int timeout,
49  const unsigned int monitorFrequency = MICROSECOND << 7)
50  : Runnable(stack),
51  m_timeout(timeout),
52  m_sleepTime(monitorFrequency) { }
53 
57  void reset () {
58  this->m_timer = CNT;
59  }
60 
61  void run () {
62  this->m_timer = CNT;
63 
64  register unsigned int delay = CNT + this->m_sleepTime;
65  while (1) {
66  waitcnt(delay);
67  delay += this->m_sleepTime;
68  const unsigned int timeSinceTimerReset = CNT - this->m_timer;
69  if (timeSinceTimerReset > this->m_timeout)
70  Utility::reboot(); // Hard reset
71  }
72  }
73 
74  private:
75  const unsigned int m_timeout;
76  const unsigned int m_sleepTime;
77  volatile unsigned int m_timer;
78 };
79 
80 }
runnable.h
PropWare::WatchDog::WatchDog
WatchDog(const uint32_t(&stack)[N], const unsigned int timeout, const unsigned int monitorFrequency=MICROSECOND<< 7)
Constructor.
Definition: watchdog.h:48
PropWare::WatchDog::reset
void reset()
Reset the timer.
Definition: watchdog.h:57
timeout
int timeout(int time)
Compares the time against the time elapsed since mark (deprecated).
Definition: timeout.c:19
utility.h
PropWare.h
PropWare::Runnable
Helper class for creating easy parallel applications.
Definition: runnable.h:75
PropWare::WatchDog
Simple WatchDog object for resetting the chip if it stops responding.
Definition: watchdog.h:37
PropWare::WatchDog::run
void run()
Invoked in the new cog, this method should be the root of the business logic.
Definition: watchdog.h:61
waitcnt
#define waitcnt(a)
Wait until system counter reaches a value.
Definition: propeller.h:176
CNT
#define CNT
The system clock count.
Definition: propeller1.h:151
PropWare::Utility::reboot
static void reboot()
Perform hard reboot.
Definition: utility.h:242
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33