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 11

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
      .DATA_WIDTH(SCR1_WB_WIDTH), // Data Width
172
      .ADDR_WIDTH(1),   // Address Width
173
      .FIFO_DEPTH(2)    // FIFO DEPTH
174
     )   u_req_fifo(
175
 
176
       .dout      (req_fifo_dout  ),
177
 
178
       .rstn      (rst_n          ),
179
       .clk       (clk            ),
180
       .wr_en     (req_fifo_wr    ), // Write
181
       .rd_en     (req_fifo_rd    ), // Read
182
       .din       (imem_addr      ),
183
       .full      (req_fifo_full  ),
184
       .empty     (req_fifo_empty )
185
);
186
 
187
 
188
 
189
 
190
`endif // SCR1_IMEM_WB_OUT_BP
191
 
192
 
193
always_comb begin
194
    req_fifo_rd = 1'b0;
195
    if (wbd_ack_i) begin
196
         req_fifo_rd = ~req_fifo_empty;
197
    end
198
end
199
 
200
//-------------------------------------------------------------------------------
201
// FIFO response
202
//-------------------------------------------------------------------------------
203
`ifdef SCR1_IMEM_WB_IN_BP
204
assign resp_fifo_hready = wbd_ack_i;
205
assign resp_fifo.hresp  = (wbd_err_i) ? 1'b0 : 1'b1;
206
assign resp_fifo.hrdata = wbd_dat_i;
207
assign wbd_stb_o        = ~req_fifo_empty;
208
assign wbd_adr_o        = req_fifo[0];
209
assign wbd_we_o         = 0; // Only Read supported
210
assign wbd_dat_o        = 32'h0; // No Write
211
assign wbd_sel_o        = 4'b1111; // Only Read allowed in imem i/f
212
 
213
 
214
`else // SCR1_IMEM_WB_IN_BP
215
always_ff @(negedge rst_n, posedge clk) begin
216
    if (~rst_n) begin
217
        resp_fifo_hready <= 1'b0;
218
    end else begin
219
        resp_fifo_hready <= wbd_ack_i ;
220
    end
221
end
222
 
223
always_ff @(posedge clk) begin
224
    if (wbd_ack_i) begin
225
        resp_fifo.hresp  <= (wbd_err_i) ? 1'b0 : 1'b1;
226
        resp_fifo.hrdata <= wbd_dat_i;
227
    end
228
end
229
 
230
assign wbd_stb_o    = ~req_fifo_empty;
231
assign wbd_adr_o    = req_fifo_dout;
232
assign wbd_we_o     = 0; // Only Read supported
233
assign wbd_dat_o    = 32'h0; // No Write
234
assign wbd_sel_o    = 4'b1111; // Only Read allowed in imem i/f
235
`endif // SCR1_IMEM_WB_IN_BP
236
 
237
 
238
 
239
`ifdef SCR1_TRGT_SIMULATION
240
//-------------------------------------------------------------------------------
241
// Assertion
242
//-------------------------------------------------------------------------------
243
 
244
// Check Core interface
245
SCR1_SVA_IMEM_WB_BRIDGE_REQ_XCHECK : assert property (
246
    @(negedge clk) disable iff (~rst_n)
247
    !$isunknown(imem_req)
248
    ) else $error("IMEM WB bridge Error: imem_req has unknown values");
249
 
250
SCR1_IMEM_WB_BRIDGE_ADDR_XCHECK : assert property (
251
    @(negedge clk) disable iff (~rst_n)
252
    imem_req |-> !$isunknown(imem_addr)
253
    ) else $error("IMEM WB bridge Error: imem_addr has unknown values");
254
 
255
SCR1_IMEM_WB_BRIDGE_ADDR_ALLIGN : assert property (
256
    @(negedge clk) disable iff (~rst_n)
257
    imem_req |-> (imem_addr[1:0] == '0)
258
    ) else $error("IMEM WB bridge Error: imem_addr has unalign values");
259
 
260
// Check WB interface
261
SCR1_IMEM_WB_BRIDGE_HREADY_XCHECK : assert property (
262
    @(negedge clk) disable iff (~rst_n)
263
    !$isunknown(hready)
264
    ) else $error("IMEM WB bridge Error: hready has unknown values");
265
 
266
SCR1_IMEM_WB_BRIDGE_HRESP_XCHECK : assert property (
267
    @(negedge clk) disable iff (~rst_n)
268
    !$isunknown(hresp)
269
    ) else $error("IMEM WB bridge Error: hresp has unknown values");
270
 
271
`endif // SCR1_TRGT_SIMULATION
272
 
273
endmodule : scr1_imem_wb

powered by: WebSVN 2.1.0

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