@@ -77,6 +77,7 @@ parameter MuxGPIOIOWidth = 36;
7777parameter NumIOAddrReg = 6 ;
7878parameter NumGPIO = 2 ;
7979
80+ parameter Capsense = 1 ;
8081parameter NumSense = 4 ;
8182parameter ADC = " " ;
8283// local param
@@ -255,7 +256,7 @@ adc_ltc2308_fifo adc_ltc2308_fifo_inst
255256 assign mux_reg_index = busaddress_r - 16'h1120 ;
256257 assign mux_reg_addr = (mux_reg_index[6 : 2 ]);
257258 assign mux_reg_byte = (mux_reg_index[1 : 0 ]);
258-
259+ generate if (Capsense >= 1 ) begin
259260 // Writes:
260261 always @ ( posedge reset_in or posedge write_address) begin
261262 if (reset_in) begin
@@ -265,7 +266,9 @@ adc_ltc2308_fifo adc_ltc2308_fifo_inst
265266 if (busaddress_r == 10'h0304 ) begin hysteresis_reg <= busdata_in_r; end
266267 end
267268 end
268-
269+ end
270+ endgenerate
271+
269272 genvar il;
270273 generate
271274 for (il= 0 ;il< NumIOAddrReg;il= il+ 1 ) begin : reg_initloop
@@ -323,7 +326,7 @@ adc_ltc2308_fifo adc_ltc2308_fifo_inst
323326// wire [GPIOWidth-1:0] gpio1_out_data = {gpio1_data_fromhm3[GPIOWidth-1:5],4'bz,charge};
324327// wire [GPIOWidth-1:0] gpio1_input_data;
325328// assign gpio_input_data[1] = {gpio1_input_data[GPIOWidth-1:5],sense,charge};
326-
329+ generate if (Capsense >= 1 ) begin
327330 bidir_io # (.IOWidth (GPIOWidth * NumGPIO),.PortNumWidth (PortNumWidth)) bidir_io_inst
328331 (
329332 .clk (reg_clk),
@@ -334,8 +337,20 @@ adc_ltc2308_fifo adc_ltc2308_fifo_inst
334337 .gpioport ({ gpioport[1 ],gpioport[0 ]} ) , // inout [IOIOWidth-1:0] gpioport_sig
335338 .data_from_gpio ({ gpio_input_data[1 ],gpio_input_data[0 ]} ) // output [IOIOWidth-1:0] read_data_sig
336339 );
337-
338-
340+ end
341+ else begin
342+ bidir_io # (.IOWidth (GPIOWidth * NumGPIO),.PortNumWidth (PortNumWidth)) bidir_io_inst
343+ (
344+ .clk (reg_clk),
345+ .portselnum (portnumsel),
346+ .out_ena ({ out_ena[1 ],out_ena[0 ]} ) , // input out_ena_sig
347+ .od ({ od[1 ],od[0 ]} ) , // input od_sig
348+ .out_data ({ iodatafromhm3[1 ], iodatafromhm3[0 ]} ) , // input [IOIOWidth-1:0] out_data_sig
349+ .gpioport ({ gpioport[1 ],gpioport[0 ]} ) , // inout [IOIOWidth-1:0] gpioport_sig
350+ .data_from_gpio ({ gpio_input_data[1 ],gpio_input_data[0 ]} ) // output [IOIOWidth-1:0] read_data_sig
351+ );
352+ end
353+ endgenerate
339354 // Read:
340355
341356 integer oo,om,oi;
@@ -346,57 +361,85 @@ adc_ltc2308_fifo adc_ltc2308_fifo_inst
346361 busdata_to_cpu <= 32'b0 ;
347362 end
348363 else if (read_address) begin
349- if (adc_address_valid) begin busdata_to_cpu <= adc_data_out; end
350- // if ((busaddress_r == 'h0200) || (busaddress_r == 'h0204)) begin busdata_to_cpu <= adc_data_out; end
351- else if (busaddress_r == 'h0300 ) begin busdata_to_cpu <= touched; end
352- else if (busaddress_r == 'h0304 ) begin busdata_to_cpu <= hysteresis_reg; end
353- else if (busaddress_r == 'h1000 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[0 ][23 : 0 ]} ; end
354- else if (busaddress_r == 'h1004 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[1 ][11 : 0 ],gpio_input_data[0 ][35 : 24 ]} ; end
355- else if (busaddress_r == 'h1008 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[1 ][35 : 12 ]} ; end
356- // else if(busaddress_r == 'h100c) begin busdata_to_cpu <= {8'b0,gpio_input_data[2][23:0]}; end
357- // else if(busaddress_r == 'h1010) begin busdata_to_cpu <= {8'b0,gpio_input_data[3][11:0],gpio_input_data[2][35:24]}; end
358- // else if(busaddress_r == 'h1014) begin busdata_to_cpu <= {8'b0,gpio_input_data[3][35:12]}; end
359- // else if ((busaddress_r >= 16'h1100) && (busaddress_r < 16'h1200)) begin
360- else if (ddr_address_valid || od_address_valid) begin
361- for (oo= 0 ;oo< NumIOAddrReg;oo= oo+ 1 ) begin : reggen_loop
362- if (busaddress_r == ('h1100 + (oo* 4 ))) begin busdata_to_cpu <= ddr_reg[oo]; end
363- else if (busaddress_r == ('h1300 + (oo* 4 ))) begin busdata_to_cpu <= od_reg[oo]; end
364+ if (Capsense >= 1 ) begin
365+ if (adc_address_valid) begin busdata_to_cpu <= adc_data_out; end
366+ else if (busaddress_r == 'h0300 ) begin busdata_to_cpu <= touched; end
367+ else if (busaddress_r == 'h0304 ) begin busdata_to_cpu <= hysteresis_reg; end
368+ else if (busaddress_r == 'h1000 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[0 ][23 : 0 ]} ; end
369+ else if (busaddress_r == 'h1004 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[1 ][11 : 0 ],gpio_input_data[0 ][35 : 24 ]} ; end
370+ else if (busaddress_r == 'h1008 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[1 ][35 : 12 ]} ; end
371+ // else if(busaddress_r == 'h100c) begin busdata_to_cpu <= {8'b0,gpio_input_data[2][23:0]}; end
372+ // else if(busaddress_r == 'h1010) begin busdata_to_cpu <= {8'b0,gpio_input_data[3][11:0],gpio_input_data[2][35:24]}; end
373+ // else if(busaddress_r == 'h1014) begin busdata_to_cpu <= {8'b0,gpio_input_data[3][35:12]}; end
374+ // else if ((busaddress_r >= 16'h1100) && (busaddress_r < 16'h1200)) begin
375+ else if (ddr_address_valid || od_address_valid) begin
376+ for (oo= 0 ;oo< NumIOAddrReg;oo= oo+ 1 ) begin : reggen_loop
377+ if (busaddress_r == ('h1100 + (oo* 4 ))) begin busdata_to_cpu <= ddr_reg[oo]; end
378+ else if (busaddress_r == ('h1300 + (oo* 4 ))) begin busdata_to_cpu <= od_reg[oo]; end
379+ end
364380 end
365- end
366- else if (mux_address_valid) begin
367- for (om= 0 ;om< NumIOAddrReg;om= om+ 1 ) begin : mux_reggen_loop
368- for (oi= 0 ;oi< Mux_regPrIOReg;oi= oi+ 1 ) begin : mux_reggen_loop
369- if (busaddress_r == ('h1120 + (om* 24 ) + (oi* 4 ))) begin busdata_to_cpu <= mux_reg[om][oi]; end
381+ else if (mux_address_valid) begin
382+ for (om= 0 ;om< NumIOAddrReg;om= om+ 1 ) begin : mux_reggen_loop
383+ for (oi= 0 ;oi< Mux_regPrIOReg;oi= oi+ 1 ) begin : mux_reggen_loop
384+ if (busaddress_r == ('h1120 + (om* 24 ) + (oi* 4 ))) begin busdata_to_cpu <= mux_reg[om][oi]; end
385+ end
386+ end
387+ end
388+ else begin busdata_to_cpu <= busdata_fromhm2; end
389+ end else begin
390+ if (adc_address_valid) begin busdata_to_cpu <= adc_data_out; end
391+ // if ((busaddress_r == 'h0200) || (busaddress_r == 'h0204)) begin busdata_to_cpu <= adc_data_out; end
392+ else if (busaddress_r == 'h0304 ) begin busdata_to_cpu <= hysteresis_reg; end
393+ else if (busaddress_r == 'h1000 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[0 ][23 : 0 ]} ; end
394+ else if (busaddress_r == 'h1004 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[1 ][11 : 0 ],gpio_input_data[0 ][35 : 24 ]} ; end
395+ else if (busaddress_r == 'h1008 ) begin busdata_to_cpu <= { 8'b0 ,gpio_input_data[1 ][35 : 12 ]} ; end
396+ // else if(busaddress_r == 'h100c) begin busdata_to_cpu <= {8'b0,gpio_input_data[2][23:0]}; end
397+ // else if(busaddress_r == 'h1010) begin busdata_to_cpu <= {8'b0,gpio_input_data[3][11:0],gpio_input_data[2][35:24]}; end
398+ // else if(busaddress_r == 'h1014) begin busdata_to_cpu <= {8'b0,gpio_input_data[3][35:12]}; end
399+ // else if ((busaddress_r >= 16'h1100) && (busaddress_r < 16'h1200)) begin
400+ else if (ddr_address_valid || od_address_valid) begin
401+ for (oo= 0 ;oo< NumIOAddrReg;oo= oo+ 1 ) begin : reggen_loop
402+ if (busaddress_r == ('h1100 + (oo* 4 ))) begin busdata_to_cpu <= ddr_reg[oo]; end
403+ else if (busaddress_r == ('h1300 + (oo* 4 ))) begin busdata_to_cpu <= od_reg[oo]; end
404+ end
405+ end
406+ else if (mux_address_valid) begin
407+ for (om= 0 ;om< NumIOAddrReg;om= om+ 1 ) begin : mux_reggen_loop
408+ for (oi= 0 ;oi< Mux_regPrIOReg;oi= oi+ 1 ) begin : mux_reggen_loop
409+ if (busaddress_r == ('h1120 + (om* 24 ) + (oi* 4 ))) begin busdata_to_cpu <= mux_reg[om][oi]; end
410+ end
370411 end
371412 end
413+ else begin busdata_to_cpu <= busdata_fromhm2; end
372414 end
373- else begin busdata_to_cpu <= busdata_fromhm2; end
374415 end
375416 end
376417 endgenerate
377-
378- assign sense = gpio_input_data[1 ][5 : 1 ];
379-
380- capsense capsense_inst
381- (
382- .clk (reg_clk) , // input clk_sig
383- .reset (sense_reset) , // input reset_sig
384- .sense (sense) , // input [num-1:0] sense_sig
385- .hysteresis (hysteresis),
386- .calibval_0 (calibval_0),
387- .counts_0 (counts_0),
388- .charge (charge) , // output charge_sig
389- .touched (touched) // output [num-1:0] touched_sig
390- );
391-
392- defparam capsense_inst.num = NumSense;
393- // States
394- defparam capsense_inst.CHARGE = 1 ;
395- defparam capsense_inst.DISCHARGE = 2 ;
396- // freqwuency in Mhz , times in us
397- defparam capsense_inst.clockfrequency = 200 ;
398- defparam capsense_inst.periodtime = 5 ;
399-
418+
419+ generate if (Capsense >= 1 ) begin
420+ assign sense = gpio_input_data[1 ][5 : 1 ];
421+
422+ capsense capsense_inst
423+ (
424+ .clk (reg_clk) , // input clk_sig
425+ .reset (sense_reset) , // input reset_sig
426+ .sense (sense) , // input [num-1:0] sense_sig
427+ .hysteresis (hysteresis),
428+ .calibval_0 (calibval_0),
429+ .counts_0 (counts_0),
430+ .charge (charge) , // output charge_sig
431+ .touched (touched) // output [num-1:0] touched_sig
432+ );
433+
434+ defparam capsense_inst.num = NumSense;
435+ // States
436+ defparam capsense_inst.CHARGE = 1 ;
437+ defparam capsense_inst.DISCHARGE = 2 ;
438+ // freqwuency in Mhz , times in us
439+ defparam capsense_inst.clockfrequency = 200 ;
440+ defparam capsense_inst.periodtime = 5 ;
441+ end
442+ endgenerate
400443
401444endmodule
402445
0 commit comments