From b78a5619b02e092060bc50457aa0aa604efdab86 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 5 May 2026 23:56:05 +0800 Subject: [PATCH] add register interpretation for reset reason --- libs/bao1x-api/src/clocks.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libs/bao1x-api/src/clocks.rs b/libs/bao1x-api/src/clocks.rs index 28441514a..a21b3523a 100644 --- a/libs/bao1x-api/src/clocks.rs +++ b/libs/bao1x-api/src/clocks.rs @@ -1,6 +1,31 @@ +use bitbybit::bitfield; + pub const FREQ_OSC_MHZ: u32 = 48; const FD_MAX: u32 = 256; +#[bitfield(u32)] +#[derive(PartialEq, Eq, Debug)] +pub struct ResetReason { + #[bit(8, r)] + chip_reset: bool, + #[bit(7, r)] + voltage_detetor_reset: bool, + #[bit(6, r)] + security_reset: bool, + #[bit(5, r)] + sw_chip_reset: bool, + #[bit(4, r)] + xrst_pad: bool, + #[bit(3, r)] + sys_reset: bool, + #[bit(2, r)] + cms_reset: bool, + #[bit(1, r)] + wdt_reset: bool, + #[bit(0, r)] + sw_core_reset: bool, +} + /// This takes in the FD input frequency (the frequency to be divided) in MHz /// and the fd value, and returns the resulting divided frequency. pub fn divide_by_fd(fd: u32, in_freq_hz: u32) -> u32 {