OpenCores
URL https://opencores.org/ocsvn/yifive/yifive/trunk

Subversion Repositories yifive

[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [syntacore/] [scr1/] [src/] [top/] [scr1_imem_wb.sv] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 11 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  yifive Wishbone interface for Instruction memory            ////
4
////                                                              ////
5
////  This file is part of the yifive cores project               ////
6
////  http://www.opencores.org/cores/yifive/                      ////
7
////                                                              ////
8
////  Description:                                                ////
9
////     integrated wishbone i/f to instruction memory            ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
////  Revision :                                                  ////
18
////     v0:    June 7, 2021, Dinesh A                            ////
19
////             wishbone integration                             ////
20
////                                                              ////
21
//////////////////////////////////////////////////////////////////////
22
////                                                              ////
23
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE.  See the GNU Lesser General Public License for more ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from http://www.opencores.org/lgpl.shtml                     ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
//     Orginal owner Details                                      ////
48
//////////////////////////////////////////////////////////////////////
49
/// Copyright by Syntacore LLC © 2016-2021. See LICENSE for details///
50
/// @file                                         ///
51
/// @brief      Instruction memory AHB bridge                      ///
52
//////////////////////////////////////////////////////////////////////
53
 
54
`include "scr1_wb.svh"
55
`include "scr1_memif.svh"
56
 
57
module scr1_imem_wb (
58
    // Control Signals
59
    input   logic                           rst_n,
60
    input   logic                           clk,
61
 
62
    // Core Interface
63
    output  logic                           imem_req_ack,
64
    input   logic                           imem_req,
65
    input   logic   [SCR1_WB_WIDTH-1:0]     imem_addr,
66
    output  logic   [SCR1_WB_WIDTH-1:0]     imem_rdata,
67
    output  type_scr1_mem_resp_e            imem_resp,
68
 
69
    // WB Interface
70
    output  logic                           wbd_stb_o, // strobe/request
71
    output  logic   [SCR1_WB_WIDTH-1:0]     wbd_adr_o, // address
72
    output  logic                           wbd_we_o,  // write
73
    output  logic   [SCR1_WB_WIDTH-1:0]     wbd_dat_o, // data output
74
    output  logic   [3:0]                   wbd_sel_o, // byte enable
75
    input   logic   [SCR1_WB_WIDTH-1:0]     wbd_dat_i, // data input
76
    input   logic                           wbd_ack_i, // acknowlegement
77
    input   logic                           wbd_err_i  // error
78
 
79
);
80
 
81
//-------------------------------------------------------------------------------
82
// Local parameters declaration
83
//-------------------------------------------------------------------------------
84
`ifndef SCR1_IMEM_WB_OUT_BP
85
localparam  SCR1_FIFO_WIDTH = 2;
86
localparam  SCR1_FIFO_CNT_WIDTH = $clog2(SCR1_FIFO_WIDTH+1);
87
`endif // SCR1_IMEM_WB_OUT_BP
88
 
89
//-------------------------------------------------------------------------------
90
// Local types declaration
91
//-------------------------------------------------------------------------------
92
typedef enum logic {
93
    SCR1_FSM_ADDR = 1'b0,
94
    SCR1_FSM_DATA = 1'b1,
95
    SCR1_FSM_ERR  = 1'bx
96
} type_scr1_fsm_e;
97
 
98
typedef struct packed {
99
    logic   [SCR1_WB_WIDTH-1:0]    haddr;
100
} type_scr1_req_fifo_s;
101
 
102
typedef struct packed {
103
    logic                           hresp;
104
    logic   [SCR1_WB_WIDTH-1:0]    hrdata;
105
} type_scr1_resp_fifo_s;
106
 
107
//-------------------------------------------------------------------------------
108
// Local signal declaration
109
//-------------------------------------------------------------------------------
110
type_scr1_fsm_e                             fsm;
111
logic                                       req_fifo_rd;
112
logic                                       req_fifo_wr;
113
logic                                       req_fifo_up;
114
`ifdef SCR1_IMEM_WB_OUT_BP
115
type_scr1_req_fifo_s                        req_fifo_r;
116
type_scr1_req_fifo_s [0:0]                  req_fifo;
117
`else // SCR1_IMEM_WB_OUT_BP
118
logic [SCR1_WB_WIDTH-1:0]                   req_fifo_dout;
119
`endif // SCR1_IMEM_WB_OUT_BP
120
 
121
logic                                       req_fifo_empty;
122
logic                                       req_fifo_full;
123
 
124
type_scr1_resp_fifo_s                       resp_fifo;
125
logic                                       resp_fifo_hready;
126
 
127
//-------------------------------------------------------------------------------
128
// Interface to Core
129
//-------------------------------------------------------------------------------
130
assign imem_req_ack = ~req_fifo_full;
131
assign req_fifo_wr  = ~req_fifo_full & imem_req;
132
 
133
assign imem_rdata = resp_fifo.hrdata;
134
 
135
assign imem_resp = (resp_fifo_hready)
136
                    ? (resp_fifo.hresp == 1'b1)
137
                        ? SCR1_MEM_RESP_RDY_OK
138
                        : SCR1_MEM_RESP_RDY_ER
139
                    : SCR1_MEM_RESP_NOTRDY;
140
 
141
//-------------------------------------------------------------------------------
142
// REQ_FIFO
143
//-------------------------------------------------------------------------------
144
`ifdef SCR1_IMEM_WB_OUT_BP
145
always_ff @(negedge rst_n, posedge clk) begin
146
    if (~rst_n) begin
147
        req_fifo_full <= 1'b0;
148
    end else begin
149
        if (~req_fifo_full) begin
150
            req_fifo_full <= imem_req & ~req_fifo_rd;
151
        end else begin
152
            req_fifo_full <= ~req_fifo_rd;
153
        end
154
    end
155
end
156
assign req_fifo_empty = ~(req_fifo_full | imem_req);
157
 
158
assign req_fifo_up    = ~req_fifo_rd & req_fifo_wr;
159
always_ff @(posedge clk) begin
160
    if (req_fifo_up) begin
161
        req_fifo_r.haddr <= imem_addr;
162
    end
163
end
164
 
165
assign req_fifo[0] = (req_fifo_full) ? req_fifo_r : imem_addr;
166
 
167
`else // SCR1_IMEM_WB_OUT_BP
168
 
169
 
170
 sync_fifo #(
171 19 dinesha
      .W(SCR1_WB_WIDTH), // Data Width
172
      .D(2)    // FIFO DEPTH
173 11 dinesha
     )   u_req_fifo(
174
 
175 19 dinesha
       .rd_data    (req_fifo_dout  ),
176 11 dinesha
 
177 19 dinesha
       .reset_n   (rst_n          ),
178 11 dinesha
       .clk       (clk            ),
179
       .wr_en     (req_fifo_wr    ), // Write
180
       .rd_en     (req_fifo_rd    ), // Read
181 19 dinesha
       .wr_data   (imem_addr      ),
182 11 dinesha
       .full      (req_fifo_full  ),
183
       .empty     (req_fifo_empty )
184
);
185
 
186
 
187
 
188
 
189
`endif // SCR1_IMEM_WB_OUT_BP
190
 
191
 
192
always_comb begin
193
    req_fifo_rd = 1'b0;
194
    if (wbd_ack_i) begin
195
         req_fifo_rd = ~req_fifo_empty;
196
    end
197
end
198
 
199
//-------------------------------------------------------------------------------
200
// FIFO response
201
//-------------------------------------------------------------------------------
202
`ifdef SCR1_IMEM_WB_IN_BP
203
assign resp_fifo_hready = wbd_ack_i;
204
assign resp_fifo.hresp  = (wbd_err_i) ? 1'b0 : 1'b1;
205
assign resp_fifo.hrdata = wbd_dat_i;
206
assign wbd_stb_o        = ~req_fifo_empty;
207
assign wbd_adr_o        = req_fifo[0];
208
assign wbd_we_o         = 0; // Only Read supported
209
assign wbd_dat_o        = 32'h0; // No Write
210
assign wbd_sel_o        = 4'b1111; // Only Read allowed in imem i/f
211
 
212
 
213
`else // SCR1_IMEM_WB_IN_BP
214
always_ff @(negedge rst_n, posedge clk) begin
215
    if (~rst_n) begin
216
        resp_fifo_hready <= 1'b0;
217
    end else begin
218
        resp_fifo_hready <= wbd_ack_i ;
219
    end
220
end
221
 
222
always_ff @(posedge clk) begin
223
    if (wbd_ack_i) begin
224
        resp_fifo.hresp  <= (wbd_err_i) ? 1'b0 : 1'b1;
225
        resp_fifo.hrdata <= wbd_dat_i;
226
    end
227
end
228
 
229
assign wbd_stb_o    = ~req_fifo_empty;
230
assign wbd_adr_o    = req_fifo_dout;
231
assign wbd_we_o     = 0; // Only Read supported
232
assign wbd_dat_o    = 32'h0; // No Write
233
assign wbd_sel_o    = 4'b1111; // Only Read allowed in imem i/f
234
`endif // SCR1_IMEM_WB_IN_BP
235
 
236
 
237
 
238
`ifdef SCR1_TRGT_SIMULATION
239
//-------------------------------------------------------------------------------
240
// Assertion
241
//-------------------------------------------------------------------------------
242
 
243
// Check Core interface
244
SCR1_SVA_IMEM_WB_BRIDGE_REQ_XCHECK : assert property (
245
    @(negedge clk) disable iff (~rst_n)
246
    !$isunknown(imem_req)
247
    ) else $error("IMEM WB bridge Error: imem_req has unknown values");
248
 
249
SCR1_IMEM_WB_BRIDGE_ADDR_XCHECK : assert property (
250
    @(negedge clk) disable iff (~rst_n)
251
    imem_req |-> !$isunknown(imem_addr)
252
    ) else $error("IMEM WB bridge Error: imem_addr has unknown values");
253
 
254
SCR1_IMEM_WB_BRIDGE_ADDR_ALLIGN : assert property (
255
    @(negedge clk) disable iff (~rst_n)
256
    imem_req |-> (imem_addr[1:0] == '0)
257
    ) else $error("IMEM WB bridge Error: imem_addr has unalign values");
258
 
259
// Check WB interface
260
SCR1_IMEM_WB_BRIDGE_HREADY_XCHECK : assert property (
261
    @(negedge clk) disable iff (~rst_n)
262
    !$isunknown(hready)
263
    ) else $error("IMEM WB bridge Error: hready has unknown values");
264
 
265
SCR1_IMEM_WB_BRIDGE_HRESP_XCHECK : assert property (
266
    @(negedge clk) disable iff (~rst_n)
267
    !$isunknown(hresp)
268
    ) else $error("IMEM WB bridge Error: hresp has unknown values");
269
 
270
`endif // SCR1_TRGT_SIMULATION
271
 
272
endmodule : scr1_imem_wb

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.