add interface reader
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 22 Mar 2018 09:35:35 +0000 (09:35 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 22 Mar 2018 09:35:35 +0000 (09:35 +0000)
interfaces.txt [new file with mode: 0644]
jtag.txt [new file with mode: 0644]
pwm.txt [new file with mode: 0644]
sd.txt [new file with mode: 0644]
spi.txt [new file with mode: 0644]
src/interface_decl.py
twi.txt [new file with mode: 0644]
uart.txt [new file with mode: 0644]

diff --git a/interfaces.txt b/interfaces.txt
new file mode 100644 (file)
index 0000000..5a1a4e2
--- /dev/null
@@ -0,0 +1,6 @@
+uart   4
+spi    1
+twi    2
+sd     2
+jtag   2
+pwm    1
diff --git a/jtag.txt b/jtag.txt
new file mode 100644 (file)
index 0000000..494fbd2
--- /dev/null
+++ b/jtag.txt
@@ -0,0 +1,5 @@
+tdi    in
+tms    in
+tclk   in
+trst   in
+tdo    out
diff --git a/pwm.txt b/pwm.txt
new file mode 100644 (file)
index 0000000..76b0c8b
--- /dev/null
+++ b/pwm.txt
@@ -0,0 +1 @@
+pwm    out
diff --git a/sd.txt b/sd.txt
new file mode 100644 (file)
index 0000000..f06731c
--- /dev/null
+++ b/sd.txt
@@ -0,0 +1,6 @@
+clk    out
+cmd    out
+d0     outen
+d1     outen
+d2     outen
+d3     outen
diff --git a/spi.txt b/spi.txt
new file mode 100644 (file)
index 0000000..a7c9d79
--- /dev/null
+++ b/spi.txt
@@ -0,0 +1,4 @@
+sclk   out
+mosi   out
+nss    out
+miso   in
index bbdd22ed2887b4a6df9d6c956a4670f643d9e7c5..1e85581c8bc95e157bfcf3ad3e4b078473067019 100644 (file)
@@ -1,3 +1,4 @@
+from UserDict import UserDict
 
 class Pin(object):
     """ pin interface declaration.
@@ -166,6 +167,39 @@ class IOInterface(Interface):
         return "cell{0}_mux_in"
 
 
+class Interfaces(UserDict):
+    """ contains a list of interface definitions
+    """
+
+    def __init__(self):
+        self.ifacecount = []
+        ifaces = {}
+        with open('interfaces.txt', 'r') as ifile:
+            for l in ifile.readlines():
+                l = l.strip()
+                l = l.split("\t")
+                print l
+                name = l[0]
+                count = int(l[1])
+                self.ifacecount.append((name, count))
+                spec = self.read_spec(name)
+                ifaces[name] = Interface(name, spec)
+        UserDict.__init__(self, ifaces)
+
+    def read_spec(self, name):
+        spec = []
+        with open('%s.txt' % name, 'r') as sfile:
+            for l in sfile.readlines():
+                l = l.split("\t")
+                d = {'name': l[0]}
+                if l[1] == 'out':
+                    d['action'] = True
+                elif l[1] == 'inout':
+                    d['outen'] = True
+                spec.append(d)
+        return spec
+
+
 # ========= Interface declarations ================ #
 
 mux_interface = Interface('cell', [{'name': 'mux', 'ready':False,
@@ -227,6 +261,8 @@ pwminterface_decl = Interface('pwm',
                             [{'name': "pwm", 'action': True}
                             ])
 
+ifaces = Interfaces()
+
 # ======================================= #
 
 # basic test
diff --git a/twi.txt b/twi.txt
new file mode 100644 (file)
index 0000000..a673042
--- /dev/null
+++ b/twi.txt
@@ -0,0 +1,2 @@
+sda    outen
+scl    outen
diff --git a/uart.txt b/uart.txt
new file mode 100644 (file)
index 0000000..9af527f
--- /dev/null
+++ b/uart.txt
@@ -0,0 +1,2 @@
+rx     in
+tx     out