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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ram_wb/] [ram_wb_b3.v] - Blame information for rev 583

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

Line No. Rev Author Line
1 412 julius
module ram_wb_b3(
2
                 wb_adr_i, wb_bte_i, wb_cti_i, wb_cyc_i, wb_dat_i, wb_sel_i,
3
                 wb_stb_i, wb_we_i,
4
 
5
                 wb_ack_o, wb_err_o, wb_rty_o, wb_dat_o,
6
 
7
                 wb_clk_i, wb_rst_i);
8
 
9
   parameter dw = 32;
10
   parameter aw = 32;
11
 
12
   input [aw-1:0]        wb_adr_i;
13
   input [1:0]           wb_bte_i;
14
   input [2:0]           wb_cti_i;
15
   input                wb_cyc_i;
16
   input [dw-1:0]        wb_dat_i;
17
   input [3:0]           wb_sel_i;
18
   input                wb_stb_i;
19
   input                wb_we_i;
20 6 julius
 
21 412 julius
   output               wb_ack_o;
22
   output               wb_err_o;
23
   output               wb_rty_o;
24
   output [dw-1:0]       wb_dat_o;
25
 
26
   input                wb_clk_i;
27
   input                wb_rst_i;
28 6 julius
 
29 412 julius
   // Memory parameters
30 439 julius
   parameter mem_size_bytes = 32'h0000_5000; // 20KBytes
31
   parameter mem_adr_width = 15; //(log2(mem_size_bytes));
32
 
33 412 julius
   parameter bytes_per_dw = (dw/8);
34
   parameter adr_width_for_num_word_bytes = 2; //(log2(bytes_per_dw))
35 439 julius
   parameter mem_words = (mem_size_bytes/bytes_per_dw);
36 6 julius
 
37 412 julius
   // synthesis attribute ram_style of mem is block
38 462 julius
   reg [dw-1:0]  mem [ 0 : mem_words-1 ]   /* verilator public */ /* synthesis ram_style = no_rw_check */;
39 439 julius
 
40
   // Register to address internal memory array
41
   reg [(mem_adr_width-adr_width_for_num_word_bytes)-1:0] adr;
42 412 julius
 
43
   wire [31:0]                      wr_data;
44 51 julius
 
45 412 julius
   // Register to indicate if the cycle is a Wishbone B3-registered feedback 
46
   // type access
47
   reg                             wb_b3_trans;
48
   wire                            wb_b3_trans_start, wb_b3_trans_stop;
49 51 julius
 
50 412 julius
   // Register to use for counting the addresses when doing burst accesses
51 439 julius
   reg [mem_adr_width-adr_width_for_num_word_bytes-1:0]  burst_adr_counter;
52 412 julius
   reg [2:0]                        wb_cti_i_r;
53
   reg [1:0]                        wb_bte_i_r;
54
   wire                            using_burst_adr;
55
   wire                            burst_access_wrong_wb_adr;
56 439 julius
 
57
   // Wire to indicate addressing error
58
   wire                            addr_err;
59 51 julius
 
60
 
61 412 julius
   // Logic to detect if there's a burst access going on
62
   assign wb_b3_trans_start = ((wb_cti_i == 3'b001)|(wb_cti_i == 3'b010)) &
63
                              wb_stb_i & !wb_b3_trans;
64 51 julius
 
65 546 julius
   assign  wb_b3_trans_stop = ((wb_cti_i == 3'b111) &
66
                              wb_stb_i & wb_b3_trans & wb_ack_o) | wb_err_o;
67 412 julius
 
68
   always @(posedge wb_clk_i)
69
     if (wb_rst_i)
70 439 julius
       wb_b3_trans <= 0;
71 412 julius
     else if (wb_b3_trans_start)
72 439 julius
       wb_b3_trans <= 1;
73 412 julius
     else if (wb_b3_trans_stop)
74 439 julius
       wb_b3_trans <= 0;
75 412 julius
 
76
   // Burst address generation logic
77
   always @(/*AUTOSENSE*/wb_ack_o or wb_b3_trans or wb_b3_trans_start
78
            or wb_bte_i_r or wb_cti_i_r or wb_adr_i or adr)
79
     if (wb_b3_trans_start)
80
       // Kick off burst_adr_counter, this assumes 4-byte words when getting
81
       // address off incoming Wishbone bus address! 
82
       // So if dw is no longer 4 bytes, change this!
83 439 julius
       burst_adr_counter = wb_adr_i[mem_adr_width-1:2];
84 412 julius
     else if ((wb_cti_i_r == 3'b010) & wb_ack_o & wb_b3_trans)
85
       // Incrementing burst
86
       begin
87
          if (wb_bte_i_r == 2'b00) // Linear burst
88 439 julius
            burst_adr_counter = adr + 1;
89 412 julius
          if (wb_bte_i_r == 2'b01) // 4-beat wrap burst
90 439 julius
            burst_adr_counter[1:0] = adr[1:0] + 1;
91 412 julius
          if (wb_bte_i_r == 2'b10) // 8-beat wrap burst
92 439 julius
            burst_adr_counter[2:0] = adr[2:0] + 1;
93 412 julius
          if (wb_bte_i_r == 2'b11) // 16-beat wrap burst
94 439 julius
            burst_adr_counter[3:0] = adr[3:0] + 1;
95 412 julius
       end // if ((wb_cti_i_r == 3'b010) & wb_ack_o_r)
96
 
97
   always @(posedge wb_clk_i)
98 439 julius
     wb_bte_i_r <= wb_bte_i;
99 412 julius
 
100
   // Register it locally
101
   always @(posedge wb_clk_i)
102 439 julius
     wb_cti_i_r <= wb_cti_i;
103 412 julius
 
104
   assign using_burst_adr = wb_b3_trans;
105
 
106 439 julius
   assign burst_access_wrong_wb_adr = (using_burst_adr &
107
                                       (adr != wb_adr_i[mem_adr_width-1:2]));
108 412 julius
 
109
   // Address registering logic
110
   always@(posedge wb_clk_i)
111
     if(wb_rst_i)
112 439 julius
       adr <= 0;
113 412 julius
     else if (using_burst_adr)
114 439 julius
       adr <= burst_adr_counter;
115 412 julius
     else if (wb_cyc_i & wb_stb_i)
116 439 julius
       adr <= wb_adr_i[mem_adr_width-1:2];
117 462 julius
 
118
   /* Memory initialisation.
119
    If not Verilator model, always do load, otherwise only load when called
120
    from SystemC testbench.
121
    */
122
 
123 412 julius
   parameter memory_file = "sram.vmem";
124
 
125 462 julius
`ifdef verilator
126
 
127
   task do_readmemh;
128
      // verilator public
129
      $readmemh(memory_file, mem);
130
   endtask // do_readmemh
131
 
132
`else
133
 
134 6 julius
   initial
135
     begin
136 412 julius
        $readmemh(memory_file, mem);
137 6 julius
     end
138 462 julius
 
139
`endif // !`ifdef verilator
140 412 julius
 
141
   assign wb_rty_o = 0;
142
 
143
   // mux for data to ram, RMW on part sel != 4'hf
144
   assign wr_data[31:24] = wb_sel_i[3] ? wb_dat_i[31:24] : wb_dat_o[31:24];
145
   assign wr_data[23:16] = wb_sel_i[2] ? wb_dat_i[23:16] : wb_dat_o[23:16];
146
   assign wr_data[15: 8] = wb_sel_i[1] ? wb_dat_i[15: 8] : wb_dat_o[15: 8];
147
   assign wr_data[ 7: 0] = wb_sel_i[0] ? wb_dat_i[ 7: 0] : wb_dat_o[ 7: 0];
148 6 julius
 
149 412 julius
   wire ram_we;
150
   assign ram_we = wb_we_i & wb_ack_o;
151
 
152
   assign wb_dat_o = mem[adr];
153
 
154
   // Write logic
155
   always @ (posedge wb_clk_i)
156
     begin
157
        if (ram_we)
158 439 julius
          mem[adr] <= wr_data;
159 412 julius
     end
160 51 julius
 
161 412 julius
   // Ack Logic
162
   reg wb_ack_o_r;
163 51 julius
 
164 546 julius
   assign wb_ack_o = wb_ack_o_r & wb_stb_i &
165
                     !(burst_access_wrong_wb_adr | addr_err);
166 412 julius
 
167
   always @ (posedge wb_clk_i)
168
     if (wb_rst_i)
169 439 julius
       wb_ack_o_r <= 1'b0;
170 412 julius
     else if (wb_cyc_i) // We have bus
171
       begin
172 439 julius
          if (addr_err & wb_stb_i)
173 412 julius
            begin
174 439 julius
               wb_ack_o_r <= 1;
175
            end
176
          else if (wb_cti_i == 3'b000)
177
            begin
178 412 julius
               // Classic cycle acks
179
               if (wb_stb_i)
180
                 begin
181
                    if (!wb_ack_o_r)
182 439 julius
                      wb_ack_o_r <= 1;
183 412 julius
                    else
184 439 julius
                      wb_ack_o_r <= 0;
185 412 julius
                 end
186
            end // if (wb_cti_i == 3'b000)
187
          else if ((wb_cti_i == 3'b001) | (wb_cti_i == 3'b010))
188
            begin
189
               // Increment/constant address bursts
190
               if (wb_stb_i)
191 439 julius
                 wb_ack_o_r <= 1;
192 412 julius
               else
193 439 julius
                 wb_ack_o_r <= 0;
194 412 julius
            end
195
          else if (wb_cti_i == 3'b111)
196
            begin
197
               // End of cycle
198
               if (!wb_ack_o_r)
199 439 julius
                 wb_ack_o_r <= wb_stb_i;
200 412 julius
               else
201 439 julius
                 wb_ack_o_r <= 0;
202 412 julius
            end
203
       end // if (wb_cyc_i)
204
     else
205 439 julius
       wb_ack_o_r <= 0;
206
 
207
 
208
   //
209
   // Error signal generation
210
   //
211 412 julius
 
212 439 julius
   // Error when out of bounds of memory - skip top byte of address in case
213
   // this is mapped somewhere other than 0x00.
214
   assign addr_err  = wb_cyc_i & wb_stb_i & (|wb_adr_i[aw-1-8:mem_adr_width]);
215 412 julius
 
216 439 julius
   // OR in other errors here...
217 546 julius
   assign wb_err_o =  wb_ack_o_r & wb_stb_i &
218
                      (burst_access_wrong_wb_adr | addr_err);
219 439 julius
 
220
   //
221
   // Access functions
222
   //
223
 
224
   // Function to access RAM (for use by Verilator).
225 462 julius
   function [31:0] get_mem32;
226 439 julius
      // verilator public
227
      input [aw-1:0]             addr;
228 462 julius
      get_mem32 = mem[addr];
229
   endfunction // get_mem32   
230 439 julius
 
231
   // Function to access RAM (for use by Verilator).
232 462 julius
   function [7:0] get_mem8;
233 439 julius
      // verilator public
234
      input [aw-1:0]             addr;
235 462 julius
            reg [31:0]           temp_word;
236 439 julius
      begin
237 462 julius
         temp_word = mem[{addr[aw-1:2],2'd0}];
238 439 julius
         // Big endian mapping.
239 462 julius
         get_mem8 = (addr[1:0]==2'b00) ? temp_word[31:24] :
240 439 julius
                    (addr[1:0]==2'b01) ? temp_word[23:16] :
241
                    (addr[1:0]==2'b10) ? temp_word[15:8] : temp_word[7:0];
242
         end
243 462 julius
   endfunction // get_mem8   
244 439 julius
 
245
   // Function to write RAM (for use by Verilator).
246 462 julius
   function set_mem32;
247 439 julius
      // verilator public
248
      input [aw-1:0]             addr;
249
      input [dw-1:0]             data;
250 462 julius
      mem[addr] = data;
251
   endfunction // set_mem32   
252 439 julius
 
253 412 julius
endmodule // ram_wb_b3
254 51 julius
 

powered by: WebSVN 2.1.0

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