Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bsp::preinit() on PSC b/c #1296

Merged
merged 3 commits into from
Apr 18, 2023
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
2 changes: 2 additions & 0 deletions task/net/src/bsp/gimletlet_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ impl bsp_support::Bsp for BspImpl {
// This system wants to be woken periodically to do logging
const WAKE_INTERVAL: Option<u64> = Some(500);

fn preinit() {}

fn configure_ethernet_pins(sys: &Sys) {
pins::RmiiPins {
refclk: Port::A.pin(1),
Expand Down
2 changes: 2 additions & 0 deletions task/net/src/bsp/gimletlet_nic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ impl bsp_support::Bsp for BspImpl {
// This system wants to be woken periodically to do logging
const WAKE_INTERVAL: Option<u64> = Some(5000);

fn preinit() {}

fn configure_ethernet_pins(sys: &Sys) {
pins::RmiiPins {
refclk: Port::A.pin(1),
Expand Down
2 changes: 2 additions & 0 deletions task/net/src/bsp/nucleo_h7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const PHYADDR: u8 = 0x0;
pub struct BspImpl;

impl crate::bsp_support::Bsp for BspImpl {
fn preinit() {}

fn configure_ethernet_pins(sys: &Sys) {
pins::RmiiPins {
refclk: Port::A.pin(1),
Expand Down
33 changes: 32 additions & 1 deletion task/net/src/bsp/psc_bc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ compile_error!("this BSP requires the ksz8463 and mgmt features");

use crate::{
bsp_support::{self, Ksz8463},
mgmt, pins,
mgmt, notifications, pins,
};
use drv_psc_seq_api::PowerState;
use drv_spi_api::SpiServer;
use drv_stm32h7_eth as eth;
use drv_stm32xx_sys_api::{Alternate, Port, Sys};
use task_jefe_api::Jefe;
use task_net_api::{
ManagementCounters, ManagementLinkStatus, MgmtError, PhyError,
};
use userlib::{sys_recv_closed, task_slot, FromPrimitive, TaskId};
use vsc7448_pac::types::PhyRegisterAddress;

task_slot!(JEFE, jefe);

////////////////////////////////////////////////////////////////////////////////

pub struct BspImpl(mgmt::Bsp);
Expand Down Expand Up @@ -53,6 +58,32 @@ impl bsp_support::Bsp for BspImpl {
.configure(sys);
}

fn preinit() {
// Wait for the sequencer to turn read our VPD.
let jefe = Jefe::from(JEFE.get_task_id());

loop {
// This laborious list is intended to ensure that new power states
// have to be added explicitly here.
match PowerState::from_u32(jefe.get_state()) {
Some(PowerState::A2) => {
break;
}
Some(PowerState::Init) | None => {
// This happens before we're in a valid power state.
//
// Only listen to our Jefe notification. Discard any error
// since this can't fail but the compiler doesn't know that.
let _ = sys_recv_closed(
&mut [],
notifications::JEFE_STATE_CHANGE_MASK,
TaskId::KERNEL,
);
}
}
}
}

fn new(eth: &eth::Ethernet, sys: &Sys) -> Self {
let spi = bsp_support::claim_spi(sys);
let ksz8463_dev = spi.device(drv_spi_api::devices::KSZ8463);
Expand Down
4 changes: 2 additions & 2 deletions task/net/src/bsp_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pub trait Bsp: Sized {
const WAKE_INTERVAL: Option<u64> = None;

/// Opportunity to do any work before the Ethernet peripheral is turned on.
/// By default this does nothing, override it if necessary.
fn preinit() {}
fn preinit();

/// Stateless function to configure ethernet pins before the Bsp struct
/// is actually constructed
fn configure_ethernet_pins(sys: &Sys);
Expand Down