2012-09-09 16:32:09 -04:00
|
|
|
################################################################################
|
|
|
|
# _____ _ ____ _ _ _ _
|
|
|
|
# | __|___ |_|___ _ _ | \|_|___|_| |_ ___| |
|
|
|
|
# | __| | | | . | | | | | | | . | | _| .'| |
|
|
|
|
# |_____|_|_|_| |___|_ | |____/|_|_ |_|_| |__,|_|
|
|
|
|
# |___| |___| |___|
|
|
|
|
#
|
2013-03-18 18:03:52 -04:00
|
|
|
# Copyright 2013 / Florent Kermarrec / florent@enjoy-digital.fr
|
2012-09-09 16:32:09 -04:00
|
|
|
#
|
2013-03-21 07:23:44 -04:00
|
|
|
# miscope example on De0 Nano
|
2013-03-18 18:57:51 -04:00
|
|
|
# --------------------------------
|
2012-09-09 16:32:09 -04:00
|
|
|
################################################################################
|
2012-09-09 15:18:09 -04:00
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# I M P O R T
|
|
|
|
#==============================================================================
|
2013-09-21 07:04:07 -04:00
|
|
|
from migen.fhdl.std import *
|
2012-09-09 16:32:09 -04:00
|
|
|
from migen.bus import csr
|
2013-09-21 07:04:07 -04:00
|
|
|
from migen.bank import csrgen
|
|
|
|
from miscope.std.misc import *
|
2012-09-09 16:32:09 -04:00
|
|
|
|
2013-09-21 07:04:07 -04:00
|
|
|
from miscope.triggering import *
|
|
|
|
from miscope.recording import *
|
|
|
|
from miscope import miio, mila
|
|
|
|
|
|
|
|
from miscope.com import uart2csr
|
2012-09-09 15:18:09 -04:00
|
|
|
|
|
|
|
from timings import *
|
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# P A R A M E T E R S
|
|
|
|
#==============================================================================
|
|
|
|
|
2013-03-18 18:57:51 -04:00
|
|
|
# Timings Param
|
2012-09-09 15:18:09 -04:00
|
|
|
clk_freq = 50*MHz
|
2012-09-09 16:32:09 -04:00
|
|
|
|
2013-03-21 07:23:44 -04:00
|
|
|
# Mila Param
|
|
|
|
trig_w = 16
|
|
|
|
dat_w = 16
|
|
|
|
rec_size = 4096
|
2012-09-09 16:32:09 -04:00
|
|
|
|
2012-09-09 15:18:09 -04:00
|
|
|
#==============================================================================
|
2013-03-18 18:57:51 -04:00
|
|
|
# M I S C O P E E X A M P L E
|
2012-09-09 15:18:09 -04:00
|
|
|
#==============================================================================
|
2013-03-18 18:03:52 -04:00
|
|
|
class SoC(Module):
|
2013-09-21 07:04:07 -04:00
|
|
|
csr_base = 0xe0000000
|
|
|
|
csr_map = {
|
|
|
|
"miio": 1,
|
|
|
|
"mila": 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-26 17:14:25 -04:00
|
|
|
def __init__(self, platform):
|
2013-03-18 18:57:51 -04:00
|
|
|
# MiIo
|
2013-09-21 07:04:07 -04:00
|
|
|
self.submodules.miio = miio.MiIo(8)
|
2013-03-21 07:23:44 -04:00
|
|
|
|
|
|
|
# MiLa
|
2013-09-21 07:04:07 -04:00
|
|
|
term = Term(trig_w)
|
|
|
|
trigger = Trigger(trig_w, [term])
|
|
|
|
recorder = Recorder(dat_w, rec_size)
|
2013-03-21 07:23:44 -04:00
|
|
|
|
2013-09-21 07:04:07 -04:00
|
|
|
self.submodules.mila = mila.MiLa(trigger, recorder)
|
2013-02-28 16:40:35 -05:00
|
|
|
|
2013-03-18 18:03:52 -04:00
|
|
|
# Uart2Csr
|
|
|
|
self.submodules.uart2csr = uart2csr.Uart2Csr(clk_freq, 115200)
|
2013-03-26 17:14:25 -04:00
|
|
|
uart_pads = platform.request("serial")
|
|
|
|
self.comb += uart_pads.tx.eq(self.uart2csr.tx)
|
|
|
|
self.comb += self.uart2csr.rx.eq(uart_pads.rx)
|
2013-02-28 16:40:35 -05:00
|
|
|
|
|
|
|
# Csr Interconnect
|
2013-09-21 07:04:07 -04:00
|
|
|
self.submodules.csrbankarray = csrgen.BankArray(self,
|
|
|
|
lambda name, memory: self.csr_map[name if memory is None else name + "_" + memory.name_override])
|
|
|
|
self.submodules.csrcon = csr.Interconnect(self.uart2csr.csr, self.csrbankarray.get_buses())
|
2013-03-18 18:57:51 -04:00
|
|
|
|
2013-02-28 16:40:35 -05:00
|
|
|
# Led
|
2013-09-21 07:04:07 -04:00
|
|
|
self.led = Cat(*[platform.request("user_led", i) for i in range(8)])
|
2013-03-21 07:23:44 -04:00
|
|
|
|
|
|
|
# Misc
|
|
|
|
self.cnt = Signal(9)
|
|
|
|
self.submodules.freqgen = FreqGen(clk_freq, 500*KHz)
|
|
|
|
self.submodules.eventgen_rising = EventGen(self.freqgen.o, RISING_EDGE, clk_freq, 100*ns)
|
|
|
|
self.submodules.eventgen_falling = EventGen(self.freqgen.o, FALLING_EDGE, clk_freq, 100*ns)
|
|
|
|
|
2013-03-18 18:57:51 -04:00
|
|
|
###
|
2013-03-21 07:23:44 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Miio
|
|
|
|
#
|
|
|
|
|
2013-03-18 18:57:51 -04:00
|
|
|
# Output
|
|
|
|
self.comb += self.led.eq(self.miio.o)
|
2013-03-21 07:23:44 -04:00
|
|
|
|
2013-03-18 18:57:51 -04:00
|
|
|
# Input
|
2013-03-21 07:23:44 -04:00
|
|
|
self.comb += self.miio.i.eq(self.miio.o)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Mila
|
|
|
|
#
|
|
|
|
self.comb +=[
|
2013-09-21 07:04:07 -04:00
|
|
|
self.mila.sink.stb.eq(1),
|
|
|
|
self.mila.sink.payload.d.eq(Cat(
|
2013-06-02 09:15:47 -04:00
|
|
|
self.freqgen.o,
|
|
|
|
self.eventgen_rising.o,
|
|
|
|
self.eventgen_falling.o,
|
|
|
|
self.cnt)
|
|
|
|
)
|
2013-03-21 07:23:44 -04:00
|
|
|
]
|
|
|
|
self.sync += self.cnt.eq(self.cnt+1)
|