From: Florent Kermarrec Date: Thu, 10 Oct 2019 19:15:49 +0000 (+0200) Subject: integration: move soc constants to soc.h of csr.h X-Git-Tag: 24jan2021_ls180~925 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=42ccc91f749d95abce1a8d5f11e97c30f3d36543;p=litex.git integration: move soc constants to soc.h of csr.h software retro-compat with soc.h included in csr.h --- diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 6119d056..b6303a36 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 08014a49..b369458e 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