# ============== common bsv templates ============ #
-assign_cell = '''cell{0}_out=wrmux{0}=={1}?'''
 # first argument is the io-cell number being assigned.
 # second argument is the mux value.
 # Third argument is the signal from the pinmap file
-input_wire = '''
+mux_wire = '''
       rule assign_{2}_on_cell{0}(wrmux{0}=={1});
         {2}<=cell{0}_in;
       endrule
 '''
+dedicated_wire = '''
+      rule assign_{1}_on_cell{0};
+        {1}<=cell{0}_in;
+      endrule
+'''
 # ============================================================
 pinmux = ''' '''
 pinmap_file = open("./pinmap.txt", "r")
         dedicated = False
     elif("dedicated" in line):
         dedicated = True
+    digits = str.maketrans(dict.fromkeys('0123456789'))
     # ==== Logic for muxed pins ==== #
     if(len(line1) > 1 and not(dedicated)):
         if(lineno > N_IO):
             exit(1)
         # ==== Mux each generic IO cell with the mapping ===== #
         # provided in the pinmap file
-        pinmux = pinmux + "            cell" + str(line1[0]) + "_out="
+        pinmux = pinmux + "      cell" + str(line1[0]) + "_out="
         i = 0
         while(i < len(line1) - 1):
             pinmux = pinmux + "wrmux" + \
         # since the interfaces are always standard and cannot change from
         # user-to-user. Plus this also reduces human-error as well :)
         for i in range(0, len(line1) - 1):
-            digits = str.maketrans(dict.fromkeys('0123456789'))
             temp = line1[i + 1].translate(digits)
             x = dictionary.get(temp)
             if(x is None):
                 exit(1)
             if(x == "input"):
                 pinmux = pinmux + \
-                    input_wire.format(line1[0], i, "wr" + line1[i + 1]) + "\n"
+                    mux_wire.format(line1[0], i, "wr" + line1[i + 1]) + "\n"
             elif(x == "inout"):
                 pinmux = pinmux + \
-                    input_wire.format(line1[0], i, "wr" + line1[i + 1] +
-                                      "_in") + "\n"
+                    mux_wire.format(line1[0], i, "wr" + line1[i + 1] +
+                                    "_in") + "\n"
         # ============================================================ #
 
     # ==================  Logic for dedicated pins ========= #
     elif(len(line1) > 1 and dedicated):
-        pinmux = pinmux + "            cell" + \
+        pinmux = pinmux + "      cell" + \
             str(line1[0]) + "_out=" + line1[1] + "_io;\n"
+        temp = line1[1].translate(digits)
+        x = dictionary.get(temp)
+        if(x == "input"):
+            pinmux = pinmux + \
+                dedicated_wire.format(line1[0], "wr" + line1[1]) + "\n"
+        elif(x == "inout"):
+            pinmux = pinmux + \
+                dedicated_wire.format(line1[0], "wr" + line1[1] + "_in") + "\n"
     # ======================================================= #
 # =========================================================
 
 bsv_file = open("./bsv_src/pinmux.bsv", "w")
 header = '''
 /*
-   This BSV file has been generated by the PinMux tool available at: <website>.
+   This BSV file has been generated by the PinMux tool available at:
+   https://bitbucket.org/casl/pinmux.
+
    Authors: Neel Gala, Luke
    Date of generation: ''' + time.strftime("%c") + '''
 */
 package pinmux;
 
    typedef struct{
-      Bit#(1) outputval;      // output from core to pad                  bit7
+      Bit#(1) outputval;      // output from core to pad                bit7
       Bit#(1) output_en;      // output enable from core to pad         bit6
-      Bit#(1) input_en;         // input enable from core to io_cell      bit5
-      Bit#(1) pullup_en;      // pullup enable from core to io_cell      bit4
-      Bit#(1) pulldown_en;      // pulldown enable from core to io_cell   bit3
-      Bit#(1) drivestrength;   // drivestrength from core to io_cell      bit2
-      Bit#(1) pushpull_en;      // pushpull enable from core to io_cell   bit1
-      Bit#(1) opendrain_en;   // opendrain enable form core to io_cell   bit0
+      Bit#(1) input_en;       // input enable from core to io_cell      bit5
+      Bit#(1) pullup_en;      // pullup enable from core to io_cell     bit4
+      Bit#(1) pulldown_en;    // pulldown enable from core to io_cell   bit3
+      Bit#(1) drivestrength;  // drivestrength from core to io_cell     bit2
+      Bit#(1) pushpull_en;    // pushpull enable from core to io_cell   bit1
+      Bit#(1) opendrain_en;   // opendrain enable form core to io_cell  bit0
    } GenericIOType deriving(Eq,Bits,FShow);
 
    interface Ifc_pinmux;