Skip to content

Instantly share code, notes, and snippets.

@ravijain056
Last active August 29, 2015 14:17
Show Gist options
  • Save ravijain056/c4fe2e69e25301844840 to your computer and use it in GitHub Desktop.
Save ravijain056/c4fe2e69e25301844840 to your computer and use it in GitHub Desktop.
2d list example
from myhdl import *
def switchchannels(mem2d, q, clk):
def assign_los(mem1d_a, mem1d_b):
print(mem1d_a, mem1d_b)
for i in range(len(mem1d_a)):
mem1d_a[i].next = mem1d_b[i]
return mem1d_a
@always(clk.posedge)
def switch():
mem2d[1] = assign_los(mem2d[1], mem2d[0])
@always(clk.posedge)
def logic():
mem2d[0][0].next = mem2d[0][1]
mem2d[0][1].next = q
return switch, logic
from random import randrange
def test_switchchannels():
clk = Signal(bool(0))
q = Signal(intbv(0)[4:])
mem2d = [[Signal(intbv(0)[4:]), Signal(intbv(0)[4:])] , [Signal(intbv(0)[4:]), Signal(intbv(0)[4:])]]
switch_inst = switchchannels(mem2d, q, clk)
@always(delay(10))
def clkgen():
clk.next = not clk
@always(clk.negedge)
def stimulus():
q.next = randrange(2)
return switch_inst, clkgen, stimulus
def simulate(timesteps):
traceSignals.timescale = "1ps"
tb = traceSignals(test_switchchannels)
sim = Simulation(tb)
sim.run(timesteps)
simulate(2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment