From d019021ff5e1bdf85e40e5a396995a73e37186bd Mon Sep 17 00:00:00 2001 From: morgan Date: Thu, 31 Aug 2023 11:54:47 +0800 Subject: [PATCH] change write_rustc_cfg_file to follow artiq repo --- src/gateware/kasli_soc.py | 58 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/gateware/kasli_soc.py b/src/gateware/kasli_soc.py index e355c16..21b8ca7 100755 --- a/src/gateware/kasli_soc.py +++ b/src/gateware/kasli_soc.py @@ -113,7 +113,6 @@ class SMAClkinForward(Module): class GenericStandalone(SoCCore): def __init__(self, description, acpki=False): self.acpki = acpki - self.rustc_cfg = dict() platform = kasli_soc.Platform() platform.toolchain.bitstream_commands.extend([ @@ -129,8 +128,8 @@ class GenericStandalone(SoCCore): self.submodules += SMAClkinForward(self.platform) - self.rustc_cfg["has_si5324"] = None - self.rustc_cfg["si5324_soft_reset"] = None + self.config["HAS_SI5324"] = None + self.config["SI5324_SOFT_RESET"] = None self.crg = self.ps7 # HACK for eem_7series to find the clock self.submodules.rtio_crg = RTIOCRG(self.platform) @@ -160,14 +159,14 @@ class GenericStandalone(SoCCore): self.csr_devices.append("rtio_core") if self.acpki: - self.rustc_cfg["ki_impl"] = "acp" + 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.rustc_cfg["ki_impl"] = "csr" + self.config["KI_IMPL"] = "csr" self.submodules.rtio = rtio.KernelInitiator(self.rtio_tsc, now64=True) self.csr_devices.append("rtio") @@ -187,7 +186,7 @@ class GenericStandalone(SoCCore): self.csr_devices.append("rtio_analyzer") if has_grabber: - self.rustc_cfg["has_grabber"] = None + self.config["HAS_GRABBER"] = None self.add_csr_group("grabber", self.grabber_csr_group) for grabber in self.grabber_csr_group: self.platform.add_false_path_constraints( @@ -200,7 +199,6 @@ class GenericMaster(SoCCore): rtio_clk_freq = description["rtio_frequency"] self.acpki = acpki - self.rustc_cfg = dict() platform = kasli_soc.Platform() platform.toolchain.bitstream_commands.extend([ @@ -229,8 +227,8 @@ class GenericMaster(SoCCore): self.csr_devices.append("rtio_crg") fix_serdes_timing_path(platform) - self.rustc_cfg["has_si5324"] = None - self.rustc_cfg["si5324_soft_reset"] = None + self.config["HAS_SI5324"] = None + self.config["SI5324_SOFT_RESET"] = None self.rtio_channels = [] has_grabber = any(peripheral["type"] == "grabber" for peripheral in description["peripherals"]) @@ -275,8 +273,8 @@ class GenericMaster(SoCCore): memory_address = self.axi2csr.register_port(coreaux.get_tx_port(), size) self.axi2csr.register_port(coreaux.get_rx_port(), size) self.add_memory_region(memory_name, self.mem_map["csr"] + memory_address, size * 2) - self.rustc_cfg["has_drtio"] = None - self.rustc_cfg["has_drtio_routing"] = None + self.config["HAS_DRTIO"] = None + self.config["HAS_DRTIO_ROUTING"] = None self.add_csr_group("drtio", drtio_csr_group) self.add_csr_group("drtioaux", drtioaux_csr_group) self.add_memory_group("drtioaux_mem", drtioaux_memory_group) @@ -285,14 +283,14 @@ class GenericMaster(SoCCore): self.csr_devices.append("rtio_core") if self.acpki: - self.rustc_cfg["ki_impl"] = "acp" + 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.rustc_cfg["ki_impl"] = "csr" + self.config["KI_IMPL"] = "csr" self.submodules.rtio = rtio.KernelInitiator(self.rtio_tsc, now64=True) self.csr_devices.append("rtio") @@ -316,7 +314,7 @@ class GenericMaster(SoCCore): self.csr_devices.append("rtio_analyzer") if has_grabber: - self.rustc_cfg["has_grabber"] = None + self.config["HAS_GRABBER"] = None self.add_csr_group("grabber", self.grabber_csr_group) @@ -326,7 +324,6 @@ class GenericSatellite(SoCCore): rtio_clk_freq = description["rtio_frequency"] self.acpki = acpki - self.rustc_cfg = dict() platform = kasli_soc.Platform() platform.toolchain.bitstream_commands.extend([ @@ -343,7 +340,6 @@ class GenericSatellite(SoCCore): self.crg = self.ps7 # HACK for eem_7series to find the clock self.submodules.rtio_crg = RTIOClockMultiplier(rtio_clk_freq) self.csr_devices.append("rtio_crg") - self.rustc_cfg["has_rtio_crg"] = None fix_serdes_timing_path(platform) data_pads = [platform.request("sfp", i) for i in range(4)] @@ -412,21 +408,21 @@ class GenericSatellite(SoCCore): # and registered in PS interface # manually, because software refers to rx/tx by halves of entire memory block, not names self.add_memory_region(memory_name, self.mem_map["csr"] + memory_address, mem_size * 2) - self.rustc_cfg["has_drtio"] = None - self.rustc_cfg["has_drtio_routing"] = None + self.config["HAS_DRTIO"] = None + self.config["HAS_DRTIO_ROUTING"] = None self.add_csr_group("drtioaux", drtioaux_csr_group) self.add_memory_group("drtioaux_mem", drtioaux_memory_group) self.add_csr_group("drtiorep", drtiorep_csr_group) if self.acpki: - self.rustc_cfg["ki_impl"] = "acp" + 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.rustc_cfg["ki_impl"] = "csr" + self.config["KI_IMPL"] = "csr" self.submodules.rtio = rtio.KernelInitiator(self.rtio_tsc, now64=True) self.csr_devices.append("rtio") @@ -449,7 +445,7 @@ class GenericSatellite(SoCCore): self.csr_devices.append("rtio_moninj") rtio_clk_period = 1e9/rtio_clk_freq - self.rustc_cfg["rtio_frequency"] = str(rtio_clk_freq/1e6) + self.config["RTIO_FREQUENCY"] = str(rtio_clk_freq/1e6) self.submodules.siphaser = SiPhaser7Series( si5324_clkin=platform.request("cdr_clk"), @@ -459,9 +455,8 @@ class GenericSatellite(SoCCore): platform.add_false_path_constraints( self.crg.cd_sys.clk, self.siphaser.mmcm_freerun_output) self.csr_devices.append("siphaser") - self.rustc_cfg["has_si5324"] = None - self.rustc_cfg["has_siphaser"] = None - self.rustc_cfg["si5324_soft_reset"] = None + self.config["HAS_SI5324"] = None + self.config["SI5324_SOFT_RESET"] = None gtx0 = self.drtio_transceiver.gtxs[0] platform.add_period_constraint(gtx0.txoutclk, rtio_clk_period) @@ -475,7 +470,7 @@ class GenericSatellite(SoCCore): self.crg.cd_sys.clk, gtx.rxoutclk) if has_grabber: - self.rustc_cfg["has_grabber"] = None + self.config["HAS_GRABBER"] = None self.add_csr_group("grabber", self.grabber_csr_group) # no RTIO CRG here @@ -494,11 +489,14 @@ def write_csr_file(soc, filename): def write_rustc_cfg_file(soc, filename): with open(filename, "w") as f: - for k, v in sorted(soc.rustc_cfg.items(), key=itemgetter(0)): - if v is None: - f.write("{}\n".format(k)) - else: - f.write("{}=\"{}\"\n".format(k, v)) + for name, origin, busword, obj in soc.get_csr_regions(): + f.write("has_{}\n".format(name.lower())) + for name, value in soc.get_constants(): + if name.upper().startswith("CONFIG_"): + if value is None: + f.write("{}\n".format(name.lower()[7:])) + else: + f.write("{}=\"{}\"\n".format(name.lower()[7:], str(value))) def main():