2012-09-12 11:56:36 -04:00
|
|
|
################################################################################
|
|
|
|
# _____ _ ____ _ _ _ _
|
|
|
|
# | __|___ |_|___ _ _ | \|_|___|_| |_ ___| |
|
|
|
|
# | __| | | | . | | | | | | | . | | _| .'| |
|
|
|
|
# |_____|_|_|_| |___|_ | |____/|_|_ |_|_| |__,|_|
|
|
|
|
# |___| |___| |___|
|
|
|
|
#
|
|
|
|
# Copyright 2012 / Florent Kermarrec / florent@enjoy-digital.fr
|
|
|
|
#
|
|
|
|
# migScope Example on De1 Board
|
|
|
|
# ----------------------------------
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# In this example signals are generated in the FPGA.
|
|
|
|
# We will use migScope to record those signals and visualize them.
|
|
|
|
#
|
|
|
|
# Example architecture:
|
|
|
|
# ----------------------
|
|
|
|
# migScope Config --> Python Client (Host) --> Vcd Output
|
|
|
|
# & Trig |
|
|
|
|
# Arduino (Uart<-->Spi Bridge)
|
|
|
|
# |
|
2012-09-12 12:07:36 -04:00
|
|
|
# De1
|
2012-09-12 11:56:36 -04:00
|
|
|
# |
|
|
|
|
# +--------------------+-----------------------+
|
|
|
|
# migIo Signal Generator migLa
|
|
|
|
# Control of Signal Ramp, Sinus, Logic Analyzer
|
|
|
|
# generator Square, ...
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# I M P O R T
|
|
|
|
#==============================================================================
|
|
|
|
from migen.fhdl.structure import *
|
|
|
|
from migen.fhdl import verilog, autofragment
|
|
|
|
from migen.bus import csr
|
|
|
|
from migen.bus.transactions import *
|
|
|
|
from migen.bank import description, csrgen
|
|
|
|
from migen.bank.description import *
|
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.append("../../")
|
|
|
|
|
2012-09-12 16:20:07 -04:00
|
|
|
from migScope import trigger, recorder, migIo
|
2012-09-12 11:56:36 -04:00
|
|
|
import spi2Csr
|
|
|
|
|
|
|
|
from timings import *
|
|
|
|
from constraints import Constraints
|
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# P A R A M E T E R S
|
|
|
|
#==============================================================================
|
|
|
|
|
|
|
|
#Timings Param
|
|
|
|
clk_freq = 50*MHz
|
|
|
|
clk_period_ns = clk_freq*ns
|
|
|
|
n = t2n(clk_period_ns)
|
|
|
|
|
|
|
|
# Bus Width
|
|
|
|
trig_width = 16
|
|
|
|
dat_width = 16
|
|
|
|
|
|
|
|
# Record Size
|
|
|
|
record_size = 1024
|
|
|
|
|
|
|
|
# Csr Addr
|
2012-09-13 07:14:27 -04:00
|
|
|
MIGIO_ADDR = 0x0000
|
2012-09-12 11:56:36 -04:00
|
|
|
TRIGGER_ADDR = 0x0200
|
|
|
|
RECORDER_ADDR = 0x0400
|
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# M I S C O P E E X A M P L E
|
|
|
|
#==============================================================================
|
|
|
|
def get():
|
|
|
|
|
2012-09-12 16:20:07 -04:00
|
|
|
# migIo
|
2012-09-13 07:14:27 -04:00
|
|
|
migIo0 = migIo.MigIo(MIGIO_ADDR, 8, "IO")
|
2012-09-13 05:34:19 -04:00
|
|
|
|
2012-09-12 11:56:36 -04:00
|
|
|
# Trigger
|
|
|
|
term0 = trigger.Term(trig_width)
|
2012-09-14 06:57:09 -04:00
|
|
|
term1 = trigger.Term(trig_width)
|
|
|
|
term2 = trigger.Term(trig_width)
|
|
|
|
term3 = trigger.Term(trig_width)
|
|
|
|
|
|
|
|
trigger0 = trigger.Trigger(TRIGGER_ADDR, trig_width, dat_width, [term0, term1, term2, term3])
|
2012-09-12 11:56:36 -04:00
|
|
|
|
|
|
|
# Recorder
|
|
|
|
recorder0 = recorder.Recorder(RECORDER_ADDR, dat_width, record_size)
|
|
|
|
|
|
|
|
# Spi2Csr
|
2012-09-14 06:57:09 -04:00
|
|
|
spi2csr0 = spi2Csr.Spi2Csr(14,8)
|
2012-09-13 05:34:19 -04:00
|
|
|
|
2012-09-12 11:56:36 -04:00
|
|
|
# Csr Interconnect
|
|
|
|
csrcon0 = csr.Interconnect(spi2csr0.csr,
|
|
|
|
[
|
2012-09-12 16:20:07 -04:00
|
|
|
migIo0.bank.interface,
|
2012-09-12 11:56:36 -04:00
|
|
|
trigger0.bank.interface,
|
|
|
|
recorder0.bank.interface
|
|
|
|
])
|
|
|
|
comb = []
|
|
|
|
sync = []
|
|
|
|
|
|
|
|
# Signal Generator
|
|
|
|
sig_gen = Signal(BV(trig_width))
|
2012-09-14 06:57:09 -04:00
|
|
|
#sync += [
|
|
|
|
# sig_gen.eq(sig_gen+1)
|
|
|
|
#]
|
2012-09-12 11:56:36 -04:00
|
|
|
|
|
|
|
# Led
|
|
|
|
led0 = Signal(BV(8))
|
2012-09-14 06:57:09 -04:00
|
|
|
comb += [led0.eq(migIo0.o[:8])]
|
2012-09-12 16:20:07 -04:00
|
|
|
|
|
|
|
#Switch
|
|
|
|
sw0 = Signal(BV(8))
|
|
|
|
comb += [migIo0.i.eq(sw0)]
|
2012-09-12 11:56:36 -04:00
|
|
|
|
2012-09-14 06:57:09 -04:00
|
|
|
sync += [
|
|
|
|
sig_gen.eq(migIo0.o)
|
|
|
|
]
|
2012-09-12 11:56:36 -04:00
|
|
|
|
|
|
|
# Dat / Trig Bus
|
|
|
|
comb += [
|
|
|
|
trigger0.in_trig.eq(sig_gen),
|
|
|
|
trigger0.in_dat.eq(sig_gen)
|
|
|
|
]
|
2012-09-14 06:57:09 -04:00
|
|
|
#comb += [led0[7].eq(trigger0.sum.i)]
|
|
|
|
#comb += [led0[6].eq(trigger0.sum.o)]
|
|
|
|
|
|
|
|
#comb += [led0[3].eq(term3.o)]
|
|
|
|
#comb += [led0[2].eq(term2.o)]
|
|
|
|
#comb += [led0[1].eq(term1.o)]
|
|
|
|
#comb += [led0[0].eq(term0.o)]
|
2012-09-12 11:56:36 -04:00
|
|
|
|
|
|
|
# Trigger --> Recorder
|
|
|
|
comb += [
|
|
|
|
recorder0.trig_dat.eq(trigger0.dat),
|
|
|
|
recorder0.trig_hit.eq(trigger0.hit)
|
|
|
|
]
|
|
|
|
|
2012-09-13 05:34:19 -04:00
|
|
|
|
2012-09-12 11:56:36 -04:00
|
|
|
# HouseKeeping
|
|
|
|
in_clk = Signal()
|
|
|
|
in_rst_n = Signal()
|
|
|
|
in_rst = Signal()
|
|
|
|
comb += [
|
|
|
|
in_rst.eq(~in_rst_n)
|
|
|
|
]
|
|
|
|
frag = autofragment.from_local()
|
|
|
|
frag += Fragment(sync=sync,comb=comb)
|
2012-09-12 16:20:07 -04:00
|
|
|
cst = Constraints(in_clk, in_rst_n, spi2csr0, led0, sw0)
|
2012-09-12 11:56:36 -04:00
|
|
|
src_verilog, vns = verilog.convert(frag,
|
|
|
|
cst.get_ios(),
|
2012-09-12 12:07:36 -04:00
|
|
|
name="de1",
|
2012-09-12 11:56:36 -04:00
|
|
|
clk_signal = in_clk,
|
|
|
|
rst_signal = in_rst,
|
|
|
|
return_ns=True)
|
|
|
|
src_qsf = cst.get_qsf(vns)
|
|
|
|
return (src_verilog, src_qsf)
|