Prusa-MMU-Private
PrusaMultiMaterialUpgradev3firmwareforMK3SMK4
watchdog.h
Go to the documentation of this file.
1 #pragma once
3 #include <stdint.h>
4 
5 namespace hal {
6 
8 namespace watchdog {
9 
10 #if defined(__AVR__)
11 constexpr uint32_t F_WDT = 128000; //frequency of the watchdog unit in Hz
12 constexpr uint32_t basePrescaler = 2048; //what prescalerBits==0 actually does.
13 constexpr uint8_t maxPrescaler = 9; //the maximum value prescalerBits can take
14 constexpr uint8_t reloadBits = 0; //number of bits in the reload register
15 #elif defined(__STM32__) //@todo to be changed to the final form
16 constexpr uint32_t F_WDT = 32000; //frequency of the watchdog unit in Hz
17 constexpr uint32_t basePrescaler = 4; //what prescalerBits==0 actually does.
18 constexpr uint8_t maxPrescaler = 6; //the maximum value prescalerBits can take
19 constexpr uint8_t reloadBits = 12; //number of bits in the reload register
20 #endif
21 
22 struct configuration {
23  uint8_t prescalerBits;
24  uint16_t reload;
25 
26 public:
27  static constexpr configuration compute(uint16_t timeout) {
28  // uint8_t prescalerBits = 0;
29  // uint32_t ticks = timeout * F_WDT / (basePrescaler * (1 << prescalerBits));
30  // while ((ticks >= (1 << reloadBits)) && (prescalerBits < maxPrescaler)) {
31  // prescalerBits++;
32  // ticks >>= 1;
33  // }
34  // if ((prescalerBits == 0) && (ticks == 0))
35  // ticks = 1; //1 tick is minimum
36  // configuration config = { prescalerBits, static_cast<uint16_t>(ticks - 1) };
37  // return config;
38  uint8_t prescalerBits = 0;
39  uint32_t ticks = 1;
40  switch (timeout) {
41  case 250:
42  prescalerBits = 4;
43  break;
44  case 8000:
45  prescalerBits = 9;
46  break;
47  }
48 
49  configuration config = { prescalerBits, static_cast<uint16_t>(ticks - 1) };
50  return config;
51  }
52 };
53 
55 void Enable(const configuration &config);
56 void Disable();
57 void Reset();
58 
59 } // namespace watchdog
60 } // namespace hal
61 
62 namespace hwd = hal::watchdog;
Define Debug mode to add additional serial output.
Definition: axis.h:6
Hardware Abstraction Layer for the CPU's internal watchdog.
Definition: watchdog.cpp:6
void Enable(const configuration &config)
watchdog interface
Definition: watchdog.cpp:8
Definition: watchdog.h:22