55module gpio_core # (
66 parameter int unsigned GpiWidth = 8 ,
77 parameter int unsigned GpoWidth = 16 ,
8- parameter int unsigned AddrWidth = 32 ,
98 parameter int unsigned DataWidth = 32 ,
10- parameter int unsigned RegAddr = 6 ,
9+ parameter int unsigned AddrWidth = 6 ,
1110 parameter int unsigned DbncWidth = 10
1211) (
1312 input logic clk_i,
@@ -35,7 +34,7 @@ module gpio_core #(
3534 localparam int unsigned GPIO_STATUS_REG = 32'h14 ;
3635 localparam int unsigned GPIO_PIN_MASK_REG = 32'h18 ;
3736
38- logic [RegAddr - 1 : 0 ] reg_addr ;
37+ logic [DataWidth - 1 : 0 ] rdata ;
3938
4039 logic [GpiWidth- 1 : 0 ] gp_i_sync;
4140 logic [GpiWidth- 1 : 0 ] gp_i_dbnc;
@@ -84,7 +83,7 @@ module gpio_core #(
8483 );
8584
8685 // Instantiate step-based debouncers for all GP inputs.
87- for (genvar i = 0 ; i < GpiWidth; i++ ) begin
86+ for (genvar i = 0 ; i < GpiWidth; i++ ) begin : gen_dbnc
8887 debounce_step dbnc (
8988 .clk_i,
9089 .rst_ni,
@@ -140,7 +139,7 @@ module gpio_core #(
140139 logic [3 : 0 ] unused_i_device_be;
141140
142141 // Assign gp_o_d regarding to device_be_i and GpoWidth.
143- for (genvar i_byte = 0 ; i_byte < 4 ; ++ i_byte) begin : g_gp_o_d ;
142+ for (genvar i_byte = 0 ; i_byte < 4 ; ++ i_byte) begin : gen_gp_o_d ;
144143 if (i_byte * 8 < GpoWidth) begin : gen_gp_o_d_inner
145144 localparam int gpo_byte_end = (i_byte + 1 ) * 8 <= GpoWidth ? (i_byte + 1 ) * 8 : GpoWidth;
146145 assign gp_o_d[gpo_byte_end - 1 : i_byte * 8 ] =
@@ -156,7 +155,7 @@ module gpio_core #(
156155 end
157156
158157 // Assign pcint_mask_d regarding to device_be_i and GpiWidth.
159- for (genvar i_byte = 0 ; i_byte < 4 ; ++ i_byte) begin : g_pcint_mask_d ;
158+ for (genvar i_byte = 0 ; i_byte < 4 ; ++ i_byte) begin : gen_pcint_mask_d ;
160159 if (i_byte * 8 < GpiWidth) begin : gen_pcint_mask_d_inner
161160 localparam int gpi_byte_end = (i_byte + 1 ) * 8 <= GpiWidth ? (i_byte + 1 ) * 8 : GpiWidth;
162161 assign pcint_mask_d[gpi_byte_end - 1 : i_byte * 8 ] =
@@ -174,42 +173,32 @@ module gpio_core #(
174173 assign pcint_mode_d = device_be_i[0 ] ? device_wdata_i[1 : 0 ] : pcint_mode;
175174
176175 // Decode write requests.
177- assign reg_addr = device_addr_i[RegAddr- 1 : 0 ];
178- assign gp_o_sel = device_req_i & (reg_addr == GPIO_OUT_REG [RegAddr- 1 : 0 ]);
179- assign gp_o_en_sel = device_req_i & (reg_addr == GPIO_OUT_EN_REG [RegAddr- 1 : 0 ]);
180- assign ctrl_sel = device_req_i & (reg_addr == GPIO_CTRL_REG [RegAddr- 1 : 0 ]);
181- assign status_sel = device_req_i & (reg_addr == GPIO_STATUS_REG [RegAddr- 1 : 0 ]);
182- assign pcint_mask_sel = device_req_i & (reg_addr == GPIO_PIN_MASK_REG [RegAddr- 1 : 0 ]);
183-
184- // Assign device_rdata_o according to request type.
176+ assign gp_o_sel = device_req_i & (device_addr_i == GPIO_OUT_REG [AddrWidth- 1 : 0 ]);
177+ assign gp_o_en_sel = device_req_i & (device_addr_i == GPIO_OUT_EN_REG [AddrWidth- 1 : 0 ]);
178+ assign ctrl_sel = device_req_i & (device_addr_i == GPIO_CTRL_REG [AddrWidth- 1 : 0 ]);
179+ assign status_sel = device_req_i & (device_addr_i == GPIO_STATUS_REG [AddrWidth- 1 : 0 ]);
180+ assign pcint_mask_sel = device_req_i & (device_addr_i == GPIO_PIN_MASK_REG [AddrWidth- 1 : 0 ]);
181+
182+ // Assign rdata according to request type.
185183 always_comb begin
186- if (reg_addr[RegAddr- 1 : 2 ] == GPIO_OUT_REG [RegAddr- 1 : 2 ])
187- device_rdata_o = {{ (DataWidth - GpoWidth){ 1'b0 }} , gp_o} ;
188- else if (reg_addr[RegAddr- 1 : 2 ] == GPIO_IN_REG [RegAddr- 1 : 2 ])
189- device_rdata_o = {{ (DataWidth - GpiWidth){ 1'b0 }} , gp_i_sync} ;
190- else if (reg_addr[RegAddr- 1 : 2 ] == GPIO_IN_DBNC_REG [RegAddr- 1 : 2 ])
191- device_rdata_o = {{ (DataWidth - GpiWidth){ 1'b0 }} , gp_i_dbnc} ;
192- else if (reg_addr[RegAddr- 1 : 2 ] == GPIO_OUT_EN_REG [RegAddr- 1 : 2 ])
193- device_rdata_o = {{ (DataWidth - GpoWidth){ 1'b0 }} , gp_o_en} ;
194- else if (reg_addr[RegAddr- 1 : 2 ] == GPIO_CTRL_REG [RegAddr- 1 : 2 ])
195- device_rdata_o = { pcint_enable, 27'b0 , pcint_i_sel, 1'b0 , pcint_mode} ;
196- else if (reg_addr[RegAddr- 1 : 2 ] == GPIO_STATUS_REG [RegAddr- 1 : 2 ])
197- device_rdata_o = { pcint_status, 31'b0 } ;
198- else if (reg_addr[RegAddr- 1 : 2 ] == GPIO_PIN_MASK_REG [RegAddr- 1 : 2 ])
199- device_rdata_o = {{ (DataWidth - GpiWidth){ 1'b0 }} , pcint_mask} ;
200- else
201- device_rdata_o = { (DataWidth){ 1'b0 }} ;
184+ unique case (device_addr_i[AddrWidth- 1 : 2 ])
185+ GPIO_OUT_REG [AddrWidth- 1 : 2 ]: rdata = {{ (DataWidth - GpoWidth){ 1'b0 }} , gp_o} ;
186+ GPIO_IN_REG [AddrWidth- 1 : 2 ]: rdata = {{ (DataWidth - GpiWidth){ 1'b0 }} , gp_i_sync} ;
187+ GPIO_IN_DBNC_REG [AddrWidth- 1 : 2 ]: rdata = {{ (DataWidth - GpiWidth){ 1'b0 }} , gp_i_dbnc} ;
188+ GPIO_OUT_EN_REG [AddrWidth- 1 : 2 ]: rdata = {{ (DataWidth - GpoWidth){ 1'b0 }} , gp_o_en} ;
189+ GPIO_CTRL_REG [AddrWidth- 1 : 2 ]: rdata = { pcint_enable, 27'b0 , pcint_i_sel, 1'b0 , pcint_mode} ;
190+ GPIO_STATUS_REG [AddrWidth- 1 : 2 ]: rdata = { pcint_status, 31'b0 } ;
191+ GPIO_PIN_MASK_REG [AddrWidth- 1 : 2 ]: rdata = {{ (DataWidth - GpiWidth){ 1'b0 }} , pcint_mask} ;
192+ default : rdata = { (DataWidth){ 1'b0 }} ;
193+ endcase
202194 end
203195
196+ assign device_rdata_o = device_req_i ? rdata : '0 ;
197+
204198 assign pcint_o = pcint_enable & pcint_status;
205199
206200 // Unused signals.
207- if (AddrWidth > RegAddr) begin : g_unused_addr_bits
208- logic [AddrWidth- 1 - RegAddr: 0 ] unused_device_addr;
209- assign unused_device_addr = device_addr_i[AddrWidth- 1 : RegAddr];
210- end
211-
212- if (DataWidth > GpoWidth) begin : g_unused_gpo_bits
201+ if (DataWidth > GpoWidth) begin : gen_unused_gpo_bits
213202 logic [DataWidth- 1 - GpoWidth: 0 ] unused_device_wdata;
214203 assign unused_device_wdata = device_wdata_i[DataWidth- 1 : GpoWidth];
215204 end
0 commit comments