Skip to content
Open
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/cosmo/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ priority = 8
max-sizes = {flash = 32768, ram = 8192 }
stacksize = 3000
start = true
task-slots = ["i2c_driver", "sensor", "cosmo_seq", "jefe"]
task-slots = ["i2c_driver", "sensor", "cosmo_seq", "packrat"]
notifications = ["timer"]

[tasks.power]
Expand Down
2 changes: 1 addition & 1 deletion app/gimlet/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ priority = 5
max-sizes = {flash = 32768, ram = 8192 }
stacksize = 2000
start = true
task-slots = ["i2c_driver", "sensor", "gimlet_seq", "jefe"]
task-slots = ["i2c_driver", "sensor", "gimlet_seq", "packrat"]
notifications = ["timer"]

[tasks.power]
Expand Down
26 changes: 23 additions & 3 deletions app/grapefruit/rev-a-ruby.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,34 @@ features = ["usart6", "hardware_flow_control"]
uses = ["usart6"]
interrupts = {"usart6.irq" = "usart-irq"}

# needed for thermal ereports
[tasks.packrat]
features = ["ereport"]
stacksize = 1280

# We don't actually tell jefe to notify us on faults,
# but this is still required
notifications = ["task-faulted"]
task-slots = ["jefe"]

# needed for thermal ereports
[tasks.rng_driver]
features = ["h753", "packrat"]
name = "drv-stm32h7-rng"
priority = 6
uses = ["rng"]
start = true
stacksize = 512
task-slots = ["sys", "packrat"]

[tasks.thermal]
name = "task-thermal"
features = ["grapefruit"]
priority = 5
max-sizes = {flash = 32768, ram = 8192 }
stacksize = 6000
max-sizes = {flash = 32768, ram = 5120 }
stacksize = 1536
start = true
task-slots = ["i2c_driver", "sensor", "jefe"]
task-slots = ["i2c_driver", "sensor", "packrat"]
notifications = ["timer"]

[config]
Expand Down
2 changes: 1 addition & 1 deletion app/minibar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ priority = 5
max-sizes = {flash = 32768, ram = 16384 }
stacksize = 8096
start = true
task-slots = ["i2c_driver", "sensor"]
task-slots = ["i2c_driver", "sensor", "packrat"]
notifications = ["timer"]

[tasks.power]
Expand Down
2 changes: 1 addition & 1 deletion app/sidecar/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ priority = 5
max-sizes = {flash = 32768, ram = 16384 }
stacksize = 4000
start = true
task-slots = ["i2c_driver", "sensor", "sequencer"]
task-slots = ["i2c_driver", "sensor", "sequencer", "packrat"]
notifications = ["timer"]

[tasks.power]
Expand Down
4 changes: 2 additions & 2 deletions task/sensor-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ impl SensorId {
/// Note that multiple sensor IDs may have the same component ID, when a
/// single device exposes multiple measurement channels.
#[cfg(feature = "component-id-lookup")]
pub fn component_id(
pub const fn component_id(
&self,
) -> fixedstr::FixedStr<'static, { config::MAX_COMPONENT_ID_LEN }> {
config::SENSOR_ID_TO_COMPONENT_ID[self.0 as usize]
}

/// Returns the name of this sensor.
#[cfg(feature = "sensor-name-lookup")]
pub fn name(
pub const fn name(
&self,
) -> fixedstr::FixedStr<'static, { config::MAX_SENSOR_NAME_LEN }> {
config::SENSOR_ID_TO_NAME[self.0 as usize]
Expand Down
6 changes: 6 additions & 0 deletions task/thermal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ static-cell.path = "../../lib/static-cell"
task-sensor-api = { path = "../sensor-api", features = ["sensor-name-lookup", "component-id-lookup"] }
task-thermal-api.path = "../thermal-api"

# ereports deps
task-packrat-api.path= "../packrat-api"
ereports = { path = "../../lib/ereports", features = ["ereporter-macro"] }
microcbor = { path = "../../lib/microcbor" }
fixedstr = { path = "../../lib/fixedstr", features = ["microcbor"] }

[build-dependencies]
anyhow = { workspace = true }
idol = { workspace = true }
Expand Down
27 changes: 13 additions & 14 deletions task/thermal/src/bsp/common/emc2305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

use drv_i2c_api::{I2cDevice, ResponseCode};
use drv_i2c_devices::emc2305::Emc2305;
use drv_i2c_devices::emc2305::Fan as EmcFan;
use ringbuf::ringbuf_entry_root;
use task_sensor_api::SensorId;
use task_thermal_api::{SensorReadError, ThermalError};
use task_thermal_api::{
SANYO_DENKI_FAN_PROPERTIES, SensorReadError, ThermalError,
};

use crate::{
Trace,
Expand Down Expand Up @@ -96,23 +99,19 @@ impl From<ControllerInitError> for SensorReadError {
#[allow(dead_code)]
pub(crate) const fn make_consecutive_nonremovable_fans<const N: usize>(
sensors: &'static [SensorId; N],
) -> [crate::control::Fan<drv_i2c_devices::emc2305::Fan>; N] {
const ONE: crate::control::Fan<drv_i2c_devices::emc2305::Fan> =
crate::control::Fan::new(
SensorId::new(0),
drv_i2c_devices::emc2305::Fan::new_const(0),
);
) -> [crate::control::Fan<EmcFan>; N] {
const ONE: crate::control::Fan<EmcFan> = crate::control::Fan::new(
SensorId::new(0),
SANYO_DENKI_FAN_PROPERTIES,
EmcFan::new_const(0),
);

let mut out = [ONE; N];
let mut idx = 0;
while idx < N {
out[idx] = crate::control::Fan::new(
sensors[idx],
drv_i2c_devices::emc2305::Fan::new_const(idx as u8),
);
out[idx].cur_state = FanState::Present(FanPresentState::Unresponsive(
SensorReadError::NoData,
));
out[idx].rpm_sensor_id = sensors[idx];
out[idx].bsp_data = EmcFan::new_const(idx as u8);
out[idx].cur_state = FanState::Present(FanPresentState::Unpolled);
out[idx].presence_acked = true;
idx += 1;
}
Expand Down
27 changes: 13 additions & 14 deletions task/thermal/src/bsp/common/max31790.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
//! Common types and helpers for Max31790 Fan Controller

use drv_i2c_api::{I2cDevice, ResponseCode};
use drv_i2c_devices::max31790::Fan as MaxFan;
use drv_i2c_devices::max31790::Max31790;
use ringbuf::ringbuf_entry_root;
use task_sensor_api::SensorId;
use task_thermal_api::{SensorReadError, ThermalError};
use task_thermal_api::{
SANYO_DENKI_FAN_PROPERTIES, SensorReadError, ThermalError,
};

use crate::{
Trace,
Expand Down Expand Up @@ -103,23 +106,19 @@ impl From<ControllerInitError> for SensorReadError {
#[allow(dead_code)]
pub(crate) const fn make_consecutive_nonremovable_fans<const N: usize>(
sensors: &'static [SensorId; N],
) -> [crate::control::Fan<drv_i2c_devices::max31790::Fan>; N] {
const ONE: crate::control::Fan<drv_i2c_devices::max31790::Fan> =
crate::control::Fan::new(
SensorId::new(0),
drv_i2c_devices::max31790::Fan::new_const(0),
);
) -> [crate::control::Fan<MaxFan>; N] {
const ONE: crate::control::Fan<MaxFan> = crate::control::Fan::new(
SensorId::new(0),
SANYO_DENKI_FAN_PROPERTIES,
MaxFan::new_const(0),
);

let mut out = [ONE; N];
let mut idx = 0;
while idx < N {
out[idx] = crate::control::Fan::new(
sensors[idx],
drv_i2c_devices::max31790::Fan::new_const(idx as u8),
);
out[idx].cur_state = FanState::Present(FanPresentState::Unresponsive(
SensorReadError::NoData,
));
out[idx].rpm_sensor_id = sensors[idx];
out[idx].bsp_data = MaxFan::new_const(idx as u8);
out[idx].cur_state = FanState::Present(FanPresentState::Unpolled);
out[idx].presence_acked = true;
idx += 1;
}
Expand Down
9 changes: 2 additions & 7 deletions task/thermal/src/bsp/cosmo_ab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ pub use drv_cpu_seq_api::SeqError;
use drv_cpu_seq_api::{PowerState, Sequencer, StateChangeReason};
use drv_i2c_devices::max31790::I2cWatchdog;
use task_sensor_api::{Sensor, SensorId};
use task_thermal_api::{
SANYO_DENKI_FAN_PROPERTIES, SensorReadError, ThermalError,
ThermalProperties,
};
use task_thermal_api::{ThermalError, ThermalProperties};
use userlib::{
TaskId, task_slot,
units::{Celsius, PWMDuty},
Expand Down Expand Up @@ -126,9 +123,7 @@ impl crate::control::BspInterface for Bsp {
if let Ok(fctl) = self.fctrl.try_initialize() {
for fan in self.fans.iter_mut() {
let bsp_data = fan.bsp_data;
fan.poll_rpm_with(&SANYO_DENKI_FAN_PROPERTIES, || {
fctl.fan_rpm(bsp_data).map_err(SensorReadError::I2cError)
});
fan.poll_rpm_with(|| fctl.fan_rpm(bsp_data));
}
}

Expand Down
9 changes: 2 additions & 7 deletions task/thermal/src/bsp/gimlet_bcdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ pub use drv_cpu_seq_api::SeqError;
use drv_cpu_seq_api::{PowerState, Sequencer, StateChangeReason};
use drv_i2c_devices::max31790::I2cWatchdog;
use task_sensor_api::{Sensor, SensorId};
use task_thermal_api::{
SANYO_DENKI_FAN_PROPERTIES, SensorReadError, ThermalError,
ThermalProperties,
};
use task_thermal_api::{ThermalError, ThermalProperties};
use userlib::{
TaskId, task_slot,
units::{Celsius, PWMDuty},
Expand Down Expand Up @@ -171,9 +168,7 @@ impl crate::control::BspInterface for Bsp {
if let Ok(fctl) = self.fctrl.try_initialize() {
for fan in self.fans.iter_mut() {
let bsp_data = fan.bsp_data;
fan.poll_rpm_with(&SANYO_DENKI_FAN_PROPERTIES, || {
fctl.fan_rpm(bsp_data).map_err(SensorReadError::I2cError)
});
fan.poll_rpm_with(|| fctl.fan_rpm(bsp_data));
}
}

Expand Down
9 changes: 2 additions & 7 deletions task/thermal/src/bsp/grapefruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use crate::control::{ActiveInputState, MiscSensorPollingOutcome};
use crate::control::{ChannelType, PidConfig};
use drv_i2c_devices::max31790::I2cWatchdog;
use task_sensor_api::SensorId;
use task_thermal_api::{
SANYO_DENKI_FAN_PROPERTIES, SensorReadError, ThermalError,
ThermalProperties,
};
use task_thermal_api::{ThermalError, ThermalProperties};
use userlib::TaskId;
use userlib::units::{Celsius, PWMDuty};

Expand Down Expand Up @@ -91,9 +88,7 @@ impl crate::control::BspInterface for Bsp {
if let Ok(fctl) = self.fctrl.try_initialize() {
for fan in self.fans.iter_mut() {
let bsp_data = fan.bsp_data;
fan.poll_rpm_with(&SANYO_DENKI_FAN_PROPERTIES, || {
fctl.fan_rpm(bsp_data).map_err(SensorReadError::I2cError)
});
fan.poll_rpm_with(|| fctl.fan_rpm(bsp_data));
}
}

Expand Down
72 changes: 25 additions & 47 deletions task/thermal/src/bsp/sidecar_bcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ use crate::control::{
DynamicTemperatureState, MiscSensorPollingOutcome, PidConfig,
TimestampedTemperatureReading,
};
use drv_i2c_devices::max31790::Fan as MaxFan;
use drv_i2c_devices::max31790::Max31790;
use drv_i2c_devices::tmp451::*;
pub use drv_sidecar_seq_api::SeqError;
use drv_sidecar_seq_api::{Sequencer, TofinoSeqState, TofinoSequencerPolicy};
use ringbuf::ringbuf_entry_root;
use task_sensor_api::SensorId;
use task_thermal_api::ThermalError;
use task_thermal_api::{
SANYO_DENKI_FAN_PROPERTIES, SensorReadError, ThermalProperties,
};
use task_thermal_api::ThermalProperties;
use task_thermal_api::{SANYO_DENKI_FAN_PROPERTIES, ThermalError};
use userlib::{TaskId, task_slot, units::Celsius};

include!(concat!(env!("OUT_DIR"), "/i2c_config.rs"));
Expand Down Expand Up @@ -155,17 +154,13 @@ impl crate::control::BspInterface for Bsp {
if let Ok(fctl) = self.fctrl_east.try_initialize() {
for fan in east.iter_mut() {
let bsp_data = fan.bsp_data;
fan.poll_rpm_with(&SANYO_DENKI_FAN_PROPERTIES, || {
fctl.fan_rpm(bsp_data).map_err(SensorReadError::I2cError)
});
fan.poll_rpm_with(|| fctl.fan_rpm(bsp_data));
}
}
if let Ok(fctl) = self.fctrl_west.try_initialize() {
for fan in west.iter_mut() {
let bsp_data = fan.bsp_data;
fan.poll_rpm_with(&SANYO_DENKI_FAN_PROPERTIES, || {
fctl.fan_rpm(bsp_data).map_err(SensorReadError::I2cError)
});
fan.poll_rpm_with(|| fctl.fan_rpm(bsp_data));
}
}

Expand Down Expand Up @@ -521,40 +516,23 @@ const MISC_SENSORS: [TemperatureSensor; NUM_TEMPERATURE_SENSORS] = [
// 5 West NW 3 (4)
// 6 West WSW 0 (1)
// 7 West WNW 1 (2)
type Fan = crate::control::Fan<drv_i2c_devices::max31790::Fan>;
const FANS: [Fan; NUM_FANS] = [
// EAST FANS
Fan::new(
sensors::MAX31790_SPEED_SENSORS[0],
drv_i2c_devices::max31790::Fan::new_const(2),
),
Fan::new(
sensors::MAX31790_SPEED_SENSORS[1],
drv_i2c_devices::max31790::Fan::new_const(3),
),
Fan::new(
sensors::MAX31790_SPEED_SENSORS[2],
drv_i2c_devices::max31790::Fan::new_const(0),
),
Fan::new(
sensors::MAX31790_SPEED_SENSORS[3],
drv_i2c_devices::max31790::Fan::new_const(1),
),
// WEST FANS
Fan::new(
sensors::MAX31790_SPEED_SENSORS[4],
drv_i2c_devices::max31790::Fan::new_const(2),
),
Fan::new(
sensors::MAX31790_SPEED_SENSORS[5],
drv_i2c_devices::max31790::Fan::new_const(3),
),
Fan::new(
sensors::MAX31790_SPEED_SENSORS[6],
drv_i2c_devices::max31790::Fan::new_const(0),
),
Fan::new(
sensors::MAX31790_SPEED_SENSORS[7],
drv_i2c_devices::max31790::Fan::new_const(1),
),
];
type Fan = crate::control::Fan<MaxFan>;
const FAN_ORDER: [u8; NUM_FANS] = [2, 3, 0, 1, 2, 3, 0, 1];
const fn make_fans() -> [Fan; NUM_FANS] {
const ONE_FAN: Fan = Fan::new(
SensorId::new(0),
SANYO_DENKI_FAN_PROPERTIES,
MaxFan::new_const(0),
);
let mut fans = [ONE_FAN; NUM_FANS];
let mut idx = 0;
while idx < NUM_FANS {
fans[idx].rpm_sensor_id = sensors::MAX31790_SPEED_SENSORS[idx];
fans[idx].bsp_data = MaxFan::new_const(FAN_ORDER[idx]);
idx += 1;
}

fans
}

const FANS: [Fan; NUM_FANS] = make_fans();
Loading
Loading