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
8  migen/bank/csrgen.py
@@ -4,6 +4,14 @@
4 4
 from migen.bus import csr
5 5
 from migen.bank.description import *
6 6
 
  7
+def get_offset(description, name, csr_data_width=8):
  8
+	offset = 0
  9
+	for c in description:
  10
+		if c.name == name:
  11
+			return offset
  12
+		offset += (c.size + csr_data_width - 1)//csr_data_width
  13
+	raise KeyError("CSR not found: "+name)
  14
+
7 15
 class Bank(Module):
8 16
 	def __init__(self, description, address=0, bus=None):
9 17
 		if bus is None:
24  migen/bank/description.py
@@ -84,13 +84,17 @@ def do_finalize(self, busword):
84 84
 			else:
85 85
 				self.sync += If(sc.re, self.storage_full[lo:hi].eq(sc.r))
86 86
 
87  
-def csrprefix(prefix, csrs):
  87
+def csrprefix(prefix, csrs, done):
88 88
 	for csr in csrs:
89  
-		csr.name = prefix + csr.name
  89
+		if csr.huid not in done:
  90
+			csr.name = prefix + csr.name
  91
+			done.add(csr.huid)
90 92
 
91  
-def memprefix(prefix, memories):
  93
+def memprefix(prefix, memories, done):
92 94
 	for memory in memories:
93  
-		memory.name_override = prefix + memory.name_override
  95
+		if memory.huid not in done:
  96
+			memory.name_override = prefix + memory.name_override
  97
+			done.add(memory.huid)
94 98
 
95 99
 class AutoCSR:
96 100
 	def get_memories(self):
@@ -98,6 +102,10 @@ def get_memories(self):
98 102
 			exclude = self.autocsr_exclude
99 103
 		except AttributeError:
100 104
 			exclude = {}
  105
+		try:
  106
+			prefixed = self.__prefixed
  107
+		except AttributeError:
  108
+			prefixed = self.__prefixed = set()
101 109
 		r = []
102 110
 		for k, v in self.__dict__.items():
103 111
 			if k not in exclude:
@@ -105,7 +113,7 @@ def get_memories(self):
105 113
 					r.append(v)
106 114
 				elif hasattr(v, "get_memories") and callable(v.get_memories):
107 115
 					memories = v.get_memories()
108  
-					memprefix(k + "_", memories)
  116
+					memprefix(k + "_", memories, prefixed)
109 117
 					r += memories
110 118
 		return sorted(r, key=lambda x: x.huid)
111 119
 
@@ -114,6 +122,10 @@ def get_csrs(self):
114 122
 			exclude = self.autocsr_exclude
115 123
 		except AttributeError:
116 124
 			exclude = {}
  125
+		try:
  126
+			prefixed = self.__prefixed
  127
+		except AttributeError:
  128
+			prefixed = self.__prefixed = set()
117 129
 		r = []
118 130
 		for k, v in self.__dict__.items():
119 131
 			if k not in exclude:
@@ -121,6 +133,6 @@ def get_csrs(self):
121 133
 					r.append(v)
122 134
 				elif hasattr(v, "get_csrs") and callable(v.get_csrs):
123 135
 					csrs = v.get_csrs()
124  
-					csrprefix(k + "_", csrs)
  136
+					csrprefix(k + "_", csrs, prefixed)
125 137
 					r += csrs
126 138
 		return sorted(r, key=lambda x: x.huid)

No commit comments for this range

Something went wrong with that request. Please try again.