Skip to content

Commit

Permalink
Make formatting of RTL files consistent
Browse files Browse the repository at this point in the history
These fixes include:
- Indentation of parameter lists.
- Indentation of input/output lists.
- Indentation of variable declaration.
- Making comments full sentences ending in period.
- Adding address and data width parameters.
- Turn Verilator lints back on and resolve width and unused warnings.
- Use ANSI style of parameter declarations.
marnovandermaas committed Jan 16, 2024
1 parent 7abf2d6 commit f4ef5ce
Showing 9 changed files with 328 additions and 300 deletions.
51 changes: 26 additions & 25 deletions rtl/fpga/top_artya7.sv
Original file line number Diff line number Diff line change
@@ -3,45 +3,46 @@
// SPDX-License-Identifier: Apache-2.0

// This is the top level SystemVerilog file that connects the IO on the board to the Ibex Demo System.
module top_artya7 (
module top_artya7 #(
parameter SRAMInitFile = ""
) (
// These inputs are defined in data/pins_artya7.xdc
input IO_CLK,
input IO_RST_N,
input [ 3:0] SW,
input [ 3:0] BTN,
output [ 3:0] LED,
output [11:0] RGB_LED,
output [ 3:0] DISP_CTRL,
input UART_RX,
output UART_TX,
input SPI_RX,
output SPI_TX,
output SPI_SCK
input IO_CLK,
input IO_RST_N,
input [ 3:0] SW,
input [ 3:0] BTN,
output [ 3:0] LED,
output [11:0] RGB_LED,
output [ 3:0] DISP_CTRL,
input UART_RX,
output UART_TX,
input SPI_RX,
output SPI_TX,
output SPI_SCK
);
parameter SRAMInitFile = "";

logic clk_sys, rst_sys_n;

// Instantiating the Ibex Demo System.
ibex_demo_system #(
.GpiWidth(8),
.GpoWidth(8),
.PwmWidth(12),
.SRAMInitFile(SRAMInitFile)
.GpiWidth ( 8 ),
.GpoWidth ( 8 ),
.PwmWidth ( 12 ),
.SRAMInitFile ( SRAMInitFile )
) u_ibex_demo_system (
//input
.clk_sys_i(clk_sys),
.clk_sys_i (clk_sys),
.rst_sys_ni(rst_sys_n),
.gp_i({SW, BTN}),
.uart_rx_i(UART_RX),
.gp_i ({SW, BTN}),
.uart_rx_i (UART_RX),

//output
.gp_o({LED, DISP_CTRL}),
.pwm_o(RGB_LED),
.gp_o ({LED, DISP_CTRL}),
.pwm_o (RGB_LED),
.uart_tx_o(UART_TX),

.spi_rx_i(SPI_RX),
.spi_tx_o(SPI_TX),
.spi_rx_i (SPI_RX),
.spi_tx_o (SPI_TX),
.spi_sck_o(SPI_SCK)
);

15 changes: 8 additions & 7 deletions rtl/system/debounce.sv
Original file line number Diff line number Diff line change
@@ -6,11 +6,14 @@
// from the debounced output. If the input remains in that state for a certain
// number of cycles (ClkCount) it is deemed stable and becomes the debounced
// output. If the input changes (i.e. it is bouncing) we reset the counter.

typedef int unsigned count_t;

module debounce #(
parameter int unsigned ClkCount = 500
parameter count_t ClkCount = 500
) (
input logic clk_i,
input logic rst_ni,
input logic clk_i,
input logic rst_ni,

input logic btn_i,
output logic btn_o
@@ -31,11 +34,9 @@ module debounce #(
end
end

/* verilator lint_off WIDTH */
assign btn_d = (cnt_q >= ClkCount) ? btn_i : btn_q;
assign btn_d = (count_t'(cnt_q) >= ClkCount) ? btn_i : btn_q;
// Clear counter if button input equals stored value or if maximum counter value is reached,
// otherwise increment counter.
/* verilator lint_off WIDTH */
assign cnt_d = (btn_i == btn_q || cnt_q >= ClkCount) ? '0 : cnt_q + 1;
assign cnt_d = (btn_i == btn_q || count_t'(cnt_q) >= ClkCount) ? '0 : cnt_q + 1;

endmodule
70 changes: 39 additions & 31 deletions rtl/system/gpio.sv
Original file line number Diff line number Diff line change
@@ -3,19 +3,22 @@
// SPDX-License-Identifier: Apache-2.0

module gpio #(
GpiWidth = 8,
GpoWidth = 16
parameter int unsigned GpiWidth = 8,
parameter int unsigned GpoWidth = 16,
parameter int unsigned AddrWidth = 32,
parameter int unsigned DataWidth = 32,
parameter int unsigned RegAddr = 12
) (
input logic clk_i,
input logic rst_ni,
input logic clk_i,
input logic rst_ni,

input logic device_req_i,
input logic [31:0] device_addr_i,
input logic device_we_i,
input logic [ 3:0] device_be_i,
input logic [31:0] device_wdata_i,
output logic device_rvalid_o,
output logic [31:0] device_rdata_o,
input logic device_req_i,
input logic [AddrWidth-1:0] device_addr_i,
input logic device_we_i,
input logic [3:0] device_be_i,
input logic [DataWidth-1:0] device_wdata_i,
output logic device_rvalid_o,
output logic [DataWidth-1:0] device_rdata_o,

input logic [GpiWidth-1:0] gp_i,
output logic [GpoWidth-1:0] gp_o
@@ -25,17 +28,17 @@ module gpio #(
localparam int unsigned GPIO_IN_REG = 32'h4;
localparam int unsigned GPIO_IN_DBNC_REG = 32'h8;

logic [11:0] reg_addr;
logic [RegAddr-1:0] reg_addr;

logic [2:0][GpiWidth-1:0] gp_i_q;
logic [GpiWidth-1:0] gp_i_dbnc;
logic [GpoWidth-1:0] gp_o_d;

logic gp_o_wr_en;
logic gp_i_rd_en_d, gp_i_rd_en_q;
logic gp_i_dbnc_rd_en_d, gp_i_dbnc_rd_en_q;
logic gp_o_wr_en;
logic gp_i_rd_en_d, gp_i_rd_en_q;
logic gp_i_dbnc_rd_en_d, gp_i_dbnc_rd_en_q;

// instantiate debouncers for all GP inputs
// Instantiate debouncers for all GP inputs.
for (genvar i = 0; i < GpiWidth; i++) begin : gen_debounce
debounce #(
.ClkCount(500)
@@ -65,36 +68,41 @@ module gpio #(
end
end

// assign gp_o_d regarding to device_be_i and GpoWidth
logic [3:0] unused_device_be;

// Assign gp_o_d regarding to device_be_i and GpoWidth.
for (genvar i_byte = 0; i_byte < 4; ++i_byte) begin : gen_gp_o_d;
if (i_byte * 8 < GpoWidth) begin : gen_gp_o_d_inner
localparam int gpo_byte_end = (i_byte + 1) * 8 <= GpoWidth ? (i_byte + 1) * 8 : GpoWidth;
assign gp_o_d[gpo_byte_end - 1 : i_byte * 8] =
device_be_i[i_byte] ? device_wdata_i[gpo_byte_end - 1 : i_byte * 8] :
gp_o[gpo_byte_end - 1 : i_byte * 8];
assign unused_device_be[i_byte] = 0;
end else begin : gen_unused_device_be
assign unused_device_be[i_byte] = device_be_i[i_byte];
end
end

// decode write and read requests
assign reg_addr = device_addr_i[11:0];
assign gp_o_wr_en = device_req_i & device_we_i & (reg_addr == GPIO_OUT_REG[11:0]);
assign gp_i_rd_en_d = device_req_i & ~device_we_i & (reg_addr == GPIO_IN_REG[11:0]);
assign gp_i_dbnc_rd_en_d = device_req_i & ~device_we_i & (reg_addr == GPIO_IN_DBNC_REG[11:0]);
// Decode write and read requests.
assign reg_addr = device_addr_i[RegAddr-1:0];
assign gp_o_wr_en = device_req_i & device_we_i & (reg_addr == GPIO_OUT_REG[RegAddr-1:0]);
assign gp_i_rd_en_d = device_req_i & ~device_we_i & (reg_addr == GPIO_IN_REG[RegAddr-1:0]);
assign gp_i_dbnc_rd_en_d = device_req_i & ~device_we_i & (reg_addr == GPIO_IN_DBNC_REG[RegAddr-1:0]);

// assign device_rdata_o according to request type
// Assign device_rdata_o according to request type.
always_comb begin
if (gp_i_dbnc_rd_en_q)
device_rdata_o = {{(32 - GpiWidth){1'b0}}, gp_i_dbnc};
device_rdata_o = {{(DataWidth - GpiWidth){1'b0}}, gp_i_dbnc};
else if (gp_i_rd_en_q)
device_rdata_o = {{(32 - GpiWidth){1'b0}}, gp_i_q[2]};
device_rdata_o = {{(DataWidth - GpiWidth){1'b0}}, gp_i_q[2]};
else
device_rdata_o = {{(32 - GpoWidth){1'b0}}, gp_o};
device_rdata_o = {{(DataWidth - GpoWidth){1'b0}}, gp_o};
end

logic unused_device_addr, unused_device_be, unused_device_wdata;
// Unused signals.
logic [AddrWidth-1-RegAddr:0] unused_device_addr;
logic [DataWidth-1-GpoWidth:0] unused_device_wdata;

assign unused_device_addr = ^device_addr_i[31:10];
// TODO: Do this more neatly
assign unused_device_be = ^device_be_i;
assign unused_device_wdata = ^device_wdata_i[31:GpoWidth];
assign unused_device_addr = device_addr_i[AddrWidth-1:RegAddr];
assign unused_device_wdata = device_wdata_i[DataWidth-1:GpoWidth];
endmodule
Loading

0 comments on commit f4ef5ce

Please sign in to comment.