|
16 | 16 | #include "memfault/components.h" |
17 | 17 | #include "memfault/ports/reboot_reason.h" |
18 | 18 |
|
| 19 | +#if MYNEWT_VAL(MEMFAULT_ENABLE) |
| 20 | + |
19 | 21 | void memfault_platform_get_device_info(sMemfaultDeviceInfo *info) { |
20 | 22 | *info = (sMemfaultDeviceInfo) { |
21 | 23 | // Note: serial number will be recovered from route used when posting |
@@ -165,3 +167,47 @@ void memfault_platform_reboot_tracking_boot(void) { |
165 | 167 | memfault_reboot_reason_get(&reset_info); |
166 | 168 | memfault_reboot_tracking_boot(s_reboot_tracking, &reset_info); |
167 | 169 | } |
| 170 | + |
| 171 | +#if MYNEWT_VAL(MEMFAULT_COREDUMP_CB) |
| 172 | + |
| 173 | + |
| 174 | +static eMemfaultRebootReason s_reboot_reason = kMfltRebootReason_UnknownError; |
| 175 | + |
| 176 | +#if MYNEWT_VAL(MEMFAULT_ASSERT_CB) |
| 177 | +void os_assert_cb(void) { |
| 178 | + s_reboot_reason = kMfltRebootReason_Assert; |
| 179 | +} |
| 180 | +#endif |
| 181 | + |
| 182 | +static eMemfaultRebootReason prv_resolve_reason_from_active_isr(void) { |
| 183 | + // ARM Cortex-M have a standard set of exception numbers used for faults. |
| 184 | + // |
| 185 | + // The bottom byte of the XPSR register tells us which interrupt we are running from. |
| 186 | + // See https://mflt.io/cortex-m-exc-numbering |
| 187 | + uint32_t vect_active = __get_xPSR() & 0xff; |
| 188 | + switch (vect_active) { |
| 189 | + case 2: |
| 190 | + return kMfltRebootReason_Nmi; |
| 191 | + case 3: |
| 192 | + return kMfltRebootReason_HardFault; |
| 193 | + case 4: |
| 194 | + return kMfltRebootReason_MemFault; |
| 195 | + case 5: |
| 196 | + return kMfltRebootReason_BusFault; |
| 197 | + case 6: |
| 198 | + return kMfltRebootReason_UsageFault; |
| 199 | + default: |
| 200 | + return kMfltRebootReason_HardFault; |
| 201 | + } |
| 202 | +} |
| 203 | + |
| 204 | +void os_coredump_cb(void *tf) { |
| 205 | + if (s_reboot_reason == kMfltRebootReason_UnknownError) { |
| 206 | + s_reboot_reason = prv_resolve_reason_from_active_isr(); |
| 207 | + } |
| 208 | + |
| 209 | + memfault_fault_handler(tf, s_reboot_reason); |
| 210 | +} |
| 211 | +#endif /* MYNEWT_VAL(MEMFAULT_COREDUMP_CB) */ |
| 212 | + |
| 213 | +#endif /* MYNEWT_VAL(MEMFAULT_ENABLE) */ |
0 commit comments