integration: move soc constants to soc.h of csr.h
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 10 Oct 2019 19:15:49 +0000 (21:15 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Thu, 10 Oct 2019 19:15:49 +0000 (21:15 +0200)
software retro-compat with soc.h included in csr.h

litex/soc/integration/builder.py
litex/soc/integration/export.py

index 6119d056e03c0755a5d3c405489eccee5c4f07d4..b6303a36545c5e51f6277371e7ed204de3d9c1e6 100644 (file)
@@ -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,
index 08014a49f7bf02c0f202080e5ac842cd4b5df4ce..b369458e296eb8cdcdbd71db827b6e9654ed7cc8 100644 (file)
@@ -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 <generated/soc.h>\n"
     r += "#ifndef __GENERATED_CSR_H\n#define __GENERATED_CSR_H\n"
     if with_access_functions:
         r += "#include <stdint.h>\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