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 434

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

Line No. Rev Author Line
1 412 julius
//`define NONBLOCK_ASSIGN <= #1
2
`define NONBLOCK_ASSIGN <=
3 6 julius
 
4 412 julius
module ram_wb_b3(
5
                 wb_adr_i, wb_bte_i, wb_cti_i, wb_cyc_i, wb_dat_i, wb_sel_i,
6
                 wb_stb_i, wb_we_i,
7
 
8
                 wb_ack_o, wb_err_o, wb_rty_o, wb_dat_o,
9
 
10
                 wb_clk_i, wb_rst_i);
11
 
12
   parameter dw = 32;
13
   parameter aw = 32;
14
 
15
   input [aw-1:0]        wb_adr_i;
16
   input [1:0]           wb_bte_i;
17
   input [2:0]           wb_cti_i;
18
   input                wb_cyc_i;
19
   input [dw-1:0]        wb_dat_i;
20
   input [3:0]           wb_sel_i;
21
   input                wb_stb_i;
22
   input                wb_we_i;
23 6 julius
 
24 412 julius
   output               wb_ack_o;
25
   output               wb_err_o;
26
   output               wb_rty_o;
27
   output [dw-1:0]       wb_dat_o;
28
 
29
   input                wb_clk_i;
30
   input                wb_rst_i;
31 6 julius
 
32 412 julius
   // Memory parameters
33
   //parameter mem_span = 32'h0000_0400;
34
   parameter mem_span = 32'h0000_5000;
35
//   parameter adr_width_for_span = 11; //(log2(mem_span));
36
   parameter adr_width_for_span = 15; //(log2(mem_span));
37
   parameter bytes_per_dw = (dw/8);
38
   parameter adr_width_for_num_word_bytes = 2; //(log2(bytes_per_dw))
39
   parameter mem_words = (mem_span/bytes_per_dw);
40 6 julius
 
41 412 julius
   // synthesis attribute ram_style of mem is block
42
   reg [dw-1:0]  mem [ 0 : mem_words-1 ] /* synthesis ram_style = no_rw_check */;
43
 
44
   reg [(adr_width_for_span-2)-1:0] adr;
45
 
46
   wire [31:0]                      wr_data;
47 51 julius
 
48 412 julius
   // Register to indicate if the cycle is a Wishbone B3-registered feedback 
49
   // type access
50
   reg                             wb_b3_trans;
51
   wire                            wb_b3_trans_start, wb_b3_trans_stop;
52 51 julius
 
53 412 julius
   // Register to use for counting the addresses when doing burst accesses
54
   reg [adr_width_for_span-1-2:0]  burst_adr_counter;
55
   reg [2:0]                        wb_cti_i_r;
56
   reg [1:0]                        wb_bte_i_r;
57
   wire                            using_burst_adr;
58
   wire                            burst_access_wrong_wb_adr;
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
       wb_b3_trans `NONBLOCK_ASSIGN 0;
71
     else if (wb_b3_trans_start)
72
       wb_b3_trans `NONBLOCK_ASSIGN 1;
73
     else if (wb_b3_trans_stop)
74
       wb_b3_trans `NONBLOCK_ASSIGN 0;
75
 
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
       burst_adr_counter <= wb_adr_i[adr_width_for_span-1:2];
84
     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
            burst_adr_counter <= adr + 1;
89
          if (wb_bte_i_r == 2'b01) // 4-beat wrap burst
90
            burst_adr_counter[1:0] <= adr[1:0] + 1;
91
          if (wb_bte_i_r == 2'b10) // 8-beat wrap burst
92
            burst_adr_counter[2:0] <= adr[2:0] + 1;
93
          if (wb_bte_i_r == 2'b11) // 16-beat wrap burst
94
            burst_adr_counter[3:0] <= adr[3:0] + 1;
95
       end // if ((wb_cti_i_r == 3'b010) & wb_ack_o_r)
96
 
97
 
98
   always @(posedge wb_clk_i)
99
     wb_bte_i_r `NONBLOCK_ASSIGN wb_bte_i;
100
 
101
   // Register it locally
102
   always @(posedge wb_clk_i)
103
     wb_cti_i_r `NONBLOCK_ASSIGN wb_cti_i;
104
 
105
   assign using_burst_adr = wb_b3_trans;
106
 
107
   assign burst_access_wrong_wb_adr = (using_burst_adr & (adr != wb_adr_i[adr_width_for_span-1:2]));
108
 
109
   // Address registering logic
110
   always@(posedge wb_clk_i)
111
     if(wb_rst_i)
112
       adr `NONBLOCK_ASSIGN 0;
113
     else if (using_burst_adr)
114
       adr `NONBLOCK_ASSIGN burst_adr_counter;
115
     else if (wb_cyc_i & wb_stb_i)
116
       adr `NONBLOCK_ASSIGN wb_adr_i[adr_width_for_span-1:2];
117
 
118
   parameter memory_file = "sram.vmem";
119
 
120 6 julius
   initial
121
     begin
122 412 julius
        $readmemh(memory_file, mem);
123 6 julius
     end
124 412 julius
 
125
   assign wb_rty_o = 0;
126
 
127
   // mux for data to ram, RMW on part sel != 4'hf
128
   assign wr_data[31:24] = wb_sel_i[3] ? wb_dat_i[31:24] : wb_dat_o[31:24];
129
   assign wr_data[23:16] = wb_sel_i[2] ? wb_dat_i[23:16] : wb_dat_o[23:16];
130
   assign wr_data[15: 8] = wb_sel_i[1] ? wb_dat_i[15: 8] : wb_dat_o[15: 8];
131
   assign wr_data[ 7: 0] = wb_sel_i[0] ? wb_dat_i[ 7: 0] : wb_dat_o[ 7: 0];
132 6 julius
 
133 412 julius
   wire ram_we;
134
   assign ram_we = wb_we_i & wb_ack_o;
135
 
136
   assign wb_dat_o = mem[adr];
137
 
138
   // Write logic
139
   always @ (posedge wb_clk_i)
140
     begin
141
        if (ram_we)
142
          mem[adr] `NONBLOCK_ASSIGN wr_data;
143
     end
144 51 julius
 
145 412 julius
   // Ack Logic
146
   reg wb_ack_o_r;
147 51 julius
 
148 412 julius
   assign wb_ack_o = wb_ack_o_r & wb_stb_i;
149
 
150
   always @ (posedge wb_clk_i)
151
     if (wb_rst_i)
152
       wb_ack_o_r `NONBLOCK_ASSIGN 1'b0;
153
     else if (wb_cyc_i) // We have bus
154
       begin
155
          if (wb_cti_i == 3'b000)
156
            begin
157
               // Classic cycle acks
158
               if (wb_stb_i)
159
                 begin
160
                    if (!wb_ack_o_r)
161
                      wb_ack_o_r `NONBLOCK_ASSIGN 1;
162
                    else
163
                      wb_ack_o_r `NONBLOCK_ASSIGN 0;
164
                 end
165
            end // if (wb_cti_i == 3'b000)
166
          else if ((wb_cti_i == 3'b001) | (wb_cti_i == 3'b010))
167
            begin
168
               // Increment/constant address bursts
169
               if (wb_stb_i)
170
                 wb_ack_o_r `NONBLOCK_ASSIGN 1;
171
               else
172
                 wb_ack_o_r `NONBLOCK_ASSIGN 0;
173
            end
174
          else if (wb_cti_i == 3'b111)
175
            begin
176
               // End of cycle
177
               if (!wb_ack_o_r)
178
                 wb_ack_o_r `NONBLOCK_ASSIGN wb_stb_i;
179
               else
180
                 wb_ack_o_r `NONBLOCK_ASSIGN 0;
181
            end
182
       end // if (wb_cyc_i)
183
     else
184
       wb_ack_o_r `NONBLOCK_ASSIGN 0;
185
 
186
   assign wb_err_o = wb_ack_o & (burst_access_wrong_wb_adr); // OR in other errors here
187
 
188
endmodule // ram_wb_b3
189 51 julius
 

powered by: WebSVN 2.1.0

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