2012-09-09 16:32:09 -04:00
|
|
|
################################################################################
|
|
|
|
# _____ _ ____ _ _ _ _
|
|
|
|
# | __|___ |_|___ _ _ | \|_|___|_| |_ ___| |
|
|
|
|
# | __| | | | . | | | | | | | . | | _| .'| |
|
|
|
|
# |_____|_|_|_| |___|_ | |____/|_|_ |_|_| |__,|_|
|
|
|
|
# |___| |___| |___|
|
|
|
|
#
|
|
|
|
# Copyright 2012 / Florent Kermarrec / florent@enjoy-digital.fr
|
|
|
|
#
|
|
|
|
# migScope Example on De0 Nano Board
|
|
|
|
# ----------------------------------
|
|
|
|
################################################################################
|
|
|
|
#
|
2012-09-09 17:46:26 -04:00
|
|
|
# In this example signals are generated in the FPGA.
|
|
|
|
# We will use migScope to record those signals and visualize them.
|
2012-09-09 16:32:09 -04:00
|
|
|
#
|
|
|
|
# Example architecture:
|
|
|
|
# ----------------------
|
2012-09-09 17:46:26 -04:00
|
|
|
# migScope Config --> Python Client (Host) --> Vcd Output
|
|
|
|
# & Trig |
|
2012-09-09 16:32:09 -04:00
|
|
|
# Arduino (Uart<-->Spi Bridge)
|
|
|
|
# |
|
|
|
|
# De0 Nano
|
|
|
|
# |
|
|
|
|
# +--------------------+-----------------------+
|
|
|
|
# migIo Signal Generator migLa
|
|
|
|
# Control of Signal Ramp, Sinus, Logic Analyzer
|
|
|
|
# generator Square, ...
|
|
|
|
###############################################################################
|
|
|
|
|
2012-09-09 15:18:09 -04:00
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# I M P O R T
|
|
|
|
#==============================================================================
|
|
|
|
from migen.fhdl.structure import *
|
|
|
|
from migen.fhdl import verilog, autofragment
|
2012-09-09 16:32:09 -04:00
|
|
|
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-17 11:00:47 -04:00
|
|
|
from migScope import trigger, recorder, migIo, migLa
|
2012-09-09 16:32:09 -04:00
|
|
|
import spi2Csr
|
2012-09-09 15:18:09 -04:00
|
|
|
|
|
|
|
from timings import *
|
|
|
|
from constraints import Constraints
|
|
|
|
|
2012-09-16 05:49:16 -04:00
|
|
|
from math import sin
|
|
|
|
|
2012-09-09 15:18:09 -04:00
|
|
|
#==============================================================================
|
|
|
|
# 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)
|
|
|
|
|
2012-09-09 16:32:09 -04:00
|
|
|
# Bus Width
|
|
|
|
trig_width = 16
|
|
|
|
dat_width = 16
|
|
|
|
|
|
|
|
# Record Size
|
2012-09-16 05:49:16 -04:00
|
|
|
record_size = 4096
|
2012-09-09 16:32:09 -04:00
|
|
|
|
|
|
|
# Csr Addr
|
2012-09-13 07:14:27 -04:00
|
|
|
MIGIO_ADDR = 0x0000
|
2012-09-17 11:00:47 -04:00
|
|
|
MIGLA_ADDR = 0x0200
|
2012-09-09 16:32:09 -04:00
|
|
|
|
2012-09-09 15:18:09 -04:00
|
|
|
#==============================================================================
|
2012-09-09 16:32:09 -04:00
|
|
|
# M I S C O P E E X A M P L E
|
2012-09-09 15:18:09 -04:00
|
|
|
#==============================================================================
|
2012-09-09 16:32:09 -04:00
|
|
|
def get():
|
2012-09-09 15:18:09 -04:00
|
|
|
|
2012-09-13 07:14:27 -04:00
|
|
|
# migIo
|
|
|
|
migIo0 = migIo.MigIo(MIGIO_ADDR, 8, "IO")
|
|
|
|
|
2012-09-17 11:00:47 -04:00
|
|
|
# migLa
|
2012-09-09 16:32:09 -04:00
|
|
|
term0 = trigger.Term(trig_width)
|
2012-09-17 11:00:47 -04:00
|
|
|
trigger0 = trigger.Trigger(trig_width, [term0])
|
|
|
|
recorder0 = recorder.Recorder(dat_width, record_size)
|
2012-09-17 09:27:37 -04:00
|
|
|
|
2012-09-17 11:00:47 -04:00
|
|
|
migLa0 = migLa.MigLa(MIGLA_ADDR, trigger0, recorder0)
|
2012-09-09 15:18:09 -04:00
|
|
|
|
2012-09-09 16:32:09 -04:00
|
|
|
# Spi2Csr
|
|
|
|
spi2csr0 = spi2Csr.Spi2Csr(16,8)
|
2012-09-13 07:14:27 -04:00
|
|
|
|
2012-09-09 16:32:09 -04:00
|
|
|
# Csr Interconnect
|
|
|
|
csrcon0 = csr.Interconnect(spi2csr0.csr,
|
|
|
|
[
|
2012-09-13 07:14:27 -04:00
|
|
|
migIo0.bank.interface,
|
2012-09-17 11:00:47 -04:00
|
|
|
migLa0.trig.bank.interface,
|
|
|
|
migLa0.rec.bank.interface
|
2012-09-09 16:32:09 -04:00
|
|
|
])
|
|
|
|
comb = []
|
|
|
|
sync = []
|
2012-09-09 15:18:09 -04:00
|
|
|
|
2012-09-16 05:49:16 -04:00
|
|
|
#
|
2012-09-09 16:32:09 -04:00
|
|
|
# Signal Generator
|
2012-09-16 05:49:16 -04:00
|
|
|
#
|
|
|
|
|
|
|
|
# Counter
|
|
|
|
cnt_gen = Signal(BV(8))
|
|
|
|
sync += [
|
|
|
|
cnt_gen.eq(cnt_gen+1)
|
|
|
|
]
|
|
|
|
|
|
|
|
# Square
|
|
|
|
square_gen = Signal(BV(8))
|
2012-09-09 16:32:09 -04:00
|
|
|
sync += [
|
2012-09-16 05:49:16 -04:00
|
|
|
If(cnt_gen[7],
|
|
|
|
square_gen.eq(255)
|
|
|
|
).Else(
|
|
|
|
square_gen.eq(0)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
sinus = [int(128*sin((2*3.1415)/256*(x+1)))+128 for x in range(256)]
|
|
|
|
sinus_re = Signal()
|
|
|
|
sinus_gen = Signal(BV(8))
|
|
|
|
comb +=[sinus_re.eq(1)]
|
|
|
|
sinus_port = MemoryPort(adr=cnt_gen, re=sinus_re, dat_r=sinus_gen)
|
|
|
|
sinus_mem = Memory(8, 256, sinus_port, init = sinus)
|
|
|
|
|
|
|
|
# Signal Selection
|
|
|
|
sig_gen = Signal(BV(8))
|
|
|
|
comb += [
|
|
|
|
If(migIo0.o == 0,
|
|
|
|
sig_gen.eq(cnt_gen)
|
|
|
|
).Elif(migIo0.o == 1,
|
|
|
|
sig_gen.eq(square_gen)
|
|
|
|
).Elif(migIo0.o == 2,
|
|
|
|
sig_gen.eq(sinus_gen)
|
|
|
|
).Else(
|
|
|
|
sig_gen.eq(0)
|
|
|
|
)
|
2012-09-09 16:32:09 -04:00
|
|
|
]
|
2012-09-09 15:18:09 -04:00
|
|
|
|
2012-09-09 17:27:51 -04:00
|
|
|
# Led
|
|
|
|
led0 = Signal(BV(8))
|
2012-09-16 05:49:16 -04:00
|
|
|
comb += [led0.eq(migIo0.o[:8])]
|
2012-09-09 17:27:51 -04:00
|
|
|
|
|
|
|
|
2012-09-17 11:00:47 -04:00
|
|
|
# MigLa0 input
|
2012-09-09 16:32:09 -04:00
|
|
|
comb += [
|
2012-09-17 11:00:47 -04:00
|
|
|
migLa0.in_trig.eq(sig_gen),
|
|
|
|
migLa0.in_dat.eq(sig_gen)
|
2012-09-09 16:32:09 -04:00
|
|
|
]
|
2012-09-09 15:18:09 -04:00
|
|
|
|
|
|
|
# HouseKeeping
|
2012-09-17 09:27:37 -04:00
|
|
|
cd_in = ClockDomain("in")
|
2012-09-12 10:28:52 -04:00
|
|
|
in_rst_n = Signal()
|
|
|
|
comb += [
|
2012-09-17 09:27:37 -04:00
|
|
|
cd_in.rst.eq(~in_rst_n)
|
2012-09-12 10:28:52 -04:00
|
|
|
]
|
2012-09-17 09:27:37 -04:00
|
|
|
|
2012-09-09 16:32:09 -04:00
|
|
|
frag = autofragment.from_local()
|
2012-09-16 05:49:16 -04:00
|
|
|
frag += Fragment(sync=sync,comb=comb,memories=[sinus_mem])
|
2012-09-17 09:27:37 -04:00
|
|
|
cst = Constraints(in_rst_n, cd_in, spi2csr0, led0)
|
2012-09-09 15:18:09 -04:00
|
|
|
src_verilog, vns = verilog.convert(frag,
|
|
|
|
cst.get_ios(),
|
2012-09-16 05:49:16 -04:00
|
|
|
name="de1",
|
2012-09-17 09:27:37 -04:00
|
|
|
clock_domains={
|
|
|
|
"sys": cd_in
|
|
|
|
},
|
2012-09-09 15:18:09 -04:00
|
|
|
return_ns=True)
|
|
|
|
src_qsf = cst.get_qsf(vns)
|
|
|
|
return (src_verilog, src_qsf)
|