litex/examples/de0_nano/top.py

107 lines
3.2 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
#==============================================================================
from migen.fhdl.structure import *
from migen.fhdl.module import *
2012-09-09 16:32:09 -04:00
from migen.bus import csr
2013-03-21 07:23:44 -04:00
from miscope import trigger, recorder, miio, mila
from miscope.bridges import uart2csr
2013-03-21 07:23:44 -04:00
from miscope.tools.misc import *
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
# Csr Addr
2013-03-21 07:23:44 -04:00
MIIO_ADDR = 0x00
MILA_ADDR = 0x01
# 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
#==============================================================================
class SoC(Module):
2013-03-26 17:14:25 -04:00
def __init__(self, platform):
2013-03-18 18:57:51 -04:00
# MiIo
2013-03-21 07:23:44 -04:00
self.submodules.miio = miio.MiIo(MIIO_ADDR, 8, "IO")
# MiLa
self.submodules.term = trigger.Term(trig_w)
self.submodules.trigger = trigger.Trigger(trig_w, [self.term])
self.submodules.recorder = recorder.Recorder(dat_w, rec_size)
self.submodules.mila = mila.MiLa(MILA_ADDR, self.trigger, self.recorder)
2013-02-28 16:40:35 -05: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
self.submodules.csrcon = csr.Interconnect(self.uart2csr.csr,
2013-02-28 16:40:35 -05:00
[
2013-03-21 07:23:44 -04:00
self.miio.bank.bus,
self.trigger.bank.bus,
self.recorder.bank.bus
2013-02-28 16:40:35 -05:00
])
2013-03-18 18:57:51 -04:00
2013-02-28 16:40:35 -05:00
# Led
2013-03-26 17:14:25 -04:00
self.led = platform.request("user_led", 0, 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 +=[
self.mila.trig[0].eq(self.freqgen.o),
self.mila.trig[1].eq(self.eventgen_rising.o),
self.mila.trig[2].eq(self.eventgen_falling.o),
self.mila.trig[3:11].eq(self.cnt),
self.mila.dat[0].eq(self.freqgen.o),
self.mila.dat[1].eq(self.eventgen_rising.o),
self.mila.dat[2].eq(self.eventgen_falling.o),
self.mila.dat[3:11].eq(self.cnt),
]
self.sync += self.cnt.eq(self.cnt+1)