Skip to content

Commit

Permalink
track/trace MAX5970 minimum and maximum values across a bounce (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcantrill authored Feb 29, 2024
1 parent 2f23c58 commit d4aba7b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions task/power/src/bsp/gimlet_bcdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ enum Trace {
max_iout: f32,
min_vout: f32,
max_vout: f32,
crossbounce_min_iout: f32,
crossbounce_max_iout: f32,
crossbounce_min_vout: f32,
crossbounce_max_vout: f32,
},
None,
}

ringbuf!(Trace, 64, Trace::None);
ringbuf!(Trace, 52, Trace::None);

fn trace_max5970(
dev: &Max5970,
Expand Down Expand Up @@ -162,20 +166,28 @@ fn trace_max5970(
max_iout,
min_vout,
max_vout,
crossbounce_min_iout: peaks.iout.crossbounce_min,
crossbounce_max_iout: peaks.iout.crossbounce_max,
crossbounce_min_vout: peaks.vout.crossbounce_min,
crossbounce_max_vout: peaks.vout.crossbounce_max,
});
}

#[derive(Copy, Clone)]
struct Max5970Peak {
min: f32,
max: f32,
crossbounce_min: f32,
crossbounce_max: f32,
}

impl Default for Max5970Peak {
fn default() -> Self {
Self {
min: f32::MAX,
max: f32::MIN,
crossbounce_min: f32::MAX,
crossbounce_max: f32::MIN,
}
}
}
Expand All @@ -190,12 +202,23 @@ impl Max5970Peak {
/// or a minimum that is greater than our previous minimum) then there must
/// have been a power cycle. This can clearly yield false negatives, but
/// it will not yield false positives: if [`bounced`] returns true, one can
/// know with confidence that the power has been cycled.
/// know with confidence that the power has been cycled. Note that we also
/// use this opportunity to retain the peaks across a bounce, which would
/// would otherwise be lost.
///
fn bounced(&mut self, min: f32, max: f32) -> bool {
let bounced = min > self.min || max < self.max;
self.min = min;
self.max = max;

if min < self.crossbounce_min {
self.crossbounce_min = min;
}

if max > self.crossbounce_max {
self.crossbounce_max = max;
}

bounced
}
}
Expand Down

0 comments on commit d4aba7b

Please sign in to comment.