corrections to inferface reader, add unit tests
[pinmux.git] / src / actual_pinmux.py
index 02603a97122a784daa32b53d57096cb7921f0896..99db5a05a14e107afc29dc4b7b218383b8a09303 100644 (file)
@@ -1,5 +1,9 @@
 from parse import *
 from string import digits
+try:
+    from string import maketrans
+except ImportError:
+    maketrans = str.maketrans
 
 
 # dictionary of properties of signals that are supported.
@@ -11,7 +15,11 @@ dictionary = {
     "spi_ss"   : "output",
     "spi_miso" : "input",
     "twi_sda"  : "inout",
-    "twi_scl"  : "inout"
+    "twi_scl"  : "inout",
+    "sd_clk": "output",
+    "sd_cmd": "output",
+    "sd_d": "inout",
+    "pwm": "output"
 }
 
 
@@ -20,25 +28,28 @@ dictionary = {
 # second argument is the mux value.
 # Third argument is the signal from the pinmap file
 mux_wire = '''
-      rule assign_{2}_on_cell{0}(wrmux{0}=={1});
-        {2}<=cell{0}_in;
+      rule assign_{2}_on_cell{0}(wrcell{0}_mux=={1});
+        {2}<=cell{0}_mux_in;
       endrule
 '''
 dedicated_wire = '''
       rule assign_{1}_on_cell{0};
-        {1}<=cell{0}_in;
+        {1}<=cell{0}_mux_in;
       endrule
 '''
 # ============================================================
 pinmux = ''' '''
-digits = str.maketrans(dict.fromkeys('0123456789'))
+digits = maketrans('0123456789', ' '*10) # delete space later
+
+def cn(idx):
+    return "cell%s_mux" % str(idx)
 
 for cell in muxed_cells:
-    pinmux = pinmux + "      cell" + str(cell[0]) + "_out="
+    pinmux = pinmux + "      %s_out=" % cn(cell[0])
     i = 0
     while(i < len(cell) - 1):
-        pinmux = pinmux + "wrmux" + \
-            str(cell[0]) + "==" + str(i) + "?" + cell[i + 1] + "_io:"
+        pinmux = pinmux + "wr%s" % cn(cell[0]) + \
+             "==" + str(i) + "?" + cell[i + 1] + "_io:\n\t\t\t"
         if(i + 2 == len(cell) - 1):
             pinmux = pinmux + cell[i + 2] + "_io"
             i = i + 2
@@ -54,14 +65,14 @@ for cell in muxed_cells:
     # user-to-user. Plus this also reduces human-error as well :)
     for i in range(0, len(cell) - 1):
         temp = cell[i + 1].translate(digits)
+        temp = temp.replace(' ', '')
         x = dictionary.get(temp)
         if(x is None):
             print(
-              "Error: The signal : " +
+              "ERROR: The signal : " +
               str(cell[i + 1]) +
-              " in lineno: " +
-              str(lineno) + "of pinmap.txt isn't present in the \
-              current dictionary.\nUpdate dictionary or fix-typo.")
+              " of pinmap.txt isn't present in the current dictionary.\
+              \nUpdate dictionary or fix-typo.")
             exit(1)
         if(x == "input"):
             pinmux = pinmux + \
@@ -74,8 +85,8 @@ for cell in muxed_cells:
 
 # ==================  Logic for dedicated pins ========= #
 for cell in dedicated_cells:
-    pinmux = pinmux + "      cell" + \
-        str(cell[0]) + "_out=" + cell[1] + "_io;\n"
+    pinmux = pinmux + "      %s" % cn(cell[0]) + \
+        "_out=" + cell[1] + "_io;\n"
     temp = cell[1].translate(digits)
     x = dictionary.get(temp)
     if(x == "input"):