satman: moved i2c to libboard_zynq (no wrapper)

drtio_port
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;
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;
#[cfg(has_si5324)]
use libboard_artiq::si5324;
@ -78,7 +78,7 @@ macro_rules! forward {
fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
_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,
// and u16 otherwise; hence the `as _` conversion.
match packet {
@ -87,7 +87,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
drtioaux::Packet::ResetRequest => {
info!("resetting RTIO");
drtiosat_reset(true);
clock::spin_us(100);
timer.delay_us(100);
drtiosat_reset(false);
for rep in _repeaters.iter() {
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 } => {
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::Packet::I2cRestartRequest { destination: _destination, busno } => {
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::Packet::I2cStopRequest { destination: _destination, busno } => {
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::Packet::I2cWriteRequest { destination: _destination, busno, data } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
match i2c::write(busno, data) {
match i2c.write(busno, data) {
Ok(ack) => drtioaux::send(0,
&drtioaux::Packet::I2cWriteReply { succeeded: true, ack: ack }),
Err(_) => drtioaux::send(0,
@ -269,7 +269,7 @@ fn process_aux_packet(_repeaters: &mut [repeater::Repeater],
}
drtioaux::Packet::I2cReadRequest { destination: _destination, busno, ack } => {
forward!(_routing_table, _destination, *_rank, _repeaters, &packet);
match i2c::read(busno, ack) {
match i2c.read(busno, ack) {
Ok(data) => drtioaux::send(0,
&drtioaux::Packet::I2cReadReply { succeeded: true, data: data }),
Err(_) => drtioaux::send(0,
@ -315,11 +315,12 @@ fn process_aux_packet(_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 =
drtioaux::recv(0).and_then(|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 {
Ok(())
}
@ -431,8 +432,9 @@ pub extern fn main() -> i32 {
info!("software ident {}", csr::CONFIG_IDENTIFIER_STR);
info!("gateware ident {}", identifier_read(&mut [0; 64]));
#[cfg(has_i2c)]
i2c::init().expect("I2C initialization failed"); // port
let mut i2c = I2c::i2c0();
i2c.init().expect("I2C initialization failed");
//see if below is applicable (probably not - not kasli)
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
let (mut io_expander0, mut io_expander1);
@ -469,7 +471,7 @@ pub extern fn main() -> i32 {
unsafe {
csr::drtio_transceiver::txenable_write(0xffffffffu32 as _);
}
init_rtio_crg();
init_rtio_crg(timer);
#[cfg(has_drtio_routing)]
let mut repeaters = [repeater::Repeater::default(); csr::DRTIOREP.len()];
@ -510,9 +512,9 @@ pub extern fn main() -> i32 {
while drtiosat_link_rx_up() {
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() {
rep.service(&routing_table, rank);
rep.service(&routing_table, rank, timer);
}
#[cfg(all(soc_platform = "kasli", hw_rev = "v2.0"))]
{