Skip to content

Commit 54164d6

Browse files
committed
start of front io power control BSP WIP
1 parent 14cdd3a commit 54164d6

File tree

14 files changed

+160
-64
lines changed

14 files changed

+160
-64
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drv/front-io-api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum FrontIOError {
3434
InvalidPhysicalToLogicalMap,
3535
InvalidModuleResult,
3636
LedInitFailure,
37+
PowerFault,
3738

3839
#[idol(server_death)]
3940
ServerRestarted,

drv/front-io-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ drv-fpga-api = { path = "../fpga-api" }
1919
drv-fpga-user-api = { path = "../fpga-user-api" }
2020
drv-i2c-api = { path = "../i2c-api" }
2121
drv-i2c-devices = { path = "../i2c-devices" }
22+
drv-sidecar-mainboard-controller = { path = "../../drv/sidecar-mainboard-controller" }
2223
drv-transceivers-api = { path = "../../drv/transceivers-api" }
2324
multitimer = { path = "../../lib/multitimer" }
2425
ringbuf = { path = "../../lib/ringbuf" }

drv/front-io-server/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
6+
build_util::expose_target_board();
67
build_util::build_notifications()?;
78

89
let disposition = build_i2c::Disposition::Devices;

drv/front-io-server/src/bsp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
// This file should never be included; if it is, the build configuration is bad
6+
compile_error!("no BSP for the given target board");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
use drv_fpga_api::{FpgaError, FpgaUserDesign};
6+
use drv_fpga_user_api::power_rail::{PowerRailStatus, RawPowerRailState};
7+
use drv_front_io_api::FrontIOError;
8+
use drv_sidecar_mainboard_controller::{Addr, MainboardController, Reg};
9+
use userlib::task_slot;
10+
11+
task_slot!(MAINBOARD, mainboard);
12+
13+
pub struct Bsp {
14+
fpga: FpgaUserDesign,
15+
}
16+
17+
impl Bsp {
18+
pub fn new() -> Result<Self, FrontIOError> {
19+
Ok(Self {
20+
fpga: FpgaUserDesign::new(
21+
MAINBOARD.get_task_id(),
22+
MainboardController::DEVICE_INDEX,
23+
),
24+
})
25+
}
26+
27+
#[inline]
28+
fn raw_state(&self) -> Result<RawPowerRailState, FpgaError> {
29+
self.fpga.read(Addr::FRONT_IO_STATE)
30+
}
31+
32+
#[inline]
33+
pub fn status(&self) -> Result<PowerRailStatus, FpgaError> {
34+
PowerRailStatus::try_from(self.raw_state()?)
35+
}
36+
37+
pub fn power_good(&self) -> Result<bool, FrontIOError> {
38+
match self.status().map_err(FrontIOError::from)? {
39+
PowerRailStatus::Enabled => Ok(true),
40+
PowerRailStatus::Disabled | PowerRailStatus::RampingUp => Ok(false),
41+
PowerRailStatus::GoodTimeout | PowerRailStatus::Aborted => {
42+
Err(FrontIOError::PowerFault)
43+
}
44+
}
45+
}
46+
47+
pub fn set_power_enable(&self, enable: bool) -> Result<(), FrontIOError> {
48+
self.fpga
49+
.write(
50+
enable.into(),
51+
Addr::FRONT_IO_STATE,
52+
Reg::FRONT_IO_STATE::ENABLE,
53+
)
54+
.map_err(FrontIOError::from)
55+
}
56+
}

drv/front-io-server/src/main.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
#![no_std]
88
#![no_main]
99

10+
#[cfg_attr(
11+
any(
12+
target_board = "sidecar-b",
13+
target_board = "sidecar-c",
14+
target_board = "sidecar-d"
15+
),
16+
path = "bsp/sidecar_bcd.rs"
17+
)]
18+
#[cfg_attr(target_board = "medusa-a", path = "bsp/medusa_a.rs")]
19+
mod bsp;
20+
21+
use crate::bsp::Bsp;
1022
use core::convert::Infallible;
1123
use drv_fpga_api::{DeviceState, FpgaError, WriteOp};
1224
use drv_front_io_api::{
@@ -38,6 +50,9 @@ include!(concat!(env!("OUT_DIR"), "/i2c_config.rs"));
3850
#[derive(Copy, Clone, PartialEq)]
3951
enum Trace {
4052
None,
53+
BspInit,
54+
BspInitComplete,
55+
BspInitFailed,
4156
FpgaInitError(FpgaError),
4257
PhyOscGood,
4358
PhyOscBad,
@@ -69,6 +84,9 @@ enum Trace {
6984
ringbuf!(Trace, 32, Trace::None);
7085

7186
struct ServerImpl {
87+
/// A BSP to help deliver core functionality whose implementation varies from board to board
88+
bsp: Bsp,
89+
7290
/// Handle for the auxflash task
7391
auxflash_task: userlib::TaskId,
7492

@@ -254,6 +272,25 @@ impl ServerImpl {
254272
}
255273

256274
impl idl::InOrderFrontIOImpl for ServerImpl {
275+
/// Enable or disable the front IO power per `enable`
276+
fn set_power_enable(
277+
&mut self,
278+
_: &RecvMessage,
279+
enable: bool,
280+
) -> Result<(), RequestError<FrontIOError>> {
281+
self.bsp
282+
.set_power_enable(enable)
283+
.map_err(RequestError::from)
284+
}
285+
286+
/// Returns if front IO power is good
287+
fn power_good(
288+
&mut self,
289+
_: &RecvMessage,
290+
) -> Result<bool, RequestError<FrontIOError>> {
291+
self.bsp.power_good().map_err(RequestError::from)
292+
}
293+
257294
/// Blow away server state, resulting in a resequencing
258295
fn board_reset(
259296
&mut self,
@@ -794,11 +831,23 @@ impl NotificationHandler for ServerImpl {
794831

795832
impl Default for ServerImpl {
796833
fn default() -> Self {
834+
ringbuf_entry!(Trace::BspInit);
835+
let bsp = match Bsp::new() {
836+
Ok(bsp) => {
837+
ringbuf_entry!(Trace::BspInitComplete);
838+
bsp
839+
}
840+
Err(_) => {
841+
ringbuf_entry!(Trace::BspInitFailed);
842+
panic!();
843+
}
844+
};
797845
let i2c_task = I2C.get_task_id();
798846
let fpga_task = FRONT_IO.get_task_id();
799847
let auxflash_task = AUXFLASH.get_task_id();
800848

801849
ServerImpl {
850+
bsp,
802851
auxflash_task,
803852
controllers: [
804853
FrontIOController::new(fpga_task, 0),

drv/sidecar-mainboard-controller/src/front_io_hsc.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

drv/sidecar-mainboard-controller/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use drv_fpga_api::*;
99
include!(concat!(env!("OUT_DIR"), "/sidecar_mainboard_controller.rs"));
1010

1111
pub mod fan_modules;
12-
pub mod front_io_hsc;
1312
pub mod ignition;
1413
pub mod tofino2;
1514

drv/sidecar-seq-api/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ pub enum SeqError {
3434
SequencerTimeout,
3535
InvalidTofinoVid,
3636
SetVddCoreVoutFailed,
37-
NoFrontIOBoard, // TODO: implement this in the front IO server
38-
FrontIOBoardPowerFault, // TODO: implement this in the front IO server
39-
FrontIOPowerNotGood, // TODO: implement this in the front IO server
37+
NoFrontIOBoard,
38+
FrontIOBoardPowerFault,
39+
FrontIOPowerNotGood,
4040
FrontIOError,
4141

4242
#[idol(server_death)]

0 commit comments

Comments
 (0)