From 567e45c2fbdad95ca40260367572be9e8f20aacf Mon Sep 17 00:00:00 2001 From: newell Date: Sun, 29 Sep 2024 17:53:03 -0700 Subject: [PATCH 1/2] Initial commit --- src/libboard_artiq/Cargo.toml.tpl | 1 + src/libksupport/src/kernel/api.rs | 11 ++++++++++- src/libksupport/src/lib.rs | 1 + src/runtime/Cargo.toml.tpl | 1 + src/runtime/src/main.rs | 1 + src/runtime/src/rtio_clocking.rs | 4 ++-- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libboard_artiq/Cargo.toml.tpl b/src/libboard_artiq/Cargo.toml.tpl index 995fc05..ab8270f 100644 --- a/src/libboard_artiq/Cargo.toml.tpl +++ b/src/libboard_artiq/Cargo.toml.tpl @@ -10,6 +10,7 @@ name = "libboard_artiq" [features] target_zc706 = ["libboard_zynq/target_zc706", "libconfig/target_zc706"] target_kasli_soc = ["libboard_zynq/target_kasli_soc", "libconfig/target_kasli_soc"] +target_ebaz4205 = ["libboard_zynq/target_ebaz4205", "libconfig/target_ebaz4205"] calibrate_wrpll_skew = [] [build-dependencies] diff --git a/src/libksupport/src/kernel/api.rs b/src/libksupport/src/kernel/api.rs index ef77e43..c5c1104 100644 --- a/src/libksupport/src/kernel/api.rs +++ b/src/libksupport/src/kernel/api.rs @@ -11,7 +11,10 @@ use super::{cache, core1::rtio_get_destination_status, dma, linalg, rpc::{rpc_recv, rpc_send, rpc_send_async}}; -use crate::{eh_artiq, i2c, rtio}; + +use crate::{eh_artiq, rtio}; +#[cfg(not(feature = "target_ebaz4205"))] +use crate::i2c; extern "C" { fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int; @@ -109,11 +112,17 @@ 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 630f19e..78a2f1d 100644 --- a/src/libksupport/src/lib.rs +++ b/src/libksupport/src/lib.rs @@ -21,6 +21,7 @@ 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/Cargo.toml.tpl b/src/runtime/Cargo.toml.tpl index 9f539e0..c844131 100644 --- a/src/runtime/Cargo.toml.tpl +++ b/src/runtime/Cargo.toml.tpl @@ -8,6 +8,7 @@ edition = "2018" [features] target_zc706 = ["libboard_zynq/target_zc706", "libsupport_zynq/target_zc706", "libconfig/target_zc706", "libboard_artiq/target_zc706"] target_kasli_soc = ["libboard_zynq/target_kasli_soc", "libsupport_zynq/target_kasli_soc", "libconfig/target_kasli_soc", "libboard_artiq/target_kasli_soc"] +target_ebaz4205 = ["libboard_zynq/target_ebaz4205", "libsupport_zynq/target_ebaz4205", "libconfig/target_ebaz4205", "libboard_artiq/target_ebaz4205"] default = ["target_zc706"] [build-dependencies] diff --git a/src/runtime/src/main.rs b/src/runtime/src/main.rs index dd24e25..ecfd1c2 100644 --- a/src/runtime/src/main.rs +++ b/src/runtime/src/main.rs @@ -100,6 +100,7 @@ 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 06918b2..42cb215 100644 --- a/src/runtime/src/rtio_clocking.rs +++ b/src/runtime/src/rtio_clocking.rs @@ -69,7 +69,7 @@ fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock { res } -#[cfg(not(has_drtio))] +#[cfg(not(any(has_drtio, feature = "target_ebaz4205")))] fn init_rtio(timer: &mut GlobalTimer) { info!("Switching SYS clocks..."); unsafe { @@ -429,7 +429,7 @@ pub fn init(timer: &mut GlobalTimer, cfg: &Config) { #[cfg(has_drtio)] init_drtio(timer); - #[cfg(not(has_drtio))] + #[cfg(not(any(has_drtio, feature = "target_ebaz4205")))] init_rtio(timer); #[cfg(all(has_si549, has_wrpll))] From d59395c41f940e15d70009432823d64b7f3f4332 Mon Sep 17 00:00:00 2001 From: newell Date: Sun, 29 Sep 2024 18:02:19 -0700 Subject: [PATCH 2/2] Add temporary gateware --- src/gateware/ebaz4205.py | 402 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 402 insertions(+) create mode 100755 src/gateware/ebaz4205.py diff --git a/src/gateware/ebaz4205.py b/src/gateware/ebaz4205.py new file mode 100755 index 0000000..9b305c3 --- /dev/null +++ b/src/gateware/ebaz4205.py @@ -0,0 +1,402 @@ +#!/usr/bin/env python + +import argparse +from operator import itemgetter + +from migen import * +from migen.build.platforms import ebaz4205 +from migen.build.generic_platform import Pins, Subsignal, IOStandard, Misc +from migen_axi.integration.soc_core import SoCCore +from misoc.interconnect.csr import * + +from artiq.gateware import rtio +from artiq.gateware.rtio.phy import ( + ttl_simple, + dds, # Need to create module for AD9834 +) +from artiq.gateware.rtio.xilinx_clocking import fix_serdes_timing_path + +import dma +import analyzer + +from config import write_csr_file, write_mem_file, write_rustc_cfg_file + +# Added while Migen PR gets lands... +from migen.build.xilinx import XilinxPlatform + + +_io = [ + # Green and Red LEDs + ("user_led", 0, Pins("W13"), IOStandard("LVCMOS33")), + ("user_led", 1, Pins("W14"), IOStandard("LVCMOS33")), + # Push Buttons + ("user_btn", 0, Pins("A17"), IOStandard("LVCMOS33")), + ("user_btn", 1, Pins("A14"), IOStandard("LVCMOS33")), + # UART + ( + "serial", + 0, + Subsignal("tx", Pins("A16")), + Subsignal("rx", Pins("F15")), + IOStandard("LVCMOS33"), + ), + # SD Card + ( + "sdcard", + 0, + Subsignal("detect", Pins("A12"), Misc("PULLUP True")), + Subsignal("data", Pins("E12 A9 F13 B15")), + Subsignal("cmd", Pins("C17")), + Subsignal("clk", Pins("D14")), + Subsignal("cd", Pins("B15")), + IOStandard("LVCMOS33"), + Misc("SLEW=FAST"), + ), + # NAND Flash + ( + "nandflash", + 0, + Subsignal("nand_data", Pins("A6 A5 B7 E8 B5 E9 C6 D9")), + Subsignal("nand_ce", Pins("E6")), + Subsignal("nand_re", Pins("D5")), + Subsignal("nand_we", Pins("D6")), + Subsignal("nand_ale", Pins("B8")), + Subsignal("nand_cle", Pins("D8")), + Subsignal("nand_rb", Pins("C5")), + IOStandard("LVCMOS33"), + ), + # ETH PHY + ( + "gmii", + 0, + Subsignal("rxd", Pins("Y16 V16 V17 Y17")), + Subsignal("txd", Pins("W18 Y18 V18 Y19")), + Subsignal("rx_clk", Pins("U14")), + Subsignal("tx_clk", Pins("U15")), + Subsignal("rx_dv", Pins("W16")), + Subsignal("tx_en", Pins("W19")), + IOStandard("LVCMOS33"), + ), + ( + "mdio", + 0, + Subsignal("mdio", Pins("Y14")), + Subsignal("mdc", Pins("W15")), + IOStandard("LVCMOS33"), + ), +] + + +# DATA1-3 2x10 2.0mm Pitch +# J3 and J5 1x4 2.54mm Pitch +_connectors = [ + ( + "DATA1", + { + "DATA1-5": "A20", + "DATA1-6": "H16", + "DATA1-7": "B19", + "DATA1-8": "B20", + "DATA1-9": "C20", + "DATA1-11": "H17", + "DATA1-13": "D20", + "DATA1-14": "D18", + "DATA1-15": "H18", + "DATA1-16": "D19", + "DATA1-17": "F20", + "DATA1-18": "E19", + "DATA1-19": "F19", + "DATA1-20": "K17", + }, + ), + ( + "DATA2", + { + "DATA2-5": "G20", + "DATA2-6": "J18", + "DATA2-7": "G19", + "DATA2-8": "H20", + "DATA2-9": "J19", + "DATA2-11": "K18", + "DATA2-13": "K19", + "DATA2-14": "J20", + "DATA2-15": "L16", + "DATA2-16": "L19", + "DATA2-17": "M18", + "DATA2-18": "L20", + "DATA2-19": "M20", + "DATA2-20": "L17", + }, + ), + ( + "DATA3", + { + "DATA3-5": "M19", + "DATA3-6": "N20", + "DATA3-7": "P18", + "DATA3-8": "M17", + "DATA3-9": "N17", + "DATA3-11": "P20", + "DATA3-13": "R18", + "DATA3-14": "R19", + "DATA3-15": "P19", + "DATA3-16": "T20", + "DATA3-17": "U20", + "DATA3-18": "T19", + "DATA3-19": "V20", + "DATA3-20": "U19", + }, + ), + ( + "J3", + { + "J3-4-TX": "U12", + "J3-3-RX": "V13", + }, + "J5", + { + "J5-4-TX": "V12", + "J5-3-RX": "V15", + }, + ), +] + + +class Platform(XilinxPlatform): + def __init__(self): + XilinxPlatform.__init__( + self, "xc7z010-clg400-1", _io, _connectors, toolchain="vivado" + ) + + +__all__ = ["Platform"] + +_ps = [ + ( + "ps", + 0, + Subsignal("clk", Pins("E7"), IOStandard("LVCMOS33"), Misc("SLEW=FAST")), + Subsignal("por_b", Pins("C7"), IOStandard("LVCMOS33"), Misc("SLEW=FAST")), + Subsignal("srst_b", Pins("B10"), IOStandard("LVCMOS18"), Misc("SLEW=FAST")), + ) +] + +_ddr = [ + ( + "ddr", + 0, + Subsignal( + "a", + Pins("N2 K2 M3 K3 M4 L1 L4 K4 K1 J4 F5 G4 E4 D4 F4"), + IOStandard("SSTL15"), + ), + Subsignal("ba", Pins("L5 R4 J5"), IOStandard("SSTL15")), + Subsignal("cas_n", Pins("P5"), IOStandard("SSTL15")), + Subsignal("cke", Pins("N3"), IOStandard("SSTL15")), + Subsignal("cs_n", Pins("N1"), IOStandard("SSTL15")), + Subsignal("ck_n", Pins("M2"), IOStandard("DIFF_SSTL15"), Misc("SLEW=FAST")), + Subsignal("ck_p", Pins("L2"), IOStandard("DIFF_SSTL15"), Misc("SLEW=FAST")), + # Pins "T1 Y1" not connected + Subsignal("dm", Pins("A1 F1"), IOStandard("SSTL15_T_DCI"), Misc("SLEW=FAST")), + Subsignal( + "dq", + Pins("C3 B3 A2 A4 D3 D1 C1 E1 E2 E3 G3 H3 J3 H2 H1 J1"), + # Pins "P1 P3 R3 R1 T4 U4 U2 U3 V1 Y3 W1 Y4 Y2 W3 V2 V3" not connected + IOStandard("SSTL15_T_DCI"), + Misc("SLEW=FAST"), + ), + Subsignal( + "dqs_n", + Pins("B2 F2"), # Pins "T2 W4" not connected + IOStandard("DIFF_SSTL15_T_DCI"), + Misc("SLEW=FAST"), + ), + Subsignal( + "dqs_p", + Pins("C2 G2"), # Pins "R2 W5" not connected + IOStandard("DIFF_SSTL15_T_DCI"), + Misc("SLEW=FAST"), + ), + Subsignal("vrn", Pins("G5"), IOStandard("SSTL15_T_DCI"), Misc("SLEW=FAST")), + Subsignal("vrp", Pins("H5"), IOStandard("SSTL15_T_DCI"), Misc("SLEW=FAST")), + Subsignal("drst_n", Pins("B4"), IOStandard("SSTL15"), Misc("SLEW=FAST")), + Subsignal("odt", Pins("N5"), IOStandard("SSTL15")), + Subsignal("ras_n", Pins("P4"), IOStandard("SSTL15")), + Subsignal("we_n", Pins("M5"), IOStandard("SSTL15")), + ) +] + + +class EBAZ4205(SoCCore): + def __init__(self, acpki=False): + self.acpki = acpki + + # platform = ebaz4205.Platform() + platform = Platform() + platform.toolchain.bitstream_commands.extend( + [ + "set_property BITSTREAM.GENERAL.COMPRESS True [current_design]", + ] + ) + platform.add_extension(_ps) + platform.add_extension(_ddr) + + # FCLK is tied to pin U18 + platform.add_extension( + [ + ("fclk", 0, Pins("U18"), IOStandard("LVCMOS33")), + ] + ) + + gmii = platform.request("gmii") + + platform.add_period_constraint(gmii.rx_clk, 10) + platform.add_period_constraint(gmii.tx_clk, 10) + platform.add_platform_command( + "set_property CLOCK_DEDICATED_ROUTE FALSE [get_nets gmii_tx_clk_IBUF]" + ) + + ident = self.__class__.__name__ + if self.acpki: + ident = "acpki_" + ident + SoCCore.__init__( + self, + platform=platform, + csr_data_width=32, + ident=ident, + ) + fix_serdes_timing_path(platform) + # When using pd_cd_sys, the default clock coming from fclk.clk[0] is 100 MHz + self.config["RTIO_FREQUENCY"] = "100" + platform.add_period_constraint(self.ps7.cd_sys.clk, 10) + + self.comb += [ + self.ps7.enet0.enet.gmii.tx_clk.eq(gmii.tx_clk), + self.ps7.enet0.enet.gmii.rx_clk.eq(gmii.rx_clk), + ] + + self.clock_domains.cd_eth_rx = ClockDomain(reset_less=False) + self.clock_domains.cd_eth_tx = ClockDomain(reset_less=False) + self.comb += [ + ClockSignal("eth_rx").eq(gmii.rx_clk), + ClockSignal("eth_tx").eq(gmii.tx_clk), + ] + + self.sync.eth_tx += [ + gmii.txd.eq(self.ps7.enet0.enet.gmii.txd), + gmii.tx_en.eq(self.ps7.enet0.enet.gmii.tx_en), + ] + self.sync.eth_rx += [ + self.ps7.enet0.enet.gmii.rxd.eq(gmii.rxd), + self.ps7.enet0.enet.gmii.rx_dv.eq(gmii.rx_dv), + ] + + # FCLK + fclk = platform.request("fclk") + self.comb += fclk.eq(self.ps7.fclk.clk[0]) + + # MDIO/MDC + 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.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=mdio_t, + ) + ] + + self.rtio_channels = [] + for i in (0, 1): + print("USER LED at RTIO channel 0x{:06x}".format(len(self.rtio_channels))) + user_led = self.platform.request("user_led", i) + phy = ttl_simple.Output(user_led) + self.submodules += phy + self.rtio_channels.append(rtio.Channel.from_phy(phy)) + self.config["RTIO_LOG_CHANNEL"] = len(self.rtio_channels) + self.rtio_channels.append(rtio.LogChannel()) + + self.submodules.rtio_tsc = rtio.TSC(glbl_fine_ts_width=3) + self.submodules.rtio_core = rtio.Core(self.rtio_tsc, self.rtio_channels) + self.csr_devices.append("rtio_core") + if self.acpki: + import acpki + + self.config["KI_IMPL"] = "acp" + self.submodules.rtio = acpki.KernelInitiator( + self.rtio_tsc, + bus=self.ps7.s_axi_acp, + user=self.ps7.s_axi_acp_user, + evento=self.ps7.event.o, + ) + self.csr_devices.append("rtio") + else: + self.config["KI_IMPL"] = "csr" + self.submodules.rtio = rtio.KernelInitiator(self.rtio_tsc, now64=True) + self.csr_devices.append("rtio") + + self.submodules.rtio_dma = dma.DMA(self.ps7.s_axi_hp0) + self.csr_devices.append("rtio_dma") + + self.submodules.cri_con = rtio.CRIInterconnectShared( + [self.rtio.cri, self.rtio_dma.cri], + [self.rtio_core.cri], + enable_routing=True, + ) + self.csr_devices.append("cri_con") + + self.submodules.rtio_moninj = rtio.MonInj(self.rtio_channels) + self.csr_devices.append("rtio_moninj") + + self.submodules.rtio_analyzer = analyzer.Analyzer( + self.rtio_tsc, self.rtio_core.cri, self.ps7.s_axi_hp1 + ) + self.csr_devices.append("rtio_analyzer") + + +def main(): + parser = argparse.ArgumentParser( + description="ARTIQ port to the EBAZ4205 control card of Ebit E9+ BTC miner" + ) + parser.add_argument( + "-r", default=None, help="build Rust interface into the specified file" + ) + parser.add_argument( + "-m", default=None, help="build Rust memory interface into the specified file" + ) + parser.add_argument( + "-c", + default=None, + help="build Rust compiler configuration into the specified file", + ) + parser.add_argument( + "-g", default=None, help="build gateware into the specified directory" + ) + parser.add_argument( + "--acpki", default=False, action="store_true", help="enable ACPKI" + ) + args = parser.parse_args() + + soc = EBAZ4205() + soc.finalize() + + if args.r is not None: + write_csr_file(soc, args.r) + if args.m is not None: + write_mem_file(soc, args.m) + if args.c is not None: + write_rustc_cfg_file(soc, args.c) + if args.g is not None: + soc.build(build_dir=args.g) + + +if __name__ == "__main__": + main()