forked from M-Labs/artiq-zynq
Compare commits
10 Commits
00e5d32d45
...
6134ad5794
Author | SHA1 | Date |
---|---|---|
morgan | 6134ad5794 | |
morgan | dbf7ac1cb9 | |
morgan | 8ba7793b24 | |
morgan | 481162430c | |
morgan | 4eed5e99f4 | |
morgan | 98f4d4cea4 | |
morgan | 14a9184fee | |
morgan | ae4bfc40e5 | |
morgan | cdc7294e99 | |
morgan | e6550c68cf |
|
@ -1,17 +1,18 @@
|
|||
from migen import *
|
||||
from migen.genlib.resetsync import AsyncResetSynchronizer
|
||||
from migen.genlib.cdc import MultiReg
|
||||
from migen.genlib.coding import PriorityEncoder
|
||||
|
||||
from misoc.cores.code_8b10b import SingleEncoder, Decoder
|
||||
from misoc.interconnect.csr import *
|
||||
from misoc.cores.code_8b10b import SingleEncoder
|
||||
from misoc.interconnect import stream
|
||||
from misoc.interconnect.csr import *
|
||||
|
||||
|
||||
class CXP_UpConn(Module, AutoCSR):
|
||||
def __init__(self, pads, tx_fifo_depth=32):
|
||||
def __init__(self, pads, sys_clk_freq, pmod, nfifos=3, fifo_depth=32):
|
||||
self.clock_domains.cd_cxp_upconn = ClockDomain()
|
||||
self.clk_reset = CSRStorage(reset=1)
|
||||
|
||||
self.bitrate2x_enable = CSRStorage()
|
||||
self.tx_enable = CSRStorage()
|
||||
|
||||
# # #
|
||||
|
||||
|
@ -26,11 +27,11 @@ class CXP_UpConn(Module, AutoCSR):
|
|||
o_LOCKED=pll_locked,
|
||||
i_RST=ResetSignal("sys"),
|
||||
|
||||
p_CLKIN1_PERIOD=8, # ns
|
||||
p_CLKIN1_PERIOD=1e9/sys_clk_freq, # ns
|
||||
i_CLKIN1=ClockSignal("sys"),
|
||||
|
||||
# VCO @ 1.25GHz
|
||||
p_CLKFBOUT_MULT=10, p_DIVCLK_DIVIDE=1,
|
||||
p_CLKFBOUT_MULT=1.25e9/sys_clk_freq, p_DIVCLK_DIVIDE=1,
|
||||
i_CLKFBIN=pll_fb_clk, o_CLKFBOUT=pll_fb_clk,
|
||||
|
||||
# 20.83MHz (48ns)
|
||||
|
@ -48,115 +49,243 @@ class CXP_UpConn(Module, AutoCSR):
|
|||
AsyncResetSynchronizer(self.cd_cxp_upconn, ~pll_locked | self.clk_reset.storage)
|
||||
]
|
||||
|
||||
self.symbol0 = CSR(9)
|
||||
self.symbol1 = CSR(9)
|
||||
|
||||
nfifos = 2
|
||||
|
||||
self.data = [ Signal(8) for _ in range(nfifos)]
|
||||
self.k_symbol = [ Signal() for _ in range(nfifos)]
|
||||
self.stb = [ Signal() for _ in range(nfifos)]
|
||||
|
||||
|
||||
self.fifo_full = CSRStatus(nfifos)
|
||||
|
||||
|
||||
self.tx_fifos = []
|
||||
self.tx_encoders = []
|
||||
|
||||
cdr = ClockDomainsRenamer({"write": "sys", "read": "cxp_upconn"})
|
||||
|
||||
# Priority Queue
|
||||
# 0: Trigger packet
|
||||
# 1: IO acknowledgment for trigger packet
|
||||
# 2: All other packets
|
||||
for i in range(nfifos):
|
||||
fifo = cdr(stream.AsyncFIFO([("data", 9)], tx_fifo_depth))
|
||||
# fifo = stream.SyncFIFO([("data", 9)], tx_fifo_depth)
|
||||
self.tx_fifos.append(fifo)
|
||||
setattr(self.submodules, "tx_fifo" + str(i), fifo)
|
||||
self.sync += [
|
||||
fifo.sink.stb.eq(self.stb[i]),
|
||||
fifo.sink.data.eq(Cat(self.data[i], self.k_symbol[i])),
|
||||
self.fifo_full.status[i].eq(~fifo.sink.ack),
|
||||
]
|
||||
|
||||
self.sync += [
|
||||
self.stb[0].eq(self.symbol0.re),
|
||||
self.data[0].eq(self.symbol0.r[:8]),
|
||||
self.k_symbol[0].eq(self.symbol0.r[8]),
|
||||
self.stb[1].eq(self.symbol1.re),
|
||||
self.data[1].eq(self.symbol1.r[:8]),
|
||||
self.k_symbol[1].eq(self.symbol1.r[8]),
|
||||
]
|
||||
self.tx_fifo0_source_data = CSRStatus(9)
|
||||
self.tx_fifo1_source_data = CSRStatus(9)
|
||||
self.tx_fifo0_stb = CSRStatus()
|
||||
self.tx_fifo1_stb = CSRStatus()
|
||||
|
||||
self.submodules.tx = UpConn_TX(pads)
|
||||
|
||||
self.comb += [
|
||||
self.tx_fifo0_source_data.status.eq(self.tx_fifos[0].source.data),
|
||||
self.tx_fifo1_source_data.status.eq(self.tx_fifos[1].source.data),
|
||||
self.tx_fifo0_stb.status.eq(self.tx_fifos[0].source.stb),
|
||||
self.tx_fifo1_stb.status.eq(self.tx_fifos[1].source.stb),
|
||||
]
|
||||
|
||||
self.sync.cxp_upconn +=[
|
||||
self.tx.data_stb.eq(self.tx_fifos[0].source.stb | self.tx_fifos[1].source.stb),
|
||||
self.tx_fifos[0].source.ack.eq(0),
|
||||
self.tx_fifos[1].source.ack.eq(0),
|
||||
If(self.tx.data_ack,
|
||||
If(self.tx_fifos[0].source.stb,
|
||||
self.tx.encoder.d.eq(self.tx_fifos[0].source.data[:8]),
|
||||
self.tx.encoder.k.eq(self.tx_fifos[0].source.data[8]),
|
||||
self.tx_fifos[0].source.ack.eq(1),
|
||||
).Elif(self.tx_fifos[1].source.stb,
|
||||
self.tx.encoder.d.eq(self.tx_fifos[1].source.data[:8]),
|
||||
self.tx.encoder.k.eq(self.tx_fifos[1].source.data[8]),
|
||||
self.tx_fifos[1].source.ack.eq(1),
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
# DEBUG: remove pads
|
||||
self.specials += Instance("OBUF", i_I=self.cd_cxp_upconn.clk, o_O=pads.n_rx)
|
||||
|
||||
class UpConn_TX(Module, AutoCSR):
|
||||
def __init__(self, pads):
|
||||
self.data_ack = Signal()
|
||||
self.data_stb = Signal()
|
||||
self.data_out = CSRStatus(10)
|
||||
|
||||
# # #
|
||||
|
||||
self.submodules.encoder = ClockDomainsRenamer("cxp_upconn")(SingleEncoder(True))
|
||||
self.submodules.fsm = ClockDomainsRenamer("cxp_upconn")(FSM(reset_state="WAIT_TX_ENABLE"))
|
||||
self.submodules.tx_fifos = TxFIFOs(nfifos, fifo_depth)
|
||||
self.submodules.tx_idle = TxIdle()
|
||||
|
||||
o = Signal()
|
||||
tx_busy = Signal()
|
||||
tx_en = Signal()
|
||||
tx_bitcount = Signal(max=10)
|
||||
tx_wordcount = Signal()
|
||||
tx_reg = Signal(10)
|
||||
|
||||
disp = Signal()
|
||||
tx_wordcount = Signal(max=4)
|
||||
priority = Signal(max=nfifos)
|
||||
idling = Signal()
|
||||
|
||||
# startup sequence
|
||||
self.fsm.act("WAIT_TX_ENABLE",
|
||||
NextValue(self.tx_idle.disp_in, 0),
|
||||
NextValue(self.tx_idle.word_idx, 0),
|
||||
|
||||
If(self.tx_enable.storage,
|
||||
NextValue(tx_wordcount, 0),
|
||||
NextValue(tx_bitcount, 0),
|
||||
NextState("LOAD_CHAR")
|
||||
)
|
||||
)
|
||||
|
||||
self.fsm.act("LOAD_CHAR",
|
||||
NextValue(idling, 1),
|
||||
NextValue(self.tx_idle.source_ack, 1),
|
||||
NextValue(tx_reg, self.tx_idle.source_data),
|
||||
NextValue(disp, self.tx_idle.disp_out),
|
||||
NextState("START_TX")
|
||||
)
|
||||
|
||||
self.fsm.act("START_TX",
|
||||
tx_en.eq(1),
|
||||
If((~self.tx_enable.storage) & (tx_wordcount == 3),
|
||||
NextState("WAIT_TX_ENABLE")
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# CXP 2.1 section 9.2.4
|
||||
# Higher priority packet can be inserted into a lower priority packet during transmission
|
||||
# Priority lv 0 can be inserted in char boundary of the packet
|
||||
# Priority lv 1-2 need to be inserted in word boundary of the packet
|
||||
self.sync.cxp_upconn += [
|
||||
self.data_ack.eq(0),
|
||||
If(tx_busy,
|
||||
self.tx_fifos.disp_in.eq(disp),
|
||||
self.tx_idle.disp_in.eq(disp),
|
||||
|
||||
If(tx_en,
|
||||
o.eq(tx_reg[0]),
|
||||
tx_reg.eq(Cat(tx_reg[1:], 0))
|
||||
),
|
||||
If(tx_bitcount != 9,
|
||||
tx_reg.eq(Cat(tx_reg[1:], 0)),
|
||||
tx_bitcount.eq(tx_bitcount + 1),
|
||||
).Elif(self.data_stb,
|
||||
tx_busy.eq(1),
|
||||
|
||||
|
||||
# char boundary
|
||||
If(tx_bitcount == 9,
|
||||
tx_bitcount.eq(0),
|
||||
tx_reg.eq(self.encoder.output),
|
||||
self.data_out.status.eq(self.encoder.output),
|
||||
self.encoder.disp_in.eq(self.encoder.disp_out),
|
||||
self.data_ack.eq(1),
|
||||
If((~self.tx_fifos.pe.n) & (self.tx_fifos.pe.o == 0),
|
||||
# trigger packet can interrupt at char level
|
||||
tx_reg.eq(self.tx_fifos.source_data[0]),
|
||||
self.tx_fifos.source_ack[0].eq(1),
|
||||
disp.eq(self.tx_fifos.disp_out[0]),
|
||||
).Else(
|
||||
# priority zero doesn't contribute to word count
|
||||
If(tx_wordcount != 3,
|
||||
tx_wordcount.eq(tx_wordcount + 1),
|
||||
).Else(
|
||||
tx_wordcount.eq(0),
|
||||
),
|
||||
|
||||
# new word boundary
|
||||
If(tx_wordcount == 3,
|
||||
If(~self.tx_fifos.pe.n,
|
||||
idling.eq(0),
|
||||
priority.eq(self.tx_fifos.pe.o),
|
||||
|
||||
self.tx_fifos.source_ack[self.tx_fifos.pe.o].eq(1),
|
||||
tx_reg.eq(self.tx_fifos.source_data[self.tx_fifos.pe.o]),
|
||||
disp.eq(self.tx_fifos.disp_out[self.tx_fifos.pe.o]),
|
||||
).Else(
|
||||
idling.eq(1),
|
||||
|
||||
self.tx_idle.source_ack.eq(1),
|
||||
tx_reg.eq(self.tx_idle.source_data),
|
||||
disp.eq(self.tx_idle.disp_out),
|
||||
)
|
||||
).Else(
|
||||
If(~idling,
|
||||
self.tx_fifos.source_ack[priority].eq(1),
|
||||
tx_reg.eq(self.tx_fifos.source_data[priority]),
|
||||
disp.eq(self.tx_fifos.disp_out[priority]),
|
||||
).Else(
|
||||
self.tx_idle.source_ack.eq(1),
|
||||
tx_reg.eq(self.tx_idle.source_data),
|
||||
disp.eq(self.tx_idle.disp_out),
|
||||
)
|
||||
),
|
||||
)
|
||||
)
|
||||
).Else(
|
||||
tx_busy.eq(0),
|
||||
o.eq(0)
|
||||
)
|
||||
]
|
||||
# DEBUG: remove pads
|
||||
self.encoded_data = CSRStatus(10)
|
||||
self.sync.cxp_upconn +=[
|
||||
If(tx_bitcount == 0,
|
||||
self.encoded_data.status.eq(tx_reg),
|
||||
)
|
||||
]
|
||||
|
||||
self.specials += Instance("OBUF", i_I=o, o_O=pads.p_tx)
|
||||
ninth_bit = Signal()
|
||||
word_bound = Signal()
|
||||
|
||||
p0 = Signal()
|
||||
p3 = Signal()
|
||||
self.comb += [
|
||||
ninth_bit.eq(tx_bitcount == 9),
|
||||
word_bound.eq(tx_wordcount == 3),
|
||||
p0.eq(self.tx_idle.word_idx == 0),
|
||||
p3.eq(self.tx_idle.word_idx == 3),
|
||||
]
|
||||
self.specials += [
|
||||
# debug sma
|
||||
Instance("OBUF", i_I=o, o_O=pads.p_tx),
|
||||
Instance("OBUF", i_I=self.cd_cxp_upconn.clk, o_O=pads.n_rx),
|
||||
|
||||
# pmod 0-7 pin
|
||||
Instance("OBUF", i_I=o, o_O=pmod[0]),
|
||||
Instance("OBUF", i_I=self.cd_cxp_upconn.clk, o_O=pmod[1]),
|
||||
Instance("OBUF", i_I=~self.tx_fifos.pe.n, o_O=pmod[2]),
|
||||
Instance("OBUF", i_I=ninth_bit, o_O=pmod[3]),
|
||||
Instance("OBUF", i_I=word_bound, o_O=pmod[4]),
|
||||
Instance("OBUF", i_I=idling, o_O=pmod[5]),
|
||||
# Instance("OBUF", i_I=self.tx_fifos.source_ack[0], o_O=pmod[6]),
|
||||
# Instance("OBUF", i_I=self.tx_fifos.source_ack[2], o_O=pmod[6]),
|
||||
# Instance("OBUF", i_I=self.tx_fifos.source_ack[1], o_O=pmod[7]),
|
||||
Instance("OBUF", i_I=p0, o_O=pmod[6]),
|
||||
Instance("OBUF", i_I=p3, o_O=pmod[7]),
|
||||
]
|
||||
self.symbol0 = CSR(9)
|
||||
self.symbol1 = CSR(9)
|
||||
self.symbol2 = CSR(9)
|
||||
|
||||
self.sync += [
|
||||
self.tx_fifos.sink_stb[0].eq(self.symbol0.re),
|
||||
self.tx_fifos.sink_data[0].eq(self.symbol0.r),
|
||||
self.tx_fifos.sink_stb[1].eq(self.symbol1.re),
|
||||
self.tx_fifos.sink_data[1].eq(self.symbol1.r),
|
||||
self.tx_fifos.sink_stb[2].eq(self.symbol2.re),
|
||||
self.tx_fifos.sink_data[2].eq(self.symbol2.r),
|
||||
]
|
||||
|
||||
class TxFIFOs(Module):
|
||||
def __init__(self, nfifos, fifo_depth):
|
||||
self.disp_in = Signal()
|
||||
self.disp_out = Array(Signal() for _ in range(nfifos))
|
||||
|
||||
self.sink_stb = Signal(nfifos)
|
||||
self.sink_ack = Signal(nfifos)
|
||||
self.sink_data = [Signal(9) for _ in range(nfifos)]
|
||||
|
||||
self.source_ack = Array(Signal() for _ in range(nfifos))
|
||||
self.source_data = Array(Signal(10) for _ in range(nfifos))
|
||||
|
||||
# # #
|
||||
|
||||
source_stb = Signal(nfifos)
|
||||
|
||||
for i in range(nfifos):
|
||||
cdr = ClockDomainsRenamer({"write": "sys", "read": "cxp_upconn"})
|
||||
fifo = cdr(stream.AsyncFIFO([("data", 9)], fifo_depth))
|
||||
encoder = ClockDomainsRenamer("cxp_upconn")(SingleEncoder(True))
|
||||
setattr(self.submodules, "tx_fifo" + str(i), fifo)
|
||||
setattr(self.submodules, "tx_encoder" + str(i), encoder)
|
||||
self.sync += [
|
||||
fifo.sink.stb.eq(self.sink_stb[i]),
|
||||
self.sink_ack[i].eq(fifo.sink.ack),
|
||||
fifo.sink.data.eq(self.sink_data[i]),
|
||||
]
|
||||
self.sync.cxp_upconn += [
|
||||
encoder.d.eq(fifo.source.data[:8]),
|
||||
encoder.k.eq(fifo.source.data[8]),
|
||||
encoder.disp_in.eq(self.disp_in),
|
||||
self.disp_out[i].eq(encoder.disp_out),
|
||||
|
||||
source_stb[i].eq(fifo.source.stb),
|
||||
fifo.source.ack.eq(self.source_ack[i]),
|
||||
self.source_data[i].eq(encoder.output),
|
||||
# reset ack after asserted
|
||||
If(self.source_ack[i], self.source_ack[i].eq(0)),
|
||||
]
|
||||
# FIFOs transmission priority
|
||||
self.submodules.pe = PriorityEncoder(nfifos)
|
||||
self.comb += self.pe.i.eq(source_stb)
|
||||
|
||||
class TxIdle(Module):
|
||||
def __init__(self):
|
||||
self.disp_in = Signal()
|
||||
self.disp_out = Signal()
|
||||
|
||||
self.word_idx = Signal(max=4)
|
||||
self.source_ack = Signal()
|
||||
self.source_data = Signal(10)
|
||||
|
||||
# # #
|
||||
|
||||
# CXP 2.1 section 9.2.5
|
||||
IDLE_CHARS = Array([
|
||||
#[data, k]
|
||||
[0b10111100, 1], #K28.5
|
||||
[0b00111100, 1], #K28.1
|
||||
[0b00111100, 1], #K28.1
|
||||
[0b10111100, 0], #D28.5
|
||||
])
|
||||
|
||||
encoder = ClockDomainsRenamer("cxp_upconn")(SingleEncoder(True))
|
||||
self.submodules += encoder
|
||||
|
||||
self.sync.cxp_upconn += [
|
||||
encoder.d.eq(IDLE_CHARS[self.word_idx][0]),
|
||||
encoder.k.eq(IDLE_CHARS[self.word_idx][1]),
|
||||
encoder.disp_in.eq(self.disp_in),
|
||||
self.disp_out.eq(encoder.disp_out),
|
||||
self.source_data.eq(encoder.output),
|
||||
|
||||
If(self.source_ack,
|
||||
# reset after asserted
|
||||
self.source_ack.eq(0),
|
||||
|
||||
If(self.word_idx != 3,
|
||||
self.word_idx.eq(self.word_idx + 1),
|
||||
).Else(
|
||||
self.word_idx.eq(0),
|
||||
)
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue