write_to_file(os.path.join(genhdir, "sdram_phy.h"), boilerplate + sdram_phy_header)
mem_header = cpuif.get_mem_header(memory_regions, getattr(soc, "flash_boot_address", None))
write_to_file(os.path.join(genhdir, "mem.h"), boilerplate + mem_header)
- csr_header = cpuif.get_csr_header(csr_regions, soc.interrupt_map)
+ csr_header = cpuif.get_csr_header(csr_regions, soc.get_constants())
write_to_file(os.path.join(genhdir, "csr.h"), boilerplate + csr_header)
if actions["build-csr-csv"]:
self._memory_regions = [] # list of (name, origin, length)
self._csr_regions = [] # list of (name, origin, busword, csr_list/Memory)
+ self._constants = [] # list of (name, value)
self._wb_masters = []
self._wb_slaves = []
def get_csr_regions(self):
return self._csr_regions
+ def add_constant(self, name, value):
+ self._constants.append((name, value))
+
+ def get_constants(self):
+ r = []
+ for name, interrupt in sorted(self.interrupt_map.items(), key=itemgetter(1)):
+ r.append((name.upper() + "_INTERRUPT", interrupt))
+ r += self._constants
+ return r
+
def do_finalize(self):
registered_mems = {regions[0] for regions in self._memory_regions}
if self.cpu_type != "none":
r += "}\n"
return r
-def get_csr_header(regions, interrupt_map):
+def get_csr_header(regions, constants):
r = "#ifndef __GENERATED_CSR_H\n#define __GENERATED_CSR_H\n#include <hw/common.h>\n"
for name, origin, busword, obj in regions:
if isinstance(obj, Memory):
nr = (csr.size + busword - 1)//busword
r += _get_rw_functions(name + "_" + csr.name, origin, nr, busword, isinstance(csr, CSRStatus))
origin += 4*nr
- try:
- interrupt_nr = interrupt_map[name]
- except KeyError:
- pass
- else:
- r += "#define "+name.upper()+"_INTERRUPT "+str(interrupt_nr)+"\n"
+
+ r += "\n/* constants */\n"
+ for name, value in constants:
+ r += "#define " + name + " " + str(value) + "\n"
+
r += "\n#endif\n"
return r