cif: move to milkymist folder
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 30 May 2013 19:38:21 +0000 (21:38 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Thu, 30 May 2013 19:38:21 +0000 (21:38 +0200)
build.py
cif.py [deleted file]
milkymist/cif.py [new file with mode: 0644]
top.py

index 73bd7720b6c6049922203a5eb3b2233882bf460c..b345a5c91e8c85d0c2c10372d3de9143b1f9bcdd 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -5,8 +5,9 @@ import os
 from mibuild.platforms import m1
 from mibuild.tools import write_to_file
 
+from milkymist import cif
+
 import top
-import cif
 
 def main():
        platform = m1.Platform()
diff --git a/cif.py b/cif.py
deleted file mode 100644 (file)
index ace7b2a..0000000
--- a/cif.py
+++ /dev/null
@@ -1,66 +0,0 @@
-from operator import itemgetter
-import re
-
-from migen.bank.description import CSRStatus
-
-def get_macros(filename):
-       f = open(filename, "r")
-       r = {}
-       for line in f:
-               match = re.match("\w*#define\s+(\w+)\s+(.*)", line, re.IGNORECASE)
-               if match:
-                       r[match.group(1)] = match.group(2)
-       return r
-
-def _get_rw_functions(reg_name, reg_base, size, read_only):
-       r = ""
-       if size > 8:
-               raise NotImplementedError("Register too large")
-       elif size > 4:
-               ctype = "unsigned long long int"
-       elif size > 2:
-               ctype = "unsigned int"
-       elif size > 1:
-               ctype = "unsigned short int"
-       else:
-               ctype = "unsigned char"
-
-       r += "static inline "+ctype+" "+reg_name+"_read(void) {\n"
-       if size > 1:
-               r += "\t"+ctype+" r = MMPTR("+hex(reg_base)+");\n"
-               for byte in range(1, size):
-                       r += "\tr <<= 8;\n\tr |= MMPTR("+hex(reg_base+4*byte)+");\n"
-               r += "\treturn r;\n}\n"
-       else:
-               r += "\treturn MMPTR("+hex(reg_base)+");\n}\n"
-
-       if not read_only:
-               r += "static inline void "+reg_name+"_write("+ctype+" value) {\n"
-               for byte in range(size):
-                       shift = (size-byte-1)*8
-                       if shift:
-                               value_shifted = "value >> "+str(shift)
-                       else:
-                               value_shifted = "value"
-                       r += "\tMMPTR("+hex(reg_base+4*byte)+") = "+value_shifted+";\n"
-               r += "}\n"
-       return r
-
-def get_csr_header(csr_base, bank_array, interrupt_map):
-       r = "#ifndef __HW_CSR_H\n#define __HW_CSR_H\n#include <hw/common.h>\n"
-       for name, csrs, mapaddr, rmap in bank_array.banks:
-               r += "\n/* "+name+" */\n"
-               reg_base = csr_base + 0x800*mapaddr
-               r += "#define "+name.upper()+"_BASE "+hex(reg_base)+"\n"
-               for csr in csrs:
-                       nr = (csr.size + 7)//8
-                       r += _get_rw_functions(name + "_" + csr.name, reg_base, nr, isinstance(csr, CSRStatus))
-                       reg_base += 4*nr
-               try:
-                       interrupt_nr = interrupt_map[name]
-               except KeyError:
-                       pass
-               else:
-                       r += "#define "+name.upper()+"_INTERRUPT "+str(interrupt_nr)+"\n"
-       r += "\n#endif\n"
-       return r
diff --git a/milkymist/cif.py b/milkymist/cif.py
new file mode 100644 (file)
index 0000000..ace7b2a
--- /dev/null
@@ -0,0 +1,66 @@
+from operator import itemgetter
+import re
+
+from migen.bank.description import CSRStatus
+
+def get_macros(filename):
+       f = open(filename, "r")
+       r = {}
+       for line in f:
+               match = re.match("\w*#define\s+(\w+)\s+(.*)", line, re.IGNORECASE)
+               if match:
+                       r[match.group(1)] = match.group(2)
+       return r
+
+def _get_rw_functions(reg_name, reg_base, size, read_only):
+       r = ""
+       if size > 8:
+               raise NotImplementedError("Register too large")
+       elif size > 4:
+               ctype = "unsigned long long int"
+       elif size > 2:
+               ctype = "unsigned int"
+       elif size > 1:
+               ctype = "unsigned short int"
+       else:
+               ctype = "unsigned char"
+
+       r += "static inline "+ctype+" "+reg_name+"_read(void) {\n"
+       if size > 1:
+               r += "\t"+ctype+" r = MMPTR("+hex(reg_base)+");\n"
+               for byte in range(1, size):
+                       r += "\tr <<= 8;\n\tr |= MMPTR("+hex(reg_base+4*byte)+");\n"
+               r += "\treturn r;\n}\n"
+       else:
+               r += "\treturn MMPTR("+hex(reg_base)+");\n}\n"
+
+       if not read_only:
+               r += "static inline void "+reg_name+"_write("+ctype+" value) {\n"
+               for byte in range(size):
+                       shift = (size-byte-1)*8
+                       if shift:
+                               value_shifted = "value >> "+str(shift)
+                       else:
+                               value_shifted = "value"
+                       r += "\tMMPTR("+hex(reg_base+4*byte)+") = "+value_shifted+";\n"
+               r += "}\n"
+       return r
+
+def get_csr_header(csr_base, bank_array, interrupt_map):
+       r = "#ifndef __HW_CSR_H\n#define __HW_CSR_H\n#include <hw/common.h>\n"
+       for name, csrs, mapaddr, rmap in bank_array.banks:
+               r += "\n/* "+name+" */\n"
+               reg_base = csr_base + 0x800*mapaddr
+               r += "#define "+name.upper()+"_BASE "+hex(reg_base)+"\n"
+               for csr in csrs:
+                       nr = (csr.size + 7)//8
+                       r += _get_rw_functions(name + "_" + csr.name, reg_base, nr, isinstance(csr, CSRStatus))
+                       reg_base += 4*nr
+               try:
+                       interrupt_nr = interrupt_map[name]
+               except KeyError:
+                       pass
+               else:
+                       r += "#define "+name.upper()+"_INTERRUPT "+str(interrupt_nr)+"\n"
+       r += "\n#endif\n"
+       return r
diff --git a/top.py b/top.py
index 6dbb0f54186785117bfc5e53511738c10b9a2308..fabfe62332efcce23b07e2016c8ccf117574dbbc 100644 (file)
--- a/top.py
+++ b/top.py
@@ -9,7 +9,7 @@ from migen.bank import csrgen
 from milkymist import m1crg, lm32, norflash, uart, s6ddrphy, dfii, asmicon, \
        identifier, timer, minimac3, framebuffer, asmiprobe, dvisampler, \
        counteradc, gpio
-from cif import get_macros
+from milkymist.cif import get_macros
 
 version = get_macros("common/version.h")["VERSION"][1:-1]