muxed
0 uart0_tx spi0_sclk
1 uart0_rx spi0_mosi
-2 spi0_ss uart0_rx
-3 uart1_tx spi0_miso
+2 twi0_sda spi0_ss
+3 twi0_scl spi0_miso
"spi_sclk" :"output",
"spi_mosi" :"output",
"spi_ss" :"output",
- "spi_miso" :"input"
+ "spi_miso" :"input",
+ "twi_sda" :"inout",
+ "twi_scl" :"inout"
}
# second argument is the mux value.
# Third argument is the signal from the pinmap file
input_wire='''
- rule assign_input_for_{2}_on_cell{0}(wrmux{0}=={1});
- wr{2}<=cell{0}_in;
+ rule assign_{2}_on_cell{0}(wrmux{0}=={1});
+ {2}<=cell{0}_in;
endrule
'''
#########################################
###### 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 :)
+ ## since the interfaces are always standard and cannot change from user-to-user.
+ ## Plus this also reduces human-error as well :)
for i in range(0,len(line1)-1):
digits = str.maketrans(dict.fromkeys('0123456789'))
temp=line1[i+1].translate(digits)
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" or x=="inout"):
- pinmux=pinmux+input_wire.format(line1[0],i,line1[i+1])+"\n"
+ if(x=="input"):
+ print(line1[i+1]+" "+x)
+ pinmux=pinmux+input_wire.format(line1[0],i,"wr"+line1[i+1])+"\n"
+ elif(x=="inout"):
+ print(line1[i+1]+" "+x)
+ pinmux=pinmux+input_wire.format(line1[0],i,"wr"+line1[i+1]+"_in")+"\n"
################################################################################
###########################################
(*always_ready,always_enabled*) method Action ss_{0} (Bit#(1) in);
(*always_ready,always_enabled*) method Bit#(1) miso_{0};
'''
+
+twiinterface_decl='''
+ (*always_ready,always_enabled*) method Action sda{0}_out (Bit#(1) in);
+ (*always_ready,always_enabled*) method Action sda{0}_outen (Bit#(1) in);
+ (*always_ready,always_enabled*) method Bit#(1) sda{0}_in;
+ (*always_ready,always_enabled*) method Action scl{0}_out (Bit#(1) in);
+ (*always_ready,always_enabled*) method Action scl{0}_outen (Bit#(1) in);
+ (*always_ready,always_enabled*) method Bit#(1) scl{0}_in;
+'''
#=======================================#
endmethod
method Bit#(1) miso_{0}=wrspi{0}_miso;
'''
+
+twiinterface_def='''
+
+ method Action sda{0}_out (Bit#(1) in);
+ wrtwi{0}_sda_out<=in;
+ endmethod
+ method Action sda{0}_outen (Bit#(1) in);
+ wrtwi{0}_sda_outen<=in;
+ endmethod
+ method sda{0}_in=wrtwi{0}_sda_in;
+
+ method Action scl{0}_out (Bit#(1) in);
+ wrtwi{0}_scl_out<=in;
+ endmethod
+ method Action scl{0}_outen (Bit#(1) in);
+ wrtwi{0}_scl_outen<=in;
+ endmethod
+ method scl{0}_in=wrtwi{0}_scl_in;
+
+'''
#==============================================#
N_IO=4
N_UART=2
N_SPI=1
+N_TWI=1
#================#
bsv_file.write('''
// interface declaration between SPI-{0} and pinmux'''.format(i))
bsv_file.write(spiinterface_decl.format(i));
+
+for i in range(0,N_TWI):
+ bsv_file.write('''
+ // interface declaration between TWI-{0} and pinmux'''.format(i))
+ bsv_file.write(twiinterface_decl.format(i));
################################################################
####=== finish interface definition and start module definition===####
bsv_file.write('''\n // following wires capture the parameters to the IO CELL if spi-{0} is
// allotted to it'''.format(i))
bsv_file.write(spiwires.format(i))
+
+for i in range(0,N_TWI):
+ bsv_file.write('''\n // following wires capture the parameters to the IO CELL if twi-{0} is
+ // allotted to it'''.format(i))
+ bsv_file.write(twiwires.format(i))
bsv_file.write("\n")
######################################################################
#########################== Actual pinmuxing ==#######################
bsv_file.write(uartinterface_def.format(i))
for i in range(0,N_SPI):
bsv_file.write(spiinterface_def.format(i))
+for i in range(0,N_TWI):
+ bsv_file.write(twiinterface_def.format(i))
bsv_file.write(footer)
########################################################################
drivestrength:0, opendrain_en:0}};
'''
+twiwires='''
+ Wire#(Bit#(1)) wrtwi{0}_sda_out<-mkDWire(0);
+ Wire#(Bit#(1)) wrtwi{0}_sda_outen<-mkDWire(0);
+ Wire#(Bit#(1)) wrtwi{0}_sda_in<-mkDWire(0);
+ Wire#(Bit#(1)) wrtwi{0}_scl_out<-mkDWire(0);
+ Wire#(Bit#(1)) wrtwi{0}_scl_outen<-mkDWire(0);
+ Wire#(Bit#(1)) wrtwi{0}_scl_in<-mkDWire(0);
+ GenericIOType twi{0}_sda_io = GenericIOType{{outputval:wrtwi{0}_sda_out, output_en:wrtwi{0}_sda_outen, input_en:~wrtwi{0}_sda_outen,
+ pullup_en:0, pulldown_en:0, pushpull_en:0,
+ drivestrength:0, opendrain_en:0}};
+ GenericIOType twi{0}_scl_io = GenericIOType{{outputval:wrtwi{0}_scl_out, output_en:wrtwi{0}_scl_outen, input_en:~wrtwi{0}_scl_outen,
+ pullup_en:0, pulldown_en:0, pushpull_en:0,
+ drivestrength:0, opendrain_en:0}};
+'''
#===================================#