diff options
Diffstat (limited to 'embassy-mspm0/src')
| -rw-r--r-- | embassy-mspm0/src/lib.rs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/embassy-mspm0/src/lib.rs b/embassy-mspm0/src/lib.rs index 7135dd9f0..9f3e4d5e8 100644 --- a/embassy-mspm0/src/lib.rs +++ b/embassy-mspm0/src/lib.rs | |||
| @@ -234,3 +234,114 @@ impl Iterator for BitIter { | |||
| 234 | } | 234 | } |
| 235 | } | 235 | } |
| 236 | } | 236 | } |
| 237 | |||
| 238 | /// Reset cause values from SYSCTL.RSTCAUSE register. | ||
| 239 | /// Based on MSPM0 L-series Technical Reference Manual Table 2-9 and | ||
| 240 | /// MSPM0 G-series Technical Reference Manual Table 2-12. | ||
| 241 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 242 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 243 | pub enum ResetCause { | ||
| 244 | /// No reset since last read | ||
| 245 | NoReset, | ||
| 246 | /// VDD < POR- violation, PMU trim parity fault, or SHUTDNSTOREx parity fault | ||
| 247 | PorHwFailure, | ||
| 248 | /// NRST pin reset (>1s) | ||
| 249 | PorExternalNrst, | ||
| 250 | /// Software-triggered POR | ||
| 251 | PorSwTriggered, | ||
| 252 | /// VDD < BOR- violation | ||
| 253 | BorSupplyFailure, | ||
| 254 | /// Wake from SHUTDOWN | ||
| 255 | BorWakeFromShutdown, | ||
| 256 | /// Non-PMU trim parity fault | ||
| 257 | #[cfg(not(any( | ||
| 258 | mspm0c110x, | ||
| 259 | mspm0c1105_c1106, | ||
| 260 | mspm0g110x, | ||
| 261 | mspm0g150x, | ||
| 262 | mspm0g151x, | ||
| 263 | mspm0g310x, | ||
| 264 | mspm0g350x, | ||
| 265 | mspm0g351x | ||
| 266 | )))] | ||
| 267 | BootrstNonPmuParityFault, | ||
| 268 | /// Fatal clock fault | ||
| 269 | BootrstClockFault, | ||
| 270 | /// Software-triggered BOOTRST | ||
| 271 | BootrstSwTriggered, | ||
| 272 | /// NRST pin reset (<1s) | ||
| 273 | BootrstExternalNrst, | ||
| 274 | /// WWDT0 violation | ||
| 275 | BootrstWwdt0Violation, | ||
| 276 | /// WWDT1 violation (G-series only) | ||
| 277 | #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x))] | ||
| 278 | SysrstWwdt1Violation, | ||
| 279 | /// BSL exit (if present) | ||
| 280 | SysrstBslExit, | ||
| 281 | /// BSL entry (if present) | ||
| 282 | SysrstBslEntry, | ||
| 283 | /// Uncorrectable flash ECC error (if present) | ||
| 284 | #[cfg(not(any(mspm0c110x, mspm0c1105_c1106, mspm0g351x, mspm0g151x)))] | ||
| 285 | SysrstFlashEccError, | ||
| 286 | /// CPU lockup violation | ||
| 287 | SysrstCpuLockupViolation, | ||
| 288 | /// Debug-triggered SYSRST | ||
| 289 | SysrstDebugTriggered, | ||
| 290 | /// Software-triggered SYSRST | ||
| 291 | SysrstSwTriggered, | ||
| 292 | /// Debug-triggered CPURST | ||
| 293 | CpurstDebugTriggered, | ||
| 294 | /// Software-triggered CPURST | ||
| 295 | CpurstSwTriggered, | ||
| 296 | } | ||
| 297 | |||
| 298 | /// Read the reset cause from the SYSCTL.RSTCAUSE register. | ||
| 299 | /// | ||
| 300 | /// This function reads the reset cause register which indicates why the last | ||
| 301 | /// system reset occurred. The register is automatically cleared after being read, | ||
| 302 | /// so this should be called only once per application startup. | ||
| 303 | /// | ||
| 304 | /// If the reset cause is not recognized, an `Err` containing the raw value is returned. | ||
| 305 | #[must_use = "Reading reset cause will clear it"] | ||
| 306 | pub fn read_reset_cause() -> Result<ResetCause, u8> { | ||
| 307 | let cause_raw = pac::SYSCTL.rstcause().read().id(); | ||
| 308 | |||
| 309 | use ResetCause::*; | ||
| 310 | use pac::sysctl::vals::Id; | ||
| 311 | |||
| 312 | match cause_raw { | ||
| 313 | Id::NORST => Ok(NoReset), | ||
| 314 | Id::PORHWFAIL => Ok(PorHwFailure), | ||
| 315 | Id::POREXNRST => Ok(PorExternalNrst), | ||
| 316 | Id::PORSW => Ok(PorSwTriggered), | ||
| 317 | Id::BORSUPPLY => Ok(BorSupplyFailure), | ||
| 318 | Id::BORWAKESHUTDN => Ok(BorWakeFromShutdown), | ||
| 319 | #[cfg(not(any( | ||
| 320 | mspm0c110x, | ||
| 321 | mspm0c1105_c1106, | ||
| 322 | mspm0g110x, | ||
| 323 | mspm0g150x, | ||
| 324 | mspm0g151x, | ||
| 325 | mspm0g310x, | ||
| 326 | mspm0g350x, | ||
| 327 | mspm0g351x | ||
| 328 | )))] | ||
| 329 | Id::BOOTNONPMUPARITY => Ok(BootrstNonPmuParityFault), | ||
| 330 | Id::BOOTCLKFAIL => Ok(BootrstClockFault), | ||
| 331 | Id::BOOTSW => Ok(BootrstSwTriggered), | ||
| 332 | Id::BOOTEXNRST => Ok(BootrstExternalNrst), | ||
| 333 | Id::BOOTWWDT0 => Ok(BootrstWwdt0Violation), | ||
| 334 | Id::SYSBSLEXIT => Ok(SysrstBslExit), | ||
| 335 | Id::SYSBSLENTRY => Ok(SysrstBslEntry), | ||
| 336 | #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x))] | ||
| 337 | Id::SYSWWDT1 => Ok(SysrstWwdt1Violation), | ||
| 338 | #[cfg(not(any(mspm0c110x, mspm0c1105_c1106, mspm0g351x, mspm0g151x)))] | ||
| 339 | Id::SYSFLASHECC => Ok(SysrstFlashEccError), | ||
| 340 | Id::SYSCPULOCK => Ok(SysrstCpuLockupViolation), | ||
| 341 | Id::SYSDBG => Ok(SysrstDebugTriggered), | ||
| 342 | Id::SYSSW => Ok(SysrstSwTriggered), | ||
| 343 | Id::CPUDBG => Ok(CpurstDebugTriggered), | ||
| 344 | Id::CPUSW => Ok(CpurstSwTriggered), | ||
| 345 | other => Err(other as u8), | ||
| 346 | } | ||
| 347 | } | ||
