From: Neel Date: Mon, 16 Jul 2018 08:45:42 +0000 (+0530) Subject: parameterized modules for mux and gpio X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=93dc2eef3dbc55079fa23871fd02d0596feef02f;p=pinmux.git parameterized modules for mux and gpio --- diff --git a/src/bsv/bsv_lib/Makefile.gpio.templates b/src/bsv/bsv_lib/Makefile.gpio.templates index 8e9060f..60a241d 100644 --- a/src/bsv/bsv_lib/Makefile.gpio.templates +++ b/src/bsv/bsv_lib/Makefile.gpio.templates @@ -1,6 +1,6 @@ ### Makefile for the srio -TOP_MODULE:=mkgpio +TOP_MODULE:=mkgpio_real TOP_FILE:=gpio.bsv HOMEDIR:=./ TOP_DIR:=./ @@ -19,7 +19,7 @@ timing_area: full_clean generate_verilog vivado_build compile: @echo Compiling $(TOP_MODULE).... @mkdir -p $(BSVBUILDDIR) - @bsc -u -sim -simdir $(BSVBUILDDIR) -bdir $(BSVBUILDDIR) -info-dir $(BSVBUILDDIR) -keep-fires -p $(BSVINCDIR) -g $(TOP_MODULE) $(TOP_DIR)/$(TOP_FILE) + @bsc -u -sim -simdir $(BSVBUILDDIR) -bdir $(BSVBUILDDIR) -info-dir $(BSVBUILDDIR) -keep-fires -p $(BSVINCDIR) -D NAME=neel -g $(TOP_MODULE) $(TOP_DIR)/$(TOP_FILE) @echo Compilation finished .PHONY: link diff --git a/src/bsv/bsv_lib/gpio.bsv b/src/bsv/bsv_lib/gpio.bsv index cf44bd4..203bfdf 100644 --- a/src/bsv/bsv_lib/gpio.bsv +++ b/src/bsv/bsv_lib/gpio.bsv @@ -24,105 +24,79 @@ package gpio; /*============================ */ `define ADDR 32 `define DATA 64 - `define USER 0 - `define IONum 32 - `define GPIO_MUX + `define USERSPACE 0 - interface GPIO; + interface GPIO#(numeric type ionum); (*always_ready,always_enabled*) - method Action gpio_in (Vector#(`IONum,Bit#(1)) inp); - method Vector#(`IONum,Bit#(1)) gpio_out; - method Vector#(`IONum,Bit#(1)) gpio_out_en; - method Vector#(`IONum,Bit#(1)) gpio_DRV0; - method Vector#(`IONum,Bit#(1)) gpio_DRV1; - method Vector#(`IONum,Bit#(1)) gpio_DRV2; - method Vector#(`IONum,Bit#(1)) gpio_PD; - method Vector#(`IONum,Bit#(1)) gpio_PPEN; - method Vector#(`IONum,Bit#(1)) gpio_PRG_SLEW; - method Vector#(`IONum,Bit#(1)) gpio_PUQ; - method Vector#(`IONum,Bit#(1)) gpio_PWRUPZHL; - method Vector#(`IONum,Bit#(1)) gpio_PWRUP_PULL_EN; - interface Vector#(`IONum,Reg#(Bit#(1))) to_plic; - `ifdef GPIO_MUX - method Vector#(`IONum,Bit#(2)) gpio_MUX; - `endif - interface AXI4_Lite_Slave_IFC#(`ADDR,`DATA,`USER) axi_slave; + method Action gpio_in (Vector#(ionum,Bit#(1)) inp); + method Vector#(ionum,Bit#(1)) gpio_out; + method Vector#(ionum,Bit#(1)) gpio_out_en; + method Vector#(ionum,Bit#(1)) gpio_DRV0; + method Vector#(ionum,Bit#(1)) gpio_DRV1; + method Vector#(ionum,Bit#(1)) gpio_DRV2; + method Vector#(ionum,Bit#(1)) gpio_PD; + method Vector#(ionum,Bit#(1)) gpio_PPEN; + method Vector#(ionum,Bit#(1)) gpio_PRG_SLEW; + method Vector#(ionum,Bit#(1)) gpio_PUQ; + method Vector#(ionum,Bit#(1)) gpio_PWRUPZHL; + method Vector#(ionum,Bit#(1)) gpio_PWRUP_PULL_EN; + interface AXI4_Lite_Slave_IFC#(`ADDR,`DATA,`USERSPACE) axi_slave; endinterface - (*synthesize*) - module mkgpio(GPIO); - Vector#(`IONum,ConfigReg#(Bool)) direction_reg <-replicateM(mkConfigReg(False)); - Vector#(`IONum,ConfigReg#(Bit#(1))) dataout_register <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) datain_register <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) drv0_reg <-replicateM(mkConfigReg(1'b1)); - Vector#(`IONum,ConfigReg#(Bit#(1))) drv1_reg <-replicateM(mkConfigReg(1'b1)); - Vector#(`IONum,ConfigReg#(Bit#(1))) drv2_reg <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) pd_reg <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) ppen_reg <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) prg_slew_reg <-replicateM(mkConfigReg(1'b1)); - Vector#(`IONum,ConfigReg#(Bit#(1))) puq_reg <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) pwrupzhl_reg <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) pwrup_pull_en_reg <-replicateM(mkConfigReg(0)); - Vector#(`IONum,ConfigReg#(Bit#(1))) toplic <-replicateM(mkConfigReg(0)); - `ifdef GPIO_MUX - Vector#(`IONum,ConfigReg#(Bit#(2))) muxer_reg <-replicateM(mkConfigReg(0)); - `endif + module mkgpio(GPIO#(ionum_)); + let ionum = valueOf(ionum_); + Vector#(ionum_,ConfigReg#(Bool)) direction_reg <-replicateM(mkConfigReg(False)); + Vector#(ionum_,ConfigReg#(Bit#(1))) dataout_register <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) datain_register <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) drv0_reg <-replicateM(mkConfigReg(1'b1)); + Vector#(ionum_,ConfigReg#(Bit#(1))) drv1_reg <-replicateM(mkConfigReg(1'b1)); + Vector#(ionum_,ConfigReg#(Bit#(1))) drv2_reg <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) pd_reg <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) ppen_reg <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) prg_slew_reg <-replicateM(mkConfigReg(1'b1)); + Vector#(ionum_,ConfigReg#(Bit#(1))) puq_reg <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) pwrupzhl_reg <-replicateM(mkConfigReg(0)); + Vector#(ionum_,ConfigReg#(Bit#(1))) pwrup_pull_en_reg <-replicateM(mkConfigReg(0)); - AXI4_Lite_Slave_Xactor_IFC #(`ADDR, `DATA, `USER) s_xactor <- mkAXI4_Lite_Slave_Xactor; - let ionum=valueOf(`IONum); - rule capture_interrupt; - for(Integer i=0;i<`IONum;i=i+1) - toplic[i]<=(!direction_reg[i])?datain_register[i]:0; - endrule - + AXI4_Lite_Slave_Xactor_IFC #(`ADDR, `DATA, `USERSPACE) s_xactor <- mkAXI4_Lite_Slave_Xactor; rule rl_wr_respond; // Get the wr request let aw <- pop_o (s_xactor.o_wr_addr); let w <- pop_o (s_xactor.o_wr_data); let b = AXI4_Lite_Wr_Resp {bresp: AXI4_LITE_OKAY, buser: aw.awuser}; if(aw.awaddr[5:0]=='h0) - for(Integer i=0;i<`IONum;i=i+1) + for(Integer i=0;i=16) - for(Integer i=0;i<`IONum-16;i=i+1) begin - muxer_reg[i+16]<= w.wdata[i*2+1:i*2]; - end - `endif else b.bresp=AXI4_LITE_SLVERR; @@ -132,76 +106,62 @@ package gpio; rule rl_rd_respond; let ar<- pop_o(s_xactor.o_rd_addr); Bit#(32) temp=0; - AXI4_Lite_Rd_Data#(`DATA,`USER) r = AXI4_Lite_Rd_Data {rresp: AXI4_LITE_OKAY, rdata: ?, ruser: 0}; + AXI4_Lite_Rd_Data#(`DATA,`USERSPACE) r = AXI4_Lite_Rd_Data {rresp: AXI4_LITE_OKAY, rdata: ?, ruser: 0}; if(ar.araddr[5:0]=='h0)begin - for(Integer i=0;i<`IONum;i=i+1) + for(Integer i=0;i=16)begin - for(Integer i=0;i<`IONum-16;i=i+1) begin - temp[i*2+ 1:i*2]=muxer_reg[i+ 16]; - end - r.rdata=duplicate(temp); - end - `endif else r.rresp=AXI4_LITE_SLVERR; @@ -209,83 +169,112 @@ package gpio; endrule interface axi_slave= s_xactor.axi_side; - method Action gpio_in (Vector#(`IONum,Bit#(1)) inp); - for(Integer i=0;i<`IONum;i=i+1) + method Action gpio_in (Vector#(ionum,Bit#(1)) inp); + for(Integer i=0;i=16) + for(Integer i=0;i=16)begin + for(Integer i=0;i