Skip to content

Commit 3a2b677

Browse files
committedApr 8, 2015
soc,cpuif: support user defined constants
1 parent 8b41ab3 commit 3a2b677

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed
 

Diff for: ‎make.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _get_args():
162162
write_to_file(os.path.join(genhdir, "sdram_phy.h"), boilerplate + sdram_phy_header)
163163
mem_header = cpuif.get_mem_header(memory_regions, getattr(soc, "flash_boot_address", None))
164164
write_to_file(os.path.join(genhdir, "mem.h"), boilerplate + mem_header)
165-
csr_header = cpuif.get_csr_header(csr_regions, soc.interrupt_map)
165+
csr_header = cpuif.get_csr_header(csr_regions, soc.get_constants())
166166
write_to_file(os.path.join(genhdir, "csr.h"), boilerplate + csr_header)
167167

168168
if actions["build-csr-csv"]:

Diff for: ‎misoclib/soc/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, platform, clk_freq,
6464

6565
self._memory_regions = [] # list of (name, origin, length)
6666
self._csr_regions = [] # list of (name, origin, busword, csr_list/Memory)
67+
self._constants = [] # list of (name, value)
6768

6869
self._wb_masters = []
6970
self._wb_slaves = []
@@ -159,6 +160,16 @@ def add_csr_region(self, name, origin, busword, obj):
159160
def get_csr_regions(self):
160161
return self._csr_regions
161162

163+
def add_constant(self, name, value):
164+
self._constants.append((name, value))
165+
166+
def get_constants(self):
167+
r = []
168+
for name, interrupt in sorted(self.interrupt_map.items(), key=itemgetter(1)):
169+
r.append((name.upper() + "_INTERRUPT", interrupt))
170+
r += self._constants
171+
return r
172+
162173
def do_finalize(self):
163174
registered_mems = {regions[0] for regions in self._memory_regions}
164175
if self.cpu_type != "none":

Diff for: ‎misoclib/soc/cpuif.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _get_rw_functions(reg_name, reg_base, nwords, busword, read_only):
6868
r += "}\n"
6969
return r
7070

71-
def get_csr_header(regions, interrupt_map):
71+
def get_csr_header(regions, constants):
7272
r = "#ifndef __GENERATED_CSR_H\n#define __GENERATED_CSR_H\n#include <hw/common.h>\n"
7373
for name, origin, busword, obj in regions:
7474
if isinstance(obj, Memory):
@@ -80,12 +80,11 @@ def get_csr_header(regions, interrupt_map):
8080
nr = (csr.size + busword - 1)//busword
8181
r += _get_rw_functions(name + "_" + csr.name, origin, nr, busword, isinstance(csr, CSRStatus))
8282
origin += 4*nr
83-
try:
84-
interrupt_nr = interrupt_map[name]
85-
except KeyError:
86-
pass
87-
else:
88-
r += "#define "+name.upper()+"_INTERRUPT "+str(interrupt_nr)+"\n"
83+
84+
r += "\n/* constants */\n"
85+
for name, value in constants:
86+
r += "#define " + name + " " + str(value) + "\n"
87+
8988
r += "\n#endif\n"
9089
return r
9190

0 commit comments

Comments
 (0)
Please sign in to comment.