uint32_t SRSR = SRC_SRSR;
if (SRSR & SRC_SRSR_LOCKUP_SYSRESETREQ) {
// use SRC_GPR5 to distinguish cases. See pages 1290 & 1294 in ref manual
uint32_t gpr5 = SRC_GPR5;
if (gpr5 == 0x0BAD00F1) {
p.println(" Reboot was caused by auto reboot after fault or bad interrupt detected");
} else {
p.println(" Reboot was caused by software write to SCB_AIRCR or CPU lockup");
}
}
if (SRSR & SRC_SRSR_CSU_RESET_B) {
p.println(" Reboot was caused by security monitor");
}
if (SRSR & SRC_SRSR_IPP_USER_RESET_B) {
// This case probably can't occur on Teensy 4.x
// because the bootloader chip monitors 3.3V power
// and manages DCDC_PSWITCH and RESET, causing the
// power on event to appear as a normal reset.
p.println(" Reboot was caused by power on/off button");
}
if (SRSR & SRC_SRSR_WDOG_RST_B) {
p.println(" Reboot was caused by watchdog 1 or 2");
}
if (SRSR & SRC_SRSR_JTAG_RST_B) {
p.println(" Reboot was caused by JTAG boundary scan");
}
if (SRSR & SRC_SRSR_JTAG_SW_RST) {
p.println(" Reboot was caused by JTAG debug");
}
if (SRSR & SRC_SRSR_WDOG3_RST_B) {
p.println(" Reboot was caused by watchdog 3");
}
if (SRSR & SRC_SRSR_TEMPSENSE_RST_B) {
p.println(" Reboot was caused by temperature sensor");
SRC_SRSR &= ~0x100u; /* Write 0 to clear. */
p.println("Panic Temp Exceeded Shutting Down");
p.println("Can be caused by Overclocking w/o Heatsink or other unknown reason");
IOMUXC_GPR_GPR16 = 0x00000007;
SNVS_LPCR |= SNVS_LPCR_TOP; //Switch off now
asm volatile ("dsb":::"memory");
while (1) asm ("wfi");
}