Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
27  migen/bus/wishbone.py
@@ -6,22 +6,23 @@
6 6
 from migen.sim.generic import Proxy
7 7
 
8 8
 _layout = [
9  
-	("adr",		30,		DIR_M_TO_S),
10  
-	("dat_w",	32, 	DIR_M_TO_S),
11  
-	("dat_r",	32, 	DIR_S_TO_M),
12  
-	("sel",		4,		DIR_M_TO_S),
13  
-	("cyc",		1,		DIR_M_TO_S),
14  
-	("stb",		1,		DIR_M_TO_S),
15  
-	("ack",		1,		DIR_S_TO_M),
16  
-	("we",		1,		DIR_M_TO_S),
17  
-	("cti",		3,		DIR_M_TO_S),
18  
-	("bte",		2,		DIR_M_TO_S),
19  
-	("err",		1,		DIR_S_TO_M)
  9
+	("adr",		30,				DIR_M_TO_S),
  10
+	("dat_w",	"data_width", 	DIR_M_TO_S),
  11
+	("dat_r",	"data_width", 	DIR_S_TO_M),
  12
+	("sel",		"sel_width",	DIR_M_TO_S),
  13
+	("cyc",		1,				DIR_M_TO_S),
  14
+	("stb",		1,				DIR_M_TO_S),
  15
+	("ack",		1,				DIR_S_TO_M),
  16
+	("we",		1,				DIR_M_TO_S),
  17
+	("cti",		3,				DIR_M_TO_S),
  18
+	("bte",		2,				DIR_M_TO_S),
  19
+	("err",		1,				DIR_S_TO_M)
20 20
 ]
21 21
 
22 22
 class Interface(Record):
23  
-	def __init__(self):
24  
-		Record.__init__(self, _layout)
  23
+	def __init__(self, data_width=32):
  24
+		Record.__init__(self, _layout, data_width=data_width,
  25
+			sel_width=data_width//8)
25 26
 
26 27
 class InterconnectPointToPoint(Module):
27 28
 	def __init__(self, master, slave):
17  migen/genlib/record.py
@@ -11,19 +11,21 @@
11 11
 # size can be an int, or a (int, bool) tuple for signed numbers
12 12
 # sublayout must be a list
13 13
 
14  
-def layout_len(layout):
  14
+def layout_len(layout, **layout_dict):
15 15
 	r = 0
16 16
 	for f in layout:
17  
-		if isinstance(f[1], (int, tuple)): # cases 1/2
  17
+		if isinstance(f[1], (int, tuple, str)): # cases 1/2
18 18
 			if(len(f) == 3):
19 19
 				fname, fsize, fdirection = f
20 20
 			else:
21 21
 				fname, fsize = f
22 22
 		elif isinstance(f[1], list): # case 3
23 23
 			fname, fsublayout = f
24  
-			fsize = layout_len(fsublayout)
  24
+			fsize = layout_len(fsublayout, **layout_dict)
25 25
 		else:
26 26
 			raise TypeError
  27
+		if isinstance(fsize, str):
  28
+			fsize = layout_dict[fsize]
27 29
 		if isinstance(fsize, tuple):
28 30
 			r += fsize[0]
29 31
 		else:
@@ -55,20 +57,23 @@ def layout_partial(layout, *elements):
55 57
 	return r
56 58
 
57 59
 class Record:
58  
-	def __init__(self, layout, name=None):
  60
+	def __init__(self, layout, name=None, **layout_dict):
59 61
 		self.name = get_obj_var_name(name, "")
60 62
 		self.layout = layout
  63
+		self.layout_dict = layout_dict
61 64
 
62 65
 		if self.name:
63 66
 			prefix = self.name + "_"
64 67
 		else:
65 68
 			prefix = ""
66 69
 		for f in self.layout:
67  
-			if isinstance(f[1], (int, tuple)): # cases 1/2
  70
+			if isinstance(f[1], (int, tuple, str)): # cases 1/2
68 71
 				if(len(f) == 3):
69 72
 					fname, fsize, fdirection = f
70 73
 				else:
71 74
 					fname, fsize = f
  75
+				if isinstance(fsize, str):
  76
+					fsize = layout_dict[fsize]
72 77
 				finst = Signal(fsize, name=prefix + fname)
73 78
 			elif isinstance(f[1], list): # case 3
74 79
 				fname, fsublayout = f
@@ -139,7 +144,7 @@ def connect_flat(self, *slaves):
139 144
 		return r
140 145
 
141 146
 	def __len__(self):
142  
-		return layout_len(self.layout)
  147
+		return layout_len(self.layout, **self.layout_dict)
143 148
 
144 149
 	def __repr__(self):
145 150
 		return "<Record " + ":".join(f[0] for f in self.layout) + " at " + hex(id(self)) + ">"

No commit comments for this range

Something went wrong with that request. Please try again.