|
| 1 | +//! @file |
| 2 | +//! |
| 3 | +//! Copyright (c) Memfault, Inc. |
| 4 | +//! See License.txt for details |
| 5 | +//! |
| 6 | +//! A port for recovering reset reason information by reading the "System Reset |
| 7 | +//! Controller" (SRC)'s "Reset Status Register" (SRC_SRSR). |
| 8 | +//! |
| 9 | +//! More details can be found in the chapter "21.8.3 SRC Reset Status Register |
| 10 | +//! (SRC_SRSR)" in the RT1021 Reference Manual |
| 11 | + |
| 12 | +#include <inttypes.h> |
| 13 | + |
| 14 | +#include "MIMXRT1021.h" |
| 15 | +#include "memfault/components.h" |
| 16 | +#include "memfault/ports/reboot_reason.h" |
| 17 | + |
| 18 | +#if MEMFAULT_ENABLE_REBOOT_DIAG_DUMP |
| 19 | +#define MEMFAULT_PRINT_RESET_INFO(...) MEMFAULT_LOG_INFO(__VA_ARGS__) |
| 20 | +#else |
| 21 | +#define MEMFAULT_PRINT_RESET_INFO(...) |
| 22 | +#endif |
| 23 | + |
| 24 | +void memfault_reboot_reason_get(sResetBootupInfo *info) { |
| 25 | + const uint32_t reset_cause = SRC->SRSR & (SRC_SRSR_W1C_BITS_MASK | SRC_SRSR_TEMPSENSE_RST_B_MASK); |
| 26 | + eMemfaultRebootReason reset_reason = kMfltRebootReason_Unknown; |
| 27 | + |
| 28 | + // clear the SRC Reset Status Register by writing a 1 to each bit |
| 29 | +#if MEMFAULT_REBOOT_REASON_CLEAR |
| 30 | + SRC->SRSR = SRC_SRSR_W1C_BITS_MASK; |
| 31 | +#endif |
| 32 | + |
| 33 | + MEMFAULT_LOG_INFO("Reset Reason, SRC_SRSR=0x%" PRIx32, reset_cause); |
| 34 | + |
| 35 | + MEMFAULT_PRINT_RESET_INFO("Reset Cause: "); |
| 36 | + if (reset_cause & SRC_SRSR_JTAG_SW_RST_MASK) { |
| 37 | + MEMFAULT_PRINT_RESET_INFO(" Software"); |
| 38 | + reset_reason = kMfltRebootReason_SoftwareReset; |
| 39 | + } else if (reset_cause & SRC_SRSR_TEMPSENSE_RST_B_MASK) { |
| 40 | + MEMFAULT_PRINT_RESET_INFO(" Temp Sensor"); |
| 41 | + reset_reason = kMfltRebootReason_UnknownError; |
| 42 | + } else if (reset_cause & SRC_SRSR_WDOG3_RST_B_MASK) { |
| 43 | + MEMFAULT_PRINT_RESET_INFO(" HW Watchdog3"); |
| 44 | + reset_reason = kMfltRebootReason_HardwareWatchdog; |
| 45 | + } else if (reset_cause & SRC_SRSR_WDOG_RST_B_MASK) { |
| 46 | + MEMFAULT_PRINT_RESET_INFO(" HW Watchdog"); |
| 47 | + // reset_cause can be use to disambiguate the watchdog types |
| 48 | + reset_reason = kMfltRebootReason_HardwareWatchdog; |
| 49 | + } else if (reset_cause & SRC_SRSR_JTAG_RST_B_MASK) { |
| 50 | + MEMFAULT_PRINT_RESET_INFO(" Debugger"); |
| 51 | + reset_reason = kMfltRebootReason_DebuggerHalted; |
| 52 | + } else if (reset_cause & SRC_SRSR_IPP_USER_RESET_B_MASK) { |
| 53 | + MEMFAULT_PRINT_RESET_INFO(" Button"); |
| 54 | + reset_reason = kMfltRebootReason_ButtonReset; |
| 55 | + } else if (reset_cause & SRC_SRSR_CSU_RESET_B_MASK) { |
| 56 | + // Central Security Unit triggered the reset (see Security Reference |
| 57 | + // Manual) |
| 58 | + MEMFAULT_PRINT_RESET_INFO(" CSU"); |
| 59 | + reset_reason = kMfltRebootReason_UnknownError; |
| 60 | + } else if (reset_cause & SRC_SRSR_LOCKUP_SYSRESETREQ_MASK) { |
| 61 | + MEMFAULT_PRINT_RESET_INFO(" Lockup"); |
| 62 | + reset_reason = kMfltRebootReason_Lockup; |
| 63 | + } else if (reset_cause & SRC_SRSR_IPP_RESET_B_MASK) { |
| 64 | + // TODO this might be equivalent to POR... |
| 65 | + MEMFAULT_PRINT_RESET_INFO(" Pin Reset"); |
| 66 | + reset_reason = kMfltRebootReason_PinReset; |
| 67 | + } else { |
| 68 | + MEMFAULT_PRINT_RESET_INFO(" Unknown"); |
| 69 | + } |
| 70 | + |
| 71 | + *info = (sResetBootupInfo){ |
| 72 | + .reset_reason_reg = reset_cause, |
| 73 | + .reset_reason = reset_reason, |
| 74 | + }; |
| 75 | +} |
0 commit comments