From da8817064a64ee72f33f71aee1e69d34f960646e Mon Sep 17 00:00:00 2001 From: newell Date: Fri, 4 Oct 2024 23:45:24 -0700 Subject: [PATCH] Add i2c support --- src/gateware/ebaz4205.py | 57 ++++++++++++++++++++----------- src/libksupport/src/kernel/api.rs | 10 +----- src/libksupport/src/lib.rs | 1 - src/runtime/src/main.rs | 1 - src/runtime/src/rtio_clocking.rs | 6 +++- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/gateware/ebaz4205.py b/src/gateware/ebaz4205.py index 3359a10..be360da 100644 --- a/src/gateware/ebaz4205.py +++ b/src/gateware/ebaz4205.py @@ -73,9 +73,19 @@ _ddr = [ ) ] +# Connector J3 +_i2c = [ + ( + "i2c", + 0, + Subsignal("scl", Pins("U12"), IOStandard("LVCMOS33")), + Subsignal("sda", Pins("V13"), IOStandard("LVCMOS33")), + ) +] + class EBAZ4205(SoCCore): - def __init__(self, rtio_clk=100e6, acpki=False): + def __init__(self, rtio_clk=125e6, acpki=False): self.acpki = acpki platform = ebaz4205.Platform() @@ -86,6 +96,7 @@ class EBAZ4205(SoCCore): ) platform.add_extension(_ps) platform.add_extension(_ddr) + platform.add_extension(_i2c) gmii = platform.request("gmii") platform.add_period_constraint(gmii.rx_clk, 10) @@ -97,12 +108,7 @@ class EBAZ4205(SoCCore): ident = self.__class__.__name__ if self.acpki: ident = "acpki_" + ident - SoCCore.__init__( - self, - platform=platform, - csr_data_width=32, - ident=ident, - ) + SoCCore.__init__(self, platform=platform, csr_data_width=32, ident=ident) fix_serdes_timing_path(platform) self.config["RTIO_FREQUENCY"] = str(rtio_clk / 1e6) platform.add_period_constraint(self.ps7.cd_sys.clk, 10) @@ -128,21 +134,34 @@ class EBAZ4205(SoCCore): # MDIO mdio = platform.request("mdio") - self.comb += [ - mdio.mdc.eq(self.ps7.enet0.enet.mdio.mdc), - ] - - mdio_t = Signal() - self.comb += mdio_t.eq(~self.ps7.enet0.enet.mdio.t_n) + self.comb += mdio.mdc.eq(self.ps7.enet0.enet.mdio.mdc) + self.specials += Instance( + "IOBUF", + i_I=self.ps7.enet0.enet.mdio.o, + io_IO=mdio.mdio, + o_O=self.ps7.enet0.enet.mdio.i, + i_T=~self.ps7.enet0.enet.mdio.t_n, + ) + # I2C + i2c = self.platform.request("i2c") self.specials += [ + # SCL Instance( "IOBUF", - i_I=self.ps7.enet0.enet.mdio.o, - io_IO=mdio.mdio, - o_O=self.ps7.enet0.enet.mdio.i, - i_T=mdio_t, - ) + i_I=self.ps7.i2c0.scl.o, + io_IO=i2c.scl, + o_O=self.ps7.i2c0.scl.i, + i_T=~self.ps7.i2c0.scl.t_n, + ), + # SDA + Instance( + "IOBUF", + i_I=self.ps7.i2c0.sda.o, + io_IO=i2c.sda, + o_O=self.ps7.i2c0.sda.i, + i_T=~self.ps7.i2c0.sda.t_n, + ), ] self.rtio_channels = [] @@ -211,7 +230,7 @@ def main(): parser.add_argument( "-g", default=None, help="build gateware into the specified directory" ) - parser.add_argument("--rtio_clk", default=100e6, help="RTIO Clock Frequency (Hz)") + parser.add_argument("--rtio-clk", default=125e6, help="RTIO Clock Frequency (Hz)") parser.add_argument( "--acpki", default=False, action="store_true", help="enable ACPKI" ) diff --git a/src/libksupport/src/kernel/api.rs b/src/libksupport/src/kernel/api.rs index dc512b5..ef77e43 100644 --- a/src/libksupport/src/kernel/api.rs +++ b/src/libksupport/src/kernel/api.rs @@ -11,9 +11,7 @@ use super::{cache, core1::rtio_get_destination_status, dma, linalg, rpc::{rpc_recv, rpc_send, rpc_send_async}}; -use crate::{eh_artiq, rtio}; -#[cfg(not(feature = "target_ebaz4205"))] -use crate::i2c; +use crate::{eh_artiq, i2c, rtio}; extern "C" { fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int; @@ -111,17 +109,11 @@ pub fn resolve(required: &[u8]) -> Option { api!(cache_put = cache::put), // i2c - #[cfg(not(feature = "target_ebaz4205"))] api!(i2c_start = i2c::start), - #[cfg(not(feature = "target_ebaz4205"))] api!(i2c_restart = i2c::restart), - #[cfg(not(feature = "target_ebaz4205"))] api!(i2c_stop = i2c::stop), - #[cfg(not(feature = "target_ebaz4205"))] api!(i2c_write = i2c::write), - #[cfg(not(feature = "target_ebaz4205"))] api!(i2c_read = i2c::read), - #[cfg(not(feature = "target_ebaz4205"))] api!(i2c_switch_select = i2c::switch_select), // subkernel diff --git a/src/libksupport/src/lib.rs b/src/libksupport/src/lib.rs index 78a2f1d..630f19e 100644 --- a/src/libksupport/src/lib.rs +++ b/src/libksupport/src/lib.rs @@ -21,7 +21,6 @@ pub use pl::csr::rtio_core; use void::Void; pub mod eh_artiq; -#[cfg(not(feature = "target_ebaz4205"))] pub mod i2c; pub mod irq; pub mod kernel; diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index ecfd1c2..dd24e25 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -100,7 +100,6 @@ pub fn main_core0() { info!("gateware ident: {}", identifier_read(&mut [0; 64])); - #[cfg(not(feature = "target_ebaz4205"))] ksupport::i2c::init(); #[cfg(feature = "target_kasli_soc")] { diff --git a/src/runtime/src/rtio_clocking.rs b/src/runtime/src/rtio_clocking.rs index 42cb215..cf464c1 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -1,6 +1,8 @@ +#[cfg(not(feature = "target_ebaz4205"))] use embedded_hal::blocking::delay::DelayMs; #[cfg(has_si5324)] use ksupport::i2c; +#[cfg(not(feature = "target_ebaz4205"))] use libboard_artiq::pl; #[cfg(has_si5324)] use libboard_artiq::si5324; @@ -10,7 +12,9 @@ use libboard_artiq::si549; use libboard_zynq::i2c::I2c; use libboard_zynq::timer::GlobalTimer; use libconfig::Config; -use log::{info, warn}; +use log::warn; +#[cfg(not(feature = "target_ebaz4205"))] +use log::info; #[derive(Debug, PartialEq, Copy, Clone)] #[allow(non_camel_case_types)]