forked from M-Labs/kirdy
LdPwrExcProtector: Cleanup
This commit is contained in:
parent
f50505feaf
commit
6af0f992d5
|
@ -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<ADC1>.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::<millivolt>(wdg.calibrated_vdda as f64))).get::<ratio>() * (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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue