automated the pinumxing logic
authorNeel <neelgala@gmail.com>
Sun, 11 Mar 2018 16:43:31 +0000 (22:13 +0530)
committerNeel <neelgala@gmail.com>
Sun, 11 Mar 2018 16:43:31 +0000 (22:13 +0530)
Currently it only supports muxing between inputs and outputs. Handling of inouts will have to be done soon.

pinmap.txt [new file with mode: 0644]
src/actual_pinmux.py
src/params.py
src/pinmux_generator.py
src/wire_def.py

diff --git a/pinmap.txt b/pinmap.txt
new file mode 100644 (file)
index 0000000..d3dc0fa
--- /dev/null
@@ -0,0 +1,5 @@
+muxed
+0      uart0_tx        spi0_sclk
+1      uart0_rx        spi0_mosi
+2  uart1_tx    spi0_ss
+3  uart1_rx spi0_miso
index 944a8161d03e38de3359c25f925d287aa6a0a682..fe16198e9afce110f65151beef3bcd59b05f956b 100644 (file)
@@ -1,17 +1,64 @@
 from params import *
-#== Actual pinmuxing ==# TODO: Need to get this as a templete
-pinmux='''
-               /*=============== THIS IS WHERE ACTUAL MUXING HAPPENS ==========*/
-               cell0_out=wrmux0==0?uart0_rx_io:uart1_rx_io;
-               rule get_input_for_rx;
-                       if(wrmux0==0)
-                               wruart0_rx<=cell0_in;
-                       else
-                               wruart1_rx<=cell0_in;
+from string import digits
+
+
+## dictionary of properties of signals that are supported.
+dictionary={
+       "uart_rx":"input",
+       "uart_tx":"output",
+       "spi_sclk":"output",
+       "spi_mosi":"output",
+       "spi_ss": "output",
+       "spi_miso":"input"
+}
+       
+
+########### 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='''         
+               rule assign_input_for_{2}(wrmux{0}=={1});
+                       wr{2}<=cell{0}_in;
                endrule
-               cell1_out=wrmux1==0?uart0_tx_io:uart1_tx_io;
-               /*==============================================================*/
 '''
-########################################################################
+#########################################
+pinmux=''' '''
+pinmap_file=open("./pinmap.txt","r")
+for lineno,line in enumerate(pinmap_file):
+       line1=line.split()
+       if(lineno>0):
+               if(lineno>N_IO):
+                       print"ERROR: Parameter N_IO("+str(N_IO)+") is less than the pin number in line: "+str(lineno)+" of pinmap.txt"
+                       exit(1)
+               ######## Mux each generic IO cell with the mapping######
+               # provided in the pinmap file
+               pinmux=pinmux+"         cell"+str(line1[0])+"_out="
+               i=0
+               while(i<len(line1)-1):
+                       pinmux=pinmux+"wrmux"+str(line1[0])+"=="+str(i)+"?"+line1[i+1]+"_io:"
+                       if(i+2==len(line1)-1):
+                               pinmux=pinmux+line1[i+2]+"_io"
+                               i=i+2
+                       else:
+                               i=i+1
+               pinmux=pinmux+";\n"
+               ########################################################
 
+               ###### check each cell if "peripheral input/inout" then assign its wire ########
+               ## Here we check the direction of each signal in the dictionary. 
+               ## We choose to keep the dictionary within the code and not user-input 
+               ## since the interfaces are always standard and cannot change from user-to-user
+               ## plus reduces human-error as well :)
+               for i in range(0,len(line1)-1):
+                       temp=line1[i+1].translate(None,digits)
+                       x=dictionary.get(temp);
+                       if(x==None):
+                               print "Error: The signal : "+str(line1[i+1])+" in lineno: "+str(lineno)+"of pinmap.txt is not present in the current dictionary.\nSoln: Either update the dictionary or fix typo."
+                               exit(1)
+                       if(x=="input"):
+                               pinmux=pinmux+input_wire.format(line1[0],i,line1[i+1])+"\n"
+               ################################################################################
+###########################################
 
index b94a501d42117924d37cebe5658121391bdaeaf9..971bad8298bd229fde9c630a12bf00ca4c5b95dc 100644 (file)
@@ -1,8 +1,8 @@
 #== Parameters ==#
 N_MUX=1                # number of selection lines for the mux per io
-N_IO=2
+N_IO=4
 N_UART=2
-N_SPI=0
+N_SPI=1
 #================#
 
 
index fed54eacecd1042bd96a3306b715938d821bc04a..e4a2176146c4958207b54dc712e28ac97b151ecf 100644 (file)
@@ -124,7 +124,13 @@ for i in range(0,N_SPI):
 bsv_file.write("\n")
 ######################################################################
 #########################== Actual pinmuxing ==#######################
+bsv_file.write('''
+               /*================= This where the muxing starts for each io-cell=================*/ 
+''')
 bsv_file.write(pinmux);
+bsv_file.write('''
+               /*================================================================================*/ 
+''')
 ######################################################################
 ################=== interface definitions for each method ===###########
 for i in range(0,N_IO):
index 1568fe41cee9f3bb286ad05a036f99043a8ef0c2..d7e3e8a3b8552b34e1a9958e7e0d76c074ea2578 100644 (file)
@@ -21,16 +21,16 @@ spiwires='''
                Wire#(Bit#(1)) wrspi{0}_mosi <-mkDWire(0);
                Wire#(Bit#(1)) wrspi{0}_ss        <-mkDWire(0);
                Wire#(Bit#(1)) wrspi{0}_miso <-mkDWire(0);
-               GenericIOType spi{0}_sclk = GenericIOType{{outputval:wrspi{0}_sclk, output_en:1, input_en:0,
+               GenericIOType spi{0}_sclk_io = GenericIOType{{outputval:wrspi{0}_sclk, output_en:1, input_en:0,
                                                                                                                           pullup_en:0, pulldown_en:0, pushpull_en:0,
                                                                                                                                drivestrength:0, opendrain_en:0}};
-               GenericIOType spi{0}_mosi = GenericIOType{{outputval:wrspi{0}_mosi, output_en:1, input_en:0,
+               GenericIOType spi{0}_mosi_io = GenericIOType{{outputval:wrspi{0}_mosi, output_en:1, input_en:0,
                                                                                                                           pullup_en:0, pulldown_en:0, pushpull_en:0,
                                                                                                                                drivestrength:0, opendrain_en:0}};
-               GenericIOType spi{0}_ss = GenericIOType{{outputval:wrspi{0}_ss, output_en:1, input_en:0,
+               GenericIOType spi{0}_ss_io = GenericIOType{{outputval:wrspi{0}_ss, output_en:1, input_en:0,
                                                                                                                           pullup_en:0, pulldown_en:0, pushpull_en:0,
                                                                                                                                drivestrength:0, opendrain_en:0}};
-               GenericIOType spi{0}_miso = GenericIOType{{outputval:0, output_en:0, input_en:1,
+               GenericIOType spi{0}_miso_io = GenericIOType{{outputval:0, output_en:0, input_en:1,
                                                                                                                           pullup_en:0, pulldown_en:0, pushpull_en:0,
                                                                                                                                drivestrength:0, opendrain_en:0}};