implement SFP0..3 LED indication (#231) #258
|
@ -10,6 +10,7 @@ from migen.genlib.cdc import MultiReg
|
||||||
from migen_axi.integration.soc_core import SoCCore
|
from migen_axi.integration.soc_core import SoCCore
|
||||||
from migen_axi.platforms import kasli_soc
|
from migen_axi.platforms import kasli_soc
|
||||||
from misoc.interconnect.csr import *
|
from misoc.interconnect.csr import *
|
||||||
|
from misoc.cores import virtual_leds
|
||||||
from misoc.integration import cpu_interface
|
from misoc.integration import cpu_interface
|
||||||
|
|
||||||
from artiq.coredevice import jsondesc
|
from artiq.coredevice import jsondesc
|
||||||
|
@ -321,6 +322,11 @@ class GenericMaster(SoCCore):
|
||||||
self.config["HAS_GRABBER"] = None
|
self.config["HAS_GRABBER"] = None
|
||||||
self.add_csr_group("grabber", self.grabber_csr_group)
|
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):
|
class GenericSatellite(SoCCore):
|
||||||
def __init__(self, description, acpki=False):
|
def __init__(self, description, acpki=False):
|
||||||
|
@ -480,6 +486,11 @@ class GenericSatellite(SoCCore):
|
||||||
self.add_csr_group("grabber", self.grabber_csr_group)
|
self.add_csr_group("grabber", self.grabber_csr_group)
|
||||||
# no RTIO CRG here
|
# 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):
|
def write_mem_file(soc, filename):
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w") as f:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use libboard_zynq::i2c;
|
use libboard_zynq::i2c;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
|
use crate::pl::csr;
|
||||||
|
|
||||||
// Only the bare minimum registers. Bits/IO connections equivalent between IC types.
|
// Only the bare minimum registers. Bits/IO connections equivalent between IC types.
|
||||||
struct Registers {
|
struct Registers {
|
||||||
// PCA9539 equivalent register names in comments
|
// PCA9539 equivalent register names in comments
|
||||||
|
@ -31,6 +33,7 @@ const IODIR1: [u8; 2] = [
|
||||||
|
|
||||||
pub struct IoExpander {
|
pub struct IoExpander {
|
||||||
address: u8,
|
address: u8,
|
||||||
|
virtual_led_mapping: &'static [(u8, u8, u8)],
|
||||||
iodir: [u8; 2],
|
iodir: [u8; 2],
|
||||||
out_current: [u8; 2],
|
out_current: [u8; 2],
|
||||||
out_target: [u8; 2],
|
out_target: [u8; 2],
|
||||||
|
@ -39,11 +42,18 @@ pub struct IoExpander {
|
||||||
|
|
||||||
impl IoExpander {
|
impl IoExpander {
|
||||||
pub fn new(i2c: &mut i2c::I2c, index: u8) -> Result<Self, &'static str> {
|
pub fn new(i2c: &mut i2c::I2c, index: u8) -> Result<Self, &'static str> {
|
||||||
|
#[cfg(hw_rev = "v1.0")]
|
||||||
|
const VIRTUAL_LED_MAPPING0: [(u8, u8, u8); 2] = [(0, 0, 6), (1, 1, 6)];
|
||||||
|
#[cfg(hw_rev = "v1.1")]
|
||||||
|
const VIRTUAL_LED_MAPPING0: [(u8, u8, u8); 2] = [(0, 0, 7), (1, 1, 6)];
|
||||||
|
|
||||||
|
const VIRTUAL_LED_MAPPING1: [(u8, u8, u8); 2] = [(2, 0, 6), (3, 1, 6)];
|
||||||
|
|
||||||
// Both expanders on SHARED I2C bus
|
// Both expanders on SHARED I2C bus
|
||||||
let mut io_expander = match index {
|
let mut io_expander = match index {
|
||||||
0 => IoExpander {
|
0 => IoExpander {
|
||||||
address: 0x40,
|
address: 0x40,
|
||||||
|
virtual_led_mapping: &VIRTUAL_LED_MAPPING0,
|
||||||
iodir: IODIR0,
|
iodir: IODIR0,
|
||||||
out_current: [0; 2],
|
out_current: [0; 2],
|
||||||
out_target: [0; 2],
|
out_target: [0; 2],
|
||||||
|
@ -56,6 +66,7 @@ impl IoExpander {
|
||||||
},
|
},
|
||||||
1 => IoExpander {
|
1 => IoExpander {
|
||||||
address: 0x42,
|
address: 0x42,
|
||||||
|
virtual_led_mapping: &VIRTUAL_LED_MAPPING1,
|
||||||
iodir: IODIR1,
|
iodir: IODIR1,
|
||||||
out_current: [0; 2],
|
out_current: [0; 2],
|
||||||
out_target: [0; 2],
|
out_target: [0; 2],
|
||||||
|
@ -143,6 +154,12 @@ impl IoExpander {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn service(&mut self, i2c: &mut i2c::I2c) -> Result<(), &'static str> {
|
pub fn service(&mut self, i2c: &mut i2c::I2c) -> Result<(), &'static str> {
|
||||||
|
#[cfg(has_virtual_leds)]
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
if self.out_target != self.out_current {
|
if self.out_target != self.out_current {
|
||||||
self.select(i2c)?;
|
self.select(i2c)?;
|
||||||
if self.out_target[0] != self.out_current[0] {
|
if self.out_target[0] != self.out_current[0] {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
use core::cell::RefCell;
|
||||||
use log::{info, warn, error};
|
use log::{info, warn, error};
|
||||||
|
|
||||||
use libboard_zynq::{timer::GlobalTimer, mpcore, gic};
|
use libboard_zynq::{timer::GlobalTimer, mpcore, gic};
|
||||||
|
@ -91,6 +92,24 @@ async fn report_async_rtio_errors() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "target_kasli_soc")]
|
||||||
|
async fn io_expanders_service(
|
||||||
|
i2c_bus: RefCell<&mut libboard_zynq::i2c::I2c>,
|
||||||
|
io_expander0: RefCell<io_expander::IoExpander>,
|
||||||
|
io_expander1: RefCell<io_expander::IoExpander>,
|
||||||
|
) {
|
||||||
|
loop {
|
||||||
|
task::r#yield().await;
|
||||||
|
io_expander0
|
||||||
|
.borrow_mut()
|
||||||
|
.service(&mut i2c_bus.borrow_mut())
|
||||||
|
.expect("I2C I/O expander #0 service failed");
|
||||||
|
io_expander1
|
||||||
|
.borrow_mut()
|
||||||
|
.service(&mut i2c_bus.borrow_mut())
|
||||||
|
.expect("I2C I/O expander #1 service failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
static mut LOG_BUFFER: [u8; 1<<17] = [0; 1<<17];
|
static mut LOG_BUFFER: [u8; 1<<17] = [0; 1<<17];
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -149,5 +168,11 @@ pub fn main_core0() {
|
||||||
|
|
||||||
task::spawn(report_async_rtio_errors());
|
task::spawn(report_async_rtio_errors());
|
||||||
|
|
||||||
|
#[cfg(feature = "target_kasli_soc")]
|
||||||
|
task::spawn(io_expanders_service(
|
||||||
|
RefCell::new(i2c_bus),
|
||||||
|
RefCell::new(io_expander0),
|
||||||
|
RefCell::new(io_expander1),
|
||||||
|
));
|
||||||
comms::main(timer, cfg);
|
comms::main(timer, cfg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -524,6 +524,16 @@ pub extern fn main_core0() -> i32 {
|
||||||
for mut rep in repeaters.iter_mut() {
|
for mut rep in repeaters.iter_mut() {
|
||||||
rep.service(&routing_table, rank, &mut timer);
|
rep.service(&routing_table, rank, &mut timer);
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "target_kasli_soc")]
|
||||||
|
{
|
||||||
|
io_expander0
|
||||||
|
.service(&mut i2c)
|
||||||
|
.expect("I2C I/O expander #0 service failed");
|
||||||
|
io_expander1
|
||||||
|
.service(&mut i2c)
|
||||||
|
.expect("I2C I/O expander #1 service failed");
|
||||||
|
}
|
||||||
|
|
||||||
hardware_tick(&mut hardware_tick_ts, &mut timer);
|
hardware_tick(&mut hardware_tick_ts, &mut timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,6 +555,15 @@ pub extern fn main_core0() -> i32 {
|
||||||
for mut rep in repeaters.iter_mut() {
|
for mut rep in repeaters.iter_mut() {
|
||||||
rep.service(&routing_table, rank, &mut timer);
|
rep.service(&routing_table, rank, &mut timer);
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "target_kasli_soc")]
|
||||||
|
{
|
||||||
|
io_expander0
|
||||||
|
.service(&mut i2c)
|
||||||
|
.expect("I2C I/O expander #0 service failed");
|
||||||
|
io_expander1
|
||||||
|
.service(&mut i2c)
|
||||||
|
.expect("I2C I/O expander #1 service failed");
|
||||||
|
}
|
||||||
hardware_tick(&mut hardware_tick_ts, &mut timer);
|
hardware_tick(&mut hardware_tick_ts, &mut timer);
|
||||||
if drtiosat_tsc_loaded() {
|
if drtiosat_tsc_loaded() {
|
||||||
info!("TSC loaded from uplink");
|
info!("TSC loaded from uplink");
|
||||||
|
|
Loading…
Reference in New Issue