NetBurner 3.5.8
PDF Version
Toggle main menu visibility
NTP1061/src/nbwatchdog.h
1
/*NB_REVISION*/
2
3
/*NB_COPYRIGHT*/
4
5
/* nbwatchdog.h
6
* Easy-to-use WDOG1 watchdog helpers for the SOMRT1061 (i.MX RT1061).
7
*
8
* A watchdog is a hardware timer that resets the processor unless the
9
* application keeps restarting it ("servicing" it). Arm it once with a timeout,
10
* then service it regularly from healthy code; if the application hangs and
11
* stops servicing it, the module reboots itself.
12
*
13
* WatchdogEnable(4000); // reboot if not serviced within ~4 s
14
* ...
15
* WatchdogService(); // call comfortably more often than the timeout
16
*
17
* ==========================================================================
18
* IMPORTANT -- how the reboot works on the SOMRT1061
19
* ==========================================================================
20
* A *raw* hardware watchdog timeout resets the i.MX RT1061 core through the
21
* System Reset Controller (SRC), but on the SOMRT1061 module the part does NOT
22
* cleanly reboot from that -- it HANGS and needs a power cycle. The clean,
23
* bootable reset path on this module is ForceReboot() / DoSWReset(), which
24
* drives the boot/reset GPIOs and writes the SRC->GPR magic value the
25
* bootloader needs. A bare watchdog reset skips all of that.
26
*
27
* So WatchdogEnable() does not rely on the raw reset. It arms WDOG1 with a
28
* pre-timeout INTERRUPT that fires ~0.5 s before the hardware timeout, and that
29
* interrupt calls ForceReboot() -- a clean, bootable reset. "Not serviced in
30
* time" therefore means an automatic clean reboot; the raw hardware reset is
31
* only ever reached if the core is so wedged that interrupts no longer run (in
32
* which case a power cycle is the recovery anyway).
33
*
34
* See ReadMe.txt for the full picture, including RSTI (reset-in) / RSTO
35
* (reset-out) and why a watchdog reboot does not reach the Ethernet PHY or
36
* HyperRAM on this module.
37
*/
38
39
#ifndef NBWATCHDOG_H
40
#define NBWATCHDOG_H
41
42
#include <stdint.h>
43
#include <sim.h>
// pulls in <MIMXRT1061.h> -> WDOG1, SRC
44
45
// ---------------------------------------------------------------------------
46
// Reset-cause reporting
47
// ---------------------------------------------------------------------------
48
61
struct
WatchdogResetCause
62
{
63
uint32_t srsr;
// raw SRC->SRSR value at capture time
64
uint16_t wrsr;
// raw WDOG1->WRSR value at capture time
65
66
bool
powerOn;
// power-on reset (WRSR.POR)
67
bool
externalPin;
// external RSTI / DoSWReset (SRSR bit 0, ipp_reset_b)
68
bool
watchdog1;
// raw WDOG1 timeout (SRSR bit 4 / WRSR.TOUT)
69
bool
softwareReset;
// core lockup / SYSRESETREQ / WRSR.SFTW
70
bool
jtag;
// JTAG-initiated reset (SRSR bit 5/6)
71
bool
temperature;
// temperature-sensor reset (SRSR bit 8)
72
};
73
76
void
WatchdogCaptureResetCause();
77
79
const
WatchdogResetCause
&WatchdogLastReset();
80
82
void
WatchdogPrintResetCause();
83
87
void
WatchdogClearResetCause();
88
89
// ---------------------------------------------------------------------------
90
// WDOG1 -- the watchdog
91
// ---------------------------------------------------------------------------
92
107
void
WatchdogEnable(uint32_t timeoutMs);
108
111
void
WatchdogService();
112
117
void
WatchdogReportStall(
char
code);
118
120
bool
WatchdogIsEnabled();
121
123
uint32_t WatchdogTimeoutMs();
124
125
// ---------------------------------------------------------------------------
126
// Pre-reboot hook (hang diagnostics)
127
// ---------------------------------------------------------------------------
128
139
typedef
void (*WatchdogPreRebootHook)(uint32_t stackedPc, uint32_t stackedLr);
140
void
WatchdogSetPreRebootHook(WatchdogPreRebootHook hook);
141
142
#endif
// NBWATCHDOG_H
WatchdogResetCause
Definition
MODRT1171/Watchdog/src/nbwatchdog.h:61
examples
PlatformSpecific
NTP1061
src
nbwatchdog.h
Generated by
1.18.0