satman: moved i2c to libboard_zynq (no wrapper)

This commit is contained in:
mwojcik 2021-07-23 14:45:48 +02:00
parent b963bbbf77
commit 3af0ee6242
1 changed files with 17 additions and 15 deletions

View File

@ -5,7 +5,7 @@
extern crate log; extern crate log;
use core::convert::TryFrom; use core::convert::TryFrom;
use board_misoc::{i2c}; // <- port, use libboard_zynq use libboard_zynq::i2c::I2c; // not using a wrapper like runtime
use libboard_zynq::timer::GlobalTimer; use libboard_zynq::timer::GlobalTimer;
#[cfg(has_si5324)] #[cfg(has_si5324)]
use libboard_artiq::si5324; use libboard_artiq::si5324;
@ -78,7 +78,7 @@ macro_rules! forward {
fn process_aux_packet(_repeaters: &mut [repeater::Repeater], fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
_routing_table: &mut drtio_routing::RoutingTable, _rank: &mut u8, _routing_table: &mut drtio_routing::RoutingTable, _rank: &mut u8,
packet: drtioaux::Packet) -> Result<(), drtioaux::Error<!>> { packet: drtioaux::Packet, timer: GlobalTimer, i2c: I2c) -> Result<(), drtioaux::Error<!>> {
// In the code below, *_chan_sel_write takes an u8 if there are fewer than 256 channels, // In the code below, *_chan_sel_write takes an u8 if there are fewer than 256 channels,
// and u16 otherwise; hence the `as _` conversion. // and u16 otherwise; hence the `as _` conversion.
match packet { match packet {
@ -87,7 +87,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
drtioaux::Packet::ResetRequest => { drtioaux::Packet::ResetRequest => {
info!("resetting RTIO"); info!("resetting RTIO");
drtiosat_reset(true); drtiosat_reset(true);
clock::spin_us(100); timer.delay_us(100);
drtiosat_reset(false); drtiosat_reset(false);
for rep in _repeaters.iter() { for rep in _repeaters.iter() {
if let Err(e) = rep.rtio_reset() { if let Err(e) = rep.rtio_reset() {
@ -245,22 +245,22 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
drtioaux::Packet::I2cStartRequest { destination: _destination, busno } => { drtioaux::Packet::I2cStartRequest { destination: _destination, busno } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet); forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
let succeeded = i2c::start(busno).is_ok(); let succeeded = i2c.start(busno).is_ok();
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded }) drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
} }
drtioaux::Packet::I2cRestartRequest { destination: _destination, busno } => { drtioaux::Packet::I2cRestartRequest { destination: _destination, busno } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet); forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
let succeeded = i2c::restart(busno).is_ok(); let succeeded = i2c.restart(busno).is_ok();
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded }) drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
} }
drtioaux::Packet::I2cStopRequest { destination: _destination, busno } => { drtioaux::Packet::I2cStopRequest { destination: _destination, busno } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet); forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
let succeeded = i2c::stop(busno).is_ok(); let succeeded = i2c.stop(busno).is_ok();
drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded }) drtioaux::send(0, &drtioaux::Packet::I2cBasicReply { succeeded: succeeded })
} }
drtioaux::Packet::I2cWriteRequest { destination: _destination, busno, data } => { drtioaux::Packet::I2cWriteRequest { destination: _destination, busno, data } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet); forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
match i2c::write(busno, data) { match i2c.write(busno, data) {
Ok(ack) => drtioaux::send(0, Ok(ack) => drtioaux::send(0,
&drtioaux::Packet::I2cWriteReply { succeeded: true, ack: ack }), &drtioaux::Packet::I2cWriteReply { succeeded: true, ack: ack }),
Err(_) => drtioaux::send(0, Err(_) => drtioaux::send(0,
@ -269,7 +269,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
} }
drtioaux::Packet::I2cReadRequest { destination: _destination, busno, ack } => { drtioaux::Packet::I2cReadRequest { destination: _destination, busno, ack } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet); forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
match i2c::read(busno, ack) { match i2c.read(busno, ack) {
Ok(data) => drtioaux::send(0, Ok(data) => drtioaux::send(0,
&drtioaux::Packet::I2cReadReply { succeeded: true, data: data }), &drtioaux::Packet::I2cReadReply { succeeded: true, data: data }),
Err(_) => drtioaux::send(0, Err(_) => drtioaux::send(0,
@ -315,11 +315,12 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
} }
fn process_aux_packets(repeaters: &mut [repeater::Repeater], fn process_aux_packets(repeaters: &mut [repeater::Repeater],
routing_table: &mut drtio_routing::RoutingTable, rank: &mut u8) { routing_table: &mut drtio_routing::RoutingTable, rank: &mut u8,
timer::GlobalTimer, i2c: I2c) {
let result = let result =
drtioaux::recv(0).and_then(|packet| { drtioaux::recv(0).and_then(|packet| {
if let Some(packet) = packet { if let Some(packet) = packet {
process_aux_packet(repeaters, routing_table, rank, packet) process_aux_packet(repeaters, routing_table, rank, packet, timer, i2c)
} else { } else {
Ok(()) Ok(())
} }
@ -431,8 +432,9 @@ pub extern fn main() -> i32 {
info!("software ident {}", csr::CONFIG_IDENTIFIER_STR); info!("software ident {}", csr::CONFIG_IDENTIFIER_STR);
info!("gateware ident {}", identifier_read(&mut [0; 64])); info!("gateware ident {}", identifier_read(&mut [0; 64]));
#[cfg(has_i2c)] let mut i2c = I2c::i2c0();
i2c::init().expect("I2C initialization failed"); // port i2c.init().expect("I2C initialization failed");
//see if below is applicable (probably not - not kasli) //see if below is applicable (probably not - not kasli)
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))] #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
let (mut io_expander0, mut io_expander1); let (mut io_expander0, mut io_expander1);
@ -469,7 +471,7 @@ pub extern fn main() -> i32 {
unsafe { unsafe {
csr::drtio_transceiver::txenable_write(0xffffffffu32 as _); csr::drtio_transceiver::txenable_write(0xffffffffu32 as _);
} }
init_rtio_crg(); init_rtio_crg(timer);
#[cfg(has_drtio_routing)] #[cfg(has_drtio_routing)]
let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()]; let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()];
@ -510,9 +512,9 @@ pub extern fn main() -> i32 {
while drtiosat_link_rx_up() { while drtiosat_link_rx_up() {
drtiosat_process_errors(); drtiosat_process_errors();
process_aux_packets(&mut repeaters, &mut routing_table, &mut rank); process_aux_packets(&mut repeaters, &mut routing_table, &mut rank, timer, i2c);
for mut rep in repeaters.iter_mut() { for mut rep in repeaters.iter_mut() {
rep.service(&routing_table, rank); rep.service(&routing_table, rank, timer);
} }
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))] #[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
{ {