dbea8d5609ebd274dc64e9c4a267a81b7713c5e4
1 # ================================== Steps to add peripherals ============
2 # Step-1: create interface declaration for the peripheral to be added.
3 # Remember these are interfaces defined for the pinmux and hence
4 # will be opposite to those defined at the peripheral.
5 # For eg. the output TX from the UART will be input (method Action)
7 # These changes will have to be done in interface_decl.py
8 # Step-2 define the wires that will be required to transfer data from the
9 # peripheral interface to the IO cell and vice-versa. Create a
10 # mkDWire for each input/output between the peripheral and the
11 # pinmux. Also create an implicit wire of GenericIOType for each cell
12 # that can be connected to a each bit from the peripheral.
13 # These changes will have to be done in wire_def.py
14 # Step-3: create the definitions for each of the methods defined above.
15 # These changes will have to be done in interface_decl.py
16 # ========================================================================
18 # default module imports
23 # project module imports
24 from interface_decl
import *
25 from interface_def
import *
27 from wire_def
import *
28 from actual_pinmux
import *
30 if not os
.path
.exists("bsv_src"):
31 os
.makedirs("bsv_src")
33 bsv_file
= open("./bsv_src/pinmux.bsv", "w")
36 This BSV file has been generated by the PinMux tool available at:
37 https://bitbucket.org/casl/pinmux.
39 Authors: Neel Gala, Luke
40 Date of generation: ''' + time
.strftime("%c") + '''
45 Bit#(1) outputval; // output from core to pad bit7
46 Bit#(1) output_en; // output enable from core to pad bit6
47 Bit#(1) input_en; // input enable from core to io_cell bit5
48 Bit#(1) pullup_en; // pullup enable from core to io_cell bit4
49 Bit#(1) pulldown_en; // pulldown enable from core to io_cell bit3
50 Bit#(1) drivestrength; // drivestrength from core to io_cell bit2
51 Bit#(1) pushpull_en; // pushpull enable from core to io_cell bit1
52 Bit#(1) opendrain_en; // opendrain enable form core to io_cell bit0
53 } GenericIOType deriving(Eq,Bits,FShow);
61 # ============================================#
62 # ==== populating the file with the code =====#
63 # ============================================#
65 # package and interface declaration followed by the generic io_cell definition
66 bsv_file
.write(header
)
70 // declare the method which will capture the user pin-mux
71 // selection values.The width of the input is dependent on the number
72 // of muxes happening per IO. For now we have a generalized width
73 // where each IO will have the same number of muxes.''')
75 for i
in range(0, N_IO
):
76 bsv_file
.write(mux_interface
.format(i
))
80 // declare the interface to the IO cells.
81 // Each IO cell will have 8 input field (output from pin mux
82 // and on output field (input to pinmux)''')
83 for i
in range(0, N_IO
):
84 bsv_file
.write('''\n // interface for IO CEll-{0}''')
85 bsv_file
.write(io_interface
.format(i
))
86 # ==============================================================
88 # == create method definitions for all peripheral interfaces ==#
89 for i
in range(0, N_UART
):
91 // interface declaration between UART-{0} and pinmux'''.format(i
))
92 bsv_file
.write(uartinterface_decl
.format(i
))
94 for i
in range(0, N_SPI
):
96 // interface declaration between SPI-{0} and pinmux'''.format(i
))
97 bsv_file
.write(spiinterface_decl
.format(i
))
99 for i
in range(0, N_TWI
):
101 // interface declaration between TWI-{0} and pinmux'''.format(i
))
102 bsv_file
.write(twiinterface_decl
.format(i
))
103 # ==============================================================
105 # ===== finish interface definition and start module definition=======
109 module mkpinmux(Ifc_pinmux);
111 # ====================================================================
113 # ======================= create wire and registers =================#
115 // the followins wires capture the pin-mux selection
116 // values for each mux assigned to a CELL
118 for i
in range(0, N_IO
):
119 bsv_file
.write(muxwire
.format(i
))
123 '''\n // following wires capture the values sent to the IO Cell''')
124 for i
in range(0, N_IO
):
125 bsv_file
.write(generic_io
.format(i
))
127 for i
in range(0, N_UART
):
129 '''\n // following wires capture signals to IO CELL if uart-{0} is
130 // allotted to it'''.format(i
))
131 bsv_file
.write(uartwires
.format(i
))
133 for i
in range(0, N_SPI
):
135 '''\n // following wires capture signals to IO CELL if spi-{0} is
136 // allotted to it'''.format(i
))
137 bsv_file
.write(spiwires
.format(i
))
139 for i
in range(0, N_TWI
):
141 '''\n // following wires capture signals to IO CELL if twi-{0} is
142 // allotted to it'''.format(i
))
143 bsv_file
.write(twiwires
.format(i
))
145 # ====================================================================
146 # ========================= Actual pinmuxing ========================#
148 /*====== This where the muxing starts for each io-cell======*/
150 bsv_file
.write(pinmux
)
152 /*============================================================*/
154 # ====================================================================
155 # ================= interface definitions for each method =============#
156 for i
in range(0, N_IO
):
157 bsv_file
.write(mux_interface_def
.format(i
))
158 for i
in range(0, N_IO
):
159 bsv_file
.write(io_interface_def
.format(i
))
160 for i
in range(0, N_UART
):
161 bsv_file
.write(uartinterface_def
.format(i
))
162 for i
in range(0, N_SPI
):
163 bsv_file
.write(spiinterface_def
.format(i
))
164 for i
in range(0, N_TWI
):
165 bsv_file
.write(twiinterface_def
.format(i
))
166 bsv_file
.write(footer
)
167 print("BSV file successfully generated: bsv_src/pinmux.bsv")
168 # ======================================================================