Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

asmicon: refresher (untested)

  • Loading branch information...
commit 7c377880fa175ef5baad170634f5bde447d4cc8f 1 parent e3ef121
Sébastien Bourdeauducq authored March 15, 2012
19  milkymist/asmicon/__init__.py
@@ -6,21 +6,23 @@
6 6
 from milkymist.asmicon.multiplexer import *
7 7
 
8 8
 class PhySettings:
9  
-	def __init__(self, dfi_a, dfi_ba, dfi_d, nphases, rdphase, wrphase):
  9
+	def __init__(self, dfi_a, dfi_d, nphases, rdphase, wrphase):
  10
+		# NB: dfi_ba is obtained from GeomSettings.bank_a
10 11
 		self.dfi_a = dfi_a
11  
-		self.dfi_ba = dfi_ba
12 12
 		self.dfi_d = dfi_d
13 13
 		self.nphases = nphases
14 14
 		self.rdphase = rdphase
15 15
 		self.wrphase = wrphase
16 16
 
17 17
 class GeomSettings:
18  
-	def __init__(self, row_a, col_a):
  18
+	def __init__(self, bank_a, row_a, col_a):
  19
+		self.bank_a = bank_a
19 20
 		self.row_a = row_a
20 21
 		self.col_a = col_a
21 22
 
22 23
 class TimingSettings:
23  
-	def __init__(self, tREFI, tRFC):
  24
+	def __init__(self, tRP, tREFI, tRFC):
  25
+		self.tRP = tRP
24 26
 		self.tREFI = tREFI
25 27
 		self.tRFC = tRFC
26 28
 
@@ -32,12 +34,12 @@ def __init__(self, phy_settings, geom_settings, timing_settings, time=0):
32 34
 		self.finalized = False
33 35
 		
34 36
 		self.dfi = dfi.Interface(self.phy_settings.dfi_a,
35  
-			self.phy_settings.dfi_ba,
  37
+			self.geom_settings.bank_a,
36 38
 			self.phy_settings.dfi_d,
37 39
 			self.phy_settings.nphases)
38 40
 		burst_length = self.phy_settings.nphases*2
39 41
 		self.address_align = log2_int(burst_length)
40  
-		aw = self.phy_settings.dfi_ba + self.geom_settings.row_a + self.geom_settings.col_a - self.address_align
  42
+		aw = self.geom_settings.bank_a + self.geom_settings.row_a + self.geom_settings.col_a - self.address_align
41 43
 		dw = self.phy_settings.dfi_d*self.phy_settings.nphases
42 44
 		self.hub = asmibus.Hub(aw, dw, time)
43 45
 	
@@ -47,8 +49,9 @@ def finalize(self):
47 49
 		self.finalized = True
48 50
 		self.hub.finalize()
49 51
 		slots = self.hub.get_slots()
50  
-		self.refresher = Refresher(self.timing_settings)
51  
-		self.bank_machines = [BankMachine(self.geom_settings, self.timing_settings, self.address_align, i, slots) for i in range(2**self.phy_settings.dfi_ba)]
  52
+		self.refresher = Refresher(self.phy_settings.dfi_a, self.geom_settings.bank_a,
  53
+			self.timing_settings.tRP, self.timing_settings.tREFI, self.timing_settings.tRFC)
  54
+		self.bank_machines = [BankMachine(self.geom_settings, self.timing_settings, self.address_align, i, slots) for i in range(2**self.geom_settings.bank_a)]
52 55
 		self.multiplexer = Multiplexer(self.phy_settings, self.geom_settings, self.timing_settings,
53 56
 			self.bank_machines, self.refresher,
54 57
 			self.dfi, self.hub)
17  milkymist/asmicon/multiplexer.py
... ...
@@ -1,5 +1,22 @@
1 1
 from migen.fhdl.structure import *
2 2
 
  3
+class CommandRequest:
  4
+	def __init__(self, dfi_a, dfi_ba):
  5
+		self.a = Signal(BV(dfi_a))
  6
+		self.ba = Signal(BV(dfi_ba))
  7
+		self.cas_n = Signal(reset=1)
  8
+		self.ras_n = Signal(reset=1)
  9
+		self.we_n = Signal(reset=1)
  10
+
  11
+class CommandRequestRW(CommandRequest):
  12
+	def __init__(self, dfi_a, dfi_ba, tagbits):
  13
+		CommandRequest.__init__(self, dfi_a, dfi_ba)
  14
+		self.stb = Signal()
  15
+		self.ack = Signal()
  16
+		self.is_read = Signal()
  17
+		self.is_write = Signal()
  18
+		self.tag = Signal(BV(tagbits))
  19
+
3 20
 class Multiplexer:
4 21
 	def __init__(self, phy_settings, geom_settings, timing_settings, bank_machines, refresher, dfi, hub):
5 22
 		pass
72  milkymist/asmicon/refresher.py
... ...
@@ -1,8 +1,74 @@
1 1
 from migen.fhdl.structure import *
  2
+from migen.corelogic.misc import timeline
  3
+from migen.corelogic.fsm import FSM
  4
+
  5
+from milkymist.asmicon.multiplexer import *
2 6
 
3 7
 class Refresher:
4  
-	def __init__(self, timing_settings):
5  
-		pass
  8
+	def __init__(self, dfi_a, dfi_ba, tRP, tREFI, tRFC):
  9
+		self.tRP = tRP
  10
+		self.tREFI = tREFI
  11
+		self.tRFC = tRFC
  12
+		
  13
+		self.req = Signal()
  14
+		self.ack = Signal()
  15
+		self.cmd_request = CommandRequest(dfi_a, dfi_ba)
6 16
 	
7 17
 	def get_fragment(self):
8  
-		return Fragment()
  18
+		comb = []
  19
+		sync = []
  20
+		
  21
+		# Refresh sequence generator:
  22
+		# PRECHARGE ALL --(tRP)--> AUTO REFRESH --(tRFC)--> done
  23
+		seq_start = Signal()
  24
+		seq_done = Signal()
  25
+		sync += [
  26
+			self.cmd_request.a.eq(2**10),
  27
+			self.cmd_request.ba.eq(0),
  28
+			self.cmd_request.cas_n.eq(1),
  29
+			self.cmd_request.ras_n.eq(1),
  30
+			self.cmd_request.we_n.eq(1)
  31
+		]
  32
+		sync += timeline(seq_start, [
  33
+			(0, [
  34
+				self.cmd_request.ras_n.eq(0),
  35
+				self.cmd_request.we_n.eq(0)
  36
+			]),
  37
+			(self.tRP, [
  38
+				self.cmd_request.cas_n.eq(0),
  39
+				self.cmd_request.ras_n.eq(0)
  40
+			]),
  41
+			(self.tRP+self.tRFC, [
  42
+				seq_done.eq(1)
  43
+			])
  44
+		])
  45
+		
  46
+		# Periodic refresh counter
  47
+		counter = Signal(BV(bits_for(self.tREFI - 1)))
  48
+		start = Signal()
  49
+		sync += [
  50
+			start.eq(0),
  51
+			If(counter == 0,
  52
+				start.eq(1),
  53
+				counter.eq(self.tREFI - 1)
  54
+			).Else(
  55
+				counter.eq(counter - 1)
  56
+			)
  57
+		]
  58
+		
  59
+		# Control FSM
  60
+		fsm = FSM("IDLE", "WAIT_GRANT", "WAIT_SEQ")
  61
+		fsm.act(fsm.IDLE, If(start, fsm.next_state(fsm.WAIT_GRANT)))
  62
+		fsm.act(fsm.WAIT_GRANT,
  63
+			self.req.eq(1),
  64
+			If(self.ack,
  65
+				seq_start.eq(1),
  66
+				fsm.next_state(fsm.WAIT_SEQ)
  67
+			)
  68
+		)
  69
+		fsm.act(fsm.WAIT_SEQ,
  70
+			self.req.eq(1),
  71
+			If(seq_done, fsm.next_state(fsm.IDLE))
  72
+		)
  73
+		
  74
+		return Fragment(comb, sync) + fsm.get_fragment()
7  top.py
@@ -21,17 +21,18 @@ def ns(t, margin=False):
21 21
 
22 22
 sdram_phy = asmicon.PhySettings(
23 23
 	dfi_a=13,
24  
-	dfi_ba=2,
25 24
 	dfi_d=64, 
26 25
 	nphases=2,
27 26
 	rdphase=0,
28 27
 	wrphase=1
29 28
 )
30 29
 sdram_geom = asmicon.GeomSettings(
  30
+	bank_a=2,
31 31
 	row_a=13,
32 32
 	col_a=10
33 33
 )
34 34
 sdram_timing = asmicon.TimingSettings(
  35
+	tRP=ns(15),
35 36
 	tREFI=ns(7800),
36 37
 	tRFC=ns(70)
37 38
 )
@@ -58,8 +59,8 @@ def get():
58 59
 	#
59 60
 	# DFI
60 61
 	#
61  
-	ddrphy0 = s6ddrphy.S6DDRPHY(sdram_phy.dfi_a, sdram_phy.dfi_ba, sdram_phy.dfi_d)
62  
-	dfii0 = dfii.DFIInjector(1, sdram_phy.dfi_a, sdram_phy.dfi_ba, sdram_phy.dfi_d, sdram_phy.nphases)
  62
+	ddrphy0 = s6ddrphy.S6DDRPHY(sdram_phy.dfi_a, sdram_geom.bank_a, sdram_phy.dfi_d)
  63
+	dfii0 = dfii.DFIInjector(1, sdram_phy.dfi_a, sdram_geom.bank_a, sdram_phy.dfi_d, sdram_phy.nphases)
63 64
 	dficon0 = dfi.Interconnect(dfii0.master, ddrphy0.dfi)
64 65
 	dficon1 = dfi.Interconnect(asmicon0.dfi, dfii0.slave)
65 66
 

0 notes on commit 7c37788

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