forked from M-Labs/artiq-zynq
Compare commits
35 Commits
074e8e94d1
...
7285479f5b
Author | SHA1 | Date |
---|---|---|
morgan | 7285479f5b | |
morgan | cb0a0358a3 | |
morgan | 790f0196b6 | |
morgan | b1069f524a | |
morgan | 98095664ce | |
morgan | 12bf931614 | |
morgan | b725594a1d | |
morgan | fe57067f70 | |
morgan | 8b2181b1a8 | |
morgan | 08ee4f1cb9 | |
morgan | 133802fef2 | |
morgan | 5af2d8c23b | |
morgan | 581d9ffebb | |
morgan | 6943a2b17e | |
morgan | 5c253fefb6 | |
morgan | aeabca2182 | |
morgan | 16ccd7eada | |
morgan | d9888d7647 | |
morgan | 6b50d83e67 | |
morgan | b2ce43155e | |
morgan | d81c770e54 | |
morgan | f83afc7195 | |
morgan | 38485aec56 | |
morgan | 7dbeefd0a4 | |
morgan | fa674e32f5 | |
morgan | 9f8f8c1ad0 | |
morgan | 397027876c | |
morgan | 8a6e89b2d8 | |
morgan | f0dda0fcf7 | |
morgan | 04932d630f | |
morgan | d9fb50c12e | |
morgan | fa5ede6174 | |
morgan | ce0f302b22 | |
morgan | 3a80f37a2f | |
morgan | f19c7fa369 |
20
flake.lock
20
flake.lock
|
@ -11,11 +11,11 @@
|
||||||
"src-pythonparser": "src-pythonparser"
|
"src-pythonparser": "src-pythonparser"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1724210813,
|
"lastModified": 1725373154,
|
||||||
"narHash": "sha256-OqQdE2lC0jKNS2fFq0Fda1nBpyT8ijmSXqdkO8xeOJ8=",
|
"narHash": "sha256-fq9EW9fDWrV0v1vNj7ZqDNpNYx8+OxoFdPwpvkPf67g=",
|
||||||
"ref": "refs/heads/master",
|
"ref": "refs/heads/master",
|
||||||
"rev": "61e96b37f9c4345e2d7bf71d47ba0b5e947de83e",
|
"rev": "0c1ffa9f4f6a3e7864459923ec4b9cc45f16327a",
|
||||||
"revCount": 8985,
|
"revCount": 9005,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/m-labs/artiq.git"
|
"url": "https://github.com/m-labs/artiq.git"
|
||||||
},
|
},
|
||||||
|
@ -102,11 +102,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1723362943,
|
"lastModified": 1724224976,
|
||||||
"narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=",
|
"narHash": "sha256-Z/ELQhrSd7bMzTO8r7NZgi9g5emh+aRKoCdaAv5fiO0=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "a58bc8ad779655e790115244571758e8de055e3d",
|
"rev": "c374d94f1536013ca8e92341b540eba4c22f9c62",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -169,11 +169,11 @@
|
||||||
"src-migen": {
|
"src-migen": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1721561053,
|
"lastModified": 1724304798,
|
||||||
"narHash": "sha256-z3LRhNmKZrjr6rFD0yxtccSa/SWvFIYmb+G/D5d2Jd8=",
|
"narHash": "sha256-tQ02N0eXY5W/Z7CrOy3Cu4WjDZDQWb8hYlzsFzr3Mus=",
|
||||||
"owner": "m-labs",
|
"owner": "m-labs",
|
||||||
"repo": "migen",
|
"repo": "migen",
|
||||||
"rev": "9279e8623f8433bc4f23ac51e5e2331bfe544417",
|
"rev": "832a7240ba32af9cbd4fdd519ddcb4f912534726",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -342,6 +342,7 @@
|
||||||
{
|
{
|
||||||
inherit fastnumbers artiq-netboot ramda migen-axi binutils-arm;
|
inherit fastnumbers artiq-netboot ramda migen-axi binutils-arm;
|
||||||
} //
|
} //
|
||||||
|
(board-package-set { target = "zc706"; variant = "cxp_demo"; }) //
|
||||||
(board-package-set { target = "zc706"; variant = "nist_clock"; }) //
|
(board-package-set { target = "zc706"; variant = "nist_clock"; }) //
|
||||||
(board-package-set { target = "zc706"; variant = "nist_clock_master"; }) //
|
(board-package-set { target = "zc706"; variant = "nist_clock_master"; }) //
|
||||||
(board-package-set { target = "zc706"; variant = "nist_clock_master_100mhz"; }) //
|
(board-package-set { target = "zc706"; variant = "nist_clock_master_100mhz"; }) //
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
from migen import *
|
||||||
|
from misoc.interconnect.csr import *
|
||||||
|
from misoc.interconnect import stream
|
||||||
|
|
||||||
|
from cxp_downconn import CXP_DownConn_PHY
|
||||||
|
from cxp_upconn import CXP_UpConn_PHY
|
||||||
|
from cxp_pipeline import *
|
||||||
|
|
||||||
|
class CXP(Module, AutoCSR):
|
||||||
|
def __init__(self, refclk, downconn_pads, upconn_pads, sys_clk_freq, debug_sma, pmod_pads):
|
||||||
|
self.submodules.upconn = UpConn_Interface(upconn_pads, sys_clk_freq, debug_sma, pmod_pads)
|
||||||
|
|
||||||
|
self.submodules.downconn = DownConn_Interface(refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads)
|
||||||
|
# TODO: support the option high speed upconn
|
||||||
|
|
||||||
|
# TODO: add link layer
|
||||||
|
|
||||||
|
class DownConn_Interface(Module, AutoCSR):
|
||||||
|
def __init__(self, refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads):
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
self.submodules.phy = phy = CXP_DownConn_PHY(refclk, downconn_pads, sys_clk_freq, debug_sma, pmod_pads)
|
||||||
|
self.gtxs = phy.gtxs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class UpConn_Interface(Module, AutoCSR):
|
||||||
|
def __init__(self, upconn_pads, sys_clk_freq, debug_sma, pmod_pads):
|
||||||
|
self.clk_reset = CSRStorage(reset=1)
|
||||||
|
self.bitrate2x_enable = CSRStorage()
|
||||||
|
self.tx_enable = CSRStorage()
|
||||||
|
self.tx_busy = CSRStatus()
|
||||||
|
|
||||||
|
self.tx_testmode_en = CSRStorage()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
self.submodules.phy = phy = CXP_UpConn_PHY(upconn_pads, sys_clk_freq, debug_sma, pmod_pads)
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
phy.bitrate2x_enable.eq(self.bitrate2x_enable.storage),
|
||||||
|
phy.tx_enable.eq(self.tx_enable.storage),
|
||||||
|
phy.clk_reset.eq(self.clk_reset.re),
|
||||||
|
self.tx_busy.status.eq(phy.tx_busy),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Packet FIFOs with transmission priority
|
||||||
|
# 0: Trigger packet
|
||||||
|
self.submodules.trig = trig = TX_Trigger()
|
||||||
|
self.comb += trig.source.connect(phy.sinks[0])
|
||||||
|
|
||||||
|
# DEBUG: INPUT
|
||||||
|
self.trig_stb = CSR()
|
||||||
|
self.trig_delay = CSRStorage(8)
|
||||||
|
self.linktrigger = CSRStorage(2)
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
trig.trig_stb.eq(self.trig_stb.re),
|
||||||
|
trig.delay.eq(self.trig_delay.storage),
|
||||||
|
trig.linktrig_mode.eq(self.linktrigger.storage),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# 1: IO acknowledgment for trigger packet
|
||||||
|
self.submodules.trig_ack = trig_ack = Trigger_ACK()
|
||||||
|
self.comb += trig_ack.source.connect(phy.sinks[1])
|
||||||
|
|
||||||
|
# DEBUG: INPUT
|
||||||
|
self.ack = CSR()
|
||||||
|
self.sync += trig_ack.ack.eq(self.ack.re),
|
||||||
|
|
||||||
|
|
||||||
|
# 2: All other packets
|
||||||
|
# Control is not timing dependent, all the link layer is done in firmware
|
||||||
|
self.submodules.command = command = TX_Command_Packet()
|
||||||
|
self.submodules.testseq = testseq = TX_Test_Packet()
|
||||||
|
|
||||||
|
|
||||||
|
self.submodules.mux = mux = stream.Multiplexer(upconn_layout, 2)
|
||||||
|
|
||||||
|
self.comb += [
|
||||||
|
command.source.connect(mux.sink0),
|
||||||
|
testseq.source.connect(mux.sink1),
|
||||||
|
mux.sel.eq(self.tx_testmode_en.storage),
|
||||||
|
|
||||||
|
mux.source.connect(phy.sinks[2])
|
||||||
|
]
|
|
@ -0,0 +1,87 @@
|
||||||
|
from migen.build.generic_platform import *
|
||||||
|
|
||||||
|
fmc_adapter_io = [
|
||||||
|
|
||||||
|
# CoaXPress high speed link
|
||||||
|
("CXP_HS", 0,
|
||||||
|
Subsignal("txp", Pins("HPC:DP0_C2M_P")),
|
||||||
|
Subsignal("txn", Pins("HPC:DP0_C2M_N")),
|
||||||
|
Subsignal("rxp", Pins("HPC:DP0_M2C_P")),
|
||||||
|
Subsignal("rxn", Pins("HPC:DP0_M2C_N")),
|
||||||
|
),
|
||||||
|
("CXP_HS", 1,
|
||||||
|
Subsignal("txp", Pins("HPC:DP1_C2M_P")),
|
||||||
|
Subsignal("txn", Pins("HPC:DP1_C2M_N")),
|
||||||
|
Subsignal("rxp", Pins("HPC:DP1_M2C_P")),
|
||||||
|
Subsignal("rxn", Pins("HPC:DP1_M2C_N")),
|
||||||
|
),
|
||||||
|
("CXP_HS", 2,
|
||||||
|
Subsignal("txp", Pins("HPC:DP2_C2M_P")),
|
||||||
|
Subsignal("txn", Pins("HPC:DP2_C2M_N")),
|
||||||
|
Subsignal("rxp", Pins("HPC:DP2_M2C_P")),
|
||||||
|
Subsignal("rxn", Pins("HPC:DP2_M2C_N")),
|
||||||
|
),
|
||||||
|
("CXP_HS", 3,
|
||||||
|
Subsignal("txp", Pins("HPC:DP3_C2M_P")),
|
||||||
|
Subsignal("txn", Pins("HPC:DP3_C2M_N")),
|
||||||
|
Subsignal("rxp", Pins("HPC:DP3_M2C_P")),
|
||||||
|
Subsignal("rxn", Pins("HPC:DP3_M2C_N")),
|
||||||
|
),
|
||||||
|
|
||||||
|
# CoaXPress low speed link
|
||||||
|
("CXP_LS", 0, Pins("HPC:LA00_CC_P"), IOStandard("LVCMOS33")),
|
||||||
|
("CXP_LS", 1, Pins("HPC:LA01_CC_N"), IOStandard("LVCMOS33")),
|
||||||
|
("CXP_LS", 2, Pins("HPC:LA01_CC_P"), IOStandard("LVCMOS33")),
|
||||||
|
("CXP_LS", 3, Pins("HPC:LA02_N"), IOStandard("LVCMOS33")),
|
||||||
|
|
||||||
|
# CoaXPress green and red LED
|
||||||
|
("CXP_LED", 0,
|
||||||
|
Subsignal("green", Pins("HPC:LA11_P"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("red", Pins("HPC:LA11_N"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
("CXP_LED", 1,
|
||||||
|
Subsignal("green", Pins("HPC:LA12_P"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("red", Pins("HPC:LA12_N"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
("CXP_LED", 2,
|
||||||
|
Subsignal("green", Pins("HPC:LA13_P"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("red", Pins("HPC:LA13_N"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
("CXP_LED", 3,
|
||||||
|
Subsignal("green", Pins("HPC:LA14_P"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("red", Pins("HPC:LA14_N"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
|
||||||
|
# Power over CoaXPress
|
||||||
|
("PoCXP", 0,
|
||||||
|
Subsignal("enable", Pins("HPC:LA21_N"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("alert", Pins("HPC:LA18_CC_P"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
("PoCXP", 1,
|
||||||
|
Subsignal("enable", Pins("HPC:LA21_P"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("alert", Pins("HPC:LA19_N"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
("PoCXP", 2,
|
||||||
|
Subsignal("enable", Pins("HPC:LA22_N"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("alert", Pins("HPC:LA19_P"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
("PoCXP", 3,
|
||||||
|
Subsignal("enable", Pins("HPC:LA22_P"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("alert", Pins("HPC:LA20_N"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
|
||||||
|
("i2c_fmc", 0,
|
||||||
|
Subsignal("scl", Pins("HPC:IIC_SCL")),
|
||||||
|
Subsignal("sda", Pins("HPC:IIC_SDA")),
|
||||||
|
IOStandard("LVCMOS33")
|
||||||
|
),
|
||||||
|
|
||||||
|
("3V3", 0, Pins("HPC:PG_M2C")),
|
||||||
|
("GND", 0, Pins("HPC:PRSNT_M2C_L HPC:CLK0_M2C_P")),
|
||||||
|
("VADJ", 0, Pins("HPC:GBTCLK1_M2C_N CLK0_M2C_N")),
|
||||||
|
|
||||||
|
("clk125_fmc", 0,
|
||||||
|
Subsignal("p", Pins("HPC:GBTCLK0_M2C_P")),
|
||||||
|
Subsignal("n", Pins("HPC:GBTCLK0_M2C_n")),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,794 @@
|
||||||
|
from migen import *
|
||||||
|
from migen.genlib.cdc import MultiReg
|
||||||
|
from migen.genlib.resetsync import AsyncResetSynchronizer
|
||||||
|
|
||||||
|
from misoc.cores.code_8b10b import Encoder, Decoder
|
||||||
|
from misoc.interconnect.csr import *
|
||||||
|
|
||||||
|
from artiq.gateware.drtio.transceiver.gtx_7series_init import *
|
||||||
|
|
||||||
|
from functools import reduce
|
||||||
|
from operator import add
|
||||||
|
|
||||||
|
class CXP_DownConn_PHY(Module, AutoCSR):
|
||||||
|
def __init__(self, refclk, pads, sys_clk_freq, debug_sma, pmod_pads):
|
||||||
|
nconn = len(pads)
|
||||||
|
self.rx_start_init = CSRStorage()
|
||||||
|
self.rx_restart = CSR()
|
||||||
|
|
||||||
|
self.tx_start_init = CSRStorage()
|
||||||
|
self.tx_restart = CSR()
|
||||||
|
self.txenable = CSRStorage()
|
||||||
|
|
||||||
|
self.rx_ready = CSRStatus(nconn)
|
||||||
|
|
||||||
|
self.qpll_reset = CSR()
|
||||||
|
self.qpll_locked = CSRStatus()
|
||||||
|
|
||||||
|
self.gtxs = []
|
||||||
|
# # #
|
||||||
|
|
||||||
|
self.submodules.qpll = qpll = QPLL(refclk, sys_clk_freq)
|
||||||
|
self.sync += [
|
||||||
|
qpll.reset.eq(self.qpll_reset.re),
|
||||||
|
self.qpll_locked.status.eq(qpll.lock),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(nconn):
|
||||||
|
if i != 0:
|
||||||
|
break
|
||||||
|
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 connection interface
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Connect slave cxp_gtx_rx clock tgt
|
||||||
|
# checkout channel interfaces & drtio_gtx
|
||||||
|
# GTPTXPhaseAlignement for inspiration
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
for gtx in self.gtxs:
|
||||||
|
self.sync += [
|
||||||
|
|
||||||
|
gtx.txenable.eq(self.txenable.storage[0]),
|
||||||
|
gtx.tx_restart.eq(self.tx_restart.re),
|
||||||
|
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"))
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# TODO: deal with 4 GTX instance of outpus
|
||||||
|
for n, gtx in enumerate(self.gtxs):
|
||||||
|
self.sync += [
|
||||||
|
self.rx_ready.status[n].eq(gtx.rx_ready),
|
||||||
|
If(gtx.dready,
|
||||||
|
self.gtx_dready.w.eq(1),
|
||||||
|
self.gtx_dout.status.eq(gtx.dout),
|
||||||
|
),
|
||||||
|
If(self.gtx_dready.re,
|
||||||
|
self.gtx_dready.w.eq(0),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
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: 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=gtx.comma_checker.comma_aligned, o_O=pmod_pads[0]),
|
||||||
|
# Instance("OBUF", i_I=gtx.comma_checker.comma_det, o_O=pmod_pads[1]),
|
||||||
|
# Instance("OBUF", i_I=gtx.comma_checker.restart_sys, 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]),
|
||||||
|
]
|
||||||
|
|
||||||
|
# DEBUG: datain
|
||||||
|
|
||||||
|
|
||||||
|
self.sync.cxp_gtx_tx += [
|
||||||
|
gtx.encoder.d[0].eq(0xBC),
|
||||||
|
gtx.encoder.k[0].eq(1),
|
||||||
|
gtx.encoder.d[1].eq(0x3C),
|
||||||
|
gtx.encoder.k[1].eq(1),
|
||||||
|
gtx.encoder.d[2].eq(0x3C),
|
||||||
|
gtx.encoder.k[2].eq(1),
|
||||||
|
gtx.encoder.d[3].eq(0xB5),
|
||||||
|
gtx.encoder.k[3].eq(0),
|
||||||
|
]
|
||||||
|
|
||||||
|
for i in range(4):
|
||||||
|
gtx.decoders[i].input.attr.add("no_retiming")
|
||||||
|
gtx.decoders[i].d.attr.add("no_retiming")
|
||||||
|
gtx.decoders[i].k.attr.add("no_retiming")
|
||||||
|
|
||||||
|
rxdata_name = "rxdata_" + str(i)
|
||||||
|
rxdata_csr = CSRStatus(10, name=rxdata_name)
|
||||||
|
setattr(self, rxdata_name, rxdata_csr)
|
||||||
|
|
||||||
|
decoded_name = "decoded_data_" + str(i)
|
||||||
|
decoded_csr = CSRStatus(8, name=decoded_name)
|
||||||
|
setattr(self, decoded_name, decoded_csr)
|
||||||
|
|
||||||
|
k_name = "rxdata_" + str(i)
|
||||||
|
k_csr = CSRStatus(1, name=k_name)
|
||||||
|
setattr(self, k_name, k_csr)
|
||||||
|
|
||||||
|
self.sync.cxp_gtx_rx += [
|
||||||
|
rxdata_csr.status.eq(gtx.decoders[i].input),
|
||||||
|
decoded_csr.status.eq(gtx.decoders[i].d),
|
||||||
|
k_csr.status.eq(gtx.decoders[i].k),
|
||||||
|
]
|
||||||
|
|
||||||
|
class QPLL(Module, AutoCSR):
|
||||||
|
def __init__(self, refclk, sys_clk_freq):
|
||||||
|
self.clk = Signal()
|
||||||
|
self.refclk = Signal()
|
||||||
|
self.lock = Signal()
|
||||||
|
self.reset = Signal()
|
||||||
|
|
||||||
|
self.daddr = CSRStorage(8)
|
||||||
|
self.dread = CSR()
|
||||||
|
self.din_stb = CSR()
|
||||||
|
self.din = CSRStorage(16)
|
||||||
|
|
||||||
|
self.dout = CSRStatus(16)
|
||||||
|
self.dready = CSR()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
# VCO @ 10GHz, linerate = 1.25Gbps
|
||||||
|
# feedback divider = 80
|
||||||
|
qpll_fbdiv = 0b0100100000
|
||||||
|
qpll_fbdiv_ratio = 1
|
||||||
|
refclk_div = 1
|
||||||
|
self.Xxout_div = 8
|
||||||
|
|
||||||
|
# DEBUG: txuserclk
|
||||||
|
fbdiv_real = 80
|
||||||
|
self.tx_usrclk_freq = (sys_clk_freq*fbdiv_real/self.Xxout_div)/40
|
||||||
|
|
||||||
|
dready = Signal()
|
||||||
|
self.specials += [
|
||||||
|
Instance("GTXE2_COMMON",
|
||||||
|
i_QPLLREFCLKSEL=0b001,
|
||||||
|
i_GTREFCLK0=refclk,
|
||||||
|
|
||||||
|
i_QPLLPD=0,
|
||||||
|
i_QPLLRESET=self.reset,
|
||||||
|
i_QPLLLOCKEN=1,
|
||||||
|
o_QPLLLOCK=self.lock,
|
||||||
|
o_QPLLOUTCLK=self.clk,
|
||||||
|
o_QPLLOUTREFCLK=self.refclk,
|
||||||
|
|
||||||
|
# See UG476 (v1.12.1) Table 2-16
|
||||||
|
p_QPLL_FBDIV=qpll_fbdiv,
|
||||||
|
p_QPLL_FBDIV_RATIO=qpll_fbdiv_ratio,
|
||||||
|
p_QPLL_REFCLK_DIV=refclk_div,
|
||||||
|
|
||||||
|
# From 7 Series FPGAs Transceivers Wizard
|
||||||
|
p_BIAS_CFG=0x0000040000001000,
|
||||||
|
p_COMMON_CFG=0x00000000,
|
||||||
|
p_QPLL_CFG=0x0680181,
|
||||||
|
p_QPLL_CLKOUT_CFG=0b0000,
|
||||||
|
p_QPLL_COARSE_FREQ_OVRD=0b010000,
|
||||||
|
p_QPLL_COARSE_FREQ_OVRD_EN=0b0,
|
||||||
|
p_QPLL_CP=0b0000011111,
|
||||||
|
p_QPLL_CP_MONITOR_EN=0b0,
|
||||||
|
p_QPLL_DMONITOR_SEL=0b0,
|
||||||
|
p_QPLL_FBDIV_MONITOR_EN= 0b0,
|
||||||
|
p_QPLL_INIT_CFG=0x000006,
|
||||||
|
p_QPLL_LOCK_CFG=0x21E8,
|
||||||
|
p_QPLL_LPF=0b1111,
|
||||||
|
|
||||||
|
# Reserved, values cannot be modified
|
||||||
|
i_BGBYPASSB=0b1,
|
||||||
|
i_BGMONITORENB=0b1,
|
||||||
|
i_BGPDB=0b1,
|
||||||
|
i_BGRCALOVRD=0b11111,
|
||||||
|
i_RCALENB=0b1,
|
||||||
|
i_QPLLRSVD1=0b0,
|
||||||
|
i_QPLLRSVD2=0b11111,
|
||||||
|
|
||||||
|
# Dynamic Reconfiguration Ports
|
||||||
|
i_DRPADDR=self.daddr.storage,
|
||||||
|
i_DRPCLK=ClockSignal("sys"),
|
||||||
|
i_DRPEN=(self.dread.re | self.din_stb.re),
|
||||||
|
i_DRPWE=self.din_stb.re,
|
||||||
|
i_DRPDI=self.din.storage,
|
||||||
|
o_DRPDO=self.dout.status,
|
||||||
|
o_DRPRDY=dready,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
If(dready,
|
||||||
|
self.dready.w.eq(1),
|
||||||
|
),
|
||||||
|
If(self.dready.re,
|
||||||
|
self.dready.w.eq(0),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Warning: Xilinx transceivers are LSB first, and comma needs to be flipped
|
||||||
|
# compared to the usual 8b10b binary representation.
|
||||||
|
class Comma_Checker(Module):
|
||||||
|
def __init__(self, comma, reset_period=10_000_000):
|
||||||
|
self.data = Signal(20)
|
||||||
|
self.comma_aligned = Signal()
|
||||||
|
self.comma_realigned = Signal()
|
||||||
|
self.comma_det = Signal()
|
||||||
|
|
||||||
|
self.aligner_en = Signal()
|
||||||
|
self.ready_sys = Signal()
|
||||||
|
self.restart_sys = Signal()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
|
||||||
|
# periodically reset rx until rx is connected and receiving valid data
|
||||||
|
# as after connecting RXP/RXN, the whole RX need to be reset
|
||||||
|
|
||||||
|
reset_counter = Signal(reset=reset_period-1, max=reset_period)
|
||||||
|
self.sync += [
|
||||||
|
self.restart_sys.eq(0),
|
||||||
|
If(~self.ready_sys,
|
||||||
|
If(reset_counter == 0,
|
||||||
|
reset_counter.eq(reset_counter.reset),
|
||||||
|
self.restart_sys.eq(1),
|
||||||
|
).Else(
|
||||||
|
reset_counter.eq(reset_counter - 1),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Data and comma checker
|
||||||
|
# From UG476 (v1.12.1) p.228
|
||||||
|
# The built-in RXBYTEISALIGNED can be falsely asserted at linerate higher than 5Gbps
|
||||||
|
# The validity of data and comma needed to be checked externally
|
||||||
|
|
||||||
|
comma_n = ~comma & 0b1111111111
|
||||||
|
|
||||||
|
# DEBUG: remove after use
|
||||||
|
self.has_comma = Signal()
|
||||||
|
self.has_error = Signal()
|
||||||
|
|
||||||
|
comma_seen = Signal()
|
||||||
|
error_seen = Signal()
|
||||||
|
one_counts = Signal(max=11)
|
||||||
|
|
||||||
|
# From CXP-001-2021 section 9.2.5.1
|
||||||
|
# For high speed connection an IDLE word shall be transmitted at least once every 100 words
|
||||||
|
counter_period = 200
|
||||||
|
|
||||||
|
counter = Signal(reset=counter_period-1, max=counter_period)
|
||||||
|
check_reset = Signal()
|
||||||
|
check = Signal()
|
||||||
|
|
||||||
|
self.sync.cxp_gtx_rx += [
|
||||||
|
If(check_reset,
|
||||||
|
counter.eq(counter.reset),
|
||||||
|
check.eq(0),
|
||||||
|
).Elif(counter == 0,
|
||||||
|
check.eq(1),
|
||||||
|
).Else(
|
||||||
|
counter.eq(counter - 1),
|
||||||
|
),
|
||||||
|
|
||||||
|
If(check_reset,
|
||||||
|
comma_seen.eq(0),
|
||||||
|
).Elif((self.data[:10] == comma) | (self.data[:10] == comma_n),
|
||||||
|
comma_seen.eq(1)
|
||||||
|
),
|
||||||
|
|
||||||
|
one_counts.eq(reduce(add, [self.data[i] for i in range(10)])),
|
||||||
|
If(check_reset,
|
||||||
|
error_seen.eq(0),
|
||||||
|
).Elif((one_counts != 4) & (one_counts != 5) & (one_counts != 6),
|
||||||
|
error_seen.eq(1),
|
||||||
|
),
|
||||||
|
|
||||||
|
# DEBUG:
|
||||||
|
self.has_comma.eq(0),
|
||||||
|
If((self.data[:10] == comma) | (self.data[:10] == comma_n),
|
||||||
|
self.has_comma.eq(1),
|
||||||
|
),
|
||||||
|
|
||||||
|
self.has_error.eq(0),
|
||||||
|
If((one_counts != 4) & (one_counts != 5) & (one_counts != 6),
|
||||||
|
self.has_error.eq(1),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# DEBUG: expose signal
|
||||||
|
self.check_reset = Signal()
|
||||||
|
self.comb +=[
|
||||||
|
self.check_reset.eq(check_reset),
|
||||||
|
]
|
||||||
|
|
||||||
|
self.submodules.rxfsm = rxfsm = ClockDomainsRenamer("cxp_gtx_rx")(FSM(reset_state="WAIT_COMMA"))
|
||||||
|
|
||||||
|
rxfsm.act("WAIT_COMMA",
|
||||||
|
If(self.comma_det,
|
||||||
|
NextState("ALIGNING"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
rxfsm.act("ALIGNING",
|
||||||
|
If(self.comma_aligned & (~self.comma_realigned),
|
||||||
|
NextState("WAIT_ALIGNED_DATA"),
|
||||||
|
).Else(
|
||||||
|
self.aligner_en.eq(1),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# wait for the aligned data to arrive at the FPGA RX interface
|
||||||
|
# as there is a delay before the data is avaiable after RXBYTEISALIGNED is asserted
|
||||||
|
self.submodules.timer = timer = ClockDomainsRenamer("cxp_gtx_rx")(WaitTimer(10_000))
|
||||||
|
|
||||||
|
rxfsm.act("WAIT_ALIGNED_DATA",
|
||||||
|
timer.wait.eq(1),
|
||||||
|
If(timer.done,
|
||||||
|
check_reset.eq(1),
|
||||||
|
NextState("CHECKING"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
rxfsm.act("CHECKING",
|
||||||
|
If(check,
|
||||||
|
check_reset.eq(1),
|
||||||
|
If(comma_seen & (~error_seen),
|
||||||
|
NextState("READY"),
|
||||||
|
).Else(
|
||||||
|
NextState("WAIT_COMMA")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
ready = Signal()
|
||||||
|
self.specials += MultiReg(ready, self.ready_sys)
|
||||||
|
rxfsm.act("READY",
|
||||||
|
ready.eq(1),
|
||||||
|
If(check,
|
||||||
|
check_reset.eq(1),
|
||||||
|
If(~(comma_seen & (~error_seen)),
|
||||||
|
NextState("WAIT_COMMA"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class GTX(Module):
|
||||||
|
# Settings:
|
||||||
|
# * GTX reference clock @ 125MHz
|
||||||
|
# * GTX data width = 20
|
||||||
|
# * GTX PLL frequency @ 3.125GHz
|
||||||
|
# * GTX line rate (TX & RX) @ 3.125Gb/s
|
||||||
|
# * GTX TX/RX USRCLK @ PLL/datawidth = 156MHz
|
||||||
|
def __init__(self, qpll, pads, sys_clk_freq, tx_mode="single", rx_mode="single"):
|
||||||
|
assert tx_mode in ["single", "master", "slave"]
|
||||||
|
assert rx_mode in ["single", "master", "slave"]
|
||||||
|
|
||||||
|
# linerate = USRCLK * datawidth
|
||||||
|
pll_fbout_mult = 8
|
||||||
|
txusr_pll_div = pll_fbout_mult*sys_clk_freq/qpll.tx_usrclk_freq
|
||||||
|
|
||||||
|
self.tx_restart = Signal()
|
||||||
|
self.rx_restart = Signal()
|
||||||
|
self.loopback_mode = Signal(3)
|
||||||
|
|
||||||
|
self.txenable = Signal()
|
||||||
|
self.rx_ready = Signal()
|
||||||
|
|
||||||
|
# Dynamic Reconfiguration Ports
|
||||||
|
self.daddr = Signal(9)
|
||||||
|
self.dclk = Signal()
|
||||||
|
self.den = Signal()
|
||||||
|
self.dwen = Signal()
|
||||||
|
self.din = Signal(16)
|
||||||
|
self.dout = Signal(16)
|
||||||
|
self.dready = Signal()
|
||||||
|
|
||||||
|
self.submodules.encoder = ClockDomainsRenamer("cxp_gtx_tx")(Encoder(4, True))
|
||||||
|
self.submodules.decoders = [ClockDomainsRenamer("cxp_gtx_rx")(
|
||||||
|
(Decoder(True))) for _ in range(4)]
|
||||||
|
|
||||||
|
|
||||||
|
# transceiver direct clock outputs
|
||||||
|
# useful to specify clock constraints in a way palatable to Vivado
|
||||||
|
self.txoutclk = Signal()
|
||||||
|
self.rxoutclk = Signal()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
# TX generates cxp_tx clock, init must be in system domain
|
||||||
|
# FIXME: 500e6 is used to fix Xx reset by holding gtxXxreset for a couple cycle more
|
||||||
|
self.submodules.tx_init = tx_init = GTXInit(500e6, False, mode=tx_mode)
|
||||||
|
self.submodules.rx_init = rx_init = GTXInit(sys_clk_freq, True, mode=rx_mode)
|
||||||
|
|
||||||
|
# RX receives restart commands from txusrclk domain
|
||||||
|
# self.submodules.rx_init = rx_init = ClockDomainsRenamer("cxp_gtx_tx")(GTXInit(500e6, True, mode=rx_mode))
|
||||||
|
|
||||||
|
self.comb += [
|
||||||
|
tx_init.cplllock.eq(qpll.lock),
|
||||||
|
rx_init.cplllock.eq(qpll.lock)
|
||||||
|
]
|
||||||
|
|
||||||
|
txdata = Signal(40)
|
||||||
|
rxdata = Signal(40)
|
||||||
|
|
||||||
|
comma_aligned = Signal()
|
||||||
|
comma_realigned = Signal()
|
||||||
|
comma_det = Signal()
|
||||||
|
comma_aligner_en = Signal()
|
||||||
|
# Note: the following parameters were set after consulting AR45360
|
||||||
|
self.specials += \
|
||||||
|
Instance("GTXE2_CHANNEL",
|
||||||
|
# PMA Attributes
|
||||||
|
p_PMA_RSV=0x001E7080,
|
||||||
|
p_PMA_RSV2=0x2050, # PMA_RSV2[5] = 0: Eye scan feature disabled
|
||||||
|
p_PMA_RSV3=0,
|
||||||
|
p_PMA_RSV4=1, # PMA_RSV[4],RX_CM_TRIM[2:0] = 0b1010: Common mode 800mV
|
||||||
|
p_RX_BIAS_CFG=0b000000000100,
|
||||||
|
p_RX_OS_CFG=0b0000010000000,
|
||||||
|
p_RX_CLK25_DIV=5,
|
||||||
|
p_TX_CLK25_DIV=5,
|
||||||
|
|
||||||
|
# Power-Down Attributes
|
||||||
|
p_PD_TRANS_TIME_FROM_P2=0x3c,
|
||||||
|
p_PD_TRANS_TIME_NONE_P2=0x3c,
|
||||||
|
p_PD_TRANS_TIME_TO_P2=0x64,
|
||||||
|
i_CPLLPD=1,
|
||||||
|
|
||||||
|
# QPLL
|
||||||
|
i_QPLLCLK=qpll.clk,
|
||||||
|
i_QPLLREFCLK=qpll.refclk,
|
||||||
|
p_RXOUT_DIV=qpll.Xxout_div,
|
||||||
|
p_TXOUT_DIV=qpll.Xxout_div,
|
||||||
|
i_RXSYSCLKSEL=0b11, # use QPLL & QPLL's REFCLK
|
||||||
|
i_TXSYSCLKSEL=0b11, # use QPLL & CPLL's REFCLK
|
||||||
|
|
||||||
|
# TX clock
|
||||||
|
p_TXBUF_EN="FALSE",
|
||||||
|
p_TX_XCLK_SEL="TXUSR",
|
||||||
|
o_TXOUTCLK=self.txoutclk,
|
||||||
|
# i_TXSYSCLKSEL=0b00,
|
||||||
|
i_TXOUTCLKSEL=0b11,
|
||||||
|
|
||||||
|
# TX Startup/Reset
|
||||||
|
i_TXPHDLYRESET=0,
|
||||||
|
i_TXDLYBYPASS=0,
|
||||||
|
i_TXPHALIGNEN=1 if tx_mode != "single" else 0,
|
||||||
|
i_GTTXRESET=tx_init.gtXxreset,
|
||||||
|
o_TXRESETDONE=tx_init.Xxresetdone,
|
||||||
|
i_TXDLYSRESET=tx_init.Xxdlysreset,
|
||||||
|
o_TXDLYSRESETDONE=tx_init.Xxdlysresetdone,
|
||||||
|
i_TXPHINIT=tx_init.txphinit if tx_mode != "single" else 0,
|
||||||
|
o_TXPHINITDONE=tx_init.txphinitdone if tx_mode != "single" else Signal(),
|
||||||
|
i_TXPHALIGN=tx_init.Xxphalign if tx_mode != "single" else 0,
|
||||||
|
i_TXDLYEN=tx_init.Xxdlyen if tx_mode != "single" else 0,
|
||||||
|
o_TXPHALIGNDONE=tx_init.Xxphaligndone,
|
||||||
|
i_TXUSERRDY=tx_init.Xxuserrdy,
|
||||||
|
p_TXPMARESET_TIME=1,
|
||||||
|
p_TXPCSRESET_TIME=1,
|
||||||
|
i_TXINHIBIT=~self.txenable,
|
||||||
|
|
||||||
|
# TX data
|
||||||
|
p_TX_DATA_WIDTH=40,
|
||||||
|
p_TX_INT_DATAWIDTH=1, # 1 if a line rate is greater than 6.6 Gbps
|
||||||
|
i_TXCHARDISPMODE=Cat(txdata[9], txdata[19], txdata[29], txdata[39]),
|
||||||
|
i_TXCHARDISPVAL=Cat(txdata[8], txdata[18], txdata[28], txdata[38]),
|
||||||
|
i_TXDATA=Cat(txdata[:8], txdata[10:18], txdata[20:28], txdata[30:38]),
|
||||||
|
i_TXUSRCLK=ClockSignal("cxp_gtx_tx"),
|
||||||
|
i_TXUSRCLK2=ClockSignal("cxp_gtx_tx"),
|
||||||
|
|
||||||
|
# TX electrical
|
||||||
|
i_TXBUFDIFFCTRL=0b100,
|
||||||
|
i_TXDIFFCTRL=0b1000,
|
||||||
|
|
||||||
|
# RX Startup/Reset
|
||||||
|
i_RXPHDLYRESET=0,
|
||||||
|
i_RXDLYBYPASS=0,
|
||||||
|
i_RXPHALIGNEN=1 if rx_mode != "single" else 0,
|
||||||
|
i_GTRXRESET=rx_init.gtXxreset,
|
||||||
|
o_RXRESETDONE=rx_init.Xxresetdone,
|
||||||
|
i_RXDLYSRESET=rx_init.Xxdlysreset,
|
||||||
|
o_RXDLYSRESETDONE=rx_init.Xxdlysresetdone,
|
||||||
|
i_RXPHALIGN=rx_init.Xxphalign if rx_mode != "single" else 0,
|
||||||
|
i_RXDLYEN=rx_init.Xxdlyen if rx_mode != "single" else 0,
|
||||||
|
o_RXPHALIGNDONE=rx_init.Xxphaligndone,
|
||||||
|
i_RXUSERRDY=rx_init.Xxuserrdy,
|
||||||
|
p_RXPMARESET_TIME=1,
|
||||||
|
p_RXPCSRESET_TIME=1,
|
||||||
|
|
||||||
|
# RX AFE
|
||||||
|
p_RX_DFE_XYD_CFG=0,
|
||||||
|
p_RX_CM_SEL=0b11, # RX_CM_SEL = 0b11: Common mode is programmable
|
||||||
|
p_RX_CM_TRIM=0b010, # PMA_RSV[4],RX_CM_TRIM[2:0] = 0b1010: Common mode 800mV
|
||||||
|
i_RXDFEXYDEN=1,
|
||||||
|
i_RXDFEXYDHOLD=0,
|
||||||
|
i_RXDFEXYDOVRDEN=0,
|
||||||
|
i_RXLPMEN=1, # RXLPMEN = 1: LPM mode is enable for non scramble 8b10b data
|
||||||
|
p_RXLPM_HF_CFG=0b00000011110000,
|
||||||
|
p_RXLPM_LF_CFG=0b00000011110000,
|
||||||
|
|
||||||
|
p_RX_DFE_GAIN_CFG=0x0207EA,
|
||||||
|
p_RX_DFE_VP_CFG=0b00011111100000011,
|
||||||
|
p_RX_DFE_UT_CFG=0b10001000000000000,
|
||||||
|
p_RX_DFE_KL_CFG=0b0000011111110,
|
||||||
|
p_RX_DFE_KL_CFG2=0x3788140A,
|
||||||
|
p_RX_DFE_H2_CFG=0b000110000000,
|
||||||
|
p_RX_DFE_H3_CFG=0b000110000000,
|
||||||
|
p_RX_DFE_H4_CFG=0b00011100000,
|
||||||
|
p_RX_DFE_H5_CFG=0b00011100000,
|
||||||
|
p_RX_DFE_LPM_CFG=0x0904, # RX_DFE_LPM_CFG = 0x0904: linerate <= 6.6Gb/s
|
||||||
|
# = 0x0104: linerate > 6.6Gb/s
|
||||||
|
|
||||||
|
# RX clock
|
||||||
|
i_RXDDIEN=1,
|
||||||
|
# i_RXSYSCLKSEL=0b00,
|
||||||
|
i_RXOUTCLKSEL=0b010,
|
||||||
|
o_RXOUTCLK=self.rxoutclk,
|
||||||
|
i_RXUSRCLK=ClockSignal("cxp_gtx_rx"),
|
||||||
|
i_RXUSRCLK2=ClockSignal("cxp_gtx_rx"),
|
||||||
|
|
||||||
|
# RX Clock Correction Attributes
|
||||||
|
p_CLK_CORRECT_USE="FALSE",
|
||||||
|
p_CLK_COR_SEQ_1_1=0b0100000000,
|
||||||
|
p_CLK_COR_SEQ_2_1=0b0100000000,
|
||||||
|
p_CLK_COR_SEQ_1_ENABLE=0b1111,
|
||||||
|
p_CLK_COR_SEQ_2_ENABLE=0b1111,
|
||||||
|
|
||||||
|
# RX data
|
||||||
|
p_RX_DATA_WIDTH=40,
|
||||||
|
p_RX_INT_DATAWIDTH=1, # 1 if a line rate is greater than 6.6 Gbps
|
||||||
|
o_RXDISPERR=Cat(rxdata[9], rxdata[19], rxdata[29], rxdata[39]),
|
||||||
|
o_RXCHARISK=Cat(rxdata[8], rxdata[18], rxdata[28], rxdata[38]),
|
||||||
|
o_RXDATA=Cat(rxdata[:8], rxdata[10:18], rxdata[20:28], rxdata[30:38]),
|
||||||
|
|
||||||
|
# RX Byte and Word Alignment Attributes
|
||||||
|
p_ALIGN_COMMA_DOUBLE="FALSE",
|
||||||
|
p_ALIGN_COMMA_ENABLE=0b1111111111,
|
||||||
|
p_ALIGN_COMMA_WORD=4, # align comma to rxdata[:10] only
|
||||||
|
p_ALIGN_MCOMMA_DET="TRUE",
|
||||||
|
p_ALIGN_MCOMMA_VALUE=0b1010000011,
|
||||||
|
p_ALIGN_PCOMMA_DET="TRUE",
|
||||||
|
p_ALIGN_PCOMMA_VALUE=0b0101111100,
|
||||||
|
p_SHOW_REALIGN_COMMA="FALSE",
|
||||||
|
p_RXSLIDE_AUTO_WAIT=7,
|
||||||
|
p_RXSLIDE_MODE="OFF",
|
||||||
|
p_RX_SIG_VALID_DLY=10,
|
||||||
|
i_RXPCOMMAALIGNEN=comma_aligner_en,
|
||||||
|
i_RXMCOMMAALIGNEN=comma_aligner_en,
|
||||||
|
i_RXCOMMADETEN=1,
|
||||||
|
i_RXSLIDE=0,
|
||||||
|
o_RXBYTEISALIGNED=comma_aligned,
|
||||||
|
o_RXBYTEREALIGN=comma_realigned,
|
||||||
|
o_RXCOMMADET=comma_det,
|
||||||
|
|
||||||
|
# RX 8B/10B Decoder Attributes
|
||||||
|
p_RX_DISPERR_SEQ_MATCH="FALSE",
|
||||||
|
p_DEC_MCOMMA_DETECT="TRUE",
|
||||||
|
p_DEC_PCOMMA_DETECT="TRUE",
|
||||||
|
p_DEC_VALID_COMMA_ONLY="FALSE",
|
||||||
|
|
||||||
|
# RX Buffer Attributes
|
||||||
|
p_RXBUF_ADDR_MODE="FAST",
|
||||||
|
p_RXBUF_EIDLE_HI_CNT=0b1000,
|
||||||
|
p_RXBUF_EIDLE_LO_CNT=0b0000,
|
||||||
|
p_RXBUF_EN="FALSE",
|
||||||
|
p_RX_BUFFER_CFG=0b000000,
|
||||||
|
p_RXBUF_RESET_ON_CB_CHANGE="TRUE",
|
||||||
|
p_RXBUF_RESET_ON_COMMAALIGN="FALSE",
|
||||||
|
p_RXBUF_RESET_ON_EIDLE="FALSE", # RXBUF_RESET_ON_EIDLE = FALSE: OOB is disabled
|
||||||
|
p_RXBUF_RESET_ON_RATE_CHANGE="TRUE",
|
||||||
|
p_RXBUFRESET_TIME=0b00001,
|
||||||
|
p_RXBUF_THRESH_OVFLW=61,
|
||||||
|
p_RXBUF_THRESH_OVRD="FALSE",
|
||||||
|
p_RXBUF_THRESH_UNDFLW=4,
|
||||||
|
p_RXDLY_CFG=0x001F,
|
||||||
|
p_RXDLY_LCFG=0x030,
|
||||||
|
p_RXDLY_TAP_CFG=0x0000,
|
||||||
|
p_RXPH_CFG=0xC00002,
|
||||||
|
p_RXPHDLY_CFG=0x084020,
|
||||||
|
p_RXPH_MONITOR_SEL=0b00000,
|
||||||
|
p_RX_XCLK_SEL="RXUSR",
|
||||||
|
p_RX_DDI_SEL=0b000000,
|
||||||
|
p_RX_DEFER_RESET_BUF_EN="TRUE",
|
||||||
|
|
||||||
|
# CDR Attributes
|
||||||
|
p_RXCDR_CFG=0x03_0000_23FF_1008_0020, # LPM @ 0.5G-1.5625G , 8B/10B encoded data, CDR setting < +/- 200ppm
|
||||||
|
# (See UG476 (v1.12.1), p.206)
|
||||||
|
p_RXCDR_FR_RESET_ON_EIDLE=0b0,
|
||||||
|
p_RXCDR_HOLD_DURING_EIDLE=0b0,
|
||||||
|
p_RXCDR_PH_RESET_ON_EIDLE=0b0,
|
||||||
|
p_RXCDR_LOCK_CFG=0b010101,
|
||||||
|
|
||||||
|
# Pads
|
||||||
|
i_GTXRXP=pads.rxp,
|
||||||
|
i_GTXRXN=pads.rxn,
|
||||||
|
o_GTXTXP=pads.txp,
|
||||||
|
o_GTXTXN=pads.txn,
|
||||||
|
|
||||||
|
# Dynamic Reconfiguration Ports
|
||||||
|
p_IS_DRPCLK_INVERTED=0b0,
|
||||||
|
i_DRPADDR=self.daddr,
|
||||||
|
i_DRPCLK=self.dclk,
|
||||||
|
i_DRPEN=self.den,
|
||||||
|
i_DRPWE=self.dwen,
|
||||||
|
i_DRPDI=self.din,
|
||||||
|
o_DRPDO=self.dout,
|
||||||
|
o_DRPRDY=self.dready,
|
||||||
|
|
||||||
|
# ! loopback for debugging
|
||||||
|
i_LOOPBACK = self.loopback_mode,
|
||||||
|
p_TX_LOOPBACK_DRIVE_HIZ = "FALSE",
|
||||||
|
p_RXPRBS_ERR_LOOPBACK = 0b0,
|
||||||
|
|
||||||
|
# Other parameters
|
||||||
|
p_PCS_RSVD_ATTR=(
|
||||||
|
(tx_mode != "single") << 1 | # PCS_RSVD_ATTR[1] = 0: TX Single Lane Auto Mode
|
||||||
|
# = 1: TX Manual Mode
|
||||||
|
(rx_mode != "single") << 2 | # [2] = 0: RX Single Lane Auto Mode
|
||||||
|
# = 1: RX Manual Mode
|
||||||
|
0 << 8 # [8] = 0: OOB is disabled
|
||||||
|
),
|
||||||
|
i_RXELECIDLEMODE=0b11, # RXELECIDLEMODE = 0b11: OOB is disabled
|
||||||
|
p_RX_DFE_LPM_HOLD_DURING_EIDLE=0b0,
|
||||||
|
p_ES_EYE_SCAN_EN="TRUE", # Must be TRUE for GTX
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TX clocking
|
||||||
|
# A PLL is used to generate the correct frequency for TXUSRCLK (UG476 Equation 3-1)
|
||||||
|
self.clock_domains.cd_cxp_gtx_tx = ClockDomain()
|
||||||
|
txpll_fb_clk = Signal()
|
||||||
|
txoutclk_buf = Signal()
|
||||||
|
txpll_clkout = Signal()
|
||||||
|
|
||||||
|
self.txpll_reset = Signal()
|
||||||
|
self.pll_daddr = Signal(7)
|
||||||
|
self.pll_dclk = Signal()
|
||||||
|
self.pll_den = Signal()
|
||||||
|
self.pll_din = Signal(16)
|
||||||
|
self.pll_dwen = Signal()
|
||||||
|
|
||||||
|
self.txpll_locked = Signal()
|
||||||
|
self.pll_dout = Signal(16)
|
||||||
|
self.pll_dready = Signal()
|
||||||
|
self.specials += [
|
||||||
|
Instance("PLLE2_ADV",
|
||||||
|
p_BANDWIDTH="HIGH",
|
||||||
|
o_LOCKED=self.txpll_locked,
|
||||||
|
i_RST=self.txpll_reset,
|
||||||
|
|
||||||
|
p_CLKIN1_PERIOD=1e9/sys_clk_freq, # ns
|
||||||
|
i_CLKIN1=txoutclk_buf,
|
||||||
|
|
||||||
|
# VCO @ 1.25GHz
|
||||||
|
p_CLKFBOUT_MULT=pll_fbout_mult, p_DIVCLK_DIVIDE=1,
|
||||||
|
i_CLKFBIN=txpll_fb_clk, o_CLKFBOUT=txpll_fb_clk,
|
||||||
|
|
||||||
|
# frequency = linerate/40
|
||||||
|
p_CLKOUT0_DIVIDE=txusr_pll_div, p_CLKOUT0_PHASE=0.0, o_CLKOUT0=txpll_clkout,
|
||||||
|
|
||||||
|
# Dynamic Reconfiguration Ports
|
||||||
|
i_DADDR = self.pll_daddr,
|
||||||
|
i_DCLK = self.pll_dclk,
|
||||||
|
i_DEN = self.pll_den,
|
||||||
|
i_DI = self.pll_din,
|
||||||
|
i_DWE = self.pll_dwen,
|
||||||
|
o_DO = self.pll_dout,
|
||||||
|
o_DRDY = self.pll_dready,
|
||||||
|
),
|
||||||
|
Instance("BUFG", i_I=self.txoutclk, o_O=txoutclk_buf),
|
||||||
|
Instance("BUFG", i_I=txpll_clkout, o_O=self.cd_cxp_gtx_tx.clk),
|
||||||
|
AsyncResetSynchronizer(self.cd_cxp_gtx_tx, ~self.txpll_locked & ~tx_init.done)
|
||||||
|
]
|
||||||
|
|
||||||
|
# RX clocking
|
||||||
|
# the CDR matches the required frequency for RXUSRCLK, no need for PLL
|
||||||
|
self.clock_domains.cd_cxp_gtx_rx = ClockDomain()
|
||||||
|
self.specials += [
|
||||||
|
Instance("BUFG", i_I=self.rxoutclk, o_O=self.cd_cxp_gtx_rx.clk),
|
||||||
|
AsyncResetSynchronizer(self.cd_cxp_gtx_rx, ~rx_init.done)
|
||||||
|
]
|
||||||
|
|
||||||
|
self.comb += [
|
||||||
|
txdata.eq(Cat(self.encoder.output[0], self.encoder.output[1], self.encoder.output[2], self.encoder.output[3])),
|
||||||
|
self.decoders[0].input.eq(rxdata[:10]),
|
||||||
|
self.decoders[1].input.eq(rxdata[10:20]),
|
||||||
|
self.decoders[2].input.eq(rxdata[20:30]),
|
||||||
|
self.decoders[3].input.eq(rxdata[30:]),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
self.submodules.comma_checker = comma_checker = Comma_Checker(0b0101111100)
|
||||||
|
self.comb += [
|
||||||
|
comma_checker.data.eq(rxdata),
|
||||||
|
comma_checker.comma_aligned.eq(comma_aligned),
|
||||||
|
comma_checker.comma_realigned.eq(comma_realigned),
|
||||||
|
comma_checker.comma_det.eq(comma_det),
|
||||||
|
comma_aligner_en.eq(comma_checker.aligner_en),
|
||||||
|
self.rx_ready.eq(comma_checker.ready_sys),
|
||||||
|
|
||||||
|
rx_init.restart.eq(self.rx_restart | comma_checker.restart_sys),
|
||||||
|
tx_init.restart.eq(self.tx_restart),
|
||||||
|
]
|
|
@ -0,0 +1,348 @@
|
||||||
|
from migen import *
|
||||||
|
from misoc.interconnect.csr import *
|
||||||
|
from misoc.interconnect import stream
|
||||||
|
from misoc.cores.liteeth_mini.mac.crc import LiteEthMACCRCEngine, LiteEthMACCRCChecker
|
||||||
|
|
||||||
|
upconn_dw = 8
|
||||||
|
upconn_layout = [("data", upconn_dw), ("k", upconn_dw//8)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def K(x, y):
|
||||||
|
return ((y << 5) | x)
|
||||||
|
|
||||||
|
class Code_Source(Module):
|
||||||
|
def __init__(self, layout, counts=4):
|
||||||
|
|
||||||
|
self.source = stream.Endpoint(layout)
|
||||||
|
self.stb = Signal()
|
||||||
|
self.data = Signal.like(self.source.data)
|
||||||
|
self.k = Signal.like(self.source.k)
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
cnt = 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")
|
||||||
|
|
||||||
|
fsm.act("IDLE",
|
||||||
|
clr_cnt.eq(1),
|
||||||
|
If(self.stb,
|
||||||
|
NextState("WRITE")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fsm.act("WRITE",
|
||||||
|
self.source.stb.eq(1),
|
||||||
|
self.source.data.eq(self.data),
|
||||||
|
self.source.k.eq(self.k),
|
||||||
|
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, insert_infront=True, counts=4):
|
||||||
|
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 counts > 0
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
if insert_infront:
|
||||||
|
fsm.act("IDLE",
|
||||||
|
self.sink.ack.eq(1),
|
||||||
|
clr_cnt.eq(1),
|
||||||
|
If(self.sink.stb,
|
||||||
|
self.sink.ack.eq(0),
|
||||||
|
NextState("INSERT"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fsm.act("INSERT",
|
||||||
|
self.sink.ack.eq(0),
|
||||||
|
self.source.stb.eq(1),
|
||||||
|
self.source.data.eq(self.data),
|
||||||
|
self.source.k.eq(self.k),
|
||||||
|
If(cnt == counts - 1,
|
||||||
|
If(self.source.ack, NextState("COPY"))
|
||||||
|
).Else(
|
||||||
|
inc_cnt.eq(self.source.ack)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fsm.act("COPY",
|
||||||
|
self.sink.connect(self.source),
|
||||||
|
If(self.sink.stb & self.sink.eop & self.source.ack,
|
||||||
|
NextState("IDLE"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
|
fsm.act("IDLE",
|
||||||
|
self.sink.ack.eq(1),
|
||||||
|
clr_cnt.eq(1),
|
||||||
|
If(self.sink.stb,
|
||||||
|
self.sink.ack.eq(0),
|
||||||
|
NextState("COPY"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fsm.act("COPY",
|
||||||
|
self.sink.connect(self.source),
|
||||||
|
self.source.eop.eq(0),
|
||||||
|
If(self.sink.stb & self.sink.eop & self.source.ack,
|
||||||
|
NextState("INSERT"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fsm.act("INSERT",
|
||||||
|
self.sink.ack.eq(0),
|
||||||
|
self.source.stb.eq(1),
|
||||||
|
self.source.data.eq(self.data),
|
||||||
|
self.source.k.eq(self.k),
|
||||||
|
If(cnt == counts - 1,
|
||||||
|
self.source.eop.eq(1),
|
||||||
|
If(self.source.ack, NextState("IDLE"))
|
||||||
|
).Else(
|
||||||
|
inc_cnt.eq(self.source.ack)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Packet_Wrapper(Module):
|
||||||
|
def __init__(self, layout):
|
||||||
|
self.submodules.pak_start = pak_start = Code_Inserter(layout)
|
||||||
|
self.submodules.pak_end = pak_end = Code_Inserter(layout, insert_infront=False)
|
||||||
|
|
||||||
|
self.sink = pak_start.sink
|
||||||
|
self.source = pak_end.source
|
||||||
|
|
||||||
|
self.comb += [
|
||||||
|
pak_start.data.eq(K(27, 7)),
|
||||||
|
pak_start.k.eq(1),
|
||||||
|
pak_end.data.eq(K(29, 7)),
|
||||||
|
pak_end.k.eq(1),
|
||||||
|
|
||||||
|
pak_start.source.connect(pak_end.sink),
|
||||||
|
]
|
||||||
|
|
||||||
|
@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):
|
||||||
|
self.trig_stb = Signal()
|
||||||
|
self.delay = Signal(upconn_dw)
|
||||||
|
self.linktrig_mode = Signal(max=4)
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
self.submodules.code_src = code_src = Code_Source(upconn_layout, counts=3)
|
||||||
|
self.comb += [
|
||||||
|
code_src.stb.eq(self.trig_stb),
|
||||||
|
code_src.data.eq(self.delay),
|
||||||
|
code_src.k.eq(0)
|
||||||
|
]
|
||||||
|
|
||||||
|
self.submodules.inserter_once = inserter_once = Code_Inserter(upconn_layout, counts=1)
|
||||||
|
self.submodules.inserter_twice = inserter_twice = Code_Inserter(upconn_layout, counts=2)
|
||||||
|
self.comb += [
|
||||||
|
inserter_once.k.eq(1),
|
||||||
|
inserter_twice.k.eq(1),
|
||||||
|
If((self.linktrig_mode == 0) | (self.linktrig_mode == 2),
|
||||||
|
inserter_once.data.eq(K(28, 2)),
|
||||||
|
inserter_twice.data.eq(K(28, 4)),
|
||||||
|
).Else(
|
||||||
|
inserter_once.data.eq(K(28, 4)),
|
||||||
|
inserter_twice.data.eq(K(28, 2)),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
tx_pipeline = [ code_src, inserter_twice, inserter_once]
|
||||||
|
|
||||||
|
for s, d in zip(tx_pipeline, tx_pipeline[1:]):
|
||||||
|
self.comb += s.source.connect(d.sink)
|
||||||
|
|
||||||
|
self.source = tx_pipeline[-1].source
|
||||||
|
|
||||||
|
class Trigger_ACK(Module):
|
||||||
|
def __init__(self):
|
||||||
|
self.ack = Signal()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
# Section 9.3.2 (CXP-001-2021)
|
||||||
|
# Send 4x K28.6 and 4x 0x01 as trigger packet ack
|
||||||
|
self.submodules.code_src = code_src = Code_Source(upconn_layout)
|
||||||
|
self.submodules.k_code_inserter = k_code_inserter = Code_Inserter(upconn_layout)
|
||||||
|
self.comb += [
|
||||||
|
code_src.stb.eq(self.ack),
|
||||||
|
code_src.data.eq(0x01),
|
||||||
|
code_src.k.eq(0),
|
||||||
|
k_code_inserter.data.eq(K(28, 6)),
|
||||||
|
k_code_inserter.k.eq(1),
|
||||||
|
|
||||||
|
code_src.source.connect(k_code_inserter.sink)
|
||||||
|
]
|
||||||
|
|
||||||
|
self.source = k_code_inserter.source
|
||||||
|
|
||||||
|
class TX_Command_Packet(Module, AutoCSR):
|
||||||
|
def __init__(self):
|
||||||
|
self.len = CSRStorage(6)
|
||||||
|
self.data = CSR(upconn_dw)
|
||||||
|
self.writeable = CSRStatus()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
# Section 12.1.2 (CXP-001-2021)
|
||||||
|
# Max control packet size is 128 bytes
|
||||||
|
self.submodules.fifo = fifo = stream.SyncFIFO(upconn_layout, 128)
|
||||||
|
self.submodules.pak_wrp = pak_wrp = Packet_Wrapper(upconn_layout)
|
||||||
|
self.source = pak_wrp.source
|
||||||
|
|
||||||
|
self.comb += fifo.source.connect(pak_wrp.sink)
|
||||||
|
|
||||||
|
len = Signal(6, reset=1)
|
||||||
|
self.sync += [
|
||||||
|
self.writeable.status.eq(fifo.sink.ack),
|
||||||
|
If(fifo.sink.ack, fifo.sink.stb.eq(0)),
|
||||||
|
If(self.data.re,
|
||||||
|
fifo.sink.stb.eq(1),
|
||||||
|
fifo.sink.data.eq(self.data.r),
|
||||||
|
|
||||||
|
fifo.sink.k.eq(0),
|
||||||
|
If(len == self.len.storage,
|
||||||
|
fifo.sink.eop.eq(1),
|
||||||
|
len.eq(len.reset),
|
||||||
|
).Else(
|
||||||
|
fifo.sink.eop.eq(0),
|
||||||
|
len.eq(len + 1),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
class TX_Test_Packet(Module, AutoCSR):
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
self.stb = CSR()
|
||||||
|
self.busy = CSRStatus()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
testdata_src = stream.Endpoint(upconn_layout)
|
||||||
|
|
||||||
|
|
||||||
|
# Section 9.9.2 (CXP-001-2021)
|
||||||
|
# 0x00, 0x01 ... 0xFF need to be send 16 times
|
||||||
|
# cnt[8:12] is used to count up 16 times while cnt[:8] is the data
|
||||||
|
cnt = Signal(max=0x1000)
|
||||||
|
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")
|
||||||
|
|
||||||
|
fsm.act("IDLE",
|
||||||
|
clr_cnt.eq(1),
|
||||||
|
If(self.stb.re,
|
||||||
|
NextState("WRITE")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fsm.act("WRITE",
|
||||||
|
testdata_src.stb.eq(1),
|
||||||
|
testdata_src.data.eq(cnt[:8]),
|
||||||
|
testdata_src.k.eq(0),
|
||||||
|
If(cnt == 0xFFF,
|
||||||
|
testdata_src.eop.eq(1),
|
||||||
|
If(testdata_src.ack, NextState("IDLE"))
|
||||||
|
).Else(
|
||||||
|
inc_cnt.eq(testdata_src.ack)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.submodules.pak_type_inserter = pak_type_inserter = Code_Inserter(upconn_layout)
|
||||||
|
self.submodules.pak_wrp = pak_wrp = Packet_Wrapper(upconn_layout)
|
||||||
|
self.comb += [
|
||||||
|
pak_type_inserter.data.eq(0x04),
|
||||||
|
pak_type_inserter.k.eq(0x04),
|
||||||
|
|
||||||
|
testdata_src.connect(pak_type_inserter.sink),
|
||||||
|
pak_type_inserter.source.connect(pak_wrp.sink),
|
||||||
|
]
|
||||||
|
|
||||||
|
self.source = pak_wrp.source
|
||||||
|
|
||||||
|
self.sync += \
|
||||||
|
If(self.stb.re,
|
||||||
|
self.busy.status.eq(1),
|
||||||
|
).Elif(self.source.eop & self.source.ack,
|
||||||
|
self.busy.status.eq(0)
|
||||||
|
)
|
|
@ -0,0 +1,374 @@
|
||||||
|
from math import ceil
|
||||||
|
|
||||||
|
from migen import *
|
||||||
|
from migen.genlib.coding import PriorityEncoder
|
||||||
|
|
||||||
|
from misoc.cores.code_8b10b import SingleEncoder
|
||||||
|
from misoc.interconnect import stream
|
||||||
|
from misoc.interconnect.csr import *
|
||||||
|
|
||||||
|
from cxp_pipeline import upconn_layout
|
||||||
|
|
||||||
|
IDLE_CHARS = Array([
|
||||||
|
#[char, k]
|
||||||
|
[0xBC, 1], #K28.5
|
||||||
|
[0x3C, 1], #K28.1
|
||||||
|
[0x3C, 1], #K28.1
|
||||||
|
[0xB5, 0], #D21.5
|
||||||
|
])
|
||||||
|
|
||||||
|
@ResetInserter()
|
||||||
|
class UpConn_ClockGen(Module):
|
||||||
|
def __init__(self, sys_clk_freq):
|
||||||
|
self.clk = Signal()
|
||||||
|
self.clk_10x = Signal() # 20.83MHz 48ns or 41.66MHz 24ns
|
||||||
|
|
||||||
|
self.freq2x_enable = Signal()
|
||||||
|
# # #
|
||||||
|
|
||||||
|
period = 1e9/sys_clk_freq
|
||||||
|
max_count = ceil(48/period)
|
||||||
|
counter = Signal(max=max_count, reset=max_count-1)
|
||||||
|
|
||||||
|
clk_div = Signal(max=10, reset=9)
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
self.clk.eq(0),
|
||||||
|
self.clk_10x.eq(0),
|
||||||
|
|
||||||
|
If(counter == 0,
|
||||||
|
self.clk_10x.eq(1),
|
||||||
|
If(self.freq2x_enable,
|
||||||
|
counter.eq(int(max_count/2)-1),
|
||||||
|
).Else(
|
||||||
|
counter.eq(counter.reset),
|
||||||
|
),
|
||||||
|
).Else(
|
||||||
|
counter.eq(counter-1),
|
||||||
|
),
|
||||||
|
|
||||||
|
If(counter == 0,
|
||||||
|
If(clk_div == 0,
|
||||||
|
self.clk.eq(1),
|
||||||
|
clk_div.eq(clk_div.reset),
|
||||||
|
).Else(
|
||||||
|
clk_div.eq(clk_div-1),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
@ResetInserter()
|
||||||
|
@CEInserter()
|
||||||
|
class SERDES_10bits(Module):
|
||||||
|
def __init__(self, pad):
|
||||||
|
self.oe = Signal()
|
||||||
|
self.d = Signal(10)
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
o = Signal()
|
||||||
|
tx_bitcount = Signal(max=10)
|
||||||
|
tx_reg = Signal(10)
|
||||||
|
|
||||||
|
# DEBUG:
|
||||||
|
self.o = Signal()
|
||||||
|
self.comb += self.o.eq(o)
|
||||||
|
|
||||||
|
self.specials += Instance("OBUF", i_I=o, o_O=pad),
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
If(self.oe,
|
||||||
|
# send LSB first
|
||||||
|
o.eq(tx_reg[0]),
|
||||||
|
tx_reg.eq(Cat(tx_reg[1:], 0)),
|
||||||
|
tx_bitcount.eq(tx_bitcount + 1),
|
||||||
|
|
||||||
|
If(tx_bitcount == 9,
|
||||||
|
tx_bitcount.eq(0),
|
||||||
|
tx_reg.eq(self.d),
|
||||||
|
),
|
||||||
|
).Else(
|
||||||
|
o.eq(0),
|
||||||
|
tx_bitcount.eq(0),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
@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):
|
||||||
|
def __init__(self, layout):
|
||||||
|
self.sink_stb = Signal()
|
||||||
|
self.sink_ack = Signal()
|
||||||
|
self.sink_data = Signal(8)
|
||||||
|
self.sink_k = Signal()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
self.submodules.buf_out = buf_out = stream.SyncFIFO(layout, 128)
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
buf_out.sink.stb.eq(self.sink_stb),
|
||||||
|
self.sink_ack.eq(buf_out.sink.ack),
|
||||||
|
buf_out.sink.data.eq(self.sink_data),
|
||||||
|
buf_out.sink.k.eq(self.sink_k),
|
||||||
|
]
|
||||||
|
|
||||||
|
self.inc = CSR()
|
||||||
|
self.dout_pak = CSRStatus(8)
|
||||||
|
self.kout_pak = CSRStatus()
|
||||||
|
self.dout_valid = CSRStatus()
|
||||||
|
|
||||||
|
self.sync += [
|
||||||
|
# output
|
||||||
|
buf_out.source.ack.eq(self.inc.re),
|
||||||
|
self.dout_pak.status.eq(buf_out.source.data),
|
||||||
|
self.kout_pak.status.eq(buf_out.source.k),
|
||||||
|
self.dout_valid.status.eq(buf_out.source.stb),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class CXP_UpConn_PHY(Module, AutoCSR):
|
||||||
|
def __init__(self, pad, sys_clk_freq, debug_sma, pmod_pads, nsink=3):
|
||||||
|
self.bitrate2x_enable = Signal()
|
||||||
|
self.clk_reset = Signal()
|
||||||
|
|
||||||
|
self.tx_enable = Signal()
|
||||||
|
self.tx_busy = Signal()
|
||||||
|
|
||||||
|
# # #
|
||||||
|
|
||||||
|
self.submodules.cg = cg = UpConn_ClockGen(sys_clk_freq)
|
||||||
|
self.submodules.interface = interface = PHY_Interface(upconn_layout, nsink)
|
||||||
|
|
||||||
|
self.sinks = interface.sinks
|
||||||
|
|
||||||
|
# DEBUG:
|
||||||
|
self.submodules.debug_buf = debug_buf = Debug_buffer(upconn_layout)
|
||||||
|
|
||||||
|
self.submodules.scheduler = scheduler = Transmit_Scheduler(interface, debug_buf)
|
||||||
|
self.submodules.serdes = serdes = SERDES_10bits(pad)
|
||||||
|
|
||||||
|
self.comb += [
|
||||||
|
self.tx_busy.eq(~interface.pe.n),
|
||||||
|
|
||||||
|
cg.reset.eq(self.clk_reset),
|
||||||
|
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.ce.eq(cg.clk_10x),
|
||||||
|
serdes.d.eq(scheduler.encoder.output),
|
||||||
|
serdes.oe.eq(scheduler.oe),
|
||||||
|
]
|
||||||
|
|
||||||
|
# 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 += [
|
||||||
|
# # debug sma
|
||||||
|
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),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# # pmod 0-7 pin
|
||||||
|
# Instance("OBUF", i_I=serdes.o, o_O=pmod_pads[0]),
|
||||||
|
# Instance("OBUF", i_I=cg.clk_10x, o_O=pmod_pads[1]),
|
||||||
|
# Instance("OBUF", i_I=~tx_fifos.pe.n, o_O=pmod_pads[2]),
|
||||||
|
# Instance("OBUF", i_I=prioity_0, o_O=pmod_pads[3]),
|
||||||
|
# Instance("OBUF", i_I=word_bound, o_O=pmod_pads[4]),
|
||||||
|
# Instance("OBUF", i_I=debug_buf.buf_out.sink.stb, o_O=pmod_pads[4]),
|
||||||
|
# Instance("OBUF", i_I=debug_buf.buf_out.sink.ack, o_O=pmod_pads[5]),
|
||||||
|
# Instance("OBUF", i_I=debug_buf.buf_out.source.stb, o_O=pmod_pads[6]),
|
||||||
|
# Instance("OBUF", i_I=debug_buf.buf_out.source.ack, o_O=pmod_pads[7]),
|
||||||
|
|
||||||
|
# Instance("OBUF", i_I=scheduler.idling, o_O=pmod_pads[5]),
|
||||||
|
# # Instance("OBUF", i_I=tx_fifos.source_ack[0], o_O=pmod[6]),
|
||||||
|
# # Instance("OBUF", i_I=tx_fifos.source_ack[2], o_O=pmod[6]),
|
||||||
|
# # Instance("OBUF", i_I=tx_fifos.source_ack[1], o_O=pmod[7]),
|
||||||
|
# Instance("OBUF", i_I=p0, o_O=pmod_pads[6]),
|
||||||
|
# Instance("OBUF", i_I=p3, o_O=pmod_pads[7]),
|
||||||
|
]
|
||||||
|
|
|
@ -25,6 +25,7 @@ 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
|
||||||
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):
|
||||||
|
@ -138,7 +139,7 @@ class ZC706(SoCCore):
|
||||||
platform.add_extension(si5324_fmc33)
|
platform.add_extension(si5324_fmc33)
|
||||||
self.comb += platform.request("si5324_33").rst_n.eq(1)
|
self.comb += platform.request("si5324_33").rst_n.eq(1)
|
||||||
|
|
||||||
cdr_clk = Signal()
|
self.cdr_clk = Signal()
|
||||||
cdr_clk_buf = Signal()
|
cdr_clk_buf = Signal()
|
||||||
si5324_out = platform.request("si5324_clkout")
|
si5324_out = platform.request("si5324_clkout")
|
||||||
platform.add_period_constraint(si5324_out.p, 8.0)
|
platform.add_period_constraint(si5324_out.p, 8.0)
|
||||||
|
@ -146,11 +147,11 @@ class ZC706(SoCCore):
|
||||||
Instance("IBUFDS_GTE2",
|
Instance("IBUFDS_GTE2",
|
||||||
i_CEB=0,
|
i_CEB=0,
|
||||||
i_I=si5324_out.p, i_IB=si5324_out.n,
|
i_I=si5324_out.p, i_IB=si5324_out.n,
|
||||||
o_O=cdr_clk,
|
o_O=self.cdr_clk,
|
||||||
p_CLKCM_CFG="TRUE",
|
p_CLKCM_CFG="TRUE",
|
||||||
p_CLKRCV_TRST="TRUE",
|
p_CLKRCV_TRST="TRUE",
|
||||||
p_CLKSWING_CFG=3),
|
p_CLKSWING_CFG=3),
|
||||||
Instance("BUFG", i_I=cdr_clk, o_O=cdr_clk_buf)
|
Instance("BUFG", i_I=self.cdr_clk, o_O=cdr_clk_buf)
|
||||||
]
|
]
|
||||||
self.config["HAS_SI5324"] = None
|
self.config["HAS_SI5324"] = None
|
||||||
self.config["SI5324_AS_SYNTHESIZER"] = None
|
self.config["SI5324_AS_SYNTHESIZER"] = None
|
||||||
|
@ -652,6 +653,74 @@ class _NIST_QC2_RTIO:
|
||||||
self.add_rtio(rtio_channels)
|
self.add_rtio(rtio_channels)
|
||||||
|
|
||||||
|
|
||||||
|
class CXP_FMC():
|
||||||
|
"""
|
||||||
|
CoaXpress FMC with 4 CXP channel and 1 SMA trigger
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
platform = self.platform
|
||||||
|
platform.add_extension(cxp_4r_fmc.fmc_adapter_io)
|
||||||
|
platform.add_extension(leds_fmc33)
|
||||||
|
|
||||||
|
debug_sma = [
|
||||||
|
("user_sma_clock_33", 0,
|
||||||
|
Subsignal("p_tx", Pins("AD18"), IOStandard("LVCMOS33")),
|
||||||
|
Subsignal("n_rx", Pins("AD19"), IOStandard("LVCMOS33")),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
pmod1_33 = [
|
||||||
|
("pmod1_33", 0, Pins("AJ21"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 1, Pins("AK21"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 2, Pins("AB21"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 3, Pins("AB16"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 4, Pins("Y20"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 5, Pins("AA20"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 6, Pins("AC18"), IOStandard("LVCMOS33")),
|
||||||
|
("pmod1_33", 7, Pins("AC19"), IOStandard("LVCMOS33")),
|
||||||
|
]
|
||||||
|
|
||||||
|
platform.add_extension(debug_sma)
|
||||||
|
platform.add_extension(pmod1_33)
|
||||||
|
pmod_pads = [platform.request("pmod1_33", i) for i in range(8)]
|
||||||
|
|
||||||
|
clk_freq = 125e6
|
||||||
|
|
||||||
|
gtx_pads = [platform.request("CXP_HS", i) for i in range(4)]
|
||||||
|
|
||||||
|
self.submodules.cxp = cxp.CXP(
|
||||||
|
refclk=self.cdr_clk,
|
||||||
|
downconn_pads=gtx_pads,
|
||||||
|
upconn_pads=platform.request("CXP_LS", 0),
|
||||||
|
sys_clk_freq=clk_freq,
|
||||||
|
debug_sma=platform.request("user_sma_clock_33"),
|
||||||
|
pmod_pads = pmod_pads
|
||||||
|
)
|
||||||
|
self.csr_devices.append("cxp")
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
# 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:
|
||||||
|
platform.add_period_constraint(gtx.cd_cxp_gtx_tx.clk, 3.2)
|
||||||
|
platform.add_period_constraint(gtx.cd_cxp_gtx_rx.clk, 3.2)
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
rtio_channels = []
|
||||||
|
# FIXME remove this placeholder RTIO channel
|
||||||
|
# There are too few RTIO channels and cannot be compiled (adr width issue of the lane distributor)
|
||||||
|
# see https://github.com/m-labs/artiq/pull/2158 for similar issue
|
||||||
|
print("USER LED at RTIO channel 0x{:06x}".format(len(rtio_channels)))
|
||||||
|
phy = ttl_simple.Output(self.platform.request("user_led_33", 0))
|
||||||
|
self.submodules += phy
|
||||||
|
rtio_channels.append(rtio.Channel.from_phy(phy))
|
||||||
|
self.config["HAS_RTIO_LOG"] = None
|
||||||
|
rtio_channels.append(rtio.LogChannel())
|
||||||
|
|
||||||
|
self.config["RTIO_LOG_CHANNEL"] = len(rtio_channels)
|
||||||
|
self.add_rtio(rtio_channels)
|
||||||
|
|
||||||
class NIST_CLOCK(ZC706, _NIST_CLOCK_RTIO):
|
class NIST_CLOCK(ZC706, _NIST_CLOCK_RTIO):
|
||||||
def __init__(self, acpki, drtio100mhz):
|
def __init__(self, acpki, drtio100mhz):
|
||||||
ZC706.__init__(self, acpki)
|
ZC706.__init__(self, acpki)
|
||||||
|
@ -684,8 +753,13 @@ class NIST_QC2_Satellite(_SatelliteBase, _NIST_QC2_RTIO):
|
||||||
_SatelliteBase.__init__(self, acpki, drtio100mhz)
|
_SatelliteBase.__init__(self, acpki, drtio100mhz)
|
||||||
_NIST_QC2_RTIO.__init__(self)
|
_NIST_QC2_RTIO.__init__(self)
|
||||||
|
|
||||||
|
class CXP_Demo(ZC706, CXP_FMC):
|
||||||
|
def __init__(self, acpki, drtio100mhz):
|
||||||
|
ZC706.__init__(self, acpki)
|
||||||
|
CXP_FMC.__init__(self)
|
||||||
|
|
||||||
VARIANTS = {cls.__name__.lower(): cls for cls in [NIST_CLOCK, NIST_CLOCK_Master, NIST_CLOCK_Satellite,
|
VARIANTS = {cls.__name__.lower(): cls for cls in [NIST_CLOCK, NIST_CLOCK_Master, NIST_CLOCK_Satellite,
|
||||||
NIST_QC2, NIST_QC2_Master, NIST_QC2_Satellite]}
|
NIST_QC2, NIST_QC2_Master, NIST_QC2_Satellite, CXP_Demo]}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
|
|
@ -0,0 +1,544 @@
|
||||||
|
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
|
||||||
|
use libboard_zynq::{println, timer::GlobalTimer};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
// use log::info;
|
||||||
|
use crate::pl::csr;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub enum CXP_SPEED {
|
||||||
|
CXP_1,
|
||||||
|
CXP_2,
|
||||||
|
CXP_3,
|
||||||
|
CXP_5,
|
||||||
|
CXP_6,
|
||||||
|
CXP_10,
|
||||||
|
CXP_12,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn loopback_testing(timer: &mut GlobalTimer, speed: CXP_SPEED) {
|
||||||
|
println!("==============================================================================");
|
||||||
|
cxp_gtx::change_linerate(timer, speed);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
info!("waiting for tx&rx setup...");
|
||||||
|
timer.delay_us(50_000);
|
||||||
|
info!(
|
||||||
|
"tx_phaligndone = {} | rx_phaligndone = {}",
|
||||||
|
csr::cxp::downconn_phy_txinit_phaligndone_read(),
|
||||||
|
csr::cxp::downconn_phy_rxinit_phaligndone_read(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// enable txdata tranmission thought MGTXTXP, required by PMA loopback
|
||||||
|
csr::cxp::downconn_phy_txenable_write(1);
|
||||||
|
|
||||||
|
info!("waiting for rx to align...");
|
||||||
|
while csr::cxp::downconn_phy_rx_ready_read() != 1 {}
|
||||||
|
info!("rx ready!");
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// for _ in 0..20 {
|
||||||
|
// NOTE: raw bits
|
||||||
|
// let data0 = csr::cxp::downconn_phy_rxdata_0_read();
|
||||||
|
// let data1 = csr::cxp::downconn_phy_rxdata_1_read();
|
||||||
|
// let data2 = csr::cxp::downconn_phy_rxdata_2_read();
|
||||||
|
// let data3 = csr::cxp::downconn_phy_rxdata_3_read();
|
||||||
|
// let rxready = csr::cxp::downconn_phy_rx_ready_read();
|
||||||
|
// timer.delay_us(100);
|
||||||
|
// if data0 == 0b0101111100 || data0 == 0b1010000011 {
|
||||||
|
// println!(
|
||||||
|
// "data[0] = {:#012b} comma = {} | rx ready = {}",
|
||||||
|
// data0,
|
||||||
|
// data0 == 0b0101111100 || data0 == 0b1010000011,
|
||||||
|
// rxready,
|
||||||
|
// );
|
||||||
|
// timer.delay_us(1_000_000);
|
||||||
|
// } else if data0 == 0b1001111100 || data0 == 0b0110000011 {
|
||||||
|
// println!(
|
||||||
|
// "data[0] = {:#012b} K28.1 | rx ready = {}",
|
||||||
|
// data0,
|
||||||
|
// rxready,
|
||||||
|
// );
|
||||||
|
// timer.delay_us(1_000_000);
|
||||||
|
// } else {
|
||||||
|
// println!(
|
||||||
|
// "data[0] = {:#012b} | rx ready = {}",
|
||||||
|
// data0,
|
||||||
|
// rxready,
|
||||||
|
// );
|
||||||
|
// timer.delay_us(1_000_000);
|
||||||
|
// }
|
||||||
|
|
||||||
|
timer.delay_us(1_000_000);
|
||||||
|
// NOTE: raw bits
|
||||||
|
// let data0 = csr::cxp::downconn_phy_rxdata_0_read();
|
||||||
|
// let data1 = csr::cxp::downconn_phy_rxdata_1_read();
|
||||||
|
// let data2 = csr::cxp::downconn_phy_rxdata_2_read();
|
||||||
|
// let data3 = csr::cxp::downconn_phy_rxdata_3_read();
|
||||||
|
// println!(
|
||||||
|
// "0b{:010b} {:010b} {:010b} {:010b}",
|
||||||
|
// data0, data1, data2, data3
|
||||||
|
// );
|
||||||
|
|
||||||
|
// NOTE:decode data
|
||||||
|
// let data0_k = csr::cxp::downconn_phy_decoded_k_0_read();
|
||||||
|
// let data1_k = csr::cxp::downconn_phy_decoded_k_1_read();
|
||||||
|
// let data2_k = csr::cxp::downconn_phy_decoded_k_2_read();
|
||||||
|
// let data3_k = csr::cxp::downconn_phy_decoded_k_3_read();
|
||||||
|
let data0_decoded = csr::cxp::downconn_phy_decoded_data_0_read();
|
||||||
|
let data1_decoded = csr::cxp::downconn_phy_decoded_data_1_read();
|
||||||
|
let data2_decoded = csr::cxp::downconn_phy_decoded_data_2_read();
|
||||||
|
let data3_decoded = csr::cxp::downconn_phy_decoded_data_3_read();
|
||||||
|
println!(
|
||||||
|
"{:#04x} {:#04x} {:#04x} {:#04x}",
|
||||||
|
data0_decoded, data1_decoded, data2_decoded, data3_decoded,
|
||||||
|
);
|
||||||
|
// println!(
|
||||||
|
// "decoded_data[0] = {:#04x} decoded_k[0] = {:#b} decoded_data[1] = {:#04x} decoded_k[1] = {:#b}",
|
||||||
|
// data0_decoded,
|
||||||
|
// data0_k,
|
||||||
|
// data1_decoded,
|
||||||
|
// data1_k,
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setup(timer: &mut GlobalTimer) {
|
||||||
|
unsafe {
|
||||||
|
info!("turning on pmc loopback mode...");
|
||||||
|
csr::cxp::downconn_phy_loopback_mode_write(0b010); // Near-End PMA Loopback
|
||||||
|
|
||||||
|
// QPLL setup
|
||||||
|
csr::cxp::downconn_phy_qpll_reset_write(1);
|
||||||
|
info!("waiting for QPLL/CPLL to lock...");
|
||||||
|
while csr::cxp::downconn_phy_qpll_locked_read() != 1 {}
|
||||||
|
info!("QPLL locked");
|
||||||
|
|
||||||
|
// tx/rx setup
|
||||||
|
csr::cxp::downconn_phy_tx_start_init_write(1);
|
||||||
|
csr::cxp::downconn_phy_rx_start_init_write(1);
|
||||||
|
|
||||||
|
info!("waiting for tx & rx setup...");
|
||||||
|
timer.delay_us(50_000);
|
||||||
|
info!(
|
||||||
|
"tx_phaligndone = {} | rx_phaligndone = {}",
|
||||||
|
csr::cxp::downconn_phy_txinit_phaligndone_read(),
|
||||||
|
csr::cxp::downconn_phy_rxinit_phaligndone_read(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
cxp_gtx::change_linerate(timer, CXP_SPEED::CXP_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod cxp_gtx {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
struct CdrConfig {
|
||||||
|
pub cfg_reg0: u16, //0x0A8
|
||||||
|
pub cfg_reg1: u16, //0x0A9
|
||||||
|
pub cfg_reg2: u16, //0x0AA
|
||||||
|
pub cfg_reg3: u16, //0x0AB
|
||||||
|
pub cfg_reg4: u16, //0x0AC
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn change_linerate(timer: &mut GlobalTimer, speed: CXP_SPEED) {
|
||||||
|
info!("Changing datarate to {:?}", speed);
|
||||||
|
// DEBUG: DRP pll for TXUSRCLK = freq(linerate)/20
|
||||||
|
let settings = txusrclk::get_txusrclk_config(speed);
|
||||||
|
txusrclk::setup(timer, settings);
|
||||||
|
|
||||||
|
change_qpll_settings(speed);
|
||||||
|
change_cdr_cfg(speed);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_qpll_reset_write(1);
|
||||||
|
info!("waiting for QPLL/CPLL to lock...");
|
||||||
|
while csr::cxp::downconn_phy_qpll_locked_read() != 1 {}
|
||||||
|
info!("QPLL locked");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_tx_restart_write(1);
|
||||||
|
csr::cxp::downconn_phy_rx_restart_write(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn change_qpll_settings(speed: CXP_SPEED) {
|
||||||
|
// Change QPLL_FBDIV
|
||||||
|
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_3 | CXP_SPEED::CXP_6 | CXP_SPEED::CXP_12 => 0x0170, // FB_Divider = 100
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("0x36 = {:#06x}", qpll_read(0x36));
|
||||||
|
qpll_write(0x36, qpll_div_reg);
|
||||||
|
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) {
|
||||||
|
let cdr_cfg = match speed {
|
||||||
|
// rxout_div = 8
|
||||||
|
CXP_SPEED::CXP_1 => {
|
||||||
|
CdrConfig {
|
||||||
|
cfg_reg0: 0x0020, //0x0A8
|
||||||
|
cfg_reg1: 0x1008, //0x0A9
|
||||||
|
cfg_reg2: 0x23FF, //0x0AA
|
||||||
|
cfg_reg3: 0x0000, //0x0AB
|
||||||
|
cfg_reg4: 0x0003, //0x0AC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// rxout_div = 4
|
||||||
|
CXP_SPEED::CXP_2 | CXP_SPEED::CXP_5 => {
|
||||||
|
CdrConfig {
|
||||||
|
cfg_reg0: 0x0020, //0x0A8
|
||||||
|
cfg_reg1: 0x1010, //0x0A9
|
||||||
|
cfg_reg2: 0x23FF, //0x0AA
|
||||||
|
cfg_reg3: 0x0000, //0x0AB
|
||||||
|
cfg_reg4: 0x0003, //0x0AC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// rxout_div = 2
|
||||||
|
CXP_SPEED::CXP_3 | CXP_SPEED::CXP_6 => {
|
||||||
|
CdrConfig {
|
||||||
|
cfg_reg0: 0x0020, //0x0A8
|
||||||
|
cfg_reg1: 0x1020, //0x0A9
|
||||||
|
cfg_reg2: 0x23FF, //0x0AA
|
||||||
|
cfg_reg3: 0x0000, //0x0AB
|
||||||
|
cfg_reg4: 0x0003, //0x0AC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// rxout_div = 1
|
||||||
|
CXP_SPEED::CXP_10 | CXP_SPEED::CXP_12 => {
|
||||||
|
CdrConfig {
|
||||||
|
cfg_reg0: 0x0020, //0x0A8
|
||||||
|
cfg_reg1: 0x1040, //0x0A9
|
||||||
|
cfg_reg2: 0x23FF, //0x0AA
|
||||||
|
cfg_reg3: 0x0000, //0x0AB
|
||||||
|
cfg_reg4: 0x000B, //0x0AC
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
gtx_write(0x0A8, cdr_cfg.cfg_reg0);
|
||||||
|
gtx_write(0x0A9, cdr_cfg.cfg_reg1);
|
||||||
|
gtx_write(0x0AA, cdr_cfg.cfg_reg2);
|
||||||
|
gtx_write(0x0AB, cdr_cfg.cfg_reg3);
|
||||||
|
gtx_write(0x0AC, cdr_cfg.cfg_reg4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn gtx_read(address: u16) -> u16 {
|
||||||
|
// DEBUG:
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_gtx_daddr_write(address);
|
||||||
|
csr::cxp::downconn_phy_gtx_dread_write(1);
|
||||||
|
while csr::cxp::downconn_phy_gtx_dready_read() != 1 {}
|
||||||
|
csr::cxp::downconn_phy_gtx_dout_read()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gtx_write(address: u16, value: u16) {
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_gtx_daddr_write(address);
|
||||||
|
csr::cxp::downconn_phy_gtx_din_write(value);
|
||||||
|
csr::cxp::downconn_phy_gtx_din_stb_write(1);
|
||||||
|
while csr::cxp::downconn_phy_gtx_dready_read() != 1 {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn qpll_read(address: u8) -> u16 {
|
||||||
|
// DEBUG:
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_qpll_daddr_write(address);
|
||||||
|
csr::cxp::downconn_phy_qpll_dread_write(1);
|
||||||
|
while csr::cxp::downconn_phy_qpll_dready_read() != 1 {}
|
||||||
|
csr::cxp::downconn_phy_qpll_dout_read()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn qpll_write(address: u8, value: u16) {
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_qpll_daddr_write(address);
|
||||||
|
csr::cxp::downconn_phy_qpll_din_write(value);
|
||||||
|
csr::cxp::downconn_phy_qpll_din_stb_write(1);
|
||||||
|
while csr::cxp::downconn_phy_qpll_dready_read() != 1 {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod txusrclk {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub struct PLLSetting {
|
||||||
|
pub clkout0_reg1: u16, //0x08
|
||||||
|
pub clkout0_reg2: u16, //0x09
|
||||||
|
pub clkfbout_reg1: u16, //0x14
|
||||||
|
pub clkfbout_reg2: u16, //0x15
|
||||||
|
pub div_reg: u16, //0x16
|
||||||
|
pub lock_reg1: u16, //0x18
|
||||||
|
pub lock_reg2: u16, //0x19
|
||||||
|
pub lock_reg3: u16, //0x1A
|
||||||
|
pub power_reg: u16, //0x28
|
||||||
|
pub filt_reg1: u16, //0x4E
|
||||||
|
pub filt_reg2: u16, //0x4F
|
||||||
|
}
|
||||||
|
|
||||||
|
fn one_clock_cycle() {
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_pll_dclk_write(1);
|
||||||
|
csr::cxp::downconn_phy_pll_dclk_write(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_addr(address: u8) {
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_pll_daddr_write(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_data(value: u16) {
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::downconn_phy_pll_din_write(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_enable(en: bool) {
|
||||||
|
unsafe {
|
||||||
|
let val = if en { 1 } else { 0 };
|
||||||
|
csr::cxp::downconn_phy_pll_den_write(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_write_enable(en: bool) {
|
||||||
|
unsafe {
|
||||||
|
let val = if en { 1 } else { 0 };
|
||||||
|
csr::cxp::downconn_phy_pll_dwen_write(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_data() -> u16 {
|
||||||
|
unsafe { csr::cxp::downconn_phy_pll_dout_read() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn drp_ready() -> bool {
|
||||||
|
unsafe { csr::cxp::downconn_phy_pll_dready_read() == 1 }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn read(address: u8) -> u16 {
|
||||||
|
set_addr(address);
|
||||||
|
set_enable(true);
|
||||||
|
// Set DADDR on the mmcm and assert DEN for one clock cycle
|
||||||
|
one_clock_cycle();
|
||||||
|
|
||||||
|
set_enable(false);
|
||||||
|
while !drp_ready() {
|
||||||
|
// keep the clock signal until data is ready
|
||||||
|
one_clock_cycle();
|
||||||
|
}
|
||||||
|
get_data()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write(address: u8, value: u16) {
|
||||||
|
set_addr(address);
|
||||||
|
set_data(value);
|
||||||
|
set_write_enable(true);
|
||||||
|
set_enable(true);
|
||||||
|
// Set DADDR, DI on the mmcm and assert DWE, DEN for one clock cycle
|
||||||
|
one_clock_cycle();
|
||||||
|
|
||||||
|
set_write_enable(false);
|
||||||
|
set_enable(false);
|
||||||
|
while !drp_ready() {
|
||||||
|
// keep the clock signal until write is finished
|
||||||
|
one_clock_cycle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(rst: bool) {
|
||||||
|
unsafe {
|
||||||
|
let val = if rst { 1 } else { 0 };
|
||||||
|
csr::cxp::downconn_phy_txpll_reset_write(val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setup(timer: &mut GlobalTimer, settings: PLLSetting) {
|
||||||
|
if false {
|
||||||
|
info!("0x08 = {:#06x}", read(0x08));
|
||||||
|
info!("0x09 = {:#06x}", read(0x09));
|
||||||
|
info!("0x14 = {:#06x}", read(0x14));
|
||||||
|
info!("0x15 = {:#06x}", read(0x15));
|
||||||
|
info!("0x16 = {:#06x}", read(0x16));
|
||||||
|
info!("0x18 = {:#06x}", read(0x18));
|
||||||
|
info!("0x19 = {:#06x}", read(0x19));
|
||||||
|
info!("0x1A = {:#06x}", read(0x1A));
|
||||||
|
info!("0x28 = {:#06x}", read(0x28));
|
||||||
|
info!("0x4E = {:#06x}", read(0x4E));
|
||||||
|
info!("0x4F = {:#06x}", read(0x4F));
|
||||||
|
} else {
|
||||||
|
// Based on "DRP State Machine" from XAPP888
|
||||||
|
// hold reset HIGH during pll config
|
||||||
|
reset(true);
|
||||||
|
write(0x08, settings.clkout0_reg1);
|
||||||
|
write(0x09, settings.clkout0_reg2);
|
||||||
|
write(0x14, settings.clkfbout_reg1);
|
||||||
|
write(0x15, settings.clkfbout_reg2);
|
||||||
|
write(0x16, settings.div_reg);
|
||||||
|
write(0x18, settings.lock_reg1);
|
||||||
|
write(0x19, settings.lock_reg2);
|
||||||
|
write(0x1A, settings.lock_reg3);
|
||||||
|
write(0x28, settings.power_reg);
|
||||||
|
write(0x4E, settings.filt_reg1);
|
||||||
|
write(0x4F, settings.filt_reg2);
|
||||||
|
reset(false);
|
||||||
|
|
||||||
|
// wait for the pll to lock
|
||||||
|
timer.delay_us(100);
|
||||||
|
|
||||||
|
let locked = unsafe { csr::cxp::downconn_phy_txpll_locked_read() == 1 };
|
||||||
|
info!("txusrclk locked = {}", locked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_txusrclk_config(speed: CXP_SPEED) -> PLLSetting {
|
||||||
|
match speed {
|
||||||
|
CXP_SPEED::CXP_1 => {
|
||||||
|
// CLKFBOUT_MULT = 8, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 32
|
||||||
|
// TXUSRCLK=62.5MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1410, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1104, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x5801, //0x19
|
||||||
|
lock_reg3: 0xdbe9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9808, //0x4E
|
||||||
|
filt_reg2: 0x9100, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CXP_SPEED::CXP_2 => {
|
||||||
|
// CLKFBOUT_MULT = 8, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 16
|
||||||
|
// TXUSRCLK=62.5MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1208, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1104, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x5801, //0x19
|
||||||
|
lock_reg3: 0xdbe9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9808, //0x4E
|
||||||
|
filt_reg2: 0x9100, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CXP_SPEED::CXP_3 => {
|
||||||
|
// CLKFBOUT_MULT = 10, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 16
|
||||||
|
// TXUSRCLK=78.125MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1208, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1145, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x7001, //0x19
|
||||||
|
lock_reg3: 0xf3e9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9908, //0x4E
|
||||||
|
filt_reg2: 0x1900, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CXP_SPEED::CXP_5 => {
|
||||||
|
// CLKFBOUT_MULT = 8, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 8
|
||||||
|
// TXUSRCLK=125MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1104, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1104, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x5801, //0x19
|
||||||
|
lock_reg3: 0xdbe9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9808, //0x4E
|
||||||
|
filt_reg2: 0x9100, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CXP_SPEED::CXP_6 => {
|
||||||
|
// CLKFBOUT_MULT = 10, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 8
|
||||||
|
// TXUSRCLK=156.25MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1104, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1145, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x7001, //0x19
|
||||||
|
lock_reg3: 0xf3e9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9908, //0x4E
|
||||||
|
filt_reg2: 0x1900, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CXP_SPEED::CXP_10 => {
|
||||||
|
// CLKFBOUT_MULT = 8, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 4
|
||||||
|
// TXUSRCLK=250MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1082, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1104, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x5801, //0x19
|
||||||
|
lock_reg3: 0xdbe9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9808, //0x4E
|
||||||
|
filt_reg2: 0x9100, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CXP_SPEED::CXP_12 => {
|
||||||
|
// CLKFBOUT_MULT = 10, DIVCLK_DIVIDE = 1 , CLKOUT0_DIVIDE = 4
|
||||||
|
// TXUSRCLK=312.5MHz
|
||||||
|
PLLSetting {
|
||||||
|
clkout0_reg1: 0x1082, //0x08
|
||||||
|
clkout0_reg2: 0x0000, //0x09
|
||||||
|
clkfbout_reg1: 0x1145, //0x14
|
||||||
|
clkfbout_reg2: 0x0000, //0x15
|
||||||
|
div_reg: 0x1041, //0x16
|
||||||
|
lock_reg1: 0x03e8, //0x18
|
||||||
|
lock_reg2: 0x7001, //0x19
|
||||||
|
lock_reg3: 0xf3e9, //0x1A
|
||||||
|
power_reg: 0x0000, //0x28
|
||||||
|
filt_reg1: 0x9908, //0x4E
|
||||||
|
filt_reg2: 0x1900, //0x4F
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add recv like in drtioaux
|
|
@ -0,0 +1,193 @@
|
||||||
|
use core_io::{Error as IoError, Write};
|
||||||
|
use crc::crc32;
|
||||||
|
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
|
||||||
|
use io::Cursor;
|
||||||
|
use libboard_zynq::{println, timer::GlobalTimer};
|
||||||
|
|
||||||
|
use crate::pl::csr;
|
||||||
|
|
||||||
|
const MAX_PACKET: usize = 128;
|
||||||
|
const DATA_MAXSIZE: usize = /*max size*/MAX_PACKET - /*Tag*/4 - /*Op code & length*/4 - /*addr*/4 - /*CRC*/4 ;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
BufferError,
|
||||||
|
LinkDown,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<IoError> for Error {
|
||||||
|
fn from(_: IoError) -> Error {
|
||||||
|
Error::BufferError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Packet {
|
||||||
|
CtrlRead {
|
||||||
|
addr: u32,
|
||||||
|
length: u8,
|
||||||
|
},
|
||||||
|
CtrlWrite {
|
||||||
|
addr: u32,
|
||||||
|
length: u8,
|
||||||
|
data: [u8; DATA_MAXSIZE],
|
||||||
|
}, // max register size is 8 bytes
|
||||||
|
CtrlReadWithTag {
|
||||||
|
tag: u8,
|
||||||
|
addr: u32,
|
||||||
|
length: u8,
|
||||||
|
},
|
||||||
|
CtrlWriteWithTag {
|
||||||
|
tag: u8,
|
||||||
|
addr: u32,
|
||||||
|
length: u8,
|
||||||
|
data: [u8; DATA_MAXSIZE],
|
||||||
|
}, // max register size is 8 bytes
|
||||||
|
EventAck {
|
||||||
|
packet_tag: u8,
|
||||||
|
},
|
||||||
|
TestPacket,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Packet {
|
||||||
|
pub fn write_to(&self, writer: &mut Cursor<&mut [u8]>) -> Result<(), Error> {
|
||||||
|
// CoaXpress use big endian
|
||||||
|
match *self {
|
||||||
|
Packet::CtrlRead { addr, length } => {
|
||||||
|
writer.write(&[0x02; 4])?;
|
||||||
|
writer.write(&[0x00, 0x00, 0x00, length])?;
|
||||||
|
writer.write(&addr.to_be_bytes())?;
|
||||||
|
}
|
||||||
|
Packet::CtrlWrite { addr, length, data } => {
|
||||||
|
writer.write(&[0x02; 4])?;
|
||||||
|
writer.write(&[0x01, 0x00, 0x00, length])?;
|
||||||
|
writer.write(&addr.to_be_bytes())?;
|
||||||
|
writer.write(&data[0..length as usize])?;
|
||||||
|
}
|
||||||
|
Packet::CtrlReadWithTag { tag, addr, length } => {
|
||||||
|
writer.write(&[0x05; 4])?;
|
||||||
|
writer.write(&[tag; 4])?;
|
||||||
|
writer.write(&[0x00, 0x00, 0x00, length])?;
|
||||||
|
writer.write(&addr.to_be_bytes())?;
|
||||||
|
}
|
||||||
|
Packet::CtrlWriteWithTag {
|
||||||
|
tag,
|
||||||
|
addr,
|
||||||
|
length,
|
||||||
|
data,
|
||||||
|
} => {
|
||||||
|
writer.write(&[0x05; 4])?;
|
||||||
|
writer.write(&[tag; 4])?;
|
||||||
|
writer.write(&[0x01, 0x00, 0x00, length])?;
|
||||||
|
writer.write(&addr.to_be_bytes())?;
|
||||||
|
writer.write(&data[0..length as usize])?;
|
||||||
|
}
|
||||||
|
Packet::EventAck { packet_tag } => {
|
||||||
|
writer.write(&[0x08; 4])?;
|
||||||
|
writer.write(&[packet_tag; 4])?;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
// Section 9.2.2.2 (CXP-001-2021)
|
||||||
|
// Only Control packet need CRC32 appended in the end of the packet
|
||||||
|
// CoaXpress use the polynomial of IEEE-802.3 (Ethernet) CRC but the checksum calculation is different
|
||||||
|
// Also, the calculation does not include the first 4 bytes of packet_type
|
||||||
|
match *self {
|
||||||
|
Packet::CtrlRead { .. }
|
||||||
|
| Packet::CtrlWrite { .. }
|
||||||
|
| Packet::CtrlReadWithTag { .. }
|
||||||
|
| Packet::CtrlWriteWithTag { .. } => {
|
||||||
|
let checksum = crc32::checksum_ieee(&writer.get_ref()[4..writer.position()]);
|
||||||
|
writer.write(&(!checksum).to_le_bytes())?;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send(packet: &Packet) -> Result<(), Error> {
|
||||||
|
if unsafe { csr::cxp::upconn_tx_enable_read() } == 0 {
|
||||||
|
Err(Error::LinkDown)?
|
||||||
|
}
|
||||||
|
|
||||||
|
match *packet {
|
||||||
|
Packet::TestPacket => send_test_packet(),
|
||||||
|
_ => send_data_packet(packet),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_data_packet(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 {
|
||||||
|
let len = writer.position();
|
||||||
|
csr::cxp::upconn_command_len_write(len as u8);
|
||||||
|
for data in writer.get_ref()[..len].iter() {
|
||||||
|
while csr::cxp::upconn_command_writeable_read() == 0 {}
|
||||||
|
csr::cxp::upconn_command_data_write(*data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_test_packet() -> Result<(), Error> {
|
||||||
|
unsafe {
|
||||||
|
while csr::cxp::upconn_tx_busy_read() == 1 {}
|
||||||
|
csr::cxp::upconn_tx_testmode_en_write(1);
|
||||||
|
// timer.delay_us(2);
|
||||||
|
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];
|
||||||
|
data_slice[..4].clone_from_slice(&data.to_be_bytes());
|
||||||
|
send(&Packet::CtrlWrite {
|
||||||
|
addr,
|
||||||
|
length: 4,
|
||||||
|
data: data_slice,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_u32(addr: u32) -> Result<(), Error> {
|
||||||
|
send(&Packet::CtrlRead { addr, length: 4 })?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_u64(addr: u32, data: u64) -> Result<(), Error> {
|
||||||
|
let mut data_slice: [u8; DATA_MAXSIZE] = [0; DATA_MAXSIZE];
|
||||||
|
data_slice[..8].clone_from_slice(&data.to_be_bytes());
|
||||||
|
send(&Packet::CtrlWrite {
|
||||||
|
addr,
|
||||||
|
length: 8,
|
||||||
|
data: data_slice,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEBUG: use only
|
||||||
|
pub fn print_packet(pak: &[u8]) {
|
||||||
|
println!("pak = [");
|
||||||
|
for i in 0..(pak.len() / 4) {
|
||||||
|
println!(
|
||||||
|
"{:#03} {:#04X} {:#04X} {:#04X} {:#04X},",
|
||||||
|
i + 1,
|
||||||
|
pak[i * 4],
|
||||||
|
pak[i * 4 + 1],
|
||||||
|
pak[i * 4 + 2],
|
||||||
|
pak[i * 4 + 3]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
println!("]");
|
||||||
|
println!("============================================");
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
use core_io::{Error as IoError, Write};
|
||||||
|
use crc::crc32;
|
||||||
|
use embedded_hal::prelude::_embedded_hal_blocking_delay_DelayUs;
|
||||||
|
use io::Cursor;
|
||||||
|
use libboard_zynq::{println, timer::GlobalTimer};
|
||||||
|
|
||||||
|
pub use crate::cxp_proto;
|
||||||
|
use crate::pl::csr;
|
||||||
|
|
||||||
|
pub fn tx_test(timer: &mut GlobalTimer) {
|
||||||
|
const LEN: usize = 4 * 50;
|
||||||
|
let mut pak_arr: [u8; LEN] = [0; LEN];
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
csr::cxp::upconn_clk_reset_write(1);
|
||||||
|
// csr::cxp::upconn_bitrate2x_enable_write(1);
|
||||||
|
csr::cxp::upconn_clk_reset_write(0);
|
||||||
|
|
||||||
|
// read_u32(0x00).expect("Cannot Write CoaXpress Register");
|
||||||
|
csr::cxp::upconn_tx_enable_write(1);
|
||||||
|
timer.delay_us(2); // send one word
|
||||||
|
cxp_proto::send(&cxp_proto::Packet::EventAck { packet_tag: 0x04 }).expect("Cannot send CoaXpress packet");
|
||||||
|
// cxp_proto::send(&cxp_proto::Packet::TestPacket).expect("Cannot send CoaXpress packet");
|
||||||
|
|
||||||
|
// timer.delay_us(2);
|
||||||
|
// DEBUG: Trigger packet
|
||||||
|
// let linktrig_mode: u8 = 0x01;
|
||||||
|
// csr::cxp::upconn_trig_delay_write(0x05);
|
||||||
|
// csr::cxp::upconn_linktrigger_write(linktrig_mode);
|
||||||
|
// csr::cxp::upconn_trig_stb_write(1); // send trig
|
||||||
|
|
||||||
|
// DEBUG: Trigger ACK packet
|
||||||
|
// csr::cxp::upconn_ack_write(1);
|
||||||
|
timer.delay_us(20);
|
||||||
|
csr::cxp::upconn_tx_enable_write(0);
|
||||||
|
|
||||||
|
// Collect data
|
||||||
|
let mut i: usize = 0;
|
||||||
|
while csr::cxp::upconn_phy_debug_buf_dout_valid_read() == 1 {
|
||||||
|
pak_arr[i] = csr::cxp::upconn_phy_debug_buf_dout_pak_read();
|
||||||
|
// println!("received {:#04X}", pak_arr[i]);
|
||||||
|
csr::cxp::upconn_phy_debug_buf_inc_write(1);
|
||||||
|
i += 1;
|
||||||
|
if i == LEN {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cxp_proto::print_packet(&pak_arr);
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,13 @@ pub mod si5324;
|
||||||
pub mod si549;
|
pub mod si549;
|
||||||
use core::{cmp, str};
|
use core::{cmp, str};
|
||||||
|
|
||||||
|
#[cfg(has_cxp)]
|
||||||
|
pub mod cxp_downconn;
|
||||||
|
#[cfg(has_cxp)]
|
||||||
|
pub mod cxp_upconn;
|
||||||
|
|
||||||
|
pub mod cxp_proto;
|
||||||
|
|
||||||
pub fn identifier_read(buf: &mut [u8]) -> &str {
|
pub fn identifier_read(buf: &mut [u8]) -> &str {
|
||||||
unsafe {
|
unsafe {
|
||||||
pl::csr::identifier::address_write(0);
|
pl::csr::identifier::address_write(0);
|
||||||
|
|
|
@ -150,5 +150,16 @@ pub fn main_core0() {
|
||||||
|
|
||||||
task::spawn(ksupport::report_async_rtio_errors());
|
task::spawn(ksupport::report_async_rtio_errors());
|
||||||
|
|
||||||
|
use libboard_artiq::{cxp_downconn, cxp_upconn};
|
||||||
|
cxp_downconn::setup(&mut timer);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_1);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_2);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_3);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_5);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_6);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_10);
|
||||||
|
// cxp_downconn::loopback_testing(&mut timer, cxp_downconn::CXP_SPEED::CXP_12);
|
||||||
|
cxp_upconn::tx_test(&mut timer);
|
||||||
|
|
||||||
comms::main(timer, cfg);
|
comms::main(timer, cfg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue