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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 412 julius
module ram_wb
2
  (
3
   // Inputs
4
   wbm0_adr_i, wbm0_bte_i, wbm0_cti_i, wbm0_cyc_i, wbm0_dat_i, wbm0_sel_i,
5
   wbm0_stb_i, wbm0_we_i,
6
   // Outputs
7
   wbm0_ack_o, wbm0_err_o, wbm0_rty_o, wbm0_dat_o,
8
 
9
   // Inputs
10
   wbm1_adr_i, wbm1_bte_i, wbm1_cti_i, wbm1_cyc_i, wbm1_dat_i, wbm1_sel_i,
11
   wbm1_stb_i, wbm1_we_i,
12
   // Outputs
13
   wbm1_ack_o, wbm1_err_o, wbm1_rty_o, wbm1_dat_o,
14 6 julius
 
15 439 julius
    // Inputs
16
   wbm2_adr_i, wbm2_bte_i, wbm2_cti_i, wbm2_cyc_i, wbm2_dat_i, wbm2_sel_i,
17
   wbm2_stb_i, wbm2_we_i,
18
   // Outputs
19
   wbm2_ack_o, wbm2_err_o, wbm2_rty_o, wbm2_dat_o,
20
 
21 412 julius
   // Clock, reset
22
   wb_clk_i, wb_rst_i
23
   );
24
   // Bus parameters
25
   parameter dw = 32;
26
   parameter aw = 32;
27
   // Memory parameters
28 439 julius
   parameter mem_size_bytes = 32'h0000_0400; // 1KBytes
29
   parameter mem_adr_width = 10; //(log2(mem_span));
30 412 julius
 
31
   input [aw-1:0]        wbm0_adr_i;
32
   input [1:0]           wbm0_bte_i;
33
   input [2:0]           wbm0_cti_i;
34
   input                wbm0_cyc_i;
35
   input [dw-1:0]        wbm0_dat_i;
36
   input [3:0]           wbm0_sel_i;
37
   input                wbm0_stb_i;
38
   input                wbm0_we_i;
39 6 julius
 
40 412 julius
   output               wbm0_ack_o;
41
   output               wbm0_err_o;
42
   output               wbm0_rty_o;
43
   output [dw-1:0]       wbm0_dat_o;
44
 
45
   input [aw-1:0]        wbm1_adr_i;
46
   input [1:0]           wbm1_bte_i;
47
   input [2:0]           wbm1_cti_i;
48
   input                wbm1_cyc_i;
49
   input [dw-1:0]        wbm1_dat_i;
50
   input [3:0]           wbm1_sel_i;
51
   input                wbm1_stb_i;
52
   input                wbm1_we_i;
53 6 julius
 
54 412 julius
   output               wbm1_ack_o;
55
   output               wbm1_err_o;
56
   output               wbm1_rty_o;
57
   output [dw-1:0]       wbm1_dat_o;
58 439 julius
 
59
   input [aw-1:0]        wbm2_adr_i;
60
   input [1:0]           wbm2_bte_i;
61
   input [2:0]           wbm2_cti_i;
62
   input                wbm2_cyc_i;
63
   input [dw-1:0]        wbm2_dat_i;
64
   input [3:0]           wbm2_sel_i;
65
   input                wbm2_stb_i;
66
   input                wbm2_we_i;
67 6 julius
 
68 439 julius
   output               wbm2_ack_o;
69
   output               wbm2_err_o;
70
   output               wbm2_rty_o;
71
   output [dw-1:0]       wbm2_dat_o;
72
 
73 412 julius
 
74
   input                wb_clk_i;
75
   input                wb_rst_i;
76
 
77
   // Internal wires to actual RAM
78 439 julius
   wire [aw-1:0]         wbs_ram_adr_i;
79
   wire [1:0]            wbs_ram_bte_i;
80
   wire [2:0]            wbs_ram_cti_i;
81
   wire                 wbs_ram_cyc_i;
82
   wire [dw-1:0]         wbs_ram_dat_i;
83
   wire [3:0]            wbs_ram_sel_i;
84
   wire                 wbs_ram_stb_i;
85
   wire                 wbs_ram_we_i;
86 6 julius
 
87 439 julius
   wire                 wbs_ram_ack_o;
88
   wire                 wbs_ram_err_o;
89
   wire                 wbs_ram_rty_o;
90
   wire [dw-1:0]         wbs_ram_dat_o;
91 412 julius
 
92 439 julius
   reg [2:0]             input_select, last_selected;
93
   wire                 arb_for_wbm0, arb_for_wbm1, arb_for_wbm2;
94 412 julius
   // Wires allowing selection of new input
95 439 julius
   assign arb_for_wbm0 = (last_selected[1] | last_selected[2] |
96
                          !wbm1_cyc_i | !wbm2_cyc_i) & !(|input_select);
97
   assign arb_for_wbm1 = (last_selected[0] | last_selected[2] |
98
                          !wbm0_cyc_i | !wbm2_cyc_i) & !(|input_select);
99
   assign arb_for_wbm2 = (last_selected[0] | last_selected[1] |
100
                          !wbm0_cyc_i | !wbm1_cyc_i) & !(|input_select);
101 6 julius
 
102 412 julius
   // Master select logic
103
   always @(posedge wb_clk_i)
104
     if (wb_rst_i)
105
       input_select <= 0;
106 439 julius
     else if ((input_select[0] & !wbm0_cyc_i) | (input_select[1] & !wbm1_cyc_i)
107
              | (input_select[2] & !wbm2_cyc_i))
108 412 julius
       input_select <= 0;
109
     else if (!(&input_select) & wbm0_cyc_i & arb_for_wbm0)
110 439 julius
       input_select <= 3'b001;
111 412 julius
     else if (!(&input_select) & wbm1_cyc_i & arb_for_wbm1)
112 439 julius
       input_select <= 3'b010;
113
     else if (!(&input_select) & wbm2_cyc_i & arb_for_wbm2)
114
       input_select <= 3'b100;
115 412 julius
 
116
   always @(posedge wb_clk_i)
117
     if (wb_rst_i)
118
       last_selected <= 0;
119
     else if (!(&input_select) & wbm0_cyc_i & arb_for_wbm0)
120 439 julius
       last_selected <= 3'b001;
121 412 julius
     else if (!(&input_select) & wbm1_cyc_i & arb_for_wbm1)
122 439 julius
       last_selected <= 3'b010;
123
     else if (!(&input_select) & wbm2_cyc_i & arb_for_wbm2)
124
       last_selected <= 3'b100;
125 412 julius
 
126 439 julius
      // Mux input signals to RAM (default to wbm0)
127
   assign wbs_ram_adr_i = (input_select[2]) ? wbm2_adr_i :
128
                            (input_select[1]) ? wbm1_adr_i :
129
                            (input_select[0]) ? wbm0_adr_i : 0;
130
   assign wbs_ram_bte_i = (input_select[2]) ? wbm2_bte_i :
131
                            (input_select[1]) ? wbm1_bte_i :
132
                            (input_select[0]) ? wbm0_bte_i : 0;
133
   assign wbs_ram_cti_i = (input_select[2]) ? wbm2_cti_i :
134
                            (input_select[1]) ? wbm1_cti_i :
135
                            (input_select[0]) ? wbm0_cti_i : 0;
136
   assign wbs_ram_cyc_i = (input_select[2]) ? wbm2_cyc_i :
137
                            (input_select[1]) ? wbm1_cyc_i :
138
                            (input_select[0]) ? wbm0_cyc_i : 0;
139
   assign wbs_ram_dat_i = (input_select[2]) ? wbm2_dat_i :
140
                            (input_select[1]) ? wbm1_dat_i :
141
                            (input_select[0]) ? wbm0_dat_i : 0;
142
   assign wbs_ram_sel_i = (input_select[2]) ? wbm2_sel_i :
143
                            (input_select[1]) ? wbm1_sel_i :
144
                            (input_select[0]) ? wbm0_sel_i : 0;
145
   assign wbs_ram_stb_i = (input_select[2]) ? wbm2_stb_i :
146
                            (input_select[1]) ? wbm1_stb_i :
147
                            (input_select[0]) ? wbm0_stb_i : 0;
148
   assign wbs_ram_we_i  = (input_select[2]) ? wbm2_we_i  :
149
                            (input_select[1]) ? wbm1_we_i  :
150
                            (input_select[0]) ? wbm0_we_i : 0;
151 412 julius
 
152
   // Output from RAM, gate the ACK, ERR, RTY signals appropriately
153 439 julius
   assign wbm0_dat_o = wbs_ram_dat_o;
154
   assign wbm0_ack_o = wbs_ram_ack_o & input_select[0];
155
   assign wbm0_err_o = wbs_ram_err_o & input_select[0];
156
   assign wbm0_rty_o = 0;
157 412 julius
 
158 439 julius
   assign wbm1_dat_o = wbs_ram_dat_o;
159
   assign wbm1_ack_o = wbs_ram_ack_o & input_select[1];
160
   assign wbm1_err_o = wbs_ram_err_o & input_select[1];
161
   assign wbm1_rty_o = 0;
162
 
163
   assign wbm2_dat_o = wbs_ram_dat_o;
164
   assign wbm2_ack_o = wbs_ram_ack_o & input_select[2];
165
   assign wbm2_err_o = wbs_ram_err_o & input_select[2];
166
   assign wbm2_rty_o = 0;
167 412 julius
 
168
   ram_wb_b3 ram_wb_b3_0
169 6 julius
     (
170 412 julius
      // Outputs
171 439 julius
      .wb_ack_o                         (wbs_ram_ack_o),
172
      .wb_err_o                         (wbs_ram_err_o),
173
      .wb_rty_o                         (wbs_ram_rty_o),
174
      .wb_dat_o                         (wbs_ram_dat_o),
175 412 julius
      // Inputs
176 439 julius
      .wb_adr_i                         (wbs_ram_adr_i),
177
      .wb_bte_i                         (wbs_ram_bte_i),
178
      .wb_cti_i                         (wbs_ram_cti_i),
179
      .wb_cyc_i                         (wbs_ram_cyc_i),
180
      .wb_dat_i                         (wbs_ram_dat_i),
181
      .wb_sel_i                         (wbs_ram_sel_i),
182
      .wb_stb_i                         (wbs_ram_stb_i),
183
      .wb_we_i                          (wbs_ram_we_i),
184 412 julius
      .wb_clk_i                         (wb_clk_i),
185
      .wb_rst_i                         (wb_rst_i));
186 6 julius
 
187 412 julius
   defparam ram_wb_b3_0.aw = aw;
188
   defparam ram_wb_b3_0.dw = dw;
189 439 julius
   defparam ram_wb_b3_0.mem_size_bytes = mem_size_bytes;
190
   defparam ram_wb_b3_0.mem_adr_width = mem_adr_width;
191 412 julius
 
192
endmodule // ram_wb
193
 
194
 

powered by: WebSVN 2.1.0

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