use csr::virtual_leds for SFP0..3 LED indication

MorganTL 2023-07-31 10:49:54 +08:00
parent c5e21a573c
commit f3d03b2989
4 changed files with 39 additions and 39 deletions

View File

@ -10,6 +10,7 @@ from migen.genlib.cdc import MultiReg
from migen_axi.integration.soc_core import SoCCore
from migen_axi.platforms import kasli_soc
from misoc.interconnect.csr import *
from misoc.cores import virtual_leds
from misoc.integration import cpu_interface
from artiq.coredevice import jsondesc
@ -307,6 +308,14 @@ class GenericMaster(SoCCore):
if has_grabber:
self.rustc_cfg["has_grabber"] = None
self.add_csr_group("grabber", self.grabber_csr_group)
self.submodules.virtual_leds = virtual_leds.VirtualLeds()
self.csr_devices.append("virtual_leds")
self.comb += [self.virtual_leds.get(i).eq(channel.rx_ready)
for i, channel in enumerate(self.drtio_transceiver.channels)]
class GenericSatellite(SoCCore):
@ -472,7 +481,13 @@ class GenericSatellite(SoCCore):
self.rustc_cfg["has_grabber"] = None
self.add_csr_group("grabber", self.grabber_csr_group)
# no RTIO CRG here
self.submodules.virtual_leds = virtual_leds.VirtualLeds()
self.csr_devices.append("virtual_leds")
self.comb += [self.virtual_leds.get(i).eq(channel.rx_ready)
for i, channel in enumerate(self.drtio_transceiver.channels)]
def write_mem_file(soc, filename):
with open(filename, "w") as f:

View File

@ -1,6 +1,8 @@
use libboard_zynq::i2c;
use log::info;
use crate::pl::csr;
// Only the bare minimum registers. Bits/IO connections equivalent between IC types.
struct Registers {
// PCA9539 equivalent register names in comments
@ -14,7 +16,6 @@ struct Registers {
const IO_DIR_INPUT_ALL: u8 = 0xFF;
const IO_DIR_OUT_SFP_TX_DISABLE: u8 = !0x02;
const IO_DIR_OUT_SFP_LED: u8 = !0x40;
//SFP0 LED has different place in v1.1
#[cfg(hw_rev = "v1.0")]
const IO_DIR_OUT_SFP0_LED: u8 = !0x40;
#[cfg(hw_rev = "v1.1")]
@ -163,15 +164,12 @@ impl<'a> IoExpander<'a> {
}
}
pub fn led_update(&mut self, led_state: u8) {
for (led_num, port, bit) in self.virtual_led_mapping.iter() {
let level = (led_state >> led_num) & 1;
pub fn service(&mut self) -> Result<(), &'static str> {
for (led, port, bit) in self.virtual_led_mapping.iter() {
let level = unsafe { csr::virtual_leds::status_read() >> led & 1 };
self.set(*port, *bit, level != 0);
}
self.service().unwrap();
}
pub fn service(&mut self) -> Result<(), &'static str> {
if self.out_target != self.out_current {
self.select()?;
if self.out_target[0] != self.out_current[0] {

View File

@ -113,7 +113,6 @@ fn wait_for_rtio_led_change() -> nb::Result<(), Void> {
let len: usize = pl::csr::DRTIO.len();
READ_RTIO_LED = 0;
for linkno in 0..len {
//let linkno = linkno as usize;
READ_RTIO_LED |= (pl::csr::DRTIO[linkno].rx_up_read)() << linkno;
}
if READ_RTIO_LED != SEEN_RTIO_LED {
@ -125,17 +124,15 @@ fn wait_for_rtio_led_change() -> nb::Result<(), Void> {
}
#[cfg(all(feature = "target_kasli_soc", has_drtio))]
async fn async_rtio_led() {
loop {
let _ = block_async!(wait_for_rtio_led_change()).await;
unsafe {
let i2c = (&mut i2c::I2C_BUS).as_mut().unwrap();
for expander_i in 0..=1 {
let mut io_expander = io_expander::IoExpander::new(i2c, expander_i).unwrap();
io_expander.led_update(READ_RTIO_LED);
}
SEEN_RTIO_LED = READ_RTIO_LED;
};
}
let _ = block_async!(wait_for_rtio_led_change()).await;
unsafe {
let i2c = (&mut i2c::I2C_BUS).as_mut().unwrap();
for expander_i in 0..=1 {
let mut io_expander = io_expander::IoExpander::new(i2c, expander_i).unwrap();
io_expander.service().expect("I2C I/O expander service failed");
}
SEEN_RTIO_LED = READ_RTIO_LED;
};
}
static mut LOG_BUFFER: [u8; 1 << 17] = [0; 1 << 17];

View File

@ -591,23 +591,6 @@ const SI5324_SETTINGS: si5324::FrequencySettings = si5324::FrequencySettings {
crystal_as_ckin2: true,
};
#[cfg(all(feature = "target_kasli_soc", has_drtio))]
fn sfp_leds_update(i2c: &mut I2c) {
let mut virtual_leds;
unsafe {
virtual_leds = csr::drtiosat::rx_up_read();
let len: usize = csr::DRTIOREP.len();
for linkno in 0..len {
virtual_leds |= (csr::DRTIOREP[linkno].rx_up_read)() << (linkno + 1);
}
}
for expander_i in 0..=1 {
let mut io_expander = io_expander::IoExpander::new(i2c, expander_i).unwrap();
io_expander.led_update(virtual_leds);
}
}
static mut LOG_BUFFER: [u8; 1 << 17] = [0; 1 << 17];
#[no_mangle]
@ -680,7 +663,11 @@ pub extern "C" fn main_core0() -> i32 {
rep.service(&routing_table, rank, &mut timer);
}
#[cfg(all(feature = "target_kasli_soc", has_drtio))]
sfp_leds_update(&mut i2c);
for expander_i in 0..=1 {
let mut io_expander = io_expander::IoExpander::new(&mut i2c, expander_i).unwrap();
io_expander.service().expect("I2C I/O expander service failed")
}
hardware_tick(&mut hardware_tick_ts, &mut timer);
}
@ -718,7 +705,10 @@ pub extern "C" fn main_core0() -> i32 {
rep.service(&routing_table, rank, &mut timer);
}
#[cfg(all(feature = "target_kasli_soc", has_drtio))]
sfp_leds_update(&mut i2c);
for expander_i in 0..=1 {
let mut io_expander = io_expander::IoExpander::new(&mut i2c, expander_i).unwrap();
io_expander.service().expect("I2C I/O expander service failed")
}
hardware_tick(&mut hardware_tick_ts, &mut timer);
if drtiosat_tsc_loaded() {
info!("TSC loaded from uplink");