suservo: move arch logic to top, fix tests

This commit is contained in:
Robert Jördens 2018-04-23 21:11:26 +00:00
parent 4903eb074c
commit f74998a5e0
4 changed files with 24 additions and 14 deletions

View File

@ -118,18 +118,7 @@ class ADC(Module, DiffMixin):
sck_en_ret = pads.sck_en_ret sck_en_ret = pads.sck_en_ret
except AttributeError: except AttributeError:
sck_en_ret = 1 sck_en_ret = 1
self.clock_domains.cd_ret = ClockDomain("ret", reset_less=True) self.clkout_io = Signal()
clkout = self._diff(pads, "clkout")
clkout_fabric = Signal()
clkout_io = Signal()
self.specials += [
Instance("BUFH", i_I=clkout, o_O=clkout_fabric),
Instance("BUFIO", i_I=clkout, o_O=clkout_io)
]
self.comb += [
# falling clkout makes two bits available
self.cd_ret.clk.eq(~clkout_fabric)
]
k = p.channels//p.lanes k = p.channels//p.lanes
assert 2*t_read == k*p.width assert 2*t_read == k*p.width
for i, sdo in enumerate(sdo): for i, sdo in enumerate(sdo):
@ -137,7 +126,7 @@ class ADC(Module, DiffMixin):
sdo_sr1 = Signal(t_read - 1) sdo_sr1 = Signal(t_read - 1)
sdo_ddr = Signal(2) sdo_ddr = Signal(2)
self.specials += io.DDRInput(sdo, sdo_ddr[1], sdo_ddr[0], self.specials += io.DDRInput(sdo, sdo_ddr[1], sdo_ddr[0],
~clkout_io) ~self.clkout_io)
self.sync.ret += [ self.sync.ret += [
If(self.reading & sck_en_ret, If(self.reading & sck_en_ret,
sdo_sr0.eq(Cat(sdo_ddr[0], sdo_sr0)), sdo_sr0.eq(Cat(sdo_ddr[0], sdo_sr0)),

View File

@ -8,7 +8,7 @@ from migen.genlib.cdc import MultiReg
from migen.build.generic_platform import * from migen.build.generic_platform import *
from migen.build.xilinx.vivado import XilinxVivadoToolchain from migen.build.xilinx.vivado import XilinxVivadoToolchain
from migen.build.xilinx.ise import XilinxISEToolchain from migen.build.xilinx.ise import XilinxISEToolchain
from migen.genlib.io import DifferentialOutput from migen.genlib.io import DifferentialOutput, DifferentialInput
from misoc.interconnect.csr import * from misoc.interconnect.csr import *
from misoc.cores import gpio from misoc.cores import gpio
@ -540,6 +540,19 @@ class SUServo(_StandaloneBase):
su = ClockDomainsRenamer({"sys": "rio_phy"})(su) su = ClockDomainsRenamer({"sys": "rio_phy"})(su)
self.submodules += sampler_pads, urukul_pads, su self.submodules += sampler_pads, urukul_pads, su
self.clock_domains.cd_ret = ClockDomain("ret", reset_less=True)
clkout = Signal()
clkout_fabric = Signal()
self.specials += [
DifferentialInput(pads.clkout_p, pads.clkout_n, clkout),
Instance("BUFH", i_I=clkout, o_O=clkout_fabric),
Instance("BUFIO", i_I=clkout, o_O=su.adc.clkout_io)
]
self.comb += [
# falling clkout makes two bits available
self.cd_ret.clk.eq(~clkout_fabric)
]
ctrls = [rtservo.RTServoCtrl(ctrl) for ctrl in su.iir.ctrl] ctrls = [rtservo.RTServoCtrl(ctrl) for ctrl in su.iir.ctrl]
self.submodules += ctrls self.submodules += ctrls
rtio_channels.extend(rtio.Channel.from_phy(ctrl) for ctrl in ctrls) rtio_channels.extend(rtio.Channel.from_phy(ctrl) for ctrl in ctrls)

View File

@ -75,6 +75,12 @@ class TB(Module):
cd_adc = ClockDomain("adc", reset_less=True) cd_adc = ClockDomain("adc", reset_less=True)
self.clock_domains += cd_adc self.clock_domains += cd_adc
self.clock_domains.cd_ret = ClockDomain("ret", reset_less=True)
self.comb += [
# falling clkout makes two bits available
self.cd_ret.clk.eq(~self.clkout)
]
self.sdo = [] self.sdo = []
self.data = [Signal((p.width, True), reset_less=True) self.data = [Signal((p.width, True), reset_less=True)
for i in range(p.channels)] for i in range(p.channels)]
@ -124,6 +130,7 @@ def main():
tb = TB(params) tb = TB(params)
adc = ADC(tb, params) adc = ADC(tb, params)
tb.submodules += adc tb.submodules += adc
tb.comb += adc.clkout_io.eq(tb.clkout)
def run(tb): def run(tb):
dut = adc dut = adc

View File

@ -23,6 +23,7 @@ class ServoSim(servo.Servo):
servo.Servo.__init__(self, self.adc_tb, self.dds_tb, servo.Servo.__init__(self, self.adc_tb, self.dds_tb,
adc_p, iir_p, dds_p) adc_p, iir_p, dds_p)
self.adc_tb.comb += self.adc.clkout_io.eq(self.adc_tb.clkout)
def test(self): def test(self):
assert (yield self.done) assert (yield self.done)