1
0
Fork 0

Compare commits

..

29 Commits

Author SHA1 Message Date
morgan cbd1a20e07 cxp GW: add write_pointer csr 2024-10-03 12:00:27 +08:00
morgan 05761c5307 pipeline GW: expose writer_ptr 2024-10-03 12:00:16 +08:00
morgan 6e7bc912c9 zc706: fix debug sma pad 2024-10-03 10:48:18 +08:00
morgan dd36c01c13 cxp GW: move rx pipeline into cxp_gtx_rx cd 2024-10-03 10:47:58 +08:00
morgan 6e98d8952a pipeline GW: rename variable
pipeline GW: cleanup
2024-10-03 10:47:58 +08:00
morgan 5eadc9b49e zc706: add todo 2024-10-02 17:49:38 +08:00
morgan da9d43e675 cxp GW: add back cdc fifo 2024-10-02 17:42:15 +08:00
morgan 7b0f94674e downconn GW: move cdc fifo out of phy 2024-10-02 17:42:06 +08:00
morgan ad8260d93a main: add testing channel 2024-10-02 17:14:07 +08:00
morgan cd7cff8a8b lib: compile mem with cxp 2024-10-02 17:14:07 +08:00
morgan 97c110b626 downconn fw: use new csr
downconn fw: fix compilation warning

downconn FW: rename csr

downconn fw: cleanup

downconn fw: add rx memory test
2024-10-02 17:14:07 +08:00
morgan 186534ff01 proto fw: use new csr
proto: fix compilation warning

proto fw: add rx memory test
2024-10-02 17:14:07 +08:00
morgan 44246c293d cxp GW: add cxp phys & gtx csr
cxp GW: cleanup doc

cxp GW: move receiver path into downconn interface

cxp GW: add rx memory
2024-10-02 17:14:07 +08:00
morgan 12ac59a757 zc706 GW: add loopback tx memory
zc706 GW: add csr & mem group for cxp

zc706: add rx memory group

zc706: only use 1 lane

zc706: fix missing csr
2024-10-02 17:14:07 +08:00
morgan 78200e93d0 proto FW: use memory buffer for tx
proto FW: restore test packet

proto FW: fix test packet doesn't return mux

proto fw: add loopback tx & restore gtx test

proto fw: add mem size
2024-10-02 17:14:07 +08:00
morgan 007d40dfc3 upconn GW: exlarge debug fifo
upconn GW: remove idle word from phy

upconn GW: remove scheduler

upconn GW: fix debug buf overflow after tx disabled

upconn GW: refactor to takes in pads

upconn GW: cleanup
2024-10-02 17:14:07 +08:00
morgan 5414730baa downconn GW: rename variable
downconn GW: remove csr

downconn GW: clenaup
2024-10-02 17:14:07 +08:00
morgan 7eeceb1dfa cxp GW: use memory buffer tx command
cxp GW: add 32bit test packet

cxp GW: add 32bit trig ack to pipeline

cxp GW: restore rx loopback test

cxp GW: add idle word inserter

cxp GW: add phy to pipeline

cxp GW: add trig to pipeline

cxp GW: add tx docs
2024-10-02 17:13:47 +08:00
morgan 7cafe6a293 pipeline GW: use memory as buffer for tx commend
pipeline GW: update packet wrapper to use 32bit layout

pipeline GW: add word wide test packet

pipeline GW: add 32bit trig ack

pipeline GW: rename variable & use constant for K

pipeline GW: add IDLE word inserter

pipeline GW: refactor trigger pak into pipelining

pipeline GW: fix buffer depth

pipeline GW: cleanup

pipeline GW: cleanup

pipeline GW: add receiver memory

pipeline GW: cleanup unncessary state machine
2024-10-02 17:13:47 +08:00
morgan 17dfd6eb7e upconn FW: test test packet
upconn fw: test trig ack

upconn fw: use new csr

upconn: fix compilation warning
2024-10-02 17:13:47 +08:00
morgan 76584a6857 cxp protocol: init
testing: add rx downconn debug in
testing: add print u32 packet helper function
protocol: uncomment error
2024-10-02 17:13:47 +08:00
morgan 891584ceb9 main: add testing
runtime main: move lib location
2024-10-02 17:13:47 +08:00
morgan 6b1b2f7959 cxp downconn firmware: GTX setup
testing: add loopmode mode & tsusrclk mmcm drp bitbang
testing: add IDLE word printout
testing: add tx packet to test packet decoder
downconn: add QPLL and GTX setup
downconn: add DRP to support all CXP linerate up to 12.5Gbps
2024-10-02 17:13:46 +08:00
morgan a2b74c9212 cxp upconn firmware: low speed serial setup
testing: add trigger & trigger ack CSR to test tranmission prioirty
upconn: add some upconn error for control flow
upconn: add control packet writer
control packet: add u32 & u64 register control
control packet: add CRC calculation & packet type inserter in fw
2024-09-30 16:31:36 +08:00
morgan 7e1cf535f9 zc706: add CXP_DEMO variant
zc706: add fmc pads
zc706: add constraint to fix comma alignment & setup/hold time issue

zc706: add cxp memory map
2024-09-26 13:19:17 +08:00
morgan 22aa9555c5 cxp: add upconn interface, downconn PHY & crc
testing: add CSR control for tx trigger & trigger ack
upconn: connect trigger, trigger ack & command_packet to UpConnPHY
downconn: add GTX PHY
2024-09-26 13:19:01 +08:00
morgan 2ce9aeb45e cxp pipeline: packet handling pipeline
tx pipeline: add CRC32 inserter
tx pipeline: add start & end of packet code inserter
tx pipeline: add packet wrapper for start & stop packet indication
tx pipeline: add code source for trigger & trigger ack packet
tx pipeline: add packet for trigger & trigger ack
tx pipeline: add test packet generator
tx pipeline: add tx_command_packet for firmware
tx command packet: add fifo to store control packet
rx pipeline: add reciever path
rx pipeline: add trig ack checker
rx pipeline: add packet decoder
decoder: add test packet checker
2024-09-26 13:16:57 +08:00
morgan 6ae29ba6b4 cxp upconn gw: add low speed serial PHY
testing: add debug fifo output b4 encoder
cxp upconn: add low speed serial
cxp upconn: add reset, tx_busy, tx_enable
cxp upconn: add clockgen module for 20.83Mbps & 41.66Mbps using counters
cxp upconn: add oserdes using CEInserter
cxp upconn: add packet scheduler with CEInserter
scheduler: send priority packet during word/char boundary
scheduler: send IDLE every 10000 words
scheduler: encode packet before sending to oserdes
2024-09-26 13:16:45 +08:00
morgan eed2a4fee9 cxp downconn gw: add gtx up to 12.5Gbps
testing: add txusrclk mmcm & loopback mode
testing: add debug output
testing: send comma in the middle of long packet to maintain lock
downconn: don't put IDLE into fifo
downconn: add GTX and QPLL support
downconn: add DRP for GTX and QPLL to support all CXP linerates
GTX: add gtx with mmcm for TXUSRCLK freq requirement
GTX: add loopback mode parameter for testing
GTX: add gtx with 40bits internal width
GTX: use built-in comma aligner
GTX: add comma checker to ensure comma is aligner on highest linerate
GTX: set QPLL as CLK source for GTX
2024-09-26 13:15:31 +08:00
10 changed files with 1007 additions and 1185 deletions

View File

@ -1,153 +1,276 @@
from migen import * from migen import *
from migen.genlib.cdc import MultiReg, PulseSynchronizer
from misoc.interconnect.csr import * from misoc.interconnect.csr import *
from misoc.interconnect import stream
from cxp_downconn import CXP_DownConn_PHY from cxp_downconn import CXP_DownConn_PHYS
from cxp_upconn import CXP_UpConn_PHY from cxp_upconn import CXP_UpConn_PHYS
from cxp_pipeline import * from cxp_pipeline import *
buffer_depth = 128
class CXP_PHYS(Module, AutoCSR):
def __init__(self, refclk, upconn_pads, downconn_pads, sys_clk_freq, debug_sma, pmod_pads):
assert len(upconn_pads) == len(downconn_pads)
self.submodules.upconn = CXP_UpConn_PHYS(upconn_pads, sys_clk_freq, debug_sma, pmod_pads)
self.submodules.downconn = CXP_DownConn_PHYS(refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads)
@FullMemoryWE() @FullMemoryWE()
class CXP(Module, AutoCSR): class CXP_Interface(Module, AutoCSR):
def __init__(self, refclk, downconn_pads, upconn_pads, sys_clk_freq, debug_sma, pmod_pads): def __init__(self, upconn_phy, downconn_phy, debug_sma, pmod_pads):
self.submodules.upconn = UpConn_Interface(upconn_pads, sys_clk_freq, debug_sma, pmod_pads) # TODO: move all transceiver csr into a transceiver interface submodule
self.submodules.downconn = DownConn_Interface(refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads) self.submodules.upconn = UpConn_Interface(upconn_phy, debug_sma, pmod_pads)
# TODO: support the option high speed upconn
self.submodules.transmitter = Transmitter() self.submodules.downconn = DownConn_Interface(downconn_phy, debug_sma, pmod_pads)
# TODO: add link layer
def get_tx_port(self): def get_tx_port(self):
return self.transmitter.mem.get_port(write_capable=True) return self.upconn.command.mem.get_port(write_capable=True)
def get_rx_port(self):
return self.downconn.packet_decoder.mem.get_port(write_capable=False)
def get_loopback_tx_port(self):
return self.downconn.command.mem.get_port(write_capable=True)
def get_mem_size(self): def get_mem_size(self):
return buffer_depth*downconn_dw return buffer_depth*word_dw
@FullMemoryWE()
class Transmitter(Module, AutoCSR):
def __init__(self):
self.cxp_tx_word_len = CSRStorage(bits_for(buffer_depth))
self.cxp_tx = CSR()
# # #
self.specials.mem = mem = Memory(downconn_dw, buffer_depth)
self.specials.mem_port = mem_port = mem.get_port()
self.source = stream.Endpoint(downconn_layout)
tx_done = Signal()
addr_next = Signal(bits_for(buffer_depth))
addr = Signal.like(addr_next)
addr_rst = Signal()
addr_inc = Signal()
# increment addr in the same cycle the moment addr_inc is rise
# since memory takes one cycle to shift to the correct addr
self.sync += [
addr.eq(addr_next),
If(self.cxp_tx.re, self.cxp_tx.w.eq(1)),
If(tx_done, self.cxp_tx.w.eq(0)),
]
self.comb += [
addr_next.eq(addr),
If(addr_rst,
addr_next.eq(addr_next.reset),
).Elif(addr_inc,
addr_next.eq(addr + 1),
),
mem_port.adr.eq(addr_next),
self.source.data.eq(mem_port.dat_r)
]
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
addr_rst.eq(1),
If(self.cxp_tx.re, NextState("TRANSMIT"))
)
fsm.act("TRANSMIT",
self.source.stb.eq(1),
If(self.source.ack,
addr_inc.eq(1),
),
If(addr_next == self.cxp_tx_word_len.storage,
tx_done.eq(1),
NextState("IDLE")
)
)
self.submodules.debug_out = debug_out = RX_Debug_Buffer()
self.comb += self.source.connect(debug_out.sink)
class DownConn_Interface(Module, AutoCSR): class DownConn_Interface(Module, AutoCSR):
def __init__(self, refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads): def __init__(self, phy, debug_sma, pmod_pads):
self.rx_start_init = CSRStorage()
self.rx_restart = CSR()
self.rx_ready = CSRStatus()
# # # # # #
self.submodules.phy = phy = CXP_DownConn_PHY(refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads) gtx = phy.gtx
self.gtxs = phy.gtxs
# DEBUG: TX pipeline # GTX Control
self.submodules.debug_src = debug_src = TX_Command_Packet() self.sync += [
self.submodules.trig_ack = trig_ack = Trigger_ACK() gtx.rx_restart.eq(self.rx_restart.re),
self.submodules.testseq = testseq = TX_Test_Packet() gtx.rx_init.clk_path_ready.eq(self.rx_start_init.storage),
self.submodules.mux = mux = stream.Multiplexer(upconn_layout, 3) self.rx_ready.status.eq(gtx.rx_ready),
self.submodules.conv = conv = stream.StrideConverter(upconn_layout, downconn_layout)
self.ack = CSR()
self.mux_sel = CSRStorage(4)
self.sync += trig_ack.ack.eq(self.ack.re),
self.comb += [
debug_src.source.connect(mux.sink0),
trig_ack.source.connect(mux.sink1),
testseq.source.connect(mux.sink2),
mux.sel.eq(self.mux_sel.storage)
] ]
tx_pipeline = [mux , conv, phy.sinks[0]]
# DEBUG: tx control
self.tx_start_init = CSRStorage()
self.tx_restart = CSR()
self.txenable = CSRStorage()
self.sync += [
gtx.txenable.eq(self.txenable.storage),
gtx.tx_restart.eq(self.tx_restart.re),
gtx.tx_init.clk_path_ready.eq(self.tx_start_init.storage),
]
# DEBUG: loopback control
self.loopback_mode = CSRStorage(3)
self.comb += gtx.loopback_mode.eq(self.loopback_mode.storage)
# DEBUG: init status
self.txinit_phaligndone = CSRStatus()
self.rxinit_phaligndone = CSRStatus()
self.comb += [
self.txinit_phaligndone.status.eq(gtx.tx_init.Xxphaligndone),
self.rxinit_phaligndone.status.eq(gtx.rx_init.Xxphaligndone),
]
# Connect all GTX connections' DRP
self.gtx_daddr = CSRStorage(9)
self.gtx_dread = CSR()
self.gtx_din_stb = CSR()
self.gtx_din = CSRStorage(16)
self.gtx_dout = CSRStatus(16)
self.gtx_dready = CSR()
self.comb += gtx.dclk.eq(ClockSignal("sys"))
self.sync += [
gtx.den.eq(0),
gtx.dwen.eq(0),
If(self.gtx_dread.re,
gtx.den.eq(1),
gtx.daddr.eq(self.gtx_daddr.storage),
).Elif(self.gtx_din_stb.re,
gtx.den.eq(1),
gtx.dwen.eq(1),
gtx.daddr.eq(self.gtx_daddr.storage),
gtx.din.eq(self.gtx_din.storage),
),
If(gtx.dready,
self.gtx_dready.w.eq(1),
self.gtx_dout.status.eq(gtx.dout),
),
If(self.gtx_dready.re,
self.gtx_dready.w.eq(0),
),
]
# DEBUG: txusrclk PLL DRP
self.txpll_reset = CSRStorage()
self.pll_daddr = CSRStorage(7)
self.pll_dclk = CSRStorage()
self.pll_den = CSRStorage()
self.pll_din = CSRStorage(16)
self.pll_dwen = CSRStorage()
self.txpll_locked = CSRStatus()
self.pll_dout = CSRStatus(16)
self.pll_dready = CSRStatus()
self.comb += [
gtx.txpll_reset.eq(self.txpll_reset.storage),
gtx.pll_daddr.eq(self.pll_daddr.storage),
gtx.pll_dclk.eq(self.pll_dclk.storage),
gtx.pll_den.eq(self.pll_den.storage),
gtx.pll_din.eq(self.pll_din.storage),
gtx.pll_dwen.eq(self.pll_dwen.storage),
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),
]
# DEBUG: tx loopback fifo control
self.tx_stb = CSRStorage()
self.sync += phy.tx_stb_sys.eq(self.tx_stb.storage)
# DEBUG: Transmission Pipeline
#
# test pak ----+
# from gw | 32 32
# |---/---> mux -----> packet -----> trigger ack ---/---> PHY
# | wrapper inserter
# data pak ----+
# from fw
# DEBUG: TX pipeline
self.submodules.command = command = TX_Command_Packet()
self.submodules.testseq = testseq = TX_Test_Packet()
self.submodules.mux = mux = stream.Multiplexer(word_layout, 2)
self.submodules.pak_wrp = pak_wrp = Packet_Wrapper()
self.submodules.trig_ack = trig_ack = Trigger_ACK_Inserter()
self.ack = CSR()
self.mux_sel = CSRStorage()
self.sync += trig_ack.stb.eq(self.ack.re),
self.comb += [
command.source.connect(mux.sink0),
testseq.source.connect(mux.sink1),
mux.sel.eq(self.mux_sel.storage),
]
tx_pipeline = [mux , pak_wrp, trig_ack, phy]
for s, d in zip(tx_pipeline, tx_pipeline[1:]): for s, d in zip(tx_pipeline, tx_pipeline[1:]):
self.comb += s.source.connect(d.sink) self.comb += s.source.connect(d.sink)
# NOTE: RX pipeline
self.submodules.debug_out = debug_out = RX_Debug_Buffer()
self.submodules.recv_path = recv_path = Receiver_Path()
rx_pipeline = [phy.sources[0], recv_path, debug_out]
# Receiver Pipeline WIP
#
# 32 32
# PHY ---/---> CDC FIFO ---/---> trigger ack ------> packet ------> debug buffer
# checker decoder
#
cdr = ClockDomainsRenamer("cxp_gtx_rx")
# Priority level 1 packet - Trigger ack packet
self.submodules.trig_ack_checker = trig_ack_checker = cdr(CXP_Trig_Ack_Checker())
self.submodules.trig_ack_ps = trig_ack_ps = PulseSynchronizer("cxp_gtx_rx", "sys")
self.comb += trig_ack_ps.i.eq(trig_ack_checker.ack)
self.trig_ack = Signal()
self.trig_clr = Signal()
# Error are latched
self.sync += [
If(trig_ack_ps.o,
self.trig_ack.eq(1),
).Elif(self.trig_clr,
self.trig_ack.eq(0),
),
]
# Priority level 2 packet - data, test packet
self.submodules.packet_decoder = packet_decoder = cdr(CXP_Data_Packet_Decode())
self.new_rx_packet = CSR()
self.decoder_error = CSR()
self.test_error = CSR()
self.submodules.new_packet_ps = new_packet_ps = PulseSynchronizer("cxp_gtx_rx", "sys")
self.submodules.decode_err_ps = decode_err_ps = PulseSynchronizer("cxp_gtx_rx", "sys")
self.submodules.test_err_ps = test_err_ps = PulseSynchronizer("cxp_gtx_rx", "sys")
self.comb += [
new_packet_ps.i.eq(packet_decoder.new_packet),
decode_err_ps.i.eq(packet_decoder.decode_err),
test_err_ps.i.eq(packet_decoder.test_err),
]
self.sync += [
If(new_packet_ps.o,
self.new_rx_packet.w.eq(1),
).Elif(self.new_rx_packet.re,
self.new_rx_packet.w.eq(0),
),
If(decode_err_ps.o,
self.decoder_error.w.eq(1),
).Elif(self.decoder_error.re,
self.decoder_error.w.eq(0),
),
If(test_err_ps.o,
self.test_error.w.eq(1),
).Elif(self.test_error.re,
self.test_error.w.eq(0),
),
]
# Cicular buffer interface
self.packet_type = CSRStatus(8)
self.write_pointer = CSRStatus(bits_for(buffer_depth)) # for firmware to sync with buffer
self.specials += [
MultiReg(packet_decoder.packet_type, self.packet_type.status),
MultiReg(packet_decoder.write_ptr, self.write_pointer.status),
]
# DEBUG: remove this cdc fifo
cdc_fifo = stream.AsyncFIFO(word_layout, 512)
self.submodules += ClockDomainsRenamer({"write": "cxp_gtx_rx", "read": "sys"})(cdc_fifo)
self.submodules.debug_out = debug_out = RX_Debug_Buffer()
rx_pipeline = [phy, trig_ack_checker, packet_decoder, cdc_fifo, debug_out]
for s, d in zip(rx_pipeline, rx_pipeline[1:]): for s, d in zip(rx_pipeline, rx_pipeline[1:]):
self.comb += s.source.connect(d.sink) self.comb += s.source.connect(d.sink)
self.packet_type = CSRStatus(8)
self.decoder_error = CSRStatus()
self.test_error = CSRStatus()
self.comb += [
self.packet_type.status.eq(recv_path.packet_type),
self.decoder_error.status.eq(recv_path.decoder_err),
self.test_error.status.eq(recv_path.test_err),
]
# DEBUG: CSR # DEBUG: CSR
self.trig_ack = CSRStatus() self.trigger_ack = CSR()
self.trig_clr = CSR() self.sync += [
self.comb += [ self.trig_clr.eq(self.trigger_ack.re),
self.trig_ack.status.eq(recv_path.trig_ack), self.trigger_ack.w.eq(self.trig_ack),
recv_path.trig_clr.eq(self.trig_clr.re),
] ]
pak_start = Signal() pak_start = Signal()
self.sync += [ self.sync += [
pak_start.eq(recv_path.packet_decoder.sink.data == 0xFBFBFBFB), pak_start.eq(packet_decoder.sink.data == 0xFBFBFBFB),
] ]
self.specials += [ self.specials += [
Instance("OBUF", i_I=phy.gtx.cd_cxp_gtx_rx.clk, o_O=debug_sma.p_tx),
# Instance("OBUF", i_I=, o_O=debug_sma.p_rx),
# # pmod 0-7 pin # # pmod 0-7 pin
Instance("OBUF", i_I=recv_path.packet_decoder.test_err, o_O=pmod_pads[0]), Instance("OBUF", i_I=packet_decoder.test_err, o_O=pmod_pads[0]),
Instance("OBUF", i_I=pak_start, o_O=pmod_pads[1]), Instance("OBUF", i_I=pak_start, o_O=pmod_pads[1]),
# Instance("OBUF", i_I=fifo_in.source.ack, o_O=pmod_pads[2]), # Instance("OBUF", i_I=fifo_in.source.ack, o_O=pmod_pads[2]),
# Instance("OBUF", i_I=gtx.comma_checker.aligner_en, o_O=pmod_pads[3]), # Instance("OBUF", i_I=gtx.comma_checker.aligner_en, o_O=pmod_pads[3]),
@ -159,73 +282,103 @@ class DownConn_Interface(Module, AutoCSR):
class UpConn_Interface(Module, AutoCSR): class UpConn_Interface(Module, AutoCSR):
def __init__(self, upconn_pads, sys_clk_freq, debug_sma, pmod_pads): def __init__(self, phy, debug_sma, pmod_pads):
self.clk_reset = CSRStorage(reset=1) self.clk_reset = CSRStorage(reset=1)
self.bitrate2x_enable = CSRStorage() self.bitrate2x_enable = CSRStorage()
self.tx_enable = CSRStorage() self.tx_enable = CSRStorage()
# TODO: add busy condition
self.tx_busy = CSRStatus() self.tx_busy = CSRStatus()
self.tx_testmode_en = CSRStorage() self.tx_testmode_en = CSRStorage()
# # # # # #
self.submodules.phy = phy = CXP_UpConn_PHY(upconn_pads, sys_clk_freq, debug_sma, pmod_pads)
self.sync += [ self.sync += [
phy.bitrate2x_enable.eq(self.bitrate2x_enable.storage), phy.bitrate2x_enable.eq(self.bitrate2x_enable.storage),
phy.tx_enable.eq(self.tx_enable.storage), phy.tx_enable.eq(self.tx_enable.storage),
phy.clk_reset.eq(self.clk_reset.re), phy.clk_reset.eq(self.clk_reset.re),
self.tx_busy.status.eq(phy.tx_busy),
] ]
# TODO: rewrite the transmite path into pipeline # Transmission Pipeline
# #
# test pak ----+ # test pak ----+
# from gw | 32 32 8 # from gw | 32 32 8
# |---/---> mux -----> trig ack -----> idle word ---/--> conv ---/---> trig -----> PHY # |---/---> mux -----> packet -----> idle word -----> trigger ack ---/--> conv ---/---> trigger -----> PHY
# | inserter inserter inserter # | wrapper inserter inserter inserter
# data pak ----+ # data pak ----+
# from fw # from fw
#
# Equivalent transmission priority:
# trigger > trigger ack > idle > test/data packet
# To maintain the trigger performance, idle word should not be inserted into trigger or trigger ack.
#
# In low speed CoaXpress, the higher priority packet can be inserted in two types of boundary
# Insertion @ char boundary: Trigger packets
# Insertion @ word boundary: Trigger ack & IDLE packets
# The 32 bit part of the pipeline handles the word boundary insertion while the 8 bit part handles the char boundary insertion
# Packet FIFOs with transmission priority # Packet FIFOs with transmission priority
# 0: Trigger packet # 0: Trigger packet
self.submodules.trig = trig = TX_Trigger() self.submodules.trig = trig = TX_Trigger()
self.comb += trig.source.connect(phy.sinks[0])
# DEBUG: INPUT # # DEBUG: INPUT
self.trig_stb = CSR() self.trig_stb = CSR()
self.trig_delay = CSRStorage(8) self.trig_delay = CSRStorage(8)
self.linktrigger = CSRStorage(2) self.linktrigger = CSRStorage(2)
self.sync += [ self.sync += [
trig.trig_stb.eq(self.trig_stb.re), trig.stb.eq(self.trig_stb.re),
trig.delay.eq(self.trig_delay.storage), trig.delay.eq(self.trig_delay.storage),
trig.linktrig_mode.eq(self.linktrigger.storage), trig.linktrig_mode.eq(self.linktrigger.storage),
] ]
# 1: IO acknowledgment for trigger packet # 1: IO acknowledgment for trigger packet
self.submodules.trig_ack = trig_ack = Trigger_ACK() self.submodules.trig_ack = trig_ack = Trigger_ACK_Inserter()
self.comb += trig_ack.source.connect(phy.sinks[1])
# DEBUG: INPUT # DEBUG: INPUT
self.ack = CSR() self.ack = CSR()
self.sync += trig_ack.ack.eq(self.ack.re), self.sync += trig_ack.stb.eq(self.ack.re),
# 2: All other packets # 2: All other packets (data & test packet)
# Control is not timing dependent, all the link layer is done in firmware # Control is not timing dependent, all the data packets are handled in firmware
self.submodules.command = command = TX_Command_Packet() self.submodules.command = command = TX_Command_Packet()
self.submodules.testseq = testseq = TX_Test_Packet() self.submodules.testseq = testseq = TX_Test_Packet()
self.submodules.mux = mux = stream.Multiplexer(word_layout, 2)
self.submodules.mux = mux = stream.Multiplexer(upconn_layout, 2)
self.comb += [ self.comb += [
command.source.connect(mux.sink0), command.source.connect(mux.sink0),
testseq.source.connect(mux.sink1), testseq.source.connect(mux.sink1),
mux.sel.eq(self.tx_testmode_en.storage), mux.sel.eq(self.tx_testmode_en.storage),
mux.source.connect(phy.sinks[2])
] ]
self.submodules.pak_wrp = pak_wrp = Packet_Wrapper()
# IDLE Word
self.submodules.idle = idle = Idle_Word_Inserter()
# Section 9.2.5.1 (CXP-001-2021)
# IDLE should be transmitter every 10000 words
cnt = Signal(max=10000)
self.sync += [
idle.stb.eq(0),
If((~idle.sink.stb) | (cnt == 9999),
idle.stb.eq(1),
cnt.eq(cnt.reset),
).Else(
cnt.eq(cnt + 1),
),
]
self.submodules.converter = converter = stream.StrideConverter(word_layout, char_layout)
tx_pipeline = [mux, pak_wrp, idle, trig_ack, converter, trig, phy]
for s, d in zip(tx_pipeline, tx_pipeline[1:]):
self.comb += s.source.connect(d.sink)

View File

@ -7,29 +7,20 @@ from misoc.interconnect.csr import *
from misoc.interconnect import stream from misoc.interconnect import stream
from artiq.gateware.drtio.transceiver.gtx_7series_init import * from artiq.gateware.drtio.transceiver.gtx_7series_init import *
from cxp_pipeline import downconn_layout from cxp_pipeline import word_layout
from functools import reduce from functools import reduce
from operator import add from operator import add
class CXP_DownConn_PHY(Module, AutoCSR): class CXP_DownConn_PHYS(Module, AutoCSR):
def __init__(self, refclk, pads, sys_clk_freq, debug_sma, pmod_pads): def __init__(self, refclk, pads, sys_clk_freq, debug_sma, pmod_pads):
nconn = len(pads)
self.rx_start_init = CSRStorage()
self.rx_restart = CSR()
self.tx_start_init = CSRStorage()
self.tx_restart = CSR()
self.txenable = CSRStorage()
self.rx_ready = CSRStatus(nconn)
self.qpll_reset = CSR() self.qpll_reset = CSR()
self.qpll_locked = CSRStatus() self.qpll_locked = CSRStatus()
self.gtxs = [] self.rx_phys = []
# # # # # #
# For speed higher than 6.6Gbps, QPLL need to be used instead of CPLL
self.submodules.qpll = qpll = QPLL(refclk, sys_clk_freq) self.submodules.qpll = qpll = QPLL(refclk, sys_clk_freq)
self.sync += [ self.sync += [
qpll.reset.eq(self.qpll_reset.re), qpll.reset.eq(self.qpll_reset.re),
@ -37,13 +28,10 @@ class CXP_DownConn_PHY(Module, AutoCSR):
] ]
for i, pad in enumerate(pads):
for i in range(nconn): rx = Receiver(qpll, pad, sys_clk_freq, "single", "single", debug_sma, pmod_pads)
if i != 0: self.rx_phys.append(rx)
break setattr(self.submodules, "rx"+str(i), rx)
gtx = GTX(self.qpll, pads[i], sys_clk_freq, tx_mode="single", rx_mode="single")
self.gtxs.append(gtx)
setattr(self.submodules, "gtx"+str(i), gtx)
# TODO: add extension gtx connections # TODO: add extension gtx connections
# TODO: add connection interface # TODO: add connection interface
@ -52,191 +40,76 @@ class CXP_DownConn_PHY(Module, AutoCSR):
# checkout channel interfaces & drtio_gtx # checkout channel interfaces & drtio_gtx
# GTPTXPhaseAlignement for inspiration # GTPTXPhaseAlignement for inspiration
# Connect all GTX connections' DRP
self.gtx_daddr = CSRStorage(9) class Receiver(Module):
self.gtx_dread = CSR() def __init__(self, qpll, pad, sys_clk_freq, tx_mode, rx_mode, debug_sma, pmod_pads):
self.gtx_din_stb = CSR() self.submodules.gtx = gtx = GTX(qpll, pad, sys_clk_freq, tx_mode="single", rx_mode="single")
self.gtx_din = CSRStorage(16)
self.gtx_dout = CSRStatus(16) self.source = stream.Endpoint(word_layout)
self.gtx_dready = CSR()
for gtx in self.gtxs: self.sync.cxp_gtx_rx += [
self.sync += [ self.source.stb.eq(0),
If(gtx.rx_ready & self.source.ack & ~((gtx.decoders[0].d == 0xBC) & (gtx.decoders[0].k == 1)),
self.source.stb.eq(1),
self.source.data.eq(Cat(gtx.decoders[0].d, gtx.decoders[1].d, gtx.decoders[2].d, gtx.decoders[3].d)),
self.source.k.eq(Cat(gtx.decoders[0].k, gtx.decoders[1].k, gtx.decoders[2].k, gtx.decoders[3].k)),
)
]
gtx.txenable.eq(self.txenable.storage[0]), # DEBUG: tx fifos for loopback
gtx.tx_restart.eq(self.tx_restart.re), # fw -> fifo (sys) -> cdc fifo -> gtx tx
gtx.rx_restart.eq(self.rx_restart.re),
gtx.tx_init.clk_path_ready.eq(self.tx_start_init.storage),
gtx.rx_init.clk_path_ready.eq(self.rx_start_init.storage),
]
self.comb += gtx.dclk.eq(ClockSignal("sys")) tx_fifo = stream.AsyncFIFO(word_layout, 512)
self.sync += [ self.submodules += ClockDomainsRenamer({"write": "sys", "read": "cxp_gtx_tx"})(tx_fifo)
gtx.den.eq(0), self.sink = tx_fifo.sink
gtx.dwen.eq(0),
If(self.gtx_dread.re,
gtx.den.eq(1),
gtx.daddr.eq(self.gtx_daddr.storage),
).Elif(self.gtx_din_stb.re,
gtx.den.eq(1),
gtx.dwen.eq(1),
gtx.daddr.eq(self.gtx_daddr.storage),
gtx.din.eq(self.gtx_din.storage),
),
]
# TODO: deal with 4 GTX instance of outpus self.tx_stb_sys = Signal()
for n, gtx in enumerate(self.gtxs): txstb = Signal()
self.sync += [ self.specials += MultiReg(self.tx_stb_sys, txstb, odomain="cxp_gtx_tx")
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),
),
If(self.gtx_dready.re,
self.gtx_dready.w.eq(0),
),
]
self.sources = [] word_count = Signal(max=100)
for n, gtx in enumerate(self.gtxs): # JANK: fix the every 98th word got eaten
# DEBUG: remove cdc fifo # cnt 97 98 99 0
# gtx rx -> fifo out -> cdc out # out fifo[97] IDLE IDLE fifo[99]
# ack 1 0 0 1
self.sync.cxp_gtx_tx += [
tx_fifo.source.ack.eq(0),
fifo_out = stream.AsyncFIFO(downconn_layout, 512) If(word_count == 99,
self.submodules += ClockDomainsRenamer({"write": "cxp_gtx_rx", "read": "sys"})(fifo_out) word_count.eq(word_count.reset),
self.sources.append(fifo_out) ).Else(
If(tx_fifo.source.stb & txstb,
for i in range(4): If(word_count != 98, tx_fifo.source.ack.eq(1)),
self.sync.cxp_gtx_rx += [ word_count.eq(word_count + 1),
fifo_out.sink.stb.eq(0),
# don't store idle word in fifo
If((gtx.rx_ready & fifo_out.sink.ack & ~((gtx.decoders[0].d == 0xBC) & (gtx.decoders[0].k == 1))),
fifo_out.sink.stb.eq(1),
fifo_out.sink.data[i*8:(i*8)+8].eq(gtx.decoders[i].d),
fifo_out.sink.k[i].eq(gtx.decoders[i].k),
),
]
# DEBUG: tx of gtx is not used in CXP
# DEBUG: txusrclk PLL DRG
self.txpll_reset = CSRStorage()
self.pll_daddr = CSRStorage(7)
self.pll_dclk = CSRStorage()
self.pll_den = CSRStorage()
self.pll_din = CSRStorage(16)
self.pll_dwen = CSRStorage()
self.txpll_locked = CSRStatus()
self.pll_dout = CSRStatus(16)
self.pll_dready = CSRStatus()
self.txinit_phaligndone = CSRStatus()
self.rxinit_phaligndone = CSRStatus()
self.tx_stb = CSRStorage()
self.sinks = []
for n, gtx in enumerate(self.gtxs):
self.comb += [
gtx.txpll_reset.eq(self.txpll_reset.storage),
gtx.pll_daddr.eq(self.pll_daddr.storage),
gtx.pll_dclk.eq(self.pll_dclk.storage),
gtx.pll_den.eq(self.pll_den.storage),
gtx.pll_din.eq(self.pll_din.storage),
gtx.pll_dwen.eq(self.pll_dwen.storage),
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),
]
# DEBUG:loopback
self.loopback_mode = CSRStorage(3)
self.comb += gtx.loopback_mode.eq(self.loopback_mode.storage)
# DEBUG: datain
# fw -> fifo (sys) -> cdc fifo -> gtx tx
fifo_in = stream.AsyncFIFO(downconn_layout, 512)
self.submodules += ClockDomainsRenamer({"write": "sys", "read": "cxp_gtx_tx"})(fifo_in)
self.sinks.append(fifo_in)
# TODO: why there this send an extra 0xFB word
txstb = Signal()
self.specials += MultiReg(self.tx_stb.storage, txstb, odomain="cxp_gtx_tx")
word_count = Signal(max=100)
# JANK: fix the every 98th word got eaten
# cnt 97 98 99 0
# out fifo[97] IDLE IDLE fifo[99]
# ack 1 0 0 1
self.sync.cxp_gtx_tx += [
fifo_in.source.ack.eq(0),
If(word_count == 99,
word_count.eq(word_count.reset),
).Else(
If(fifo_in.source.stb & txstb,
If(word_count != 98, fifo_in.source.ack.eq(1)),
word_count.eq(word_count + 1),
)
) )
] )
]
# NOTE: prevent the first word send twice due to stream stb delay # NOTE: prevent the first word send twice due to stream stb delay
self.comb += [ self.comb += [
If((fifo_in.source.stb & fifo_in.source.ack & (word_count != 99)), If((tx_fifo.source.stb & tx_fifo.source.ack & (word_count != 99)),
gtx.encoder.d[0].eq(fifo_in.source.data[:8]), gtx.encoder.d[0].eq(tx_fifo.source.data[:8]),
gtx.encoder.d[1].eq(fifo_in.source.data[8:16]), gtx.encoder.d[1].eq(tx_fifo.source.data[8:16]),
gtx.encoder.d[2].eq(fifo_in.source.data[16:24]), gtx.encoder.d[2].eq(tx_fifo.source.data[16:24]),
gtx.encoder.d[3].eq(fifo_in.source.data[24:]), gtx.encoder.d[3].eq(tx_fifo.source.data[24:]),
gtx.encoder.k[0].eq(fifo_in.source.k[0]), gtx.encoder.k[0].eq(tx_fifo.source.k[0]),
gtx.encoder.k[1].eq(fifo_in.source.k[1]), gtx.encoder.k[1].eq(tx_fifo.source.k[1]),
gtx.encoder.k[2].eq(fifo_in.source.k[2]), gtx.encoder.k[2].eq(tx_fifo.source.k[2]),
gtx.encoder.k[3].eq(fifo_in.source.k[3]), gtx.encoder.k[3].eq(tx_fifo.source.k[3]),
).Else( ).Else(
# NOTE: IDLE WORD # NOTE: IDLE WORD
gtx.encoder.d[0].eq(0xBC), gtx.encoder.d[0].eq(0xBC),
gtx.encoder.k[0].eq(1), gtx.encoder.k[0].eq(1),
gtx.encoder.d[1].eq(0x3C), gtx.encoder.d[1].eq(0x3C),
gtx.encoder.k[1].eq(1), gtx.encoder.k[1].eq(1),
gtx.encoder.d[2].eq(0x3C), gtx.encoder.d[2].eq(0x3C),
gtx.encoder.k[2].eq(1), gtx.encoder.k[2].eq(1),
gtx.encoder.d[3].eq(0xB5), gtx.encoder.d[3].eq(0xB5),
gtx.encoder.k[3].eq(0), gtx.encoder.k[3].eq(0),
) )
] ]
# DEBUG: IO SMA & PMOD
if n == 0:
self.specials += [
# Instance("OBUF", i_I=gtx.cd_cxp_gtx_rx.clk, o_O=debug_sma.p_tx),
# Instance("OBUF", i_I=gtx.cd_cxp_gtx_tx.clk, o_O=debug_sma.n_rx),
# # pmod 0-7 pin
# Instance("OBUF", i_I=txstb, o_O=pmod_pads[0]),
# Instance("OBUF", i_I=fifo_in.source.stb, o_O=pmod_pads[1]),
# Instance("OBUF", i_I=fifo_in.source.ack, o_O=pmod_pads[2]),
# Instance("OBUF", i_I=gtx.comma_checker.aligner_en, o_O=pmod_pads[3]),
# Instance("OBUF", i_I=gtx.comma_checker.check_reset, o_O=pmod_pads[4]),
# Instance("OBUF", i_I=gtx.comma_checker.has_comma, o_O=pmod_pads[5]),
# Instance("OBUF", i_I=gtx.comma_checker.has_error, o_O=pmod_pads[6]),
# Instance("OBUF", i_I=gtx.comma_checker.ready_sys, o_O=pmod_pads[7]),
# Instance("OBUF", i_I=gtx.dclk, o_O=pmod_pads[0]),
# Instance("OBUF", i_I=gtx.den, o_O=pmod_pads[1]),
# Instance("OBUF", i_I=gtx.dwen, o_O=pmod_pads[2]),
# Instance("OBUF", i_I=gtx.dready, o_O=pmod_pads[3]),
]
class QPLL(Module, AutoCSR): class QPLL(Module, AutoCSR):
def __init__(self, refclk, sys_clk_freq): def __init__(self, refclk, sys_clk_freq):

View File

@ -1,296 +1,292 @@
from migen import * from migen import *
from misoc.interconnect.csr import * from misoc.interconnect.csr import *
from misoc.interconnect import stream from misoc.interconnect import stream
from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine, LiteEthMACCRCChecker
char_width = 8
char_layout = [("data", char_width), ("k", char_width//8)]
import struct word_dw = 32
word_layout = [("data", word_dw), ("k", word_dw//8)]
upconn_dw = 8 buffer_depth = 128
upconn_layout = [("data", upconn_dw), ("k", upconn_dw//8)]
downconn_dw = 32
downconn_layout = [("data", downconn_dw), ("k", downconn_dw//8)]
def K(x, y): def K(x, y):
return ((y << 5) | x) return ((y << 5) | x)
KCode = { KCode = {
"pak_start" : K(27, 7), "pak_start" : C(K(27, 7), char_width),
"io_ack" : K(28, 6), "io_ack" : C(K(28, 6), char_width),
"trig_indic_28_2" : K(28, 2), "trig_indic_28_2" : C(K(28, 2), char_width),
"trig_indic_28_4" : K(28, 4), "trig_indic_28_4" : C(K(28, 4), char_width),
"pak_end" : K(29, 7), "pak_end" : C(K(29, 7), char_width),
"idle_comma" : C(K(28, 5), char_width),
"idle_alignment" : C(K(28, 1), char_width),
} }
class Packet_Wrapper(Module):
def _bytes2word(bytes, big_endian=True): def __init__(self):
if big_endian: self.sink = stream.Endpoint(word_layout)
return struct.unpack(">I", struct.pack(">4B", *bytes))[0] self.source = stream.Endpoint(word_layout)
else:
return struct.unpack("<I", struct.pack(">4B", *bytes))[0]
class Code_Source(Module):
def __init__(self, layout, data, k):
self.source = stream.Endpoint(layout)
self.stb = Signal()
# # # # # #
assert len(data) == len(k) > 0
counts = len(data)
cnt = Signal() if counts == 1 else Signal(max=counts)
clr_cnt = Signal()
inc_cnt = Signal()
self.sync += [
If(clr_cnt,
cnt.eq(cnt.reset),
).Elif(inc_cnt,
cnt.eq(cnt + 1),
)
]
self.submodules.fsm = fsm = FSM(reset_state="IDLE") self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
clr_cnt.eq(1),
If(self.stb,
NextState("WRITE")
)
)
fsm.act("WRITE",
self.source.stb.eq(1),
self.source.data.eq(Array(data)[cnt]),
self.source.k.eq(Array(k)[cnt]),
If(cnt == counts - 1,
self.source.eop.eq(1),
If(self.source.ack, NextState("IDLE"))
).Else(
inc_cnt.eq(self.source.ack)
)
)
class Code_Inserter(Module):
def __init__(self, layout, data, k, insert_infront=True):
self.sink = stream.Endpoint(layout)
self.source = stream.Endpoint(layout)
self.data = Signal.like(self.sink.data)
self.k = Signal.like(self.sink.k)
# # #
assert len(data) == len(k) > 0
counts = len(data)
cnt = Signal() if counts == 1 else Signal(max=counts)
clr_cnt = Signal()
inc_cnt = Signal()
self.sync += [
If(clr_cnt,
cnt.eq(cnt.reset),
).Elif(inc_cnt,
cnt.eq(cnt + 1),
)
]
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
remove_sink_oep = 0 if insert_infront else 1
# add code in front: IDLE -> INSERT -> COPY
# add code at end: IDLE -> COPY -> INSERT
fsm.act("IDLE", fsm.act("IDLE",
self.sink.ack.eq(1), self.sink.ack.eq(1),
clr_cnt.eq(1),
If(self.sink.stb, If(self.sink.stb,
self.sink.ack.eq(0), self.sink.ack.eq(0),
NextState("INSERT" if insert_infront else "COPY"), NextState("INSERT_HEADER"),
) )
) )
fsm.act("INSERT", fsm.act("INSERT_HEADER",
self.sink.ack.eq(0), self.sink.ack.eq(0),
self.source.stb.eq(1), self.source.stb.eq(1),
self.source.data.eq(Array(data)[cnt]), self.source.data.eq(Replicate(KCode["pak_start"], 4)),
self.source.k.eq(Array(k)[cnt]), self.source.k.eq(0b1111),
If(cnt == counts - 1, If(self.source.ack, NextState("COPY")),
If(remove_sink_oep, self.source.eop.eq(1)),
If(self.source.ack, NextState("COPY" if insert_infront else "IDLE"))
).Else(
inc_cnt.eq(self.source.ack)
)
) )
fsm.act("COPY", fsm.act("COPY",
self.sink.connect(self.source), self.sink.connect(self.source),
If(remove_sink_oep, self.source.eop.eq(0)), self.source.eop.eq(0),
If(self.sink.stb & self.sink.eop & self.source.ack, If(self.sink.stb & self.sink.eop & self.source.ack,
NextState("IDLE" if insert_infront else "INSERT"), NextState("INSERT_FOOTER"),
) ),
) )
fsm.act("INSERT_FOOTER",
self.sink.ack.eq(0),
self.source.stb.eq(1),
self.source.data.eq(Replicate(KCode["pak_end"], 4)),
self.source.k.eq(0b1111),
self.source.eop.eq(1),
If(self.source.ack, NextState("IDLE")),
)
class Packet_Wrapper(Module): class TX_Trigger(Module):
def __init__(self, layout):
self.submodules.pak_start = pak_start = Code_Inserter(layout, [KCode["pak_start"]]*4, [1]*4)
self.submodules.pak_end = pak_end = Code_Inserter(layout, [KCode["pak_end"]]*4, [1]*4, insert_infront=False)
self.comb += pak_start.source.connect(pak_end.sink),
self.sink = pak_start.sink
self.source = pak_end.source
@ResetInserter()
@CEInserter()
class CXPCRC32(Module):
# Section 9.2.2.2 (CXP-001-2021)
width = 32
polynom = 0x04C11DB7
seed = 2**width-1
check = 0x00000000
def __init__(self, data_width):
self.data = Signal(data_width)
self.value = Signal(self.width)
self.error = Signal()
# # #
self.submodules.engine = LiteEthMACCRCEngine(data_width, self.width, self.polynom)
reg = Signal(self.width, reset=self.seed)
self.sync += reg.eq(self.engine.next)
self.comb += [
self.engine.data.eq(self.data),
self.engine.last.eq(reg),
self.value.eq(reg[::-1]),
self.error.eq(self.engine.next != self.check)
]
class CXPCRC32Checker(LiteEthMACCRCChecker):
def __init__(self, layout):
LiteEthMACCRCChecker.__init__(self, CXPCRC32, layout)
class TX_Trigger(Module, AutoCSR):
def __init__(self): def __init__(self):
self.trig_stb = Signal() self.stb = Signal()
self.delay = Signal(upconn_dw) self.delay = Signal(char_width)
self.linktrig_mode = Signal(max=4) self.linktrig_mode = Signal(max=4)
# # # # # #
self.sink = stream.Endpoint(char_layout)
self.source = stream.Endpoint(char_layout)
# Table 15 & 16 (CXP-001-2021) # Table 15 & 16 (CXP-001-2021)
# Send [K28.2, K28.4, K28.4] or [K28.4, K28.2, K28.2] and 3x delay as trigger packet # Send [K28.2, K28.4, K28.4] or [K28.4, K28.2, K28.2] and 3x delay as trigger packet
self.submodules.code_src = code_src = Code_Source(upconn_layout, [self.delay]*3, [0]*3) trig_packet = [Signal(char_width), Signal(char_width), Signal(char_width), self.delay, self.delay, self.delay]
self.comb += code_src.stb.eq(self.trig_stb), trig_packet_k = [1, 1, 1, 0, 0, 0]
self.comb += [
header = [Signal(8) for _ in range(3)]
self.comb += \
If((self.linktrig_mode == 0) | (self.linktrig_mode == 2), If((self.linktrig_mode == 0) | (self.linktrig_mode == 2),
header[0].eq(KCode["trig_indic_28_2"]), trig_packet[0].eq(KCode["trig_indic_28_2"]),
header[1].eq(KCode["trig_indic_28_4"]), trig_packet[1].eq(KCode["trig_indic_28_4"]),
header[2].eq(KCode["trig_indic_28_4"]), trig_packet[2].eq(KCode["trig_indic_28_4"]),
).Else( ).Else(
header[0].eq(KCode["trig_indic_28_4"]), trig_packet[0].eq(KCode["trig_indic_28_4"]),
header[1].eq(KCode["trig_indic_28_2"]), trig_packet[1].eq(KCode["trig_indic_28_2"]),
header[2].eq(KCode["trig_indic_28_2"]), trig_packet[2].eq(KCode["trig_indic_28_2"]),
),
]
self.submodules.fsm = fsm = FSM(reset_state="COPY")
cnt = Signal(max=6)
fsm.act("COPY",
NextValue(cnt, cnt.reset),
self.sink.connect(self.source),
If(self.stb, NextState("WRITE_TRIG"))
)
fsm.act("WRITE_TRIG",
self.sink.ack.eq(0),
self.source.stb.eq(1),
self.source.data.eq(Array(trig_packet)[cnt]),
self.source.k.eq(Array(trig_packet_k)[cnt]),
If(self.source.ack,
If(cnt == 5,
NextState("COPY"),
).Else(
NextValue(cnt, cnt + 1),
)
) )
)
self.submodules.inserter = inserter = Code_Inserter(upconn_layout, header, [1]*3) class Idle_Word_Inserter(Module):
self.comb += code_src.source.connect(inserter.sink)
self.source = inserter.source
class Trigger_ACK(Module):
def __init__(self): def __init__(self):
self.ack = Signal() self.stb = Signal()
# # #
# Section 9.2.5 (CXP-001-2021)
# Send K28.5, K28.1, K28.1, D21.5 as idle word
self.submodules.fsm = fsm = FSM(reset_state="COPY")
self.sink = stream.Endpoint(word_layout)
self.source = stream.Endpoint(word_layout)
fsm.act("COPY",
self.sink.connect(self.source),
If(self.stb, NextState("WRITE_IDLE"))
)
fsm.act("WRITE_IDLE",
self.sink.ack.eq(0),
self.source.stb.eq(1),
self.source.data.eq(Cat(KCode["idle_comma"], KCode["idle_alignment"], KCode["idle_alignment"], C(0xB5, char_width))),
self.source.k.eq(0b1110),
If(self.source.ack, NextState("COPY")),
)
class Trigger_ACK_Inserter(Module):
def __init__(self):
self.stb = Signal()
# # # # # #
# Section 9.3.2 (CXP-001-2021) # Section 9.3.2 (CXP-001-2021)
# Send 4x K28.6 and 4x 0x01 as trigger packet ack # Send 4x K28.6 and 4x 0x01 as trigger packet ack
self.submodules.code_src = code_src = Code_Source(upconn_layout, [0x01]*4, [0]*4) self.submodules.fsm = fsm = FSM(reset_state="COPY")
self.submodules.inserter = inserter = Code_Inserter(upconn_layout, [KCode["io_ack"]]*4, [1]*4)
self.comb += [
code_src.stb.eq(self.ack),
code_src.source.connect(inserter.sink)
]
self.source = inserter.source self.sink = stream.Endpoint(word_layout)
self.source = stream.Endpoint(word_layout)
fsm.act("COPY",
self.sink.connect(self.source),
If(self.stb, NextState("WRITE_ACK0"))
)
fsm.act("WRITE_ACK0",
self.sink.ack.eq(0),
self.source.stb.eq(1),
self.source.data.eq(Replicate(KCode["io_ack"], 4)),
self.source.k.eq(0b1111),
If(self.source.ack, NextState("WRITE_ACK1")),
)
fsm.act("WRITE_ACK1",
self.sink.ack.eq(0),
self.source.stb.eq(1),
self.source.data.eq(Replicate(C(0x01, char_width), 4)),
self.source.k.eq(0b0000),
If(self.source.ack, NextState("COPY")),
)
@FullMemoryWE()
class TX_Command_Packet(Module, AutoCSR): class TX_Command_Packet(Module, AutoCSR):
# Section 12.1.2 (CXP-001-2021) def __init__(self):
# Max control packet size is 128 bytes self.tx_word_len = CSRStorage(bits_for(buffer_depth))
def __init__(self, fifo_depth=128): self.tx = CSR()
self.len = CSRStorage(log2_int(fifo_depth))
self.data = CSR(upconn_dw)
self.writeable = CSRStatus()
# # # # # #
self.submodules.fifo = fifo = stream.SyncFIFO(upconn_layout, fifo_depth) self.specials.mem = mem = Memory(word_dw, buffer_depth)
self.submodules.pak_wrp = pak_wrp = Packet_Wrapper(upconn_layout) self.specials.mem_port = mem_port = mem.get_port()
self.source = pak_wrp.source self.source = stream.Endpoint(word_layout)
self.comb += fifo.source.connect(pak_wrp.sink)
cnt = Signal(log2_int(fifo_depth), reset=1) tx_done = Signal()
addr_next = Signal(bits_for(buffer_depth))
addr = Signal.like(addr_next)
addr_rst = Signal()
addr_inc = Signal()
# increment addr in the same cycle the moment addr_inc is high
# as memory takes one cycle to shift to the correct addr
self.sync += [ self.sync += [
self.writeable.status.eq(fifo.sink.ack), addr.eq(addr_next),
If(fifo.sink.ack, fifo.sink.stb.eq(0)), If(self.tx.re, self.tx.w.eq(1)),
If(self.data.re, If(tx_done, self.tx.w.eq(0)),
fifo.sink.stb.eq(1),
fifo.sink.data.eq(self.data.r),
fifo.sink.k.eq(0),
If(cnt == self.len.storage,
fifo.sink.eop.eq(1),
cnt.eq(cnt.reset),
).Else(
fifo.sink.eop.eq(0),
cnt.eq(cnt + 1),
),
)
] ]
self.comb += [
addr_next.eq(addr),
If(addr_rst,
addr_next.eq(addr_next.reset),
).Elif(addr_inc,
addr_next.eq(addr + 1),
),
mem_port.adr.eq(addr_next),
self.source.data.eq(mem_port.dat_r)
]
self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE",
addr_rst.eq(1),
If(self.tx.re, NextState("TRANSMIT"))
)
fsm.act("TRANSMIT",
self.source.stb.eq(1),
If(self.source.ack,
addr_inc.eq(1),
),
If(addr_next == self.tx_word_len.storage,
self.source.eop.eq(1),
tx_done.eq(1),
NextState("IDLE")
)
)
class TX_Test_Packet(Module, AutoCSR): class TX_Test_Packet(Module, AutoCSR):
def __init__(self): def __init__(self):
self.tx = CSR()
self.stb = CSR()
self.busy = CSRStatus()
# # # # # #
self.submodules.test_pattern_src = test_pattern_src = Code_Source(upconn_layout, [*range(0x100)]*16, [0]*0x100*16) tx_done = Signal()
self.submodules.pak_type_inserter = pak_type_inserter = Code_Inserter(upconn_layout, [0x04]*4, [0]*4) self.sync += [
self.submodules.pak_wrp = pak_wrp = Packet_Wrapper(upconn_layout) If(self.tx.re, self.tx.w.eq(1)),
self.comb += [ If(tx_done, self.tx.w.eq(0)),
test_pattern_src.source.connect(pak_type_inserter.sink),
pak_type_inserter.source.connect(pak_wrp.sink),
] ]
self.source = pak_wrp.source self.source = stream.Endpoint(word_layout)
self.sync += [ self.submodules.fsm = fsm = FSM(reset_state="IDLE")
test_pattern_src.stb.eq(self.stb.re),
If(self.stb.re, cnt = Signal(0xFFF)
self.busy.status.eq(1), fsm.act("IDLE",
).Elif(self.source.eop & self.source.ack, NextValue(cnt, cnt.reset),
self.busy.status.eq(0) If(self.tx.re,
NextState("WRITE_PACKET_TYPE")
) )
] )
fsm.act("WRITE_PACKET_TYPE",
self.source.stb.eq(1),
self.source.data.eq(Replicate(C(0x04, char_width), 4)),
self.source.k.eq(0b0000),
If(self.source.ack,NextState("WRITE_TEST_COUNTER"))
)
fsm.act("WRITE_TEST_COUNTER",
self.source.stb.eq(1),
self.source.data.eq(Cat(cnt[:8], cnt[:8]+1, cnt[:8]+2, cnt[:8]+3)),
self.source.k.eq(0b0000),
If(self.source.ack,
If(cnt == 0xFFF-3,
tx_done.eq(1),
self.source.eop.eq(1),
NextState("IDLE")
).Else(
NextValue(cnt, cnt + 4),
)
)
)
class RX_Debug_Buffer(Module,AutoCSR): class RX_Debug_Buffer(Module,AutoCSR):
def __init__(self): def __init__(self):
self.submodules.buf_out = buf_out = stream.SyncFIFO(downconn_layout, 128) self.submodules.buf_out = buf_out = stream.SyncFIFO(word_layout, 128)
self.sink = buf_out.sink self.sink = buf_out.sink
self.inc = CSR() self.inc = CSR()
self.dout_pak = CSRStatus(downconn_dw) self.dout_pak = CSRStatus(word_dw)
self.kout_pak = CSRStatus(downconn_dw//8) self.kout_pak = CSRStatus(word_dw//8)
self.dout_valid = CSRStatus() self.dout_valid = CSRStatus()
self.sync += [ self.sync += [
@ -301,110 +297,63 @@ class RX_Debug_Buffer(Module,AutoCSR):
self.dout_valid.status.eq(buf_out.source.stb), self.dout_valid.status.eq(buf_out.source.stb),
] ]
class Receiver_Path(Module, AutoCSR): @FullMemoryWE()
def __init__(self):
self.trig_ack = Signal()
self.trig_clr = Signal()
self.packet_type = Signal(8)
self.decoder_err = Signal()
self.decoder_err_clr = Signal()
self.test_err = Signal()
self.test_err_clr = Signal()
# # #
self.submodules.trig_ack_checker = trig_ack_checker = CXP_Trig_Ack_Checker()
self.submodules.packet_decoder = packet_decoder = CXP_Data_Packet_Decode()
# Error are latched
self.sync += [
If(trig_ack_checker.ack,
self.trig_ack.eq(1),
).Elif(self.trig_clr,
self.trig_ack.eq(0),
),
If(packet_decoder.decode_err,
self.decoder_err.eq(1),
).Elif(self.decoder_err_clr,
self.decoder_err.eq(0),
),
If(packet_decoder.test_err,
self.test_err.eq(1),
).Elif(self.test_err_clr,
self.test_err.eq(0),
)
]
self.comb += [
self.packet_type.eq(packet_decoder.packet_type),
]
pipeline = [ trig_ack_checker, packet_decoder ]
for s, d in zip(pipeline, pipeline[1:]):
self.comb += s.source.connect(d.sink)
self.sink = pipeline[0].sink
self.source = pipeline[-1].source
class CXP_Data_Packet_Decode(Module): class CXP_Data_Packet_Decode(Module):
def __init__(self): def __init__(self):
self.sink = stream.Endpoint(downconn_layout)
# This is where data stream comes out
self.source = stream.Endpoint(downconn_layout)
self.packet_type = Signal(8) self.packet_type = Signal(8)
self.decode_err = Signal() self.write_ptr = Signal(bits_for(buffer_depth))
self.buffer = Signal(40*downconn_dw) self.new_packet = Signal()
self.decode_err = Signal()
self.test_err = Signal() self.test_err = Signal()
# # # # # #
# decoder -> priorities mux(normal packet vs trigger ack) -> data packet mux (control ack, data stream, heartbeat, testmode, (optional Genlcam event)) # DEBUG: remove debug
# TODO: decode all packet type here
# TODO: data&event -> memory
# TODO: heartbeat
type = { type = {
"data_stream": 0x01, "data_stream": 0x01,
"control_ack_no_tag": 0x03, "control_ack_no_tag": 0x03,
"test_packet": 0x04, "test_packet": 0x04,
"control_ack_with_tag": 0x06, "control_ack_with_tag": 0x06,
"event_ack": 0x08, "event": 0x07,
"heartbeat": 0x09, "heartbeat": 0x09,
"debug" : 0x02, "debug" : 0x02,
} }
self.sink = stream.Endpoint(word_layout)
self.source = stream.Endpoint(word_layout)
self.submodules.fsm = fsm = FSM(reset_state="IDLE") self.submodules.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE", fsm.act("IDLE",
self.sink.ack.eq(1), self.sink.ack.eq(1),
# TODO: add error correction? # TODO: add error correction?
If((self.sink.stb & (self.sink.data == _bytes2word([KCode["pak_start"]]*4)) & (self.sink.k == 0b1111)), If((self.sink.stb & (self.sink.data == Replicate(KCode["pak_start"], 4)) & (self.sink.k == 0b1111)),
NextState("DECODE"), NextState("DECODE"),
) )
) )
# TODO: decode all packet type here
cnt = Signal(max=0x100) cnt = Signal(max=0x100)
fsm.act("DECODE", fsm.act("DECODE",
self.sink.ack.eq(1), self.sink.ack.eq(1),
If(self.sink.stb, If(self.sink.stb,
self.new_packet.eq(1),
NextValue(self.packet_type, self.sink.data[:8]), NextValue(self.packet_type, self.sink.data[:8]),
Case(self.sink.data[:8],{ Case(self.sink.data[:8],{
type["data_stream"]: NextState("STREAMING"), type["data_stream"]: NextState("STREAMING"),
type["debug"]: NextState("STREAMING"), type["control_ack_no_tag"]: NextState("LOAD_BUFFER"),
type["test_packet"]: [ type["test_packet"]: [
NextValue(cnt, 0), NextValue(cnt, cnt.reset),
NextState("VERIFY_TEST_PATTERN"), NextState("VERIFY_TEST_PATTERN"),
], ],
type["control_ack_with_tag"]: NextState("LOAD_BUFFER"),
type["event"]: NextState("LOAD_BUFFER"),
type["debug"]: NextState("LOAD_BUFFER"),
"default": [ "default": [
self.decode_err.eq(1), self.decode_err.eq(1),
# wait till next valid packet # wait till next valid packet
@ -420,11 +369,11 @@ class CXP_Data_Packet_Decode(Module):
fsm.act("VERIFY_TEST_PATTERN", fsm.act("VERIFY_TEST_PATTERN",
self.sink.ack.eq(1), self.sink.ack.eq(1),
If(self.sink.stb, If(self.sink.stb,
If(((self.sink.data == _bytes2word([KCode["pak_end"]]*4)) & (self.sink.k == 0b1111)), If(((self.sink.data == Replicate(KCode["pak_end"], 4)) & (self.sink.k == 0b1111)),
NextState("IDLE"), NextState("IDLE"),
).Else( ).Else(
If(((self.sink.data != Cat(cnt, cnt+1, cnt+2, cnt+3))), If(((self.sink.data != Cat(cnt, cnt+1, cnt+2, cnt+3))),
self.test_err.eq(1), self.test_err.eq(1),
), ),
If(cnt == 0xFC, If(cnt == 0xFC,
NextValue(cnt, cnt.reset), NextValue(cnt, cnt.reset),
@ -436,8 +385,9 @@ class CXP_Data_Packet_Decode(Module):
) )
# For stream data packet
fsm.act("STREAMING", fsm.act("STREAMING",
If((self.sink.stb & (self.sink.data == _bytes2word([KCode["pak_end"]]*4)) & (self.sink.k == 0b1111)), If((self.sink.stb & (self.sink.data == Replicate(KCode["pak_end"], 4)) & (self.sink.k == 0b1111)),
# discard K29,7 # discard K29,7
self.sink.ack.eq(1), self.sink.ack.eq(1),
NextState("IDLE") NextState("IDLE")
@ -445,49 +395,41 @@ class CXP_Data_Packet_Decode(Module):
self.sink.connect(self.source), self.sink.connect(self.source),
) )
) )
# # input pipeline stage - determine packet length based on type
# self.sync += [
# packet_start.eq((self.sink.data[0] == K(27, 7)) & (self.sink.k[0] == 1)),
# packet_end.eq((self.sink.data[0] == K(29, 7)) & (self.sink.k[0] == 1)),
# If((self.sink.data[0] == K(27, 7)) & (self.sink.k[0] == 1), # A circular buffer for firmware to read packet from
# packet_buffer_load.eq(1), self.specials.mem = mem = Memory(word_dw, buffer_depth)
# ), self.specials.mem_port = mem_port = mem.get_port(write_capable=True)
self.comb += mem_port.adr.eq(self.write_ptr),
# trig_ack.eq((self.sink.data[0] == K(28, 6)) & (self.sink.k[0] == 1)), # For control ack, event packet
# If(trig_ack, fsm.act("LOAD_BUFFER",
# self.trig_ack.eq(self.sink.data[0]), mem_port.we.eq(0),
# trig_ack.eq(0), self.sink.ack.eq(1),
# ).Elif(packet_buffer_load, If(self.sink.stb,
# # TODO: add test packet counting If(((self.sink.data == Replicate(KCode["pak_end"], 4)) & (self.sink.k == 0b1111)),
# Case(buffer_count, NextState("IDLE"),
# {i: buffer[i*downconn_dw:(i+1)*downconn_dw].eq(self.sink.data) ).Else(
# for i in range(40)}), mem_port.we.eq(1),
# buffer_count.eq(buffer_count + 1), mem_port.dat_w.eq(self.sink.data),
NextValue(self.write_ptr, self.write_ptr + 1),
)
)
)
class CXP_Trig_Ack_Checker(Module, AutoCSR): class CXP_Trig_Ack_Checker(Module, AutoCSR):
def __init__(self): def __init__(self):
self.sink = stream.Endpoint(downconn_layout) self.sink = stream.Endpoint(word_layout)
self.source = stream.Endpoint(downconn_layout) self.source = stream.Endpoint(word_layout)
self.ack = Signal() self.ack = Signal()
# # # # # #
self.submodules.fsm = fsm = FSM(reset_state="IDLE") self.submodules.fsm = fsm = FSM(reset_state="COPY")
fsm.act("IDLE",
self.sink.ack.eq(1),
If(self.sink.stb,
self.sink.ack.eq(0),
NextState("COPY"),
)
)
fsm.act("COPY", fsm.act("COPY",
If((self.sink.stb & (self.sink.data == _bytes2word([KCode["io_ack"]]*4)) & (self.sink.k == 0b1111)), If((self.sink.stb & (self.sink.data == Replicate(KCode["io_ack"], 4)) & (self.sink.k == 0b1111)),
# discard K28,6 # discard K28,6
self.sink.ack.eq(1), self.sink.ack.eq(1),
NextState("CHECK_ACK") NextState("CHECK_ACK")
@ -498,10 +440,10 @@ class CXP_Trig_Ack_Checker(Module, AutoCSR):
fsm.act("CHECK_ACK", fsm.act("CHECK_ACK",
If(self.sink.stb, If(self.sink.stb,
NextState("IDLE"), NextState("COPY"),
# discard the word after K28,6 # discard the word after K28,6
self.sink.ack.eq(1), self.sink.ack.eq(1),
If(self.sink.data == _bytes2word([0x01]*4), If(self.sink.data == Replicate(C(0x01, char_width), 4),
self.ack.eq(1), self.ack.eq(1),
) )
) )

View File

@ -1,21 +1,12 @@
from math import ceil from math import ceil
from migen import * from migen import *
from migen.genlib.coding import PriorityEncoder
from misoc.cores.code_8b10b import SingleEncoder from misoc.cores.code_8b10b import SingleEncoder
from misoc.interconnect import stream from misoc.interconnect import stream
from misoc.interconnect.csr import * from misoc.interconnect.csr import *
from cxp_pipeline import upconn_layout from cxp_pipeline import char_layout
IDLE_CHARS = Array([
#[char, k]
[0xBC, 1], #K28.5
[0x3C, 1], #K28.1
[0x3C, 1], #K28.1
[0xB5, 0], #D21.5
])
@ResetInserter() @ResetInserter()
class UpConn_ClockGen(Module): class UpConn_ClockGen(Module):
@ -94,173 +85,6 @@ class SERDES_10bits(Module):
) )
] ]
@ResetInserter()
class Transmit_Scheduler(Module):
def __init__(self, interface, debug_buf):
self.tx_enable = Signal()
self.oe = Signal()
self.ce = Signal()
# # #
self.submodules.startup_fsm = startup_fsm = CEInserter()(FSM(reset_state="WAIT_TX_ENABLE"))
self.submodules.encoder = encoder = CEInserter()(SingleEncoder(True))
self.comb += [
startup_fsm.ce.eq(self.ce),
encoder.ce.eq(self.ce),
]
tx_charcount = Signal(max=4)
tx_wordcount = Signal(max=10000)
idling = Signal()
priorities = Signal.like(interface.pe.o)
# DEBUG:
self.idling = Signal()
self.tx_charcount = Signal(max=4)
self.comb += [
self.idling.eq(idling),
self.tx_charcount.eq(tx_charcount),
]
startup_fsm.act("WAIT_TX_ENABLE",
If(self.tx_enable,
NextValue(idling, 1),
NextValue(tx_charcount, 0),
NextValue(encoder.d, IDLE_CHARS[0][0]),
NextValue(encoder.k, IDLE_CHARS[0][1]),
NextState("START_TX"),
# DEBUG:
If(debug_buf.sink_ack,
NextValue(debug_buf.sink_stb, 1),
NextValue(debug_buf.sink_data, IDLE_CHARS[0][0]),
NextValue(debug_buf.sink_k, IDLE_CHARS[0][1]),
)
)
)
startup_fsm.act("START_TX",
self.oe.eq(1),
If((~self.tx_enable) & (tx_charcount == 3),
NextState("WAIT_TX_ENABLE")
)
)
# hold ack for only one sys clk cycle to prevent data loss
for ack in interface.sink_ack:
self.sync += ack.eq(0)
self.sync += [
debug_buf.sink_stb.eq(0),
If(self.oe & self.ce,
encoder.disp_in.eq(encoder.disp_out),
If((~interface.pe.n) & (interface.pe.o == 0),
# trigger packets are inserted at char boundary and don't contribute to word count
interface.sink_ack[0].eq(1),
encoder.d.eq(interface.sink_data[0]),
encoder.k.eq(interface.sink_k[0]),
# DEBUG:
If(debug_buf.sink_ack,
debug_buf.sink_stb.eq(1),
debug_buf.sink_data.eq(interface.sink_data[0]),
debug_buf.sink_k.eq(interface.sink_k[0]),
)
).Else(
If(tx_charcount == 3,
tx_charcount.eq(0),
# Section 9.2.4 (CXP-001-2021)
# other priorities packets are inserted at word boundary
If((~interface.pe.n) & (tx_wordcount != 9999),
idling.eq(0),
priorities.eq(interface.pe.o),
tx_wordcount.eq(tx_wordcount + 1),
interface.sink_ack[interface.pe.o].eq(1),
encoder.d.eq(interface.sink_data[interface.pe.o]),
encoder.k.eq(interface.sink_k[interface.pe.o]),
# DEBUG:
If(debug_buf.sink_ack,
debug_buf.sink_stb.eq(1),
debug_buf.sink_data.eq(interface.sink_data[interface.pe.o]),
debug_buf.sink_k.eq(interface.sink_k[interface.pe.o]),
)
).Else(
# Section 9.2.5.1 (CXP-001-2021)
# IDLE word shall be transmitted at least once every 10,000 words, but should not be inserted into trigger packet
idling.eq(1),
tx_wordcount.eq(0),
encoder.d.eq(IDLE_CHARS[0][0]),
encoder.k.eq(IDLE_CHARS[0][1]),
# DEBUG:
If(debug_buf.sink_ack,
debug_buf.sink_stb.eq(1),
debug_buf.sink_data.eq(IDLE_CHARS[0][0]),
debug_buf.sink_k.eq(IDLE_CHARS[0][1]),
)
)
).Else(
tx_charcount.eq(tx_charcount + 1),
If(~idling,
tx_wordcount.eq(tx_wordcount + 1),
interface.sink_ack[priorities].eq(1),
encoder.d.eq(interface.sink_data[priorities]),
encoder.k.eq(interface.sink_k[priorities]),
# DEBUG:
If(debug_buf.sink_ack,
debug_buf.sink_stb.eq(1),
debug_buf.sink_data.eq(interface.sink_data[priorities]),
debug_buf.sink_k.eq(interface.sink_k[priorities]),
)
).Else(
encoder.d.eq(IDLE_CHARS[tx_charcount + 1][0]),
encoder.k.eq(IDLE_CHARS[tx_charcount + 1][1]),
# DEBUG:
If(debug_buf.sink_ack,
debug_buf.sink_stb.eq(1),
debug_buf.sink_data.eq(IDLE_CHARS[tx_charcount + 1][0]),
debug_buf.sink_k.eq(IDLE_CHARS[tx_charcount + 1][1]),
)
)
),
),
)
]
class PHY_Interface(Module):
def __init__(self, layout, nsink):
sink_stb = Signal(nsink)
self.sink_ack = Array(Signal() for _ in range(nsink))
self.sink_data = Array(Signal(8) for _ in range(nsink))
self.sink_k = Array(Signal() for _ in range(nsink))
# # #
self.sinks = []
for i in range(nsink):
sink = stream.Endpoint(layout)
self.sinks += [sink]
self.comb += [
sink.ack.eq(self.sink_ack[i]),
sink_stb[i].eq(sink.stb),
self.sink_data[i].eq(sink.data),
self.sink_k[i].eq(sink.k),
]
# FIFOs transmission priority
self.submodules.pe = PriorityEncoder(nsink)
self.comb += self.pe.i.eq(sink_stb)
class Debug_buffer(Module,AutoCSR): class Debug_buffer(Module,AutoCSR):
def __init__(self, layout): def __init__(self, layout):
self.sink_stb = Signal() self.sink_stb = Signal()
@ -270,7 +94,7 @@ class Debug_buffer(Module,AutoCSR):
# # # # # #
self.submodules.buf_out = buf_out = stream.SyncFIFO(layout, 128) self.submodules.buf_out = buf_out = stream.SyncFIFO(layout, 512)
self.sync += [ self.sync += [
buf_out.sink.stb.eq(self.sink_stb), buf_out.sink.stb.eq(self.sink_stb),
@ -293,63 +117,70 @@ class Debug_buffer(Module,AutoCSR):
] ]
class CXP_UpConn_PHY(Module, AutoCSR): class Transmitter(Module, AutoCSR):
def __init__(self, pad, sys_clk_freq, debug_sma, pmod_pads, nsink=3): def __init__(self, pad, sys_clk_freq, debug_sma, pmod_pads):
self.bitrate2x_enable = Signal() self.bitrate2x_enable = Signal()
self.clk_reset = Signal() self.clk_reset = Signal()
self.tx_enable = Signal() self.tx_enable = Signal()
self.tx_busy = Signal()
# # # # # #
self.sink = stream.Endpoint(char_layout)
self.submodules.cg = cg = UpConn_ClockGen(sys_clk_freq) self.submodules.cg = cg = UpConn_ClockGen(sys_clk_freq)
self.submodules.interface = interface = PHY_Interface(upconn_layout, nsink) self.submodules.encoder = encoder = SingleEncoder(True)
self.submodules.debug_buf = debug_buf = Debug_buffer(char_layout)
self.sinks = interface.sinks oe = Signal()
self.sync += [
If(self.tx_enable,
self.sink.ack.eq(0),
# DEBUG: # DEBUG:
self.submodules.debug_buf = debug_buf = Debug_buffer(upconn_layout) debug_buf.sink_stb.eq(0),
If(cg.clk,
oe.eq(1),
encoder.disp_in.eq(encoder.disp_out),
self.sink.ack.eq(1),
encoder.d.eq(self.sink.data),
encoder.k.eq(self.sink.k),
# DEBUG:
If(debug_buf.sink_ack,
debug_buf.sink_stb.eq(1),
debug_buf.sink_data.eq(self.sink.data),
debug_buf.sink_k.eq(self.sink.k),
)
)
).Else(
# DEBUG:
debug_buf.sink_stb.eq(0),
# no backpressure
self.sink.ack.eq(1),
oe.eq(0),
)
]
self.submodules.scheduler = scheduler = Transmit_Scheduler(interface, debug_buf)
self.submodules.serdes = serdes = SERDES_10bits(pad) self.submodules.serdes = serdes = SERDES_10bits(pad)
self.comb += [ self.comb += [
self.tx_busy.eq(~interface.pe.n),
cg.reset.eq(self.clk_reset), cg.reset.eq(self.clk_reset),
cg.freq2x_enable.eq(self.bitrate2x_enable), cg.freq2x_enable.eq(self.bitrate2x_enable),
scheduler.reset.eq(self.clk_reset),
scheduler.ce.eq(cg.clk),
scheduler.tx_enable.eq(self.tx_enable),
serdes.reset.eq(self.clk_reset), serdes.reset.eq(self.clk_reset),
serdes.ce.eq(cg.clk_10x), serdes.ce.eq(cg.clk_10x),
serdes.d.eq(scheduler.encoder.output), serdes.d.eq(encoder.output),
serdes.oe.eq(scheduler.oe), serdes.oe.eq(oe),
] ]
# DEBUG: remove pads # DEBUG: remove pads
prioity_0 = Signal()
word_bound = Signal()
p0 = Signal()
p3 = Signal()
self.comb += [
prioity_0.eq((~interface.pe.n) & (interface.pe.o == 0)),
word_bound.eq(scheduler.tx_charcount == 3),
# because of clk delay
p0.eq(scheduler.tx_charcount == 2),
p3.eq(scheduler.tx_charcount == 1),
]
self.specials += [ self.specials += [
# # debug sma # # debug sma
Instance("OBUF", i_I=serdes.o, o_O=debug_sma.p_tx), # Instance("OBUF", i_I=serdes.o, o_O=debug_sma.p_tx),
Instance("OBUF", i_I=cg.clk_10x, o_O=debug_sma.n_rx), # Instance("OBUF", i_I=cg.clk_10x, o_O=debug_sma.n_rx),
@ -372,3 +203,10 @@ class CXP_UpConn_PHY(Module, AutoCSR):
# Instance("OBUF", i_I=p3, o_O=pmod_pads[7]), # Instance("OBUF", i_I=p3, o_O=pmod_pads[7]),
] ]
class CXP_UpConn_PHYS(Module, AutoCSR):
def __init__(self, pads, sys_clk_freq, debug_sma, pmod_pads):
self.tx_phys = []
for i, pad in enumerate(pads):
tx = Transmitter(pad, sys_clk_freq, debug_sma, pmod_pads)
self.tx_phys.append(tx)
setattr(self.submodules, "tx"+str(i), tx)

View File

@ -25,7 +25,8 @@ import analyzer
import acpki import acpki
import drtio_aux_controller import drtio_aux_controller
import zynq_clocking import zynq_clocking
import cxp_4r_fmc, cxp import cxp_4r_fmc
import cxp
from config import write_csr_file, write_mem_file, write_rustc_cfg_file from config import write_csr_file, write_mem_file, write_rustc_cfg_file
class SMAClkinForward(Module): class SMAClkinForward(Module):
@ -682,39 +683,74 @@ class CXP_FMC():
platform.add_extension(debug_sma) platform.add_extension(debug_sma)
platform.add_extension(pmod1_33) platform.add_extension(pmod1_33)
debug_sma_pad = platform.request("user_sma_clock_33")
pmod_pads = [platform.request("pmod1_33", i) for i in range(8)] pmod_pads = [platform.request("pmod1_33", i) for i in range(8)]
clk_freq = 125e6 clk_freq = 125e6
gtx_pads = [platform.request("CXP_HS", i) for i in range(4)] links = 1
cxp_downconn_pads = [platform.request("CXP_HS", i) for i in range(links)]
cxp_upconn_pads = [platform.request("CXP_LS", i) for i in range(links)]
self.submodules.cxp = cxp.CXP(
self.submodules.cxp_phys = cxp_phys = cxp.CXP_PHYS(
refclk=self.cdr_clk, refclk=self.cdr_clk,
downconn_pads=gtx_pads, upconn_pads=cxp_upconn_pads,
upconn_pads=platform.request("CXP_LS", 0), downconn_pads=cxp_downconn_pads,
sys_clk_freq=clk_freq, sys_clk_freq=clk_freq,
debug_sma=platform.request("user_sma_clock_33"), debug_sma=debug_sma_pad,
pmod_pads = pmod_pads pmod_pads = pmod_pads
) )
self.csr_devices.append("cxp") self.csr_devices.append("cxp_phys")
# TODO: add memory for tx & rx CXP
memory_name = "cxp_tx"
mem_size = self.cxp.get_mem_size()
memory_address = self.axi2csr.register_port(self.cxp.get_tx_port(), mem_size)
self.add_memory_region(memory_name, self.mem_map["csr"] + memory_address, mem_size)
cxp_memory_group = [ memory_name ]
self.add_memory_group("cxp_mem", cxp_memory_group)
cxp_csr_group = []
cxp_tx_mem_group = []
cxp_rx_mem_group = []
cxp_loopback_mem_group = []
for i, (tx, rx) in enumerate(zip(cxp_phys.upconn.tx_phys, cxp_phys.downconn.rx_phys)):
cxp_name = "cxp" + str(i)
# TODO: cdr = ClockDomainsRenamer({"cxp_gtx_rx": "cxp_gtx_rx" + str(i)})
cxp_interface = cxp.CXP_Interface(tx, rx, debug_sma_pad, pmod_pads)
setattr(self.submodules, cxp_name, cxp_interface )
self.csr_devices.append(cxp_name)
cxp_csr_group.append(cxp_name)
mem_size = cxp_interface .get_mem_size()
tx_mem_name = "cxp_tx" + str(i) + "_mem"
memory_address = self.axi2csr.register_port(cxp_interface.get_tx_port(), mem_size)
self.add_memory_region(tx_mem_name, self.mem_map["csr"] + memory_address, mem_size)
cxp_tx_mem_group.append(tx_mem_name)
rx_mem_name = "cxp_rx" + str(i) + "_mem"
memory_address = self.axi2csr.register_port(cxp_interface.get_rx_port(), mem_size)
self.add_memory_region(rx_mem_name, self.mem_map["csr"] + memory_address, mem_size)
cxp_rx_mem_group.append(rx_mem_name)
# DEBUG loopback tx memory
loopback_mem_name = "cxp_loopback_tx" + str(i) + "_mem"
cxp_loopback_mem_group.append(loopback_mem_name)
memory_address = self.axi2csr.register_port(cxp_interface.get_loopback_tx_port(), mem_size)
self.add_memory_region(loopback_mem_name, self.mem_map["csr"] + memory_address, mem_size)
self.add_memory_group("cxp_tx_mem", cxp_tx_mem_group)
self.add_memory_group("cxp_rx_mem", cxp_rx_mem_group)
self.add_memory_group("cxp_loopback_mem", cxp_loopback_mem_group)
self.add_csr_group("cxp", cxp_csr_group)
# max freq of cxp_gtx_rx = linerate/internal_datawidth = 12.5Gbps/40 = 312.5MHz # max freq of cxp_gtx_rx = linerate/internal_datawidth = 12.5Gbps/40 = 312.5MHz
# zc706 use speed grade 2 which only support up to 10.3125Gbps (4ns) # zc706 use speed grade 2 which only support up to 10.3125Gbps (4ns)
# pushing to 12.5Gbps (3.2ns) will result in Pulse width violation but setup/hold times are met # pushing to 12.5Gbps (3.2ns) will result in Pulse width violation but setup/hold times are met
for gtx in self.cxp.downconn.gtxs: for rx in cxp_phys.downconn.rx_phys :
platform.add_period_constraint(gtx.cd_cxp_gtx_tx.clk, 3.2) platform.add_period_constraint(rx.gtx.cd_cxp_gtx_tx.clk, 3.2)
platform.add_period_constraint(gtx.cd_cxp_gtx_rx.clk, 3.2) platform.add_period_constraint(rx.gtx.cd_cxp_gtx_rx.clk, 3.2)
# constraint the CLK path # constraint the CLK path
platform.add_false_path_constraints(self.sys_crg.cd_sys.clk, gtx.cd_cxp_gtx_tx.clk, gtx.cd_cxp_gtx_rx.clk) platform.add_false_path_constraints(self.sys_crg.cd_sys.clk, rx.gtx.cd_cxp_gtx_tx.clk, rx.gtx.cd_cxp_gtx_rx.clk)
rtio_channels = [] rtio_channels = []
# FIXME remove this placeholder RTIO channel # FIXME remove this placeholder RTIO channel

View File

@ -3,7 +3,8 @@ use libboard_zynq::{println, timer::GlobalTimer};
use log::info; use log::info;
// use log::info; // use log::info;
use crate::{cxp_proto, pl::csr}; use crate::{cxp_proto,
pl::{csr, csr::CXP}};
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
@ -17,64 +18,62 @@ pub enum CXP_SPEED {
CXP_12, CXP_12,
} }
pub fn loopback_testing(timer: &mut GlobalTimer, speed: CXP_SPEED) { pub fn loopback_testing(channel: usize, timer: &mut GlobalTimer, speed: CXP_SPEED) {
println!("=============================================================================="); println!("==============================================================================");
cxp_gtx::change_linerate(timer, speed); cxp_gtx::change_linerate(channel, timer, speed);
unsafe { unsafe {
info!("waiting for tx&rx setup..."); info!("waiting for tx&rx setup...");
timer.delay_us(50_000); timer.delay_us(50_000);
info!( info!(
"tx_phaligndone = {} | rx_phaligndone = {}", "tx_phaligndone = {} | rx_phaligndone = {}",
csr::cxp::downconn_phy_txinit_phaligndone_read(), (CXP[channel].downconn_txinit_phaligndone_read)(),
csr::cxp::downconn_phy_rxinit_phaligndone_read(), (CXP[channel].downconn_rxinit_phaligndone_read)(),
); );
// enable txdata tranmission thought MGTXTXP, required by PMA loopback // enable txdata tranmission thought MGTXTXP, required by PMA loopback
csr::cxp::downconn_phy_txenable_write(1); (CXP[channel].downconn_txenable_write)(1);
info!("waiting for rx to align..."); info!("waiting for rx to align...");
while csr::cxp::downconn_phy_rx_ready_read() != 1 {} while (CXP[channel].downconn_rx_ready_read)() != 1 {}
info!("rx ready!"); info!("rx ready!");
csr::cxp::downconn_phy_tx_stb_write(1); (CXP[channel].downconn_tx_stb_write)(1);
cxp_proto::downconn_send_test_packet(); cxp_proto::downconn_send_test_packet(channel);
timer.delay_us(20000); // wait packet has arrive at rx
csr::cxp::downconn_phy_tx_stb_write(0);
// cxp_proto::downconn_debug_send_trig_ack(); cxp_proto::downconn_debug_send_trig_ack(channel);
cxp_proto::downconn_debug_send(&cxp_proto::Packet::CtrlRead { cxp_proto::downconn_debug_send(
addr: 0x00, channel,
length: 0x04, &cxp_proto::Packet::CtrlRead {
}); addr: 0x00,
length: 0x04,
},
)
.expect("loopback gtx tx error");
timer.delay_us(200); // wait packet has arrive at async fifo in timer.delay_us(200); // wait packet has arrive at RX async fifo
csr::cxp::downconn_phy_tx_stb_write(1); (CXP[channel].downconn_tx_stb_write)(0);
timer.delay_us(200);
csr::cxp::downconn_phy_tx_stb_write(0);
info!("trig ack = {}", csr::cxp::downconn_trig_ack_read()); info!("trig ack = {}", (CXP[channel].downconn_trigger_ack_read)());
csr::cxp::downconn_trig_clr_write(1); (CXP[channel].downconn_trigger_ack_write)(1);
info!("after clr trig ack = {}", csr::cxp::downconn_trig_ack_read()); info!("after clr trig ack = {}", (CXP[channel].downconn_trigger_ack_read)());
info!("decoder error = {}", csr::cxp::downconn_decoder_error_read()); info!("decoder error = {}", (CXP[channel].downconn_decoder_error_read)());
info!("test error = {}", csr::cxp::downconn_test_error_read()); info!("test error = {}", (CXP[channel].downconn_test_error_read)());
info!("packet type = {:#06X}", csr::cxp::downconn_packet_type_read()); info!("packet type = {:#06X}", (CXP[channel].downconn_packet_type_read)());
// TODO: investigate how to make my packet appear
// TODO: discard idle word
cxp_proto::receive(channel);
// DEBUG: print loopback packets // DEBUG: print loopback packets
const LEN: usize = 20; const LEN: usize = 20;
let mut pak_arr: [u32; LEN] = [0; LEN]; let mut pak_arr: [u32; LEN] = [0; LEN];
let mut k_arr: [u8; LEN] = [0; LEN]; let mut k_arr: [u8; LEN] = [0; LEN];
let mut i: usize = 0; let mut i: usize = 0;
while csr::cxp::downconn_debug_out_dout_valid_read() == 1 { while (CXP[channel].downconn_debug_out_dout_valid_read)() == 1 {
pak_arr[i] = csr::cxp::downconn_debug_out_dout_pak_read(); pak_arr[i] = (CXP[channel].downconn_debug_out_dout_pak_read)();
k_arr[i] = csr::cxp::downconn_debug_out_kout_pak_read(); k_arr[i] = (CXP[channel].downconn_debug_out_kout_pak_read)();
// println!("received {:#04X}", pak_arr[i]); // println!("received {:#04X}", pak_arr[i]);
csr::cxp::downconn_debug_out_inc_write(1); (CXP[channel].downconn_debug_out_inc_write)(1);
i += 1; i += 1;
if i == LEN { if i == LEN {
break; break;
@ -85,67 +84,69 @@ pub fn loopback_testing(timer: &mut GlobalTimer, speed: CXP_SPEED) {
} }
pub fn setup(timer: &mut GlobalTimer) { pub fn setup(timer: &mut GlobalTimer) {
// TODO: do a for loop for channel?
let channel: usize = 0;
unsafe { unsafe {
info!("turning on pmc loopback mode..."); info!("turning on pmc loopback mode...");
csr::cxp::downconn_phy_loopback_mode_write(0b010); // Near-End PMA Loopback (CXP[channel].downconn_loopback_mode_write)(0b010); // Near-End PMA Loopback
// QPLL setup // QPLL setup
csr::cxp::downconn_phy_qpll_reset_write(1); csr::cxp_phys::downconn_qpll_reset_write(1);
info!("waiting for QPLL/CPLL to lock..."); info!("waiting for QPLL/CPLL to lock...");
while csr::cxp::downconn_phy_qpll_locked_read() != 1 {} while csr::cxp_phys::downconn_qpll_locked_read() != 1 {}
info!("QPLL locked"); info!("QPLL locked");
// tx/rx setup // tx/rx setup
csr::cxp::downconn_phy_tx_start_init_write(1); (CXP[channel].downconn_tx_start_init_write)(1);
csr::cxp::downconn_phy_rx_start_init_write(1); (CXP[channel].downconn_rx_start_init_write)(1);
info!("waiting for tx & rx setup..."); info!("waiting for tx & rx setup...");
timer.delay_us(50_000); timer.delay_us(50_000);
info!( info!(
"tx_phaligndone = {} | rx_phaligndone = {}", "tx_phaligndone = {} | rx_phaligndone = {}",
csr::cxp::downconn_phy_txinit_phaligndone_read(), (CXP[channel].downconn_txinit_phaligndone_read)(),
csr::cxp::downconn_phy_rxinit_phaligndone_read(), (CXP[channel].downconn_rxinit_phaligndone_read)(),
); );
} }
cxp_gtx::change_linerate(timer, CXP_SPEED::CXP_1); cxp_gtx::change_linerate(channel, timer, CXP_SPEED::CXP_1);
} }
pub mod cxp_gtx { pub mod cxp_gtx {
use super::*; use super::*;
struct CdrConfig { struct CdrConfig {
pub cfg_reg0: u16, //0x0A8 pub cfg_reg0: u16, // addr = 0xA8
pub cfg_reg1: u16, //0x0A9 pub cfg_reg1: u16, // addr = 0xA9
pub cfg_reg2: u16, //0x0AA pub cfg_reg2: u16, // addr = 0xAA
pub cfg_reg3: u16, //0x0AB pub cfg_reg3: u16, // addr = 0xAB
pub cfg_reg4: u16, //0x0AC pub cfg_reg4: u16, // addr = 0xAC
} }
pub fn change_linerate(timer: &mut GlobalTimer, speed: CXP_SPEED) { pub fn change_linerate(channel: usize, timer: &mut GlobalTimer, speed: CXP_SPEED) {
info!("Changing datarate to {:?}", speed); info!("Changing datarate to {:?}", speed);
// DEBUG: DRP pll for TXUSRCLK = freq(linerate)/20 // DEBUG: DRP pll for TXUSRCLK = freq(linerate)/20
let settings = txusrclk::get_txusrclk_config(speed); let settings = txusrclk::get_txusrclk_config(speed);
txusrclk::setup(timer, settings); txusrclk::setup(channel, timer, settings);
change_qpll_settings(speed); change_qpll_fb_divider(speed);
change_cdr_cfg(speed); change_gtx_divider(channel, speed);
change_cdr_cfg(channel, speed);
unsafe { unsafe {
csr::cxp::downconn_phy_qpll_reset_write(1); csr::cxp_phys::downconn_qpll_reset_write(1);
info!("waiting for QPLL/CPLL to lock..."); info!("waiting for QPLL/CPLL to lock...");
while csr::cxp::downconn_phy_qpll_locked_read() != 1 {} while csr::cxp_phys::downconn_qpll_locked_read() != 1 {}
info!("QPLL locked"); info!("QPLL locked");
} }
unsafe { unsafe {
csr::cxp::downconn_phy_tx_restart_write(1); (CXP[channel].downconn_tx_restart_write)(1);
csr::cxp::downconn_phy_rx_restart_write(1); (CXP[channel].downconn_rx_restart_write)(1);
} }
} }
fn change_qpll_settings(speed: CXP_SPEED) { fn change_qpll_fb_divider(speed: CXP_SPEED) {
// Change QPLL_FBDIV
let qpll_div_reg = match speed { let qpll_div_reg = match speed {
CXP_SPEED::CXP_1 | CXP_SPEED::CXP_2 | CXP_SPEED::CXP_5 | CXP_SPEED::CXP_10 => 0x0120, // FB_Divider = 80 CXP_SPEED::CXP_1 | CXP_SPEED::CXP_2 | CXP_SPEED::CXP_5 | CXP_SPEED::CXP_10 => 0x0120, // FB_Divider = 80
CXP_SPEED::CXP_3 | CXP_SPEED::CXP_6 | CXP_SPEED::CXP_12 => 0x0170, // FB_Divider = 100 CXP_SPEED::CXP_3 | CXP_SPEED::CXP_6 | CXP_SPEED::CXP_12 => 0x0170, // FB_Divider = 100
@ -154,24 +155,24 @@ pub mod cxp_gtx {
println!("0x36 = {:#06x}", qpll_read(0x36)); println!("0x36 = {:#06x}", qpll_read(0x36));
qpll_write(0x36, qpll_div_reg); qpll_write(0x36, qpll_div_reg);
println!("0x36 = {:#06x}", qpll_read(0x36)); println!("0x36 = {:#06x}", qpll_read(0x36));
// DEBUG: remove txoutdiv
let txrxout_div = match speed {
CXP_SPEED::CXP_1 => 0x33, // 8
CXP_SPEED::CXP_2 | CXP_SPEED::CXP_3 => 0x22, // 4
CXP_SPEED::CXP_5 | CXP_SPEED::CXP_6 => 0x11, // 2
CXP_SPEED::CXP_10 | CXP_SPEED::CXP_12 => 0x00, // 1
};
// OUT_DIV
println!("0x88 = {:#06x}", gtx_read(0x88));
gtx_write(0x88, txrxout_div);
println!("0x88 = {:#06x}", gtx_read(0x88));
} }
fn change_cdr_cfg(speed: CXP_SPEED) { fn change_gtx_divider(channel: usize, speed: CXP_SPEED) {
let div_reg = match speed {
CXP_SPEED::CXP_1 => 0x33, // RXOUT_DIV = 8
CXP_SPEED::CXP_2 | CXP_SPEED::CXP_3 => 0x22, // RXOUT_DIV = 4
CXP_SPEED::CXP_5 | CXP_SPEED::CXP_6 => 0x11, // RXOUT_DIV = 2
CXP_SPEED::CXP_10 | CXP_SPEED::CXP_12 => 0x00, // RXOUT_DIV = 1
};
println!("0x88 = {:#06x}", gtx_read(channel, 0x88));
gtx_write(channel, 0x88, div_reg);
println!("0x88 = {:#06x}", gtx_read(channel, 0x88));
}
fn change_cdr_cfg(channel: usize, speed: CXP_SPEED) {
let cdr_cfg = match speed { let cdr_cfg = match speed {
// rxout_div = 8 // when RXOUT_DIV = 8
CXP_SPEED::CXP_1 => { CXP_SPEED::CXP_1 => {
CdrConfig { CdrConfig {
cfg_reg0: 0x0020, //0x0A8 cfg_reg0: 0x0020, //0x0A8
@ -181,7 +182,7 @@ pub mod cxp_gtx {
cfg_reg4: 0x0003, //0x0AC cfg_reg4: 0x0003, //0x0AC
} }
} }
// rxout_div = 4 // when RXOUT_DIV = 4
CXP_SPEED::CXP_2 | CXP_SPEED::CXP_5 => { CXP_SPEED::CXP_2 | CXP_SPEED::CXP_5 => {
CdrConfig { CdrConfig {
cfg_reg0: 0x0020, //0x0A8 cfg_reg0: 0x0020, //0x0A8
@ -191,7 +192,7 @@ pub mod cxp_gtx {
cfg_reg4: 0x0003, //0x0AC cfg_reg4: 0x0003, //0x0AC
} }
} }
// rxout_div = 2 // when RXOUT_DIV= 2
CXP_SPEED::CXP_3 | CXP_SPEED::CXP_6 => { CXP_SPEED::CXP_3 | CXP_SPEED::CXP_6 => {
CdrConfig { CdrConfig {
cfg_reg0: 0x0020, //0x0A8 cfg_reg0: 0x0020, //0x0A8
@ -201,7 +202,7 @@ pub mod cxp_gtx {
cfg_reg4: 0x0003, //0x0AC cfg_reg4: 0x0003, //0x0AC
} }
} }
// rxout_div = 1 // when RXOUT_DIV= 1
CXP_SPEED::CXP_10 | CXP_SPEED::CXP_12 => { CXP_SPEED::CXP_10 | CXP_SPEED::CXP_12 => {
CdrConfig { CdrConfig {
cfg_reg0: 0x0020, //0x0A8 cfg_reg0: 0x0020, //0x0A8
@ -213,50 +214,48 @@ pub mod cxp_gtx {
} }
}; };
gtx_write(0x0A8, cdr_cfg.cfg_reg0); gtx_write(channel, 0x0A8, cdr_cfg.cfg_reg0);
gtx_write(0x0A9, cdr_cfg.cfg_reg1); gtx_write(channel, 0x0A9, cdr_cfg.cfg_reg1);
gtx_write(0x0AA, cdr_cfg.cfg_reg2); gtx_write(channel, 0x0AA, cdr_cfg.cfg_reg2);
gtx_write(0x0AB, cdr_cfg.cfg_reg3); gtx_write(channel, 0x0AB, cdr_cfg.cfg_reg3);
gtx_write(0x0AC, cdr_cfg.cfg_reg4); gtx_write(channel, 0x0AC, cdr_cfg.cfg_reg4);
} }
#[allow(dead_code)] #[allow(dead_code)]
fn gtx_read(address: u16) -> u16 { fn gtx_read(channel: usize, address: u16) -> u16 {
// DEBUG:
unsafe { unsafe {
csr::cxp::downconn_phy_gtx_daddr_write(address); (CXP[channel].downconn_gtx_daddr_write)(address);
csr::cxp::downconn_phy_gtx_dread_write(1); (CXP[channel].downconn_gtx_dread_write)(1);
while csr::cxp::downconn_phy_gtx_dready_read() != 1 {} while (CXP[channel].downconn_gtx_dready_read)() != 1 {}
csr::cxp::downconn_phy_gtx_dout_read() (CXP[channel].downconn_gtx_dout_read)()
} }
} }
fn gtx_write(address: u16, value: u16) { fn gtx_write(channel: usize, address: u16, value: u16) {
unsafe { unsafe {
csr::cxp::downconn_phy_gtx_daddr_write(address); (CXP[channel].downconn_gtx_daddr_write)(address);
csr::cxp::downconn_phy_gtx_din_write(value); (CXP[channel].downconn_gtx_din_write)(value);
csr::cxp::downconn_phy_gtx_din_stb_write(1); (CXP[channel].downconn_gtx_din_stb_write)(1);
while csr::cxp::downconn_phy_gtx_dready_read() != 1 {} while (CXP[channel].downconn_gtx_dready_read)() != 1 {}
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
fn qpll_read(address: u8) -> u16 { fn qpll_read(address: u8) -> u16 {
// DEBUG:
unsafe { unsafe {
csr::cxp::downconn_phy_qpll_daddr_write(address); csr::cxp_phys::downconn_qpll_daddr_write(address);
csr::cxp::downconn_phy_qpll_dread_write(1); csr::cxp_phys::downconn_qpll_dread_write(1);
while csr::cxp::downconn_phy_qpll_dready_read() != 1 {} while csr::cxp_phys::downconn_qpll_dready_read() != 1 {}
csr::cxp::downconn_phy_qpll_dout_read() csr::cxp_phys::downconn_qpll_dout_read()
} }
} }
fn qpll_write(address: u8, value: u16) { fn qpll_write(address: u8, value: u16) {
unsafe { unsafe {
csr::cxp::downconn_phy_qpll_daddr_write(address); csr::cxp_phys::downconn_qpll_daddr_write(address);
csr::cxp::downconn_phy_qpll_din_write(value); csr::cxp_phys::downconn_qpll_din_write(value);
csr::cxp::downconn_phy_qpll_din_stb_write(1); csr::cxp_phys::downconn_qpll_din_stb_write(1);
while csr::cxp::downconn_phy_qpll_dready_read() != 1 {} while csr::cxp_phys::downconn_qpll_dready_read() != 1 {}
} }
} }
} }
@ -278,119 +277,119 @@ pub mod txusrclk {
pub filt_reg2: u16, //0x4F pub filt_reg2: u16, //0x4F
} }
fn one_clock_cycle() { fn one_clock_cycle(channel: usize) {
unsafe { unsafe {
csr::cxp::downconn_phy_pll_dclk_write(1); (CXP[channel].downconn_pll_dclk_write)(1);
csr::cxp::downconn_phy_pll_dclk_write(0); (CXP[channel].downconn_pll_dclk_write)(0);
} }
} }
fn set_addr(address: u8) { fn set_addr(channel: usize, address: u8) {
unsafe { unsafe {
csr::cxp::downconn_phy_pll_daddr_write(address); (CXP[channel].downconn_pll_daddr_write)(address);
} }
} }
fn set_data(value: u16) { fn set_data(channel: usize, value: u16) {
unsafe { unsafe {
csr::cxp::downconn_phy_pll_din_write(value); (CXP[channel].downconn_pll_din_write)(value);
} }
} }
fn set_enable(en: bool) { fn set_enable(channel: usize, en: bool) {
unsafe { unsafe {
let val = if en { 1 } else { 0 }; let val = if en { 1 } else { 0 };
csr::cxp::downconn_phy_pll_den_write(val); (CXP[channel].downconn_pll_den_write)(val);
} }
} }
fn set_write_enable(en: bool) { fn set_write_enable(channel: usize, en: bool) {
unsafe { unsafe {
let val = if en { 1 } else { 0 }; let val = if en { 1 } else { 0 };
csr::cxp::downconn_phy_pll_dwen_write(val); (CXP[channel].downconn_pll_dwen_write)(val);
} }
} }
fn get_data() -> u16 { fn get_data(channel: usize) -> u16 {
unsafe { csr::cxp::downconn_phy_pll_dout_read() } unsafe { (CXP[channel].downconn_pll_dout_read)() }
} }
fn drp_ready() -> bool { fn drp_ready(channel: usize) -> bool {
unsafe { csr::cxp::downconn_phy_pll_dready_read() == 1 } unsafe { (CXP[channel].downconn_pll_dready_read)() == 1 }
} }
#[allow(dead_code)] #[allow(dead_code)]
fn read(address: u8) -> u16 { fn read(channel: usize, address: u8) -> u16 {
set_addr(address); set_addr(channel, address);
set_enable(true); set_enable(channel, true);
// Set DADDR on the mmcm and assert DEN for one clock cycle // Set DADDR on the mmcm and assert DEN for one clock cycle
one_clock_cycle(); one_clock_cycle(channel);
set_enable(false); set_enable(channel, false);
while !drp_ready() { while !drp_ready(channel) {
// keep the clock signal until data is ready // keep the clock signal until data is ready
one_clock_cycle(); one_clock_cycle(channel);
} }
get_data() get_data(channel)
} }
fn write(address: u8, value: u16) { fn write(channel: usize, address: u8, value: u16) {
set_addr(address); set_addr(channel, address);
set_data(value); set_data(channel, value);
set_write_enable(true); set_write_enable(channel, true);
set_enable(true); set_enable(channel, true);
// Set DADDR, DI on the mmcm and assert DWE, DEN for one clock cycle // Set DADDR, DI on the mmcm and assert DWE, DEN for one clock cycle
one_clock_cycle(); one_clock_cycle(channel);
set_write_enable(false); set_write_enable(channel, false);
set_enable(false); set_enable(channel, false);
while !drp_ready() { while !drp_ready(channel) {
// keep the clock signal until write is finished // keep the clock signal until write is finished
one_clock_cycle(); one_clock_cycle(channel);
} }
} }
fn reset(rst: bool) { fn reset(channel: usize, rst: bool) {
unsafe { unsafe {
let val = if rst { 1 } else { 0 }; let val = if rst { 1 } else { 0 };
csr::cxp::downconn_phy_txpll_reset_write(val) (CXP[channel].downconn_txpll_reset_write)(val)
} }
} }
pub fn setup(timer: &mut GlobalTimer, settings: PLLSetting) { pub fn setup(channel: usize, timer: &mut GlobalTimer, settings: PLLSetting) {
if false { if false {
info!("0x08 = {:#06x}", read(0x08)); info!("0x08 = {:#06x}", read(channel, 0x08));
info!("0x09 = {:#06x}", read(0x09)); info!("0x09 = {:#06x}", read(channel, 0x09));
info!("0x14 = {:#06x}", read(0x14)); info!("0x14 = {:#06x}", read(channel, 0x14));
info!("0x15 = {:#06x}", read(0x15)); info!("0x15 = {:#06x}", read(channel, 0x15));
info!("0x16 = {:#06x}", read(0x16)); info!("0x16 = {:#06x}", read(channel, 0x16));
info!("0x18 = {:#06x}", read(0x18)); info!("0x18 = {:#06x}", read(channel, 0x18));
info!("0x19 = {:#06x}", read(0x19)); info!("0x19 = {:#06x}", read(channel, 0x19));
info!("0x1A = {:#06x}", read(0x1A)); info!("0x1A = {:#06x}", read(channel, 0x1A));
info!("0x28 = {:#06x}", read(0x28)); info!("0x28 = {:#06x}", read(channel, 0x28));
info!("0x4E = {:#06x}", read(0x4E)); info!("0x4E = {:#06x}", read(channel, 0x4E));
info!("0x4F = {:#06x}", read(0x4F)); info!("0x4F = {:#06x}", read(channel, 0x4F));
} else { } else {
// Based on "DRP State Machine" from XAPP888 // Based on "DRP State Machine" from XAPP888
// hold reset HIGH during pll config // hold reset HIGH during pll config
reset(true); reset(channel, true);
write(0x08, settings.clkout0_reg1); write(channel, 0x08, settings.clkout0_reg1);
write(0x09, settings.clkout0_reg2); write(channel, 0x09, settings.clkout0_reg2);
write(0x14, settings.clkfbout_reg1); write(channel, 0x14, settings.clkfbout_reg1);
write(0x15, settings.clkfbout_reg2); write(channel, 0x15, settings.clkfbout_reg2);
write(0x16, settings.div_reg); write(channel, 0x16, settings.div_reg);
write(0x18, settings.lock_reg1); write(channel, 0x18, settings.lock_reg1);
write(0x19, settings.lock_reg2); write(channel, 0x19, settings.lock_reg2);
write(0x1A, settings.lock_reg3); write(channel, 0x1A, settings.lock_reg3);
write(0x28, settings.power_reg); write(channel, 0x28, settings.power_reg);
write(0x4E, settings.filt_reg1); write(channel, 0x4E, settings.filt_reg1);
write(0x4F, settings.filt_reg2); write(channel, 0x4F, settings.filt_reg2);
reset(false); reset(channel, false);
// wait for the pll to lock // wait for the pll to lock
timer.delay_us(100); timer.delay_us(100);
let locked = unsafe { csr::cxp::downconn_phy_txpll_locked_read() == 1 }; let locked = unsafe { (CXP[channel].downconn_txpll_locked_read)() == 1 };
info!("txusrclk locked = {}", locked); info!("txusrclk locked = {}", locked);
} }
} }
@ -519,5 +518,3 @@ pub mod txusrclk {
} }
} }
} }
// TODO: add recv like in drtioaux

View File

@ -2,19 +2,22 @@ use core::slice;
use core_io::{Error as IoError, Write}; use core_io::{Error as IoError, Write};
use crc::crc32; use crc::crc32;
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
use io::Cursor; use io::Cursor;
use libboard_zynq::{println, timer::GlobalTimer}; use libboard_zynq::println;
use crate::{mem::mem::CXP_MEM, pl::csr}; // TODO: fix the import
use crate::{mem::mem::{CXP_LOOPBACK_MEM, CXP_RX_MEM, CXP_TX_MEM},
pl::csr::CXP};
const MAX_PACKET: usize = 128; const MAX_PACKET: usize = 128;
const DATA_MAXSIZE: usize = /*max size*/MAX_PACKET - /*Tag*/4 - /*Op code & length*/4 - /*addr*/4 - /*CRC*/4 ; const DATA_MAXSIZE: usize = /*max size*/MAX_PACKET - /*Tag*/4 - /*Op code & length*/4 - /*addr*/4 - /*CRC*/4 ;
const MEM_LEN: usize = 0x200;
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
BufferError, BufferError,
LinkDown, LinkDown,
UnknownPacket(u8),
} }
impl From<IoError> for Error { impl From<IoError> for Error {
@ -107,71 +110,89 @@ impl Packet {
} }
} }
pub fn send(packet: &Packet) -> Result<(), Error> { pub fn receive(channel: usize) -> Result<(), Error> {
if unsafe { csr::cxp::upconn_tx_enable_read() } == 0 { unsafe {
// let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
let ptr = CXP_RX_MEM[0].base as *mut u32;
// let mut reader = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
print_packet(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
}
Ok(())
}
pub fn send(channel: usize, packet: &Packet) -> Result<(), Error> {
if unsafe { (CXP[channel].upconn_tx_enable_read)() } == 0 {
Err(Error::LinkDown)? Err(Error::LinkDown)?
} }
match *packet { match *packet {
Packet::TestPacket => send_test_packet(), Packet::TestPacket => send_test_packet(channel),
_ => send_data_packet(packet), _ => send_data_packet(channel, packet),
} }
} }
fn send_data_packet(packet: &Packet) -> Result<(), Error> { fn send_data_packet(channel: usize, packet: &Packet) -> Result<(), Error> {
let mut buffer: [u8; MAX_PACKET] = [0; MAX_PACKET];
let mut writer = Cursor::new(&mut buffer[..]);
packet.write_to(&mut writer)?;
unsafe { unsafe {
let len = writer.position(); // TODO: put this in mem group
csr::cxp::upconn_command_len_write(len as u8); while (CXP[channel].upconn_command_tx_read)() == 1 {}
for data in writer.get_ref()[..len].iter() { let ptr = CXP_TX_MEM[0].base as *mut u32;
while csr::cxp::upconn_command_writeable_read() == 0 {} let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
csr::cxp::upconn_command_data_write(*data);
} packet.write_to(&mut writer)?;
(CXP[channel].upconn_command_tx_word_len_write)(writer.position() as u8 / 4);
(CXP[channel].upconn_command_tx_write)(1);
}
Ok(())
}
fn send_test_packet(channel: usize) -> Result<(), Error> {
unsafe {
while (CXP[channel].upconn_testseq_tx_read)() == 1 {}
(CXP[channel].upconn_tx_testmode_en_write)(1);
(CXP[channel].upconn_testseq_tx_write)(1);
// wait till all test packet is out before switching back
while (CXP[channel].upconn_testseq_tx_read)() == 1 {}
(CXP[channel].upconn_tx_testmode_en_write)(0);
} }
Ok(()) Ok(())
} }
fn send_test_packet() -> Result<(), Error> { pub fn write_u32(channel: usize, addr: u32, data: u32) -> Result<(), Error> {
unsafe {
while csr::cxp::upconn_tx_busy_read() == 1 {}
csr::cxp::upconn_tx_testmode_en_write(1);
csr::cxp::upconn_testseq_stb_write(1);
while csr::cxp::upconn_testseq_busy_read() == 1 {}
csr::cxp::upconn_tx_testmode_en_write(0);
}
Ok(())
}
pub fn write_u32(addr: u32, data: u32) -> Result<(), Error> {
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE]; let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
data_slice[..4].clone_from_slice(&data.to_be_bytes()); data_slice[..4].clone_from_slice(&data.to_be_bytes());
send(&Packet::CtrlWrite { send(
addr, channel,
length: 4, &Packet::CtrlWrite {
data: data_slice, addr,
})?; length: 4,
data: data_slice,
},
)?;
Ok(()) Ok(())
} }
pub fn read_u32(addr: u32) -> Result<(), Error> { pub fn read_u32(channel: usize, addr: u32) -> Result<(), Error> {
send(&Packet::CtrlRead { addr, length: 4 })?; send(channel, &Packet::CtrlRead { addr, length: 4 })?;
Ok(()) Ok(())
} }
pub fn write_u64(addr: u32, data: u64) -> Result<(), Error> { pub fn write_u64(channel: usize, addr: u32, data: u64) -> Result<(), Error> {
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE]; let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
data_slice[..8].clone_from_slice(&data.to_be_bytes()); data_slice[..8].clone_from_slice(&data.to_be_bytes());
send(&Packet::CtrlWrite { send(
addr, channel,
length: 8, &Packet::CtrlWrite {
data: data_slice, addr,
})?; length: 8,
data: data_slice,
},
)?;
Ok(()) Ok(())
} }
@ -211,71 +232,36 @@ pub fn print_packetu32(pak: &[u32], k: &[u8]) {
println!("============================================"); println!("============================================");
} }
pub fn downconn_debug_send(packet: &Packet) -> Result<(), Error> { pub fn downconn_debug_send(channel: usize, packet: &Packet) -> Result<(), Error> {
let mut buffer: [u8; MAX_PACKET] = [0; MAX_PACKET];
let mut writer = Cursor::new(&mut buffer[..]);
packet.write_to(&mut writer)?;
unsafe {
csr::cxp::downconn_mux_sel_write(0);
let len = writer.position();
csr::cxp::downconn_debug_src_len_write(len as u8);
for data in writer.get_ref()[..len].iter() {
while csr::cxp::downconn_debug_src_writeable_read() == 0 {}
csr::cxp::upconn_command_data_write(*data);
csr::cxp::downconn_debug_src_data_write(*data);
}
}
Ok(())
}
pub fn downconn_debug_send_trig_ack() {
unsafe {
csr::cxp::downconn_mux_sel_write(1);
csr::cxp::downconn_ack_write(1);
}
}
pub fn downconn_send_test_packet() {
unsafe {
csr::cxp::downconn_mux_sel_write(2);
csr::cxp::downconn_testseq_stb_write(1);
while csr::cxp::downconn_testseq_busy_read() == 1 {}
}
}
pub fn ram_writer_send(packet: &Packet) -> Result<(), Error> {
unsafe { unsafe {
// TODO: put this in mem group // TODO: put this in mem group
while csr::cxp::transmitter_cxp_tx_read() == 1 {} while (CXP[channel].downconn_command_tx_read)() == 1 {}
let ptr = CXP_MEM[0].base as *mut u32; let ptr = CXP_LOOPBACK_MEM[0].base as *mut u32;
let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, 0x200 as usize)); let mut writer = Cursor::new(slice::from_raw_parts_mut(ptr as *mut u8, MEM_LEN));
packet.write_to(&mut writer)?; packet.write_to(&mut writer)?;
csr::cxp::transmitter_cxp_tx_word_len_write(writer.position() as u8 / 4); (CXP[channel].downconn_command_tx_word_len_write)(writer.position() as u8 / 4);
csr::cxp::transmitter_cxp_tx_write(1); (CXP[channel].downconn_command_tx_write)(1);
while csr::cxp::transmitter_cxp_tx_read() == 1 {}
// read the fifo
const LEN: usize = 10;
let mut pak_arr: [u32; LEN] = [0; LEN];
let mut k_arr: [u8; LEN] = [0; LEN];
let mut i: usize = 0;
while csr::cxp::transmitter_debug_out_dout_valid_read() == 1 {
pak_arr[i] = csr::cxp::transmitter_debug_out_dout_pak_read();
k_arr[i] = csr::cxp::transmitter_debug_out_kout_pak_read();
// println!("received {:#04X}", pak_arr[i]);
csr::cxp::transmitter_debug_out_inc_write(1);
i += 1;
if i == LEN {
break;
}
}
print_packetu32(&pak_arr, &k_arr);
} }
Ok(()) Ok(())
} }
pub fn downconn_debug_send_trig_ack(channel: usize) {
unsafe {
(CXP[channel].downconn_ack_write)(1);
}
}
pub fn downconn_send_test_packet(channel: usize) {
unsafe {
while (CXP[channel].downconn_testseq_tx_read)() == 1 {}
(CXP[channel].downconn_mux_sel_write)(1);
(CXP[channel].downconn_testseq_tx_write)(1);
// wait till all test packet is out before switching back
while (CXP[channel].downconn_testseq_tx_read)() == 1 {}
(CXP[channel].downconn_mux_sel_write)(0);
}
}

View File

@ -1,45 +1,42 @@
use core_io::{Error as IoError, Write};
use crc::crc32;
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs; use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
use io::Cursor; use libboard_zynq::timer::GlobalTimer;
use libboard_zynq::{println, timer::GlobalTimer};
pub use crate::cxp_proto; pub use crate::cxp_proto;
use crate::pl::csr; use crate::pl::{csr, csr::CXP};
pub fn tx_test(timer: &mut GlobalTimer) { pub fn tx_test(channel: usize, timer: &mut GlobalTimer) {
const LEN: usize = 4 * 50; const LEN: usize = 4 * 30;
let mut pak_arr: [u8; LEN] = [0; LEN]; let mut pak_arr: [u8; LEN] = [0; LEN];
unsafe { unsafe {
csr::cxp::upconn_clk_reset_write(1); (CXP[channel].upconn_clk_reset_write)(1);
// csr::cxp::upconn_bitrate2x_enable_write(1); // CXP[channel].upconn_bitrate2x_enable_write(1);
csr::cxp::upconn_clk_reset_write(0); (CXP[channel].upconn_clk_reset_write)(0);
// read_u32(0x00).expect("Cannot Write CoaXpress Register"); (CXP[channel].upconn_tx_enable_write)(1);
csr::cxp::upconn_tx_enable_write(1);
timer.delay_us(2); // send one word timer.delay_us(2); // send one word
cxp_proto::send(&cxp_proto::Packet::EventAck { packet_tag: 0x04 }).expect("Cannot send CoaXpress packet"); cxp_proto::read_u32(channel, 0x00).expect("Cannot Write CoaXpress Register");
// cxp_proto::send(&cxp_proto::Packet::TestPacket).expect("Cannot send CoaXpress packet"); // cxp_proto::write_u64(channel, 0x00, 0x01);
// cxp_proto::send(channel, &cxp_proto::Packet::EventAck { packet_tag: 0x04 }).expect("Cannot send CoaXpress packet");
// cxp_proto::send(channel, &cxp_proto::Packet::TestPacket).expect("Cannot send CoaXpress packet");
// timer.delay_us(2); timer.delay_us(2);
// DEBUG: Trigger packet // DEBUG: Trigger packet
// let linktrig_mode: u8 = 0x01; (CXP[channel].upconn_trig_delay_write)(0x86);
// csr::cxp::upconn_trig_delay_write(0x05); (CXP[channel].upconn_linktrigger_write)(0x00);
// csr::cxp::upconn_linktrigger_write(linktrig_mode); (CXP[channel].upconn_trig_stb_write)(1); // send trig
// csr::cxp::upconn_trig_stb_write(1); // send trig
// DEBUG: Trigger ACK packet // DEBUG: Trigger ACK packet
// csr::cxp::upconn_ack_write(1); // CXP[channel].upconn_ack_write(1);
timer.delay_us(20); timer.delay_us(20);
csr::cxp::upconn_tx_enable_write(0); (CXP[channel].upconn_tx_enable_write)(0);
// Collect data // Collect data
let mut i: usize = 0; let mut i: usize = 0;
while csr::cxp::upconn_phy_debug_buf_dout_valid_read() == 1 { while csr::cxp_phys::upconn_tx0_debug_buf_dout_valid_read() == 1 {
pak_arr[i] = csr::cxp::upconn_phy_debug_buf_dout_pak_read(); pak_arr[i] = csr::cxp_phys::upconn_tx0_debug_buf_dout_pak_read();
// println!("received {:#04X}", pak_arr[i]); csr::cxp_phys::upconn_tx0_debug_buf_inc_write(1);
csr::cxp::upconn_phy_debug_buf_inc_write(1);
i += 1; i += 1;
if i == LEN { if i == LEN {
break; break;

View File

@ -25,7 +25,7 @@ pub mod fiq;
#[cfg(feature = "target_kasli_soc")] #[cfg(feature = "target_kasli_soc")]
pub mod io_expander; pub mod io_expander;
pub mod logger; pub mod logger;
#[cfg(has_drtio)] #[cfg(any(has_drtio, has_cxp_phys))]
#[rustfmt::skip] #[rustfmt::skip]
#[path = "../../../build/mem.rs"] #[path = "../../../build/mem.rs"]
pub mod mem; pub mod mem;
@ -42,9 +42,9 @@ pub mod si5324;
pub mod si549; pub mod si549;
use core::{cmp, str}; use core::{cmp, str};
#[cfg(has_cxp)] #[cfg(has_cxp_phys)]
pub mod cxp_downconn; pub mod cxp_downconn;
#[cfg(has_cxp)] #[cfg(has_cxp_phys)]
pub mod cxp_upconn; pub mod cxp_upconn;
pub mod cxp_proto; pub mod cxp_proto;

View File

@ -151,18 +151,18 @@ pub fn main_core0() {
task::spawn(ksupport::report_async_rtio_errors()); task::spawn(ksupport::report_async_rtio_errors());
cxp_downconn::setup(&mut timer); cxp_downconn::setup(&mut timer);
cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_1); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_1);
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_2); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_2);
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_3); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_3);
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_5); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_5);
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_6); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_6);
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_10); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_10);
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_12); // cxp_downconn::loopback_testing(0, &mut timer, cxp_downconn::CXP_SPEED::CXP_12);
// loop { loop {
// use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs; use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
// cxp_upconn::tx_test(&mut timer); cxp_upconn::tx_test(0, &mut timer);
// timer.delay_us(5_000_000); timer.delay_us(5_000_000);
// } }
comms::main(timer, cfg); comms::main(timer, cfg);
} }