From 6af0f992d5ce48c157680d7910bbf12114959c2e Mon Sep 17 00:00:00 2001 From: linuswck Date: Fri, 26 Jan 2024 12:56:53 +0800 Subject: [PATCH] LdPwrExcProtector: Cleanup --- src/laser_diode/ld_pwr_exc_protector.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/laser_diode/ld_pwr_exc_protector.rs b/src/laser_diode/ld_pwr_exc_protector.rs index 22bcc12..512a709 100644 --- a/src/laser_diode/ld_pwr_exc_protector.rs +++ b/src/laser_diode/ld_pwr_exc_protector.rs @@ -10,7 +10,6 @@ use uom::si::{ f64::ElectricPotential, ratio::ratio }; -use crate::info; // 12 bit Resolution const MAX_SAMPLE: u16 = 4095; @@ -44,13 +43,11 @@ impl Default for Status { } } } -// power excursion protection -// LdPwrExcProtector + pub struct LdPwrExcProtector { pac: ADC2, phy: LdPwrExcProtectorPhy, alarm_status: Status, - //Calibrated VDDA in millivolt from Adc.calibrate() calibrated_vdda: u32, } @@ -103,13 +100,13 @@ impl LdPwrExcProtector { pac_adc.sqr3.write(|w| w .sq1().variant(PD_MON_ADC_CH_ID) ); - // Set all sampling channel to have fastest sampling interval + // Set all sampling channels to have fastest sampling interval pac_adc.smpr1.reset(); pac_adc.smpr2.reset(); - // Set the high threshold to be max value initially + // Set the higher threshold to be max value initially pac_adc.htr.write(|w| w.ht().variant(MAX_SAMPLE)); - // Set the low threshold to be min value initially + // Set the lower threshold to be min value initially pac_adc.ltr.write(|w| w.lt().variant(0)); // SWStart should only be set when ADON = 1. Otherwise no conversion is launched. @@ -117,7 +114,6 @@ impl LdPwrExcProtector { .swstart().set_bit() ); - // Turn LD Power Off by default phy.pwr_en_ch0.set_low(); unsafe { @@ -147,7 +143,6 @@ impl LdPwrExcProtector { if let Some(ref mut wdg ) = LdPwrExcProtector::get() { let code: u32 = ((htr / (ElectricPotential::new::(wdg.calibrated_vdda as f64))).get::() * (MAX_SAMPLE as f64)) as u32; wdg.pac.htr.write(|w| unsafe {w.bits(code)}); - info!("trigger_threshold_v: {:?}", code); } } @@ -220,7 +215,7 @@ impl LdPwrExcProtector { } } - fn power_excursion_handler(){ + fn pwr_excursion_handler(){ if let Some(ref mut wdg ) = LdPwrExcProtector::get() { let sample = wdg.pac.dr.read().data().bits(); LdPwrExcProtector::pwr_off(); @@ -233,8 +228,8 @@ impl LdPwrExcProtector { #[interrupt] fn ADC(){ cortex_m::interrupt::free(|_| { - LdPwrExcProtector::power_excursion_handler(); - // Disable interrupt to avoid getting stuck in infinite interrupt loop + LdPwrExcProtector::pwr_excursion_handler(); + // Disable interrupt to avoid getting stuck in infinite loop LdPwrExcProtector::disable_watchdog_interrupt(); LdPwrExcProtector::clear_interrupt_bit(); }