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

Subversion Repositories openrisc_me

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

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 412 julius
   assign  wb_b3_trans_stop = (wb_cti_i == 3'b111) &
66
                              wb_stb_i & wb_b3_trans & wb_ack_o;
67
 
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 412 julius
   assign wb_ack_o = wb_ack_o_r & wb_stb_i;
165
 
166
   always @ (posedge wb_clk_i)
167
     if (wb_rst_i)
168 439 julius
       wb_ack_o_r <= 1'b0;
169 412 julius
     else if (wb_cyc_i) // We have bus
170
       begin
171 439 julius
          if (addr_err & wb_stb_i)
172 412 julius
            begin
173 439 julius
               wb_ack_o_r <= 1;
174
            end
175
          else if (wb_cti_i == 3'b000)
176
            begin
177 412 julius
               // Classic cycle acks
178
               if (wb_stb_i)
179
                 begin
180
                    if (!wb_ack_o_r)
181 439 julius
                      wb_ack_o_r <= 1;
182 412 julius
                    else
183 439 julius
                      wb_ack_o_r <= 0;
184 412 julius
                 end
185
            end // if (wb_cti_i == 3'b000)
186
          else if ((wb_cti_i == 3'b001) | (wb_cti_i == 3'b010))
187
            begin
188
               // Increment/constant address bursts
189
               if (wb_stb_i)
190 439 julius
                 wb_ack_o_r <= 1;
191 412 julius
               else
192 439 julius
                 wb_ack_o_r <= 0;
193 412 julius
            end
194
          else if (wb_cti_i == 3'b111)
195
            begin
196
               // End of cycle
197
               if (!wb_ack_o_r)
198 439 julius
                 wb_ack_o_r <= wb_stb_i;
199 412 julius
               else
200 439 julius
                 wb_ack_o_r <= 0;
201 412 julius
            end
202
       end // if (wb_cyc_i)
203
     else
204 439 julius
       wb_ack_o_r <= 0;
205
 
206
 
207
   //
208
   // Error signal generation
209
   //
210 412 julius
 
211 439 julius
   // Error when out of bounds of memory - skip top byte of address in case
212
   // this is mapped somewhere other than 0x00.
213
   assign addr_err  = wb_cyc_i & wb_stb_i & (|wb_adr_i[aw-1-8:mem_adr_width]);
214 412 julius
 
215 439 julius
   // OR in other errors here...
216
   assign wb_err_o = wb_ack_o & (burst_access_wrong_wb_adr | addr_err);
217
 
218
   //
219
   // Access functions
220
   //
221
 
222
   // Function to access RAM (for use by Verilator).
223 462 julius
   function [31:0] get_mem32;
224 439 julius
      // verilator public
225
      input [aw-1:0]             addr;
226 462 julius
      get_mem32 = mem[addr];
227
   endfunction // get_mem32   
228 439 julius
 
229
   // Function to access RAM (for use by Verilator).
230 462 julius
   function [7:0] get_mem8;
231 439 julius
      // verilator public
232
      input [aw-1:0]             addr;
233 462 julius
            reg [31:0]           temp_word;
234 439 julius
      begin
235 462 julius
         temp_word = mem[{addr[aw-1:2],2'd0}];
236 439 julius
         // Big endian mapping.
237 462 julius
         get_mem8 = (addr[1:0]==2'b00) ? temp_word[31:24] :
238 439 julius
                    (addr[1:0]==2'b01) ? temp_word[23:16] :
239
                    (addr[1:0]==2'b10) ? temp_word[15:8] : temp_word[7:0];
240
         end
241 462 julius
   endfunction // get_mem8   
242 439 julius
 
243
   // Function to write RAM (for use by Verilator).
244 462 julius
   function set_mem32;
245 439 julius
      // verilator public
246
      input [aw-1:0]             addr;
247
      input [dw-1:0]             data;
248 462 julius
      mem[addr] = data;
249
   endfunction // set_mem32   
250 439 julius
 
251 412 julius
endmodule // ram_wb_b3
252 51 julius
 

powered by: WebSVN 2.1.0

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