Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/cosmo/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,12 @@ device = "dimm"
description = "DIMM L, sensor 1"
sensors.temperature = 1

[[config.sensor.devices]]
name = "fan_ctrl"
device = "thermal_loop"
description = "Thermal loop"
sensors.pwm = 1
Comment thread
hawkw marked this conversation as resolved.

################################################################################
[config.spi.spi2]
controller = 2
Expand Down
8 changes: 8 additions & 0 deletions app/gimlet/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,14 @@ removable = true

################################################################################

[[config.sensor.devices]]
name = "fan_ctrl"
device = "thermal_loop"
description = "Thermal loop"
sensors.pwm = 1

################################################################################

[config.spi.spi2]
controller = 2

Expand Down
6 changes: 6 additions & 0 deletions app/grapefruit/app-ruby.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,9 @@ name = "lm75_h"
sensors = { temperature = 1 }
description = "LM75 (H)"
refdes = "U104"

[[config.sensor.devices]]
name = "fan_ctrl"
device = "thermal_loop"
description = "Thermal loop"
sensors.pwm = 1
6 changes: 6 additions & 0 deletions app/minibar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ power = { rails = [ "V1P0_SYS" ] }
sensors = { temperature = 1, voltage = 1, current = 1 }
refdes = "U7"

[[config.sensor.devices]]
name = "fan_ctrl"
device = "thermal_loop"
description = "Thermal loop"
sensors.pwm = 1

[config.spi.spi2]
controller = 2

Expand Down
6 changes: 6 additions & 0 deletions app/sidecar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,12 @@ device = "qsfp"
description = "QSFP transceiver 31"
sensors.temperature = 1

[[config.sensor.devices]]
name = "fan_ctrl"
device = "thermal_loop"
description = "Thermal loop"
sensors.pwm = 1

[config.spi.spi1]
controller = 1

Expand Down
3 changes: 3 additions & 0 deletions build/i2c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ pub enum Sensor {
InputCurrent,
InputVoltage,
Speed,
Pwm,
}

impl std::fmt::Display for Sensor {
Expand All @@ -467,6 +468,7 @@ impl std::fmt::Display for Sensor {
Sensor::InputCurrent => "INPUT_CURRENT",
Sensor::InputVoltage => "INPUT_VOLTAGE",
Sensor::Speed => "SPEED",
Sensor::Pwm => "PWM",
}
)
}
Expand Down Expand Up @@ -1547,6 +1549,7 @@ impl ConfigGenerator {
Sensor::InputCurrent => "input_current",
Sensor::InputVoltage => "input_voltage",
Sensor::Speed => "speed",
Sensor::Pwm => "pwm",
};
if values.len() == 1 {
writeln!(
Expand Down
15 changes: 10 additions & 5 deletions build/xtask/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ pub const DEFAULT_KERNEL_STACK: u32 = 1024;
/// without breaking CI.
///
/// # Changelog
/// Version 10 requires Humility to be aware of the `handoff` kernel feature,
/// which lets the RoT inform the SP when measurements have been taken. If
/// Humility is unaware of this feature, the SP will reset itself repeatedly,
/// which interferes with subsequent programming of auxiliary flash.
const HUBRIS_ARCHIVE_VERSION: u32 = 10;
/// ## Version 11
/// Adds a `pwm` sensor, which requires Humility to either accept that sensor
/// kind or accept unrecognized sensors without bailing.
///
/// ## Version 10
/// Requires Humility to be aware of the `handoff` kernel feature, which lets
/// the RoT inform the SP when measurements have been taken. If Humility is
/// unaware of this feature, the SP will reset itself repeatedly, which
/// interferes with subsequent programming of auxiliary flash.
const HUBRIS_ARCHIVE_VERSION: u32 = 11;

/// `PackageConfig` contains a bundle of data that's commonly used when
/// building a full app image, grouped together to avoid passing a bunch
Expand Down
41 changes: 34 additions & 7 deletions task/thermal/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ impl<'a> ThermalControl<'a> {
ControlResult::Pwm(target_pwm) => {
// Send the new RPM to all of our fans
ringbuf_entry!(Trace::ControlPwm(target_pwm.0));
self.set_pwm(target_pwm)?;
self.set_pwm(Ok(target_pwm), now_ms)?;
}
ControlResult::PowerDown => {
ringbuf_entry!(Trace::PowerDownAt(sys_get_timer().now));
Expand All @@ -1504,7 +1504,7 @@ impl<'a> ThermalControl<'a> {
if let Err(e) = self.bsp.power_down() {
ringbuf_entry!(Trace::PowerDownFailed(e));
}
self.set_pwm(PWMDuty(0))?;
self.set_pwm(Err(task_sensor_api::NoData::DeviceOff), now_ms)?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels strange to treat DeviceOff as an error. Under what circumstances would we hit PowerDown?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because we want set_pwm to be solely responsible for logging values to the sensors task, but need a way to distinguish between "the PWM value is 0 because everything is fine" versus "there's a big problem, set the PWM value to 0"

(see discussions with Eliza above)

}
}

Expand Down Expand Up @@ -1674,10 +1674,37 @@ impl<'a> ThermalControl<'a> {
/// set to zero. Returns the last error if one occurred, but does not short
/// circuit (i.e. attempts to set *all* present fan duty cycles, even if one
/// fails)
pub fn set_pwm(&mut self, pwm: PWMDuty) -> Result<(), ThermalError> {
if pwm.0 > 100 {
return Err(ThermalError::InvalidPWM);
}
///
/// The PWM value (or error code) is sent to the `sensors` task for logging,
/// timestamped with the `now_ms` argument.
pub fn set_pwm(
&mut self,
pwm: Result<PWMDuty, task_sensor_api::NoData>,
now_ms: u64,
) -> Result<(), ThermalError> {
// We'll post the PWM value to the sensors task for logging
use task_sensor_api::config::other_sensors;
pub const OUTPUT_PWM_SENSOR: SensorId =
other_sensors::THERMAL_LOOP_FAN_CTRL_PWM_SENSOR;
let pwm = match pwm {
Ok(pwm) => {
if pwm.0 > 100 {
self.sensor_api.nodata(
OUTPUT_PWM_SENSOR,
task_sensor_api::NoData::DeviceError,
now_ms,
);
return Err(ThermalError::InvalidPWM);
}
self.sensor_api
.post(OUTPUT_PWM_SENSOR, pwm.0 as f32, now_ms);
pwm
}
Err(e) => {
self.sensor_api.nodata(OUTPUT_PWM_SENSOR, e, now_ms);
PWMDuty(0)
}
};
self.last_pwm = pwm;
let mut last_err = Ok(());
for (index, sensor_id) in self.fans.enumerate() {
Expand Down Expand Up @@ -1705,7 +1732,7 @@ impl<'a> ThermalControl<'a> {
/// This is used by ThermalMode::Manual to accomodate the removal and
/// replacement of fan modules.
pub fn maintain_pwm(&mut self) -> Result<(), ThermalError> {
self.set_pwm(self.last_pwm)
self.set_pwm(Ok(self.last_pwm), sys_get_timer().now)
}

pub fn set_watchdog(
Expand Down
2 changes: 1 addition & 1 deletion task/thermal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl<'a> ServerImpl<'a> {
initial_pwm: PWMDuty,
) -> Result<(), ThermalError> {
self.set_mode(ThermalMode::Manual);
self.control.set_pwm(initial_pwm)
self.control.set_pwm(Ok(initial_pwm), sys_get_timer().now)
}

/// Configures the control loop to run in automatic mode.
Expand Down
Loading