addeds i2c (twi) interface and also support for inouts
[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 "twi_sda" :"inout",
14 "twi_scl" :"inout"
15 }
16
17
18 ########### common bsv templates ############
19 assign_cell='''cell{0}_out=wrmux{0}=={1}?'''
20 # first argument is the io-cell number being assigned.
21 # second argument is the mux value.
22 # Third argument is the signal from the pinmap file
23 input_wire='''
24 rule assign_{2}_on_cell{0}(wrmux{0}=={1});
25 {2}<=cell{0}_in;
26 endrule
27 '''
28 #########################################
29 pinmux=''' '''
30 pinmap_file=open("./pinmap.txt","r")
31 for lineno,line in enumerate(pinmap_file):
32 line1=line.split()
33 if(lineno>0):
34 if(lineno>N_IO):
35 print("ERROR: Parameter N_IO("+str(N_IO)+") is less than the pin number in line: "+str(lineno)+" of pinmap.txt")
36 exit(1)
37 ######## Mux each generic IO cell with the mapping######
38 # provided in the pinmap file
39 pinmux=pinmux+" cell"+str(line1[0])+"_out="
40 i=0
41 while(i<len(line1)-1):
42 pinmux=pinmux+"wrmux"+str(line1[0])+"=="+str(i)+"?"+line1[i+1]+"_io:"
43 if(i+2==len(line1)-1):
44 pinmux=pinmux+line1[i+2]+"_io"
45 i=i+2
46 else:
47 i=i+1
48 pinmux=pinmux+";\n"
49 ########################################################
50
51 ###### check each cell if "peripheral input/inout" then assign its wire ########
52 ## Here we check the direction of each signal in the dictionary.
53 ## We choose to keep the dictionary within the code and not user-input
54 ## since the interfaces are always standard and cannot change from user-to-user.
55 ## Plus this also reduces human-error as well :)
56 for i in range(0,len(line1)-1):
57 digits = str.maketrans(dict.fromkeys('0123456789'))
58 temp=line1[i+1].translate(digits)
59 x=dictionary.get(temp);
60 if(x==None):
61 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.")
62 exit(1)
63 if(x=="input"):
64 print(line1[i+1]+" "+x)
65 pinmux=pinmux+input_wire.format(line1[0],i,"wr"+line1[i+1])+"\n"
66 elif(x=="inout"):
67 print(line1[i+1]+" "+x)
68 pinmux=pinmux+input_wire.format(line1[0],i,"wr"+line1[i+1]+"_in")+"\n"
69 ################################################################################
70 ###########################################
71