tinyriscv/rtl/perips/spi/spi_reg_top.sv

614 lines
14 KiB
Systemverilog

// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
// Register Top module auto-generated by `reggen`
module spi_reg_top (
input logic clk_i,
input logic rst_ni,
// To HW
output spi_reg_pkg::spi_reg2hw_t reg2hw, // Write
input spi_reg_pkg::spi_hw2reg_t hw2reg, // Read
input logic reg_we,
input logic reg_re,
input logic [31:0] reg_wdata,
input logic [ 3:0] reg_be,
input logic [31:0] reg_addr,
output logic [31:0] reg_rdata
);
import spi_reg_pkg::* ;
localparam int AW = 4;
localparam int DW = 32;
localparam int DBW = DW/8; // Byte Width
logic reg_error;
logic addrmiss, wr_err;
logic [DW-1:0] reg_rdata_next;
assign reg_rdata = reg_rdata_next;
assign reg_error = wr_err;
// Define SW related signals
// Format: <reg>_<field>_{wd|we|qs}
// or <reg>_{wd|we|qs} if field == 1 or 0
logic ctrl0_we;
logic ctrl0_enable_qs;
logic ctrl0_enable_wd;
logic ctrl0_int_en_qs;
logic ctrl0_int_en_wd;
logic ctrl0_int_pending_qs;
logic ctrl0_int_pending_wd;
logic ctrl0_role_mode_qs;
logic ctrl0_role_mode_wd;
logic [1:0] ctrl0_cp_mode_qs;
logic [1:0] ctrl0_cp_mode_wd;
logic [1:0] ctrl0_spi_mode_qs;
logic [1:0] ctrl0_spi_mode_wd;
logic ctrl0_read_qs;
logic ctrl0_read_wd;
logic ctrl0_msb_first_qs;
logic ctrl0_msb_first_wd;
logic ctrl0_ss_sw_ctrl_qs;
logic ctrl0_ss_sw_ctrl_wd;
logic ctrl0_ss_level_qs;
logic ctrl0_ss_level_wd;
logic [3:0] ctrl0_ss_delay_qs;
logic [3:0] ctrl0_ss_delay_wd;
logic [2:0] ctrl0_clk_div_qs;
logic [2:0] ctrl0_clk_div_wd;
logic status_re;
logic status_tx_fifo_full_qs;
logic status_tx_fifo_empty_qs;
logic status_rx_fifo_full_qs;
logic status_rx_fifo_empty_qs;
logic status_busy_qs;
logic txdata_we;
logic [7:0] txdata_wd;
logic rxdata_re;
logic [7:0] rxdata_qs;
// Register instances
// R[ctrl0]: V(False)
// F[enable]: 0:0
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_enable (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_enable_wd),
// from internal hardware
.de (hw2reg.ctrl0.enable.de),
.d (hw2reg.ctrl0.enable.d),
// to internal hardware
.qe (reg2hw.ctrl0.enable.qe),
.q (reg2hw.ctrl0.enable.q),
// to register interface (read)
.qs (ctrl0_enable_qs)
);
// F[int_en]: 1:1
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_int_en (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_int_en_wd),
// from internal hardware
.de (hw2reg.ctrl0.int_en.de),
.d (hw2reg.ctrl0.int_en.d),
// to internal hardware
.qe (reg2hw.ctrl0.int_en.qe),
.q (reg2hw.ctrl0.int_en.q),
// to register interface (read)
.qs (ctrl0_int_en_qs)
);
// F[int_pending]: 2:2
prim_subreg #(
.DW (1),
.SWACCESS("W1C"),
.RESVAL (1'h0)
) u_ctrl0_int_pending (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_int_pending_wd),
// from internal hardware
.de (hw2reg.ctrl0.int_pending.de),
.d (hw2reg.ctrl0.int_pending.d),
// to internal hardware
.qe (reg2hw.ctrl0.int_pending.qe),
.q (reg2hw.ctrl0.int_pending.q),
// to register interface (read)
.qs (ctrl0_int_pending_qs)
);
// F[role_mode]: 3:3
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_role_mode (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_role_mode_wd),
// from internal hardware
.de (hw2reg.ctrl0.role_mode.de),
.d (hw2reg.ctrl0.role_mode.d),
// to internal hardware
.qe (reg2hw.ctrl0.role_mode.qe),
.q (reg2hw.ctrl0.role_mode.q),
// to register interface (read)
.qs (ctrl0_role_mode_qs)
);
// F[cp_mode]: 5:4
prim_subreg #(
.DW (2),
.SWACCESS("RW"),
.RESVAL (2'h0)
) u_ctrl0_cp_mode (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_cp_mode_wd),
// from internal hardware
.de (hw2reg.ctrl0.cp_mode.de),
.d (hw2reg.ctrl0.cp_mode.d),
// to internal hardware
.qe (reg2hw.ctrl0.cp_mode.qe),
.q (reg2hw.ctrl0.cp_mode.q),
// to register interface (read)
.qs (ctrl0_cp_mode_qs)
);
// F[spi_mode]: 7:6
prim_subreg #(
.DW (2),
.SWACCESS("RW"),
.RESVAL (2'h0)
) u_ctrl0_spi_mode (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_spi_mode_wd),
// from internal hardware
.de (hw2reg.ctrl0.spi_mode.de),
.d (hw2reg.ctrl0.spi_mode.d),
// to internal hardware
.qe (reg2hw.ctrl0.spi_mode.qe),
.q (reg2hw.ctrl0.spi_mode.q),
// to register interface (read)
.qs (ctrl0_spi_mode_qs)
);
// F[read]: 8:8
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_read (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_read_wd),
// from internal hardware
.de (hw2reg.ctrl0.read.de),
.d (hw2reg.ctrl0.read.d),
// to internal hardware
.qe (reg2hw.ctrl0.read.qe),
.q (reg2hw.ctrl0.read.q),
// to register interface (read)
.qs (ctrl0_read_qs)
);
// F[msb_first]: 9:9
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_msb_first (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_msb_first_wd),
// from internal hardware
.de (hw2reg.ctrl0.msb_first.de),
.d (hw2reg.ctrl0.msb_first.d),
// to internal hardware
.qe (reg2hw.ctrl0.msb_first.qe),
.q (reg2hw.ctrl0.msb_first.q),
// to register interface (read)
.qs (ctrl0_msb_first_qs)
);
// F[ss_sw_ctrl]: 10:10
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_ss_sw_ctrl (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_ss_sw_ctrl_wd),
// from internal hardware
.de (hw2reg.ctrl0.ss_sw_ctrl.de),
.d (hw2reg.ctrl0.ss_sw_ctrl.d),
// to internal hardware
.qe (reg2hw.ctrl0.ss_sw_ctrl.qe),
.q (reg2hw.ctrl0.ss_sw_ctrl.q),
// to register interface (read)
.qs (ctrl0_ss_sw_ctrl_qs)
);
// F[ss_level]: 11:11
prim_subreg #(
.DW (1),
.SWACCESS("RW"),
.RESVAL (1'h0)
) u_ctrl0_ss_level (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_ss_level_wd),
// from internal hardware
.de (hw2reg.ctrl0.ss_level.de),
.d (hw2reg.ctrl0.ss_level.d),
// to internal hardware
.qe (reg2hw.ctrl0.ss_level.qe),
.q (reg2hw.ctrl0.ss_level.q),
// to register interface (read)
.qs (ctrl0_ss_level_qs)
);
// F[ss_delay]: 15:12
prim_subreg #(
.DW (4),
.SWACCESS("RW"),
.RESVAL (4'h0)
) u_ctrl0_ss_delay (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_ss_delay_wd),
// from internal hardware
.de (hw2reg.ctrl0.ss_delay.de),
.d (hw2reg.ctrl0.ss_delay.d),
// to internal hardware
.qe (reg2hw.ctrl0.ss_delay.qe),
.q (reg2hw.ctrl0.ss_delay.q),
// to register interface (read)
.qs (ctrl0_ss_delay_qs)
);
// F[clk_div]: 31:29
prim_subreg #(
.DW (3),
.SWACCESS("RW"),
.RESVAL (3'h0)
) u_ctrl0_clk_div (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (ctrl0_we),
.wd (ctrl0_clk_div_wd),
// from internal hardware
.de (hw2reg.ctrl0.clk_div.de),
.d (hw2reg.ctrl0.clk_div.d),
// to internal hardware
.qe (reg2hw.ctrl0.clk_div.qe),
.q (reg2hw.ctrl0.clk_div.q),
// to register interface (read)
.qs (ctrl0_clk_div_qs)
);
// R[status]: V(True)
// F[tx_fifo_full]: 0:0
prim_subreg_ext #(
.DW (1)
) u_status_tx_fifo_full (
.re (status_re),
.we (1'b0),
.wd ('0),
.d (hw2reg.status.tx_fifo_full.d),
.qre (),
.qe (),
.q (reg2hw.status.tx_fifo_full.q),
.qs (status_tx_fifo_full_qs)
);
// F[tx_fifo_empty]: 1:1
prim_subreg_ext #(
.DW (1)
) u_status_tx_fifo_empty (
.re (status_re),
.we (1'b0),
.wd ('0),
.d (hw2reg.status.tx_fifo_empty.d),
.qre (),
.qe (),
.q (reg2hw.status.tx_fifo_empty.q),
.qs (status_tx_fifo_empty_qs)
);
// F[rx_fifo_full]: 2:2
prim_subreg_ext #(
.DW (1)
) u_status_rx_fifo_full (
.re (status_re),
.we (1'b0),
.wd ('0),
.d (hw2reg.status.rx_fifo_full.d),
.qre (),
.qe (),
.q (reg2hw.status.rx_fifo_full.q),
.qs (status_rx_fifo_full_qs)
);
// F[rx_fifo_empty]: 3:3
prim_subreg_ext #(
.DW (1)
) u_status_rx_fifo_empty (
.re (status_re),
.we (1'b0),
.wd ('0),
.d (hw2reg.status.rx_fifo_empty.d),
.qre (),
.qe (),
.q (reg2hw.status.rx_fifo_empty.q),
.qs (status_rx_fifo_empty_qs)
);
// F[busy]: 4:4
prim_subreg_ext #(
.DW (1)
) u_status_busy (
.re (status_re),
.we (1'b0),
.wd ('0),
.d (hw2reg.status.busy.d),
.qre (),
.qe (),
.q (reg2hw.status.busy.q),
.qs (status_busy_qs)
);
// R[txdata]: V(False)
prim_subreg #(
.DW (8),
.SWACCESS("WO"),
.RESVAL (8'h0)
) u_txdata (
.clk_i (clk_i),
.rst_ni (rst_ni),
// from register interface
.we (txdata_we),
.wd (txdata_wd),
// from internal hardware
.de (1'b0),
.d ('0),
// to internal hardware
.qe (reg2hw.txdata.qe),
.q (reg2hw.txdata.q),
// to register interface (read)
.qs ()
);
// R[rxdata]: V(True)
prim_subreg_ext #(
.DW (8)
) u_rxdata (
.re (rxdata_re),
.we (1'b0),
.wd ('0),
.d (hw2reg.rxdata.d),
.qre (reg2hw.rxdata.re),
.qe (),
.q (reg2hw.rxdata.q),
.qs (rxdata_qs)
);
logic [3:0] addr_hit;
always_comb begin
addr_hit = '0;
addr_hit[0] = (reg_addr == SPI_CTRL0_OFFSET);
addr_hit[1] = (reg_addr == SPI_STATUS_OFFSET);
addr_hit[2] = (reg_addr == SPI_TXDATA_OFFSET);
addr_hit[3] = (reg_addr == SPI_RXDATA_OFFSET);
end
assign addrmiss = (reg_re || reg_we) ? ~|addr_hit : 1'b0 ;
// Check sub-word write is permitted
always_comb begin
wr_err = (reg_we &
((addr_hit[0] & (|(SPI_PERMIT[0] & ~reg_be))) |
(addr_hit[1] & (|(SPI_PERMIT[1] & ~reg_be))) |
(addr_hit[2] & (|(SPI_PERMIT[2] & ~reg_be))) |
(addr_hit[3] & (|(SPI_PERMIT[3] & ~reg_be)))));
end
assign ctrl0_we = addr_hit[0] & reg_we & !reg_error;
assign ctrl0_enable_wd = reg_wdata[0];
assign ctrl0_int_en_wd = reg_wdata[1];
assign ctrl0_int_pending_wd = reg_wdata[2];
assign ctrl0_role_mode_wd = reg_wdata[3];
assign ctrl0_cp_mode_wd = reg_wdata[5:4];
assign ctrl0_spi_mode_wd = reg_wdata[7:6];
assign ctrl0_read_wd = reg_wdata[8];
assign ctrl0_msb_first_wd = reg_wdata[9];
assign ctrl0_ss_sw_ctrl_wd = reg_wdata[10];
assign ctrl0_ss_level_wd = reg_wdata[11];
assign ctrl0_ss_delay_wd = reg_wdata[15:12];
assign ctrl0_clk_div_wd = reg_wdata[31:29];
assign status_re = addr_hit[1] & reg_re & !reg_error;
assign txdata_we = addr_hit[2] & reg_we & !reg_error;
assign txdata_wd = reg_wdata[7:0];
assign rxdata_re = addr_hit[3] & reg_re & !reg_error;
// Read data return
always_comb begin
reg_rdata_next = '0;
unique case (1'b1)
addr_hit[0]: begin
reg_rdata_next[0] = ctrl0_enable_qs;
reg_rdata_next[1] = ctrl0_int_en_qs;
reg_rdata_next[2] = ctrl0_int_pending_qs;
reg_rdata_next[3] = ctrl0_role_mode_qs;
reg_rdata_next[5:4] = ctrl0_cp_mode_qs;
reg_rdata_next[7:6] = ctrl0_spi_mode_qs;
reg_rdata_next[8] = ctrl0_read_qs;
reg_rdata_next[9] = ctrl0_msb_first_qs;
reg_rdata_next[10] = ctrl0_ss_sw_ctrl_qs;
reg_rdata_next[11] = ctrl0_ss_level_qs;
reg_rdata_next[15:12] = ctrl0_ss_delay_qs;
reg_rdata_next[31:29] = ctrl0_clk_div_qs;
end
addr_hit[1]: begin
reg_rdata_next[0] = status_tx_fifo_full_qs;
reg_rdata_next[1] = status_tx_fifo_empty_qs;
reg_rdata_next[2] = status_rx_fifo_full_qs;
reg_rdata_next[3] = status_rx_fifo_empty_qs;
reg_rdata_next[4] = status_busy_qs;
end
addr_hit[2]: begin
reg_rdata_next[7:0] = '0;
end
addr_hit[3]: begin
reg_rdata_next[7:0] = rxdata_qs;
end
default: begin
reg_rdata_next = '1;
end
endcase
end
// Unused signal tieoff
// wdata / byte enable are not always fully used
// add a blanket unused statement to handle lint waivers
logic unused_wdata;
logic unused_be;
assign unused_wdata = ^reg_wdata;
assign unused_be = ^reg_be;
endmodule