diff --git a/src/gateware/cxp_downconn.py b/src/gateware/cxp_downconn.py index 11e015d..6a05f61 100644 --- a/src/gateware/cxp_downconn.py +++ b/src/gateware/cxp_downconn.py @@ -12,6 +12,7 @@ from operator import add class CXP_DownConn(Module, AutoCSR): def __init__(self, refclk, pads, sys_clk_freq, debug_sma, pmod_pads): + nconn = len(pads) self.rx_start_init = CSRStorage() self.rx_restart = CSR() @@ -19,9 +20,7 @@ class CXP_DownConn(Module, AutoCSR): self.tx_restart = CSR() self.txenable = CSRStorage() - self.txinit_phaligndone = CSRStatus() - self.rxinit_phaligndone = CSRStatus() - self.rx_ready = CSRStatus() + self.rx_ready = CSRStatus(nconn) self.qpll_reset = CSR() self.qpll_locked = CSRStatus() @@ -36,7 +35,6 @@ class CXP_DownConn(Module, AutoCSR): ] - nconn = len(pads) for i in range(nconn): if i != 0: @@ -65,9 +63,6 @@ class CXP_DownConn(Module, AutoCSR): for gtx in self.gtxs: self.sync += [ - self.txinit_phaligndone.status.eq(gtx.tx_init.Xxphaligndone), - self.rxinit_phaligndone.status.eq(gtx.rx_init.Xxphaligndone), - self.rx_ready.status.eq(gtx.rx_ready), gtx.txenable.eq(self.txenable.storage[0]), gtx.tx_restart.eq(self.tx_restart.re), @@ -78,7 +73,6 @@ class CXP_DownConn(Module, AutoCSR): self.comb += gtx.dclk.eq(ClockSignal("sys")) self.sync += [ - gtx.den.eq(0), gtx.dwen.eq(0), If(self.gtx_dread.re, @@ -90,6 +84,12 @@ class CXP_DownConn(Module, AutoCSR): gtx.daddr.eq(self.gtx_daddr.storage), gtx.din.eq(self.gtx_din.storage), ), + ] + + # TODO: deal with 4 GTX instance of outpus + for n, gtx in enumerate(self.gtxs): + self.sync += [ + self.rx_ready.status[n].eq(gtx.rx_ready), If(gtx.dready, self.gtx_dready.w.eq(1), self.gtx_dout.status.eq(gtx.dout), @@ -115,6 +115,9 @@ class CXP_DownConn(Module, AutoCSR): self.pll_dout = CSRStatus(16) self.pll_dready = CSRStatus() + self.txinit_phaligndone = CSRStatus() + self.rxinit_phaligndone = CSRStatus() + for n, gtx in enumerate(self.gtxs): self.comb += [ gtx.txpll_reset.eq(self.txpll_reset.storage), @@ -124,7 +127,8 @@ class CXP_DownConn(Module, AutoCSR): gtx.pll_din.eq(self.pll_din.storage), gtx.pll_dwen.eq(self.pll_dwen.storage), - self.txpll_locked.status.eq(gtx.txpll_locked), + self.txinit_phaligndone.status.eq(gtx.tx_init.Xxphaligndone), + self.rxinit_phaligndone.status.eq(gtx.rx_init.Xxphaligndone), self.txpll_locked.status.eq(gtx.txpll_locked), self.pll_dout.status.eq(gtx.pll_dout), self.pll_dready.status.eq(gtx.pll_dready), ] @@ -169,37 +173,28 @@ class CXP_DownConn(Module, AutoCSR): gtx.encoder.k[3].eq(0), ] - self.rxdata_0 = CSRStatus(10) - self.rxdata_1 = CSRStatus(10) - self.rxdata_2 = CSRStatus(10) - self.rxdata_3 = CSRStatus(10) - self.decoded_data_0 = CSRStatus(8) - self.decoded_data_1 = CSRStatus(8) - self.decoded_data_2 = CSRStatus(8) - self.decoded_data_3 = CSRStatus(8) - self.decoded_k_0 = CSRStatus() - self.decoded_k_1 = CSRStatus() - self.decoded_k_2 = CSRStatus() - self.decoded_k_3 = CSRStatus() + for i in range(4): + gtx.decoders[i].input.attr.add("no_retiming") + gtx.decoders[i].d.attr.add("no_retiming") + gtx.decoders[i].k.attr.add("no_retiming") - self.sync.cxp_gtx_rx += [ - self.rxdata_0.status.eq(gtx.decoders[0].input), - self.decoded_data_0.status.eq(gtx.decoders[0].d), - self.decoded_k_0.status.eq(gtx.decoders[0].k), + rxdata_name = "rxdata_" + str(i) + rxdata_csr = CSRStatus(10, name=rxdata_name) + setattr(self, rxdata_name, rxdata_csr) - self.rxdata_1.status.eq(gtx.decoders[1].input), - self.decoded_data_1.status.eq(gtx.decoders[1].d), - self.decoded_k_1.status.eq(gtx.decoders[1].k), + decoded_name = "decoded_data_" + str(i) + decoded_csr = CSRStatus(8, name=decoded_name) + setattr(self, decoded_name, decoded_csr) - self.rxdata_2.status.eq(gtx.decoders[2].input), - self.decoded_data_2.status.eq(gtx.decoders[2].d), - self.decoded_k_2.status.eq(gtx.decoders[2].k), - - self.rxdata_3.status.eq(gtx.decoders[3].input), - self.decoded_data_3.status.eq(gtx.decoders[3].d), - self.decoded_k_3.status.eq(gtx.decoders[3].k), - ] + k_name = "rxdata_" + str(i) + k_csr = CSRStatus(1, name=k_name) + setattr(self, k_name, k_csr) + self.sync.cxp_gtx_rx += [ + rxdata_csr.status.eq(gtx.decoders[i].input), + decoded_csr.status.eq(gtx.decoders[i].d), + k_csr.status.eq(gtx.decoders[i].k), + ] class QPLL(Module, AutoCSR): def __init__(self, refclk, sys_clk_freq): @@ -392,8 +387,6 @@ class Comma_Checker(Module): rxfsm.act("WAIT_COMMA", If(self.comma_det, - # # start aligner early, so word aligned will fall - # self.aligner_en_rxclk.eq(1), NextState("ALIGNING"), ) )