diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 6119d056e..b6303a365 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -107,6 +107,9 @@ class Builder: write_to_file( os.path.join(generated_dir, "mem.h"), cpu_interface.get_mem_header(self.soc.mem_regions)) + write_to_file( + os.path.join(generated_dir, "soc.h"), + cpu_interface.get_soc_header(self.soc.constants)) write_to_file( os.path.join(generated_dir, "csr.h"), cpu_interface.get_csr_header(self.soc.csr_regions, diff --git a/litex/soc/integration/export.py b/litex/soc/integration/export.py index 08014a49f..b369458e2 100644 --- a/litex/soc/integration/export.py +++ b/litex/soc/integration/export.py @@ -115,6 +115,27 @@ def get_mem_header(regions): r += "#endif\n" return r +def get_soc_header(constants, with_access_functions=True): + r = generated_banner("//") + r += "#ifndef __GENERATED_SOC_H\n#define __GENERATED_SOC_H\n" + for name, value in constants.items(): + if value is None: + r += "#define "+name+"\n" + continue + if isinstance(value, str): + value = "\"" + value + "\"" + ctype = "const char *" + else: + value = str(value) + ctype = "int" + r += "#define "+name+" "+value+"\n" + if with_access_functions: + r += "static inline "+ctype+" "+name.lower()+"_read(void) {\n" + r += "\treturn "+value+";\n}\n" + + r += "\n#endif\n" + return r + def _get_rw_functions_c(reg_name, reg_base, nwords, busword, alignment, read_only, with_access_functions): r = "" @@ -159,6 +180,7 @@ def _get_rw_functions_c(reg_name, reg_base, nwords, busword, alignment, read_onl def get_csr_header(regions, constants, with_access_functions=True): alignment = constants.get("CONFIG_CSR_ALIGNMENT", 32) r = generated_banner("//") + r += "#include \n" r += "#ifndef __GENERATED_CSR_H\n#define __GENERATED_CSR_H\n" if with_access_functions: r += "#include \n" @@ -187,22 +209,6 @@ def get_csr_header(regions, constants, with_access_functions=True): r += "#define CSR_"+name.upper()+"_"+csr.name.upper()+"_"+field.name.upper()+"_OFFSET "+str(field.offset)+"\n" r += "#define CSR_"+name.upper()+"_"+csr.name.upper()+"_"+field.name.upper()+"_SIZE "+str(field.size)+"\n" - r += "\n/* constants */\n" - for name, value in constants.items(): - if value is None: - r += "#define "+name+"\n" - continue - if isinstance(value, str): - value = "\"" + value + "\"" - ctype = "const char *" - else: - value = str(value) - ctype = "int" - r += "#define "+name+" "+value+"\n" - if with_access_functions: - r += "static inline "+ctype+" "+name.lower()+"_read(void) {\n" - r += "\treturn "+value+";\n}\n" - r += "\n#endif\n" return r