|
| 1 | +// Copyright 2025 ETH Zurich and University of Bologna. |
| 2 | +// Solderpad Hardware License, Version 0.51, see LICENSE for details. |
| 3 | +// SPDX-License-Identifier: SHL-0.51 |
| 4 | +// |
| 5 | +// Authors: |
| 6 | +// - Enrico Zelioli <ezelioli@iis.ee.ethz.ch> |
| 7 | + |
| 8 | +module soc_ctrl_regs #( |
| 9 | + parameter type obi_req_t = logic, |
| 10 | + parameter type obi_rsp_t = logic, |
| 11 | + parameter int unsigned BootAddrDefault = 32'h0 |
| 12 | +) ( |
| 13 | + input logic clk_i, |
| 14 | + input logic rst_ni, |
| 15 | + input obi_req_t obi_req_i, |
| 16 | + output obi_rsp_t obi_rsp_o, |
| 17 | + // To hardware |
| 18 | + output logic [31:0] boot_addr_o, |
| 19 | + output logic fetch_en_o, |
| 20 | + output logic sram_dly_o |
| 21 | +); |
| 22 | + |
| 23 | + import soc_ctrl_regs_pkg::*; |
| 24 | + |
| 25 | + // Registers |
| 26 | + logic [31:0] boot_addr_d, boot_addr_q; |
| 27 | + logic fetch_en_d, fetch_en_q; |
| 28 | + logic [31:0] core_status_d, core_status_q; |
| 29 | + logic boot_mode_d, boot_mode_q; |
| 30 | + logic sram_dly_d, sram_dly_q; |
| 31 | + |
| 32 | + // Internal signals |
| 33 | + obi_req_t obi_req_d, obi_req_q; |
| 34 | + logic [31:0] rdata_d, rdata_q; |
| 35 | + logic err_d, err_q; |
| 36 | + |
| 37 | + // Latch OBI request |
| 38 | + assign obi_req_d = obi_req_i; |
| 39 | + |
| 40 | + // Output assignment |
| 41 | + assign boot_addr_o = boot_addr_q; |
| 42 | + assign fetch_en_o = fetch_en_q; |
| 43 | + assign sram_dly_o = sram_dly_q; |
| 44 | + |
| 45 | + always_comb begin : obi_response |
| 46 | + obi_rsp_o = '0; |
| 47 | + obi_rsp_o.gnt = 1'b1; |
| 48 | + obi_rsp_o.rvalid = obi_req_q.req; |
| 49 | + obi_rsp_o.r.err = err_q; |
| 50 | + obi_rsp_o.r.rid = obi_req_q.a.aid; |
| 51 | + obi_rsp_o.r.rdata = rdata_q; |
| 52 | + end |
| 53 | + |
| 54 | + always_comb begin : read_write_fsm |
| 55 | + rdata_d = '0; |
| 56 | + err_d = '0; |
| 57 | + boot_addr_d = boot_addr_q; |
| 58 | + fetch_en_d = fetch_en_q; |
| 59 | + core_status_d = core_status_q; |
| 60 | + boot_mode_d = boot_mode_q; |
| 61 | + sram_dly_d = sram_dly_q; |
| 62 | + |
| 63 | + if (obi_req_i.req) begin |
| 64 | + |
| 65 | + if (obi_req_i.a.we) begin : write |
| 66 | + automatic logic [31:0] wdata = obi_req_i.a.wdata; |
| 67 | + unique case (obi_req_i.a.addr[IntAddrWidth-1:0]) |
| 68 | + SOC_CTRL_BOOTADDR_OFFSET: begin |
| 69 | + boot_addr_d = wdata; |
| 70 | + end |
| 71 | + SOC_CTRL_FETCHEN_OFFSET: begin |
| 72 | + fetch_en_d = wdata[0]; |
| 73 | + end |
| 74 | + SOC_CTRL_CORESTATUS_OFFSET: begin |
| 75 | + core_status_d = wdata; |
| 76 | + end |
| 77 | + SOC_CTRL_BOOTMODE_OFFSET: begin |
| 78 | + boot_mode_d = wdata[0]; |
| 79 | + end |
| 80 | + SOC_CTRL_SRAM_DLY_OFFSET: begin |
| 81 | + sram_dly_d = wdata[0]; |
| 82 | + end |
| 83 | + default: begin |
| 84 | + err_d = 1'b1; |
| 85 | + end |
| 86 | + endcase |
| 87 | + |
| 88 | + end else begin : read |
| 89 | + unique case (obi_req_i.a.addr[IntAddrWidth-1:0]) |
| 90 | + SOC_CTRL_BOOTADDR_OFFSET: begin |
| 91 | + rdata_d = boot_addr_q; |
| 92 | + end |
| 93 | + SOC_CTRL_FETCHEN_OFFSET: begin |
| 94 | + rdata_d = {31'h0, fetch_en_q}; |
| 95 | + end |
| 96 | + SOC_CTRL_CORESTATUS_OFFSET: begin |
| 97 | + rdata_d = core_status_q; |
| 98 | + end |
| 99 | + SOC_CTRL_BOOTMODE_OFFSET: begin |
| 100 | + rdata_d = {31'h0, boot_mode_q}; |
| 101 | + end |
| 102 | + SOC_CTRL_SRAM_DLY_OFFSET: begin |
| 103 | + rdata_d = {31'b0, sram_dly_q}; |
| 104 | + end |
| 105 | + default: begin |
| 106 | + err_d = 1'b1; |
| 107 | + end |
| 108 | + endcase |
| 109 | + end |
| 110 | + |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + always_ff @(posedge clk_i or negedge rst_ni) begin |
| 115 | + if (~rst_ni) begin |
| 116 | + boot_addr_q <= BootAddrDefault; |
| 117 | + fetch_en_q <= '0; |
| 118 | + core_status_q <= '0; |
| 119 | + boot_mode_q <= '0; |
| 120 | + sram_dly_q <= '0; |
| 121 | + obi_req_q <= '0; |
| 122 | + rdata_q <= '0; |
| 123 | + err_q <= '0; |
| 124 | + end else begin |
| 125 | + boot_addr_q <= boot_addr_d; |
| 126 | + fetch_en_q <= fetch_en_d; |
| 127 | + core_status_q <= core_status_d; |
| 128 | + boot_mode_q <= boot_mode_d; |
| 129 | + sram_dly_q <= sram_dly_d; |
| 130 | + obi_req_q <= obi_req_d; |
| 131 | + rdata_q <= rdata_d; |
| 132 | + err_q <= err_d; |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | +endmodule |
0 commit comments