litex/examples/de0_nano/top.py

107 lines
3.0 KiB
Python
Raw Normal View History

2012-09-09 16:32:09 -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
2012-09-09 16:32:09 -04:00
2013-09-22 05:35:02 -04:00
from miscope.std.misc import *
2013-09-22 05:45:30 -04:00
2013-09-22 07:28:12 -04:00
from miscope.trigger import Term
2013-09-22 05:45:30 -04:00
from miscope.miio import MiIo
from miscope.mila import MiLa
2013-09-21 07:04:07 -04:00
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
2013-09-22 07:28:12 -04:00
mila_width = 16
mila_depth = 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
#==============================================================================
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-22 05:45:30 -04:00
self.submodules.miio = MiIo(8)
2013-03-21 07:23:44 -04:00
# MiLa
2013-09-22 07:28:12 -04:00
term = Term(mila_width)
2013-09-22 12:41:44 -04:00
self.submodules.mila = MiLa(mila_width, mila_depth, [term], rle=True)
2013-02-28 16:40:35 -05:00
# Uart2Csr
2013-09-25 09:07:23 -04:00
self.submodules.uart2csr = uart2csr.Uart2Csr(platform.request("serial"), clk_freq, 115200)
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
2013-09-22 12:41:44 -04:00
self.cnt = Signal(16)
2013-03-21 07:23:44 -04:00
self.submodules.freqgen = FreqGen(clk_freq, 500*KHz)
2013-09-22 05:35:02 -04:00
self.submodules.eventgen_rising = EventGen(RISING_EDGE, clk_freq, 100*ns)
self.submodules.eventgen_falling = EventGen(FALLING_EDGE, clk_freq, 100*ns)
self.comb += [
self.eventgen_rising.i.eq(self.freqgen.o),
self.eventgen_falling.i.eq(self.freqgen.o)
]
2013-03-21 07:23:44 -04:00
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.dat.eq(Cat(
2013-06-02 09:15:47 -04:00
self.freqgen.o,
self.eventgen_rising.o,
self.eventgen_falling.o,
2013-09-22 12:41:44 -04:00
self.cnt[8:12])
2013-06-02 09:15:47 -04:00
)
2013-03-21 07:23:44 -04:00
]
self.sync += self.cnt.eq(self.cnt+1)