change rule names to allow implicit scheduling
[pinmux.git] / src / actual_pinmux.py
1 from params import *
2 from string import digits
3
4
5 ## dictionary of properties of signals that are supported.
6 dictionary={
7 "uart_rx" :"input",
8 "uart_tx" :"output",
9 "spi_sclk" :"output",
10 "spi_mosi" :"output",
11 "spi_ss" :"output",
12 "spi_miso" :"input"
13 }
14
15
16 ########### common bsv templates ############
17 assign_cell='''cell{0}_out=wrmux{0}=={1}?'''
18 # first argument is the io-cell number being assigned.
19 # second argument is the mux value.
20 # Third argument is the signal from the pinmap file
21 input_wire='''
22 rule assign_input_for_{2}_on_cell{0}(wrmux{0}=={1});
23 wr{2}<=cell{0}_in;
24 endrule
25 '''
26 #########################################
27 pinmux=''' '''
28 pinmap_file=open("./pinmap.txt","r")
29 for lineno,line in enumerate(pinmap_file):
30 line1=line.split()
31 if(lineno>0):
32 if(lineno>N_IO):
33 print"ERROR: Parameter N_IO("+str(N_IO)+") is less than the pin number in line: "+str(lineno)+" of pinmap.txt"
34 exit(1)
35 ######## Mux each generic IO cell with the mapping######
36 # provided in the pinmap file
37 pinmux=pinmux+" cell"+str(line1[0])+"_out="
38 i=0
39 while(i<len(line1)-1):
40 pinmux=pinmux+"wrmux"+str(line1[0])+"=="+str(i)+"?"+line1[i+1]+"_io:"
41 if(i+2==len(line1)-1):
42 pinmux=pinmux+line1[i+2]+"_io"
43 i=i+2
44 else:
45 i=i+1
46 pinmux=pinmux+";\n"
47 ########################################################
48
49 ###### check each cell if "peripheral input/inout" then assign its wire ########
50 ## Here we check the direction of each signal in the dictionary.
51 ## We choose to keep the dictionary within the code and not user-input
52 ## since the interfaces are always standard and cannot change from user-to-user
53 ## plus reduces human-error as well :)
54 for i in range(0,len(line1)-1):
55 temp=line1[i+1].translate(None,digits)
56 x=dictionary.get(temp);
57 if(x==None):
58 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."
59 exit(1)
60 if(x=="input" or x=="inout"):
61 pinmux=pinmux+input_wire.format(line1[0],i,line1[i+1])+"\n"
62 ################################################################################
63 ###########################################
64