Skip to content
Open
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
15 changes: 15 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions app/gimlet/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ task-slots = ["net"]
features = ["vlan"]
notifications = ["socket"]

[tasks.drooper]
name = "drooper"
start = true
priority = 6
task-slots = ["i2c_driver"]
notifications = ["timer"]

[config.net.sockets.rpc]
kind = "udp"
owner = {name = "udprpc", notification = "socket"}
Expand Down
7 changes: 7 additions & 0 deletions drv/i2c-devices/src/bmr491.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ impl Bmr491 {
})
}

pub fn set_vout(&self, v: u16) -> Result<(), Error> {
let mut vout = VOUT_COMMAND::CommandData(0);
let value = Volts(v as f32);
vout.set(self.read_mode()?, pmbus::units::Volts(value.0))?;
pmbus_write!(self.device, VOUT_COMMAND, vout)
}

pub fn read_vout(&self) -> Result<Volts, Error> {
let vout = pmbus_read!(self.device, bmr491::READ_VOUT)?;
Ok(Volts(vout.get(self.read_mode()?)?.0))
Expand Down
14 changes: 14 additions & 0 deletions idl/drooper.idol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Interface to the task to droop the IBC voltage.
Interface(
name: "Drooper",
ops: {
"droop": (
doc: "Droop the 12V rails for a given ms time period.",
args: {
"time_ms": "u64",
},
reply: Simple("()"),
idempotent: true,
),
}
)
30 changes: 30 additions & 0 deletions task/drooper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "drooper"
version = "0.1.0"
edition = "2021"

[dependencies]
idol-runtime.workspace = true
num-traits.workspace = true
userlib = { path = "../../sys/userlib", features = ["panic-messages"] }
zerocopy.workspace = true
zerocopy-derive.workspace = true

drv-i2c-devices = { path = "../../drv/i2c-devices" }
drv-i2c-api = { path = "../../drv/i2c-api" }

[build-dependencies]
idol.workspace = true

build-i2c = { path = "../../build/i2c" }

# This section is here to discourage RLS/rust-analyzer from doing test builds,
# since test builds don't work for cross compilation.
[[bin]]
name = "drooper"
test = false
doctest = false
bench = false

[lints]
workspace = true
18 changes: 18 additions & 0 deletions task/drooper/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
idol::Generator::new()
.with_counters(
idol::CounterSettings::default().with_server_counters(false),
)
.build_server_support(
"../../idl/drooper.idol",
"server_stub.rs",
idol::server::ServerStyle::InOrder,
)?;

build_i2c::codegen(build_i2c::Disposition::Devices)?;
Ok(())
}
63 changes: 63 additions & 0 deletions task/drooper/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//!
//! drooper: A task to simulate the IBC droop seen in mfg-quality#140
//!
//! Running this task will cause all U.2s to undergo a PCIe reset event.
//! (Use with caution!)
//!
//! For example, to drop the voltage for 30 ms:
//! $ humility hiffy -c drooper.droop -a time_ms=30
//!

#![no_std]
#![no_main]

use drv_i2c_devices::bmr491::*;

use core::convert::Infallible;
use idol_runtime::RequestError;
use userlib::{task_slot, RecvMessage, UnwrapLite};

task_slot!(I2C, i2c_driver);

#[export_name = "main"]
fn main() -> ! {
let mut server = ServerImpl {};
let mut buffer = [0; idl::INCOMING_SIZE];

loop {
idol_runtime::dispatch(&mut buffer, &mut server);
}
}

struct ServerImpl {}

impl idl::InOrderDrooperImpl for ServerImpl {
fn droop(
&mut self,
_msg: &RecvMessage,
time_ms: u32,
) -> Result<(), RequestError<Infallible>> {
let (device, rail) = i2c_config::pmbus::v12_sys_a2(I2C.get_task_id());
let ibc = Bmr491::new(&device, rail);

// Droop the voltage for the requested time period in ms.
// We pick 9V because it's approximately what we see in the field for mfg-quality#140.
let _ = ibc.set_vout(9);
userlib::hl::sleep_for(time_ms as u64);

// Restore to 12V.
let _ = ibc.set_vout(12);

Ok(())
}
}

mod idl {
include!(concat!(env!("OUT_DIR"), "/server_stub.rs"));
}

include!(concat!(env!("OUT_DIR"), "/i2c_config.rs"));
Loading