Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

tb/asmicon: bankmachine test bench

  • Loading branch information...
commit 185bd66ee4b439e3c92a2bda3791cce972766cdc 1 parent b1e5b9e
Sébastien Bourdeauducq authored March 31, 2012
48  tb/asmicon/bankmachine.py
... ...
@@ -0,0 +1,48 @@
  1
+from migen.fhdl.structure import *
  2
+from migen.bus.asmibus import *
  3
+from migen.sim.generic import Simulator, TopLevel
  4
+from migen.sim.icarus import Runner
  5
+
  6
+from milkymist.asmicon.bankmachine import *
  7
+
  8
+from common import sdram_geom, sdram_timing, CommandLogger
  9
+
  10
+def my_generator():
  11
+	for x in range(10):
  12
+		t = TWrite(x)
  13
+		yield t
  14
+	for x in range(10):
  15
+		t = TWrite(x + 2200)
  16
+		yield t
  17
+
  18
+class Completer:
  19
+	def __init__(self, hub, cmd):
  20
+		self.hub = hub
  21
+		self.cmd = cmd
  22
+		
  23
+	def get_fragment(self):
  24
+		sync = [
  25
+			self.hub.call.eq(self.cmd.stb & self.cmd.ack & (self.cmd.is_read | self.cmd.is_write)),
  26
+			self.hub.tag_call.eq(self.cmd.tag)
  27
+		]
  28
+		return Fragment(sync=sync)
  29
+
  30
+def main():
  31
+	hub = Hub(12, 128, 2)
  32
+	initiator = Initiator(hub.get_port(), my_generator())
  33
+	hub.finalize()
  34
+	
  35
+	dut = BankMachine(sdram_geom, sdram_timing, 2, 0, hub.get_slots())
  36
+	logger = CommandLogger(dut.cmd, True)
  37
+	completer = Completer(hub, dut.cmd)
  38
+	
  39
+	def end_simulation(s):
  40
+		s.interrupt = initiator.done
  41
+	
  42
+	fragment = hub.get_fragment() + initiator.get_fragment() + \
  43
+		dut.get_fragment() + logger.get_fragment() + completer.get_fragment() + \
  44
+		Fragment(sim=[end_simulation])
  45
+	sim = Simulator(fragment, Runner(), TopLevel("my.vcd"))
  46
+	sim.run()
  47
+
  48
+main()
43  tb/asmicon/common.py
... ...
@@ -1,9 +1,44 @@
  1
+from fractions import Fraction
  2
+from math import ceil
  3
+
1 4
 from migen.fhdl.structure import *
2 5
 from migen.sim.generic import Proxy
3 6
 
  7
+from milkymist import asmicon
  8
+
  9
+MHz = 1000000
  10
+clk_freq = (83 + Fraction(1, 3))*MHz
  11
+
  12
+clk_period_ns = 1000000000/clk_freq
  13
+def ns(t, margin=True):
  14
+	if margin:
  15
+		t += clk_period_ns/2
  16
+	return ceil(t/clk_period_ns)
  17
+
  18
+sdram_geom = asmicon.GeomSettings(
  19
+	bank_a=2,
  20
+	row_a=13,
  21
+	col_a=10
  22
+)
  23
+sdram_timing = asmicon.TimingSettings(
  24
+	tRP=ns(15),
  25
+	tRCD=ns(15),
  26
+	tWR=ns(15),
  27
+	tREFI=ns(7800, False),
  28
+	tRFC=ns(70),
  29
+	
  30
+	CL=3,
  31
+	rd_delay=4,
  32
+
  33
+	slot_time=16,
  34
+	read_time=32,
  35
+	write_time=16
  36
+)
  37
+
4 38
 class CommandLogger:
5  
-	def __init__(self, cmd):
  39
+	def __init__(self, cmd, rw=False):
6 40
 		self.cmd = cmd
  41
+		self.rw = rw
7 42
 	
8 43
 	def do_simulation(self, s):
9 44
 		elts = ["@" + str(s.cycle_counter)]
@@ -38,7 +73,11 @@ def do_simulation(self, s):
38 73
 			print("\t".join(elts))
39 74
 	
40 75
 	def get_fragment(self):
41  
-		return Fragment(sim=[self.do_simulation])
  76
+		if self.rw:
  77
+			comb = [self.cmd.ack.eq(1)]
  78
+		else:
  79
+			comb = []
  80
+		return Fragment(comb, sim=[self.do_simulation])
42 81
 
43 82
 class SlotsLogger:
44 83
 	def __init__(self, slicer, slots):
9  tb/asmicon/selector.py
@@ -5,16 +5,9 @@
5 5
 from migen.sim.generic import Simulator, TopLevel
6 6
 from migen.sim.icarus import Runner
7 7
 
8  
-from milkymist import asmicon
9 8
 from milkymist.asmicon.bankmachine import _AddressSlicer, _Selector, _Buffer
10 9
 
11  
-from common import SlotsLogger
12  
-
13  
-sdram_geom = asmicon.GeomSettings(
14  
-	bank_a=2,
15  
-	row_a=13,
16  
-	col_a=10
17  
-)
  10
+from common import SlotsLogger, sdram_geom
18 11
 
19 12
 def my_generator(dt, offset):
20 13
 	for t in range(dt):

0 notes on commit 185bd66

Please sign in to comment.
Something went wrong with that request. Please try again.