Skip to content

Commit 3c1c95f

Browse files
committed
dut_power: make turn_off_with_reason() fallible
The operating system call to set the GPIO output state may fail. Make sure that this results in an orderly teardown of the tacd instead of a panic. This also necessitates a change to the test and demo_mode gpio stubs, so they can be `?`-operatored into anyhow Results (simply by making them anyhow results). Signed-off-by: Leonard Göhrs <[email protected]>
1 parent afb4a88 commit 3c1c95f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/digital_io/gpio/demo_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct LineHandle {
2727
}
2828

2929
impl LineHandle {
30-
pub fn set_value(&self, val: u8) -> Result<(), ()> {
30+
pub fn set_value(&self, val: u8) -> Result<()> {
3131
// This does not actually set up any IIO things.
3232
// It is just a hack to let adc/iio/demo_mode.rs
3333
// communicate with this function so that toggling an output

src/digital_io/gpio/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct LineHandle {
3232
}
3333

3434
impl LineHandle {
35-
pub fn set_value(&self, val: u8) -> Result<(), ()> {
35+
pub fn set_value(&self, val: u8) -> Result<()> {
3636
println!("GPIO simulation set {} to {}", self.name, val);
3737
self.val.store(val, Ordering::Relaxed);
3838
Ok(())

src/dut_power.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ fn turn_off_with_reason(
263263
pwr_line: &LineHandle,
264264
discharge_line: &LineHandle,
265265
fail_state: &AtomicU8,
266-
) {
267-
pwr_line.set_value(1 - PWR_LINE_ASSERTED).unwrap();
268-
discharge_line.set_value(DISCHARGE_LINE_ASSERTED).unwrap();
266+
) -> Result<()> {
267+
pwr_line.set_value(1 - PWR_LINE_ASSERTED)?;
268+
discharge_line.set_value(DISCHARGE_LINE_ASSERTED)?;
269269
fail_state.store(reason as u8, Ordering::Relaxed);
270+
271+
Ok(())
270272
}
271273

272274
/// Labgrid has a fixed assumption of how a REST based power port should work.
@@ -409,7 +411,7 @@ impl DutPwrThread {
409411
&pwr_line,
410412
&discharge_line,
411413
&state,
412-
);
414+
)?;
413415
} else {
414416
// We have a fresh ADC value. Signal "everything is well"
415417
// to the watchdog task.
@@ -466,7 +468,7 @@ impl DutPwrThread {
466468
&pwr_line,
467469
&discharge_line,
468470
&state,
469-
);
471+
)?;
470472

471473
continue;
472474
}
@@ -477,7 +479,7 @@ impl DutPwrThread {
477479
&pwr_line,
478480
&discharge_line,
479481
&state,
480-
);
482+
)?;
481483

482484
continue;
483485
}
@@ -488,7 +490,7 @@ impl DutPwrThread {
488490
&pwr_line,
489491
&discharge_line,
490492
&state,
491-
);
493+
)?;
492494

493495
continue;
494496
}
@@ -521,7 +523,7 @@ impl DutPwrThread {
521523
}
522524

523525
// Make sure to enter fail safe mode before leaving the thread
524-
turn_off_with_reason(OutputState::Off, &pwr_line, &discharge_line, &state);
526+
turn_off_with_reason(OutputState::Off, &pwr_line, &discharge_line, &state)?;
525527

526528
Ok(())
527529
})?;

0 commit comments

Comments
 (0)