1 #############################======= Steps to add peripherals =======#######################
2 # Step-1: create interface declaration for the peripheral to be added. Remember these are
3 # interfaces defined for the pinmux and hence will be opposite to those defined
4 # at the peripheral. For eg. the output TX from the UART will be input (method Action)
5 # for the pinmux. These changes will have to be done in interface_decl.py
6 # Step-2 define the wires that will be required to transfer data from the peripheral interface
7 # to the IO cell and vice-versa. Create a mkDWire for each input/output between the
8 # the peripheral and the pinmux. Also create an implicit wire of GenericIOType
9 # for each cell that can be connected to a each bit from the peripheral.
10 # These changes will have to be done in wire_def.py
11 # Step-3: create the definitions for each of the methods defined above.
12 # These changes will have to be done in interface_decl.py
13 ############################################################################################
15 # default module imports
20 # project module imports
21 from interface_decl
import *
22 from interface_def
import *
24 from wire_def
import *
25 from actual_pinmux
import *
27 if not os
.path
.exists("bsv_src"):
28 os
.makedirs("bsv_src")
30 bsv_file
=open("./bsv_src/pinmux.bsv","w")
33 This BSV file has been generated by the PinMux tool available at: <website>.
34 Authors: Neel Gala, Luke
35 Date of generation: '''+time
.strftime("%c")+'''
40 Bit#(1) outputval; // output from core to pad bit7
41 Bit#(1) output_en; // output enable from core to pad bit6
42 Bit#(1) input_en; // input enable from core to io_cell bit5
43 Bit#(1) pullup_en; // pullup enable from core to io_cell bit4
44 Bit#(1) pulldown_en; // pulldown enable from core to io_cell bit3
45 Bit#(1) drivestrength; // drivestrength from core to io_cell bit2
46 Bit#(1) pushpull_en; // pushpull enable from core to io_cell bit1
47 Bit#(1) opendrain_en; // opendrain enable form core to io_cell bit0
48 } GenericIOType deriving(Eq,Bits,FShow);
56 ###############################################
57 ###=== populating the file with the code ===###
58 ###############################################
60 # package and interface declaration followed by the generic io_cell definition
61 bsv_file
.write(header
)
65 // declare the method which will capture the user pin-mux selection values.
66 // The width of the input is dependent on the number of muxes happening per IO.
67 // For now we have a generalized width where each IO will have the same number
70 for i
in range(0,N_IO
):
71 bsv_file
.write(mux_interface
.format(i
))
75 // declare the interface to the IO cells.
76 // Each IO cell will have 8 input field (output from pin mux
77 // and on output field (input to pinmux)''' );
78 for i
in range(0,N_IO
):
79 bsv_file
.write('''\n // interface for IO CEll-{0}''')
80 bsv_file
.write(io_interface
.format(i
))
81 ################################################################
83 #== create method definitions for all peripheral interfaces ==#
84 for i
in range(0,N_UART
):
86 // interface declaration between UART-{0} and pinmux'''.format(i
))
87 bsv_file
.write(uartinterface_decl
.format(i
));
89 for i
in range(0,N_SPI
):
91 // interface declaration between SPI-{0} and pinmux'''.format(i
))
92 bsv_file
.write(spiinterface_decl
.format(i
));
94 for i
in range(0,N_TWI
):
96 // interface declaration between TWI-{0} and pinmux'''.format(i
))
97 bsv_file
.write(twiinterface_decl
.format(i
));
98 ################################################################
100 ####=== finish interface definition and start module definition===####
103 module mkpinmux(Ifc_pinmux);
105 ######################################################################
107 #######################== create wire and registers ===###############
109 // the followins wires capture the pin-mux selection
110 // values for each mux assigned to a CELL
112 for i
in range(0,N_IO
):
113 bsv_file
.write(muxwire
.format(i
))
116 bsv_file
.write('''\n // following wires capture the values to be sent to the IO Cell''')
117 for i
in range(0,N_IO
):
118 bsv_file
.write(generic_io
.format(i
))
120 for i
in range(0,N_UART
):
121 bsv_file
.write('''\n // following wires capture the parameters to the IO CELL if uart-{0} is
122 // allotted to it'''.format(i
))
123 bsv_file
.write(uartwires
.format(i
))
125 for i
in range(0,N_SPI
):
126 bsv_file
.write('''\n // following wires capture the parameters to the IO CELL if spi-{0} is
127 // allotted to it'''.format(i
))
128 bsv_file
.write(spiwires
.format(i
))
130 for i
in range(0,N_TWI
):
131 bsv_file
.write('''\n // following wires capture the parameters to the IO CELL if twi-{0} is
132 // allotted to it'''.format(i
))
133 bsv_file
.write(twiwires
.format(i
))
135 ######################################################################
136 #########################== Actual pinmuxing ==#######################
138 /*================= This where the muxing starts for each io-cell=================*/
140 bsv_file
.write(pinmux
);
142 /*================================================================================*/
144 ######################################################################
145 ################=== interface definitions for each method ===###########
146 for i
in range(0,N_IO
):
147 bsv_file
.write(mux_interface_def
.format(i
))
148 for i
in range(0,N_IO
):
149 bsv_file
.write(io_interface_def
.format(i
))
150 for i
in range(0,N_UART
):
151 bsv_file
.write(uartinterface_def
.format(i
))
152 for i
in range(0,N_SPI
):
153 bsv_file
.write(spiinterface_def
.format(i
))
154 for i
in range(0,N_TWI
):
155 bsv_file
.write(twiinterface_def
.format(i
))
156 bsv_file
.write(footer
)
157 ########################################################################