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

Merged
sb10q merged 10 commits from morgan/artiq-zynq:feature into master 2023-08-28 16:08:11 +08:00
2 changed files with 3 additions and 3 deletions
Showing only changes of commit f917c62948 - Show all commits

View File

@ -109,7 +109,7 @@ static mut LAST_VIRTUAL_LED_STATUS: u8 = 0;
fn wait_for_virtual_leds_change() -> nb::Result<(), Void> {
unsafe {
morgan marked this conversation as resolved Outdated
Outdated
Review

The only unsafe line is the next one, no?

The only unsafe line is the next one, no?

LAST_VIRTUAL_LED_STATUS is a static mut. So it need an unsafe too

```LAST_VIRTUAL_LED_STATUS``` is a static mut. So it need an unsafe too
Outdated
Review

I don't think this should be gated on has_drtio.

I don't think this should be gated on has_drtio.
if pl::csr::virtual_leds::status_read() != LAST_VIRTUAL_LED_STATUS {
LAST_VIRTUAL_LED_STATUS = pl::csr::virtual_leds::status_read();
LAST_VIRTUAL_LED_STATUS = pl::csr::virtual_leds::status_read();
morgan marked this conversation as resolved Outdated

Could save a CSR call by getting the value before the if

Could save a CSR call by getting the value before the ``if``
Ok(())
} else {
Err(nb::Error::WouldBlock)
@ -122,7 +122,7 @@ async fn async_rtio_led() {
let i2c1 = unsafe { (&mut i2c::I2C_BUS).as_mut().unwrap() };
let mut io_expander0 = io_expander::IoExpander::new(i2c0, 0).unwrap();
Outdated
Review

It's confusing to create IO expander objects, which also should be singletons and do more than controlling LEDs, into a function whose name indicates it is about LEDs.

It's confusing to create IO expander objects, which also should be singletons and do more than controlling LEDs, into a function whose name indicates it is about LEDs.
Outdated
Review

As I told you before, those I/O expander objects should be created only once in the entire firmware.

Additionally, you create them once with i2c::I2C_BUS and once with &mut *i2c_ptr, which is inconsistent.

As I told you before, those I/O expander objects should be created only once in the entire firmware. Additionally, you create them once with ``i2c::I2C_BUS`` and once with ``&mut *i2c_ptr``, which is inconsistent.
let mut io_expander1 = io_expander::IoExpander::new(i2c1, 1).unwrap();
loop{
loop {
morgan marked this conversation as resolved Outdated
Outdated
Review

Just inline it.

 block_async!(|| {
   let current = unsafe { pl::csr::virtual_leds::status_read() };
   ...
Just inline it. ``` block_async!(|| { let current = unsafe { pl::csr::virtual_leds::status_read() }; ... ```
let _ = block_async!(wait_for_virtual_leds_change()).await;
info!("switching");
morgan marked this conversation as resolved Outdated

Debug leftover? Remove pls

Debug leftover? Remove pls
io_expander0.service().expect("I2C I/O expander #0 service failed");

View File

@ -660,7 +660,7 @@ pub extern "C" fn main_core0() -> i32 {
let mut i2c0 = I2c::i2c0();
Outdated
Review

Better than before but is there really no other solution than disabling the borrow checker?

Better than before but is there really no other solution than disabling the borrow checker?
let mut i2c1 = I2c::i2c0();
i2c0.init().expect("I2C0 initialization failed");
i2c1.init().expect("I2C1 initialization failed");
i2c1.init().expect("I2C1 initialization failed");
let mut io_expander0 = io_expander::IoExpander::new(&mut i2c0, 0).unwrap();
let mut io_expander1 = io_expander::IoExpander::new(&mut i2c1, 1).unwrap();