1 |
20 |
dinesha |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// Tubo 8051 cores common library Module ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the Turbo 8051 cores project ////
|
6 |
|
|
//// http://www.opencores.org/cores/turbo8051/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// Turbo 8051 definitions. ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// To Do: ////
|
12 |
|
|
//// nothing ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// Author(s): ////
|
15 |
|
|
//// - Dinesh Annayya, dinesha@opencores.org ////
|
16 |
|
|
//// ////
|
17 |
|
|
//////////////////////////////////////////////////////////////////////
|
18 |
|
|
//// ////
|
19 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
20 |
|
|
//// ////
|
21 |
|
|
//// This source file may be used and distributed without ////
|
22 |
|
|
//// restriction provided that this copyright statement is not ////
|
23 |
|
|
//// removed from the file and that any derivative work contains ////
|
24 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// This source file is free software; you can redistribute it ////
|
27 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
28 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
29 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
30 |
|
|
//// later version. ////
|
31 |
|
|
//// ////
|
32 |
|
|
//// This source is distributed in the hope that it will be ////
|
33 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
34 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
35 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
36 |
|
|
//// details. ////
|
37 |
|
|
//// ////
|
38 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
39 |
|
|
//// Public License along with this source; if not, download it ////
|
40 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
41 |
|
|
//// ////
|
42 |
|
|
//////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
|
|
/**********************************************
|
45 |
50 |
dinesha |
Web-bone , Read from Wishbone Memory and Write to internal Memory
|
46 |
|
|
|
47 |
|
|
This block handles following task
|
48 |
|
|
1. Check the Descriptor Q for not empty
|
49 |
|
|
2. If the Descriptor Q is not empty, the read the 32 bit descriptor
|
50 |
|
|
3. The 32 bit descriptor holds following information
|
51 |
|
|
[11:0] - Packet Length
|
52 |
|
|
[25:12] - MSB [15:2] of Packet Start Location
|
53 |
|
|
[31:26] - Packet Status
|
54 |
|
|
4. Based on the Packet Length, Read the data from external Data memory
|
55 |
|
|
and write it to Internal Memory
|
56 |
|
|
|
57 |
20 |
dinesha |
**********************************************/
|
58 |
|
|
|
59 |
|
|
module wb_rd_mem2mem (
|
60 |
|
|
|
61 |
|
|
rst_n ,
|
62 |
|
|
clk ,
|
63 |
|
|
|
64 |
50 |
dinesha |
// descriptor handshake
|
65 |
|
|
cfg_desc_baddr ,
|
66 |
|
|
desc_q_empty ,
|
67 |
20 |
dinesha |
|
68 |
|
|
// Master Interface Signal
|
69 |
|
|
mem_taddr ,
|
70 |
|
|
mem_full ,
|
71 |
|
|
mem_afull ,
|
72 |
|
|
mem_wr ,
|
73 |
|
|
mem_din ,
|
74 |
|
|
|
75 |
|
|
// Slave Interface Signal
|
76 |
|
|
wbo_dout ,
|
77 |
|
|
wbo_taddr ,
|
78 |
|
|
wbo_addr ,
|
79 |
|
|
wbo_be ,
|
80 |
|
|
wbo_we ,
|
81 |
|
|
wbo_ack ,
|
82 |
|
|
wbo_stb ,
|
83 |
|
|
wbo_cyc ,
|
84 |
|
|
wbo_err ,
|
85 |
|
|
wbo_rty
|
86 |
|
|
);
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
parameter D_WD = 16; // Data Width
|
90 |
|
|
parameter BE_WD = 2; // Byte Enable
|
91 |
|
|
parameter ADR_WD = 28; // Address Width
|
92 |
|
|
parameter TAR_WD = 4; // Target Width
|
93 |
|
|
|
94 |
|
|
//---------------------
|
95 |
|
|
// State Machine Parameter
|
96 |
|
|
//--------------------
|
97 |
|
|
|
98 |
57 |
dinesha |
parameter IDLE = 0;
|
99 |
|
|
parameter DESC_RD = 1;
|
100 |
|
|
parameter DATA_WAIT = 2;
|
101 |
|
|
parameter TXFR = 3;
|
102 |
|
|
parameter MEM_WRITE2 = 4;
|
103 |
|
|
parameter MEM_WRITE3 = 5;
|
104 |
|
|
parameter MEM_WRITE4 = 6;
|
105 |
20 |
dinesha |
|
106 |
|
|
|
107 |
|
|
//-------------------------------------------
|
108 |
|
|
// Input Declaration
|
109 |
|
|
//------------------------------------------
|
110 |
|
|
|
111 |
|
|
input clk ; // CLK_I The clock input [CLK_I] coordinates all activities
|
112 |
|
|
// for the internal logic within the WISHBONE interconnect.
|
113 |
|
|
// All WISHBONE output signals are registered at the
|
114 |
|
|
// rising edge of [CLK_I].
|
115 |
|
|
// All WISHBONE input signals must be stable before the
|
116 |
|
|
// rising edge of [CLK_I].
|
117 |
|
|
input rst_n ; // RST_I The reset input [RST_I] forces the WISHBONE interface
|
118 |
|
|
// to restart. Furthermore, all internal self-starting state
|
119 |
|
|
// machines will be forced into an initial state.
|
120 |
|
|
|
121 |
50 |
dinesha |
//---------------------------------
|
122 |
|
|
// Descriptor Interface
|
123 |
|
|
//---------------------------------
|
124 |
|
|
input [15:6] cfg_desc_baddr ; // descriptor Base Address
|
125 |
|
|
input desc_q_empty ;
|
126 |
|
|
|
127 |
20 |
dinesha |
//------------------------------------------
|
128 |
|
|
// Stanard Memory Interface
|
129 |
|
|
//------------------------------------------
|
130 |
|
|
|
131 |
|
|
input [TAR_WD-1:0] mem_taddr ; // target address
|
132 |
|
|
input mem_full ; // memory full
|
133 |
|
|
input mem_afull ; // memory afull
|
134 |
50 |
dinesha |
output mem_wr ; // memory Write
|
135 |
|
|
output [8:0] mem_din ; // memory read data
|
136 |
20 |
dinesha |
|
137 |
|
|
//------------------------------------------
|
138 |
|
|
// External Memory WB Interface
|
139 |
|
|
//------------------------------------------
|
140 |
|
|
output wbo_stb ; // STB_O The strobe output [STB_O] indicates a valid data
|
141 |
|
|
// transfer cycle. It is used to qualify various other signals
|
142 |
|
|
// on the interface such as [SEL_O(7..0)]. The SLAVE must
|
143 |
|
|
// assert either the [ACK_I], [ERR_I] or [RTY_I] signals in
|
144 |
|
|
// response to every assertion of the [STB_O] signal.
|
145 |
|
|
output wbo_we ; // WE_O The write enable output [WE_O] indicates whether the
|
146 |
|
|
// current local bus cycle is a READ or WRITE cycle. The
|
147 |
|
|
// signal is negated during READ cycles, and is asserted
|
148 |
|
|
// during WRITE cycles.
|
149 |
|
|
input wbo_ack ; // The acknowledge input [ACK_I], when asserted,
|
150 |
|
|
// indicates the termination of a normal bus cycle.
|
151 |
|
|
// Also see the [ERR_I] and [RTY_I] signal descriptions.
|
152 |
|
|
|
153 |
|
|
output [TAR_WD-1:0] wbo_taddr;
|
154 |
|
|
output [ADR_WD-1:0] wbo_addr ; // The address output array [ADR_O(63..0)] is used
|
155 |
|
|
// to pass a binary address, with the most significant
|
156 |
|
|
// address bit at the higher numbered end of the signal array.
|
157 |
|
|
// The lower array boundary is specific to the data port size.
|
158 |
|
|
// The higher array boundary is core-specific.
|
159 |
|
|
// In some cases (such as FIFO interfaces)
|
160 |
|
|
// the array may not be present on the interface.
|
161 |
|
|
|
162 |
|
|
output [BE_WD-1:0] wbo_be ; // Byte Enable
|
163 |
|
|
// SEL_O(7..0) The select output array [SEL_O(7..0)] indicates
|
164 |
|
|
// where valid data is expected on the [DAT_I(63..0)] signal
|
165 |
|
|
// array during READ cycles, and where it is placed on the
|
166 |
|
|
// [DAT_O(63..0)] signal array during WRITE cycles.
|
167 |
|
|
// Also see the [DAT_I(63..0)], [DAT_O(63..0)] and [STB_O]
|
168 |
|
|
// signal descriptions.
|
169 |
|
|
|
170 |
|
|
output wbo_cyc ; // CYC_O The cycle output [CYC_O], when asserted,
|
171 |
|
|
// indicates that a valid bus cycle is in progress.
|
172 |
|
|
// The signal is asserted for the duration of all bus cycles.
|
173 |
|
|
// For example, during a BLOCK transfer cycle there can be
|
174 |
|
|
// multiple data transfers. The [CYC_O] signal is asserted
|
175 |
|
|
// during the first data transfer, and remains asserted
|
176 |
|
|
// until the last data transfer. The [CYC_O] signal is useful
|
177 |
|
|
// for interfaces with multi-port interfaces
|
178 |
|
|
// (such as dual port memories). In these cases,
|
179 |
|
|
// the [CYC_O] signal requests use of a common bus from an
|
180 |
|
|
// arbiter. Once the arbiter grants the bus to the MASTER,
|
181 |
|
|
// it is held until [CYC_O] is negated.
|
182 |
|
|
|
183 |
|
|
input [D_WD-1:0] wbo_dout; // DAT_I(63..0) The data input array [DAT_I(63..0)] is
|
184 |
|
|
// used to pass binary data. The array boundaries are
|
185 |
|
|
// determined by the port size. Also see the [DAT_O(63..0)]
|
186 |
|
|
// and [SEL_O(7..0)] signal descriptions.
|
187 |
|
|
|
188 |
|
|
input wbo_err; // ERR_I The error input [ERR_I] indicates an abnormal
|
189 |
|
|
// cycle termination. The source of the error, and the
|
190 |
|
|
// response generated by the MASTER is defined by the IP core
|
191 |
|
|
// supplier in the WISHBONE DATASHEET. Also see the [ACK_I]
|
192 |
|
|
// and [RTY_I] signal descriptions.
|
193 |
|
|
|
194 |
|
|
input wbo_rty; // RTY_I The retry input [RTY_I] indicates that the indicates
|
195 |
|
|
// that the interface is not ready to accept or send data, and
|
196 |
|
|
// that the cycle should be retried. When and how the cycle is
|
197 |
|
|
// retried is defined by the IP core supplier in the WISHBONE
|
198 |
|
|
// DATASHEET. Also see the [ERR_I] and [RTY_I] signal
|
199 |
|
|
// descriptions.
|
200 |
|
|
|
201 |
|
|
//----------------------------------------
|
202 |
|
|
// Register Declration
|
203 |
|
|
//----------------------------------------
|
204 |
|
|
|
205 |
57 |
dinesha |
reg [2:0] state ;
|
206 |
20 |
dinesha |
reg [15:0] cnt ;
|
207 |
|
|
reg [TAR_WD-1:0] wbo_taddr ;
|
208 |
|
|
reg [ADR_WD-1:0] wbo_addr ;
|
209 |
|
|
reg wbo_stb ;
|
210 |
|
|
reg wbo_we ;
|
211 |
|
|
reg [BE_WD-1:0] wbo_be ;
|
212 |
|
|
reg wbo_cyc ;
|
213 |
50 |
dinesha |
reg [15:0] mem_addr ;
|
214 |
20 |
dinesha |
|
215 |
50 |
dinesha |
|
216 |
20 |
dinesha |
|
217 |
|
|
|
218 |
50 |
dinesha |
reg [3:0] desc_ptr;
|
219 |
57 |
dinesha |
reg [23:0] tWrData; // Temp Write Data
|
220 |
|
|
reg [8:0] mem_din;
|
221 |
|
|
reg mem_wr;
|
222 |
50 |
dinesha |
|
223 |
20 |
dinesha |
always @(negedge rst_n or posedge clk) begin
|
224 |
|
|
if(rst_n == 0) begin
|
225 |
|
|
state <= IDLE;
|
226 |
|
|
wbo_taddr <= 0;
|
227 |
|
|
wbo_addr <= 0;
|
228 |
|
|
wbo_stb <= 0;
|
229 |
|
|
wbo_we <= 0;
|
230 |
|
|
wbo_be <= 0;
|
231 |
|
|
wbo_cyc <= 0;
|
232 |
50 |
dinesha |
desc_ptr <= 0;
|
233 |
|
|
mem_addr <= 0;
|
234 |
57 |
dinesha |
mem_din <= 0;
|
235 |
|
|
tWrData <= 0;
|
236 |
|
|
mem_wr <= 0;
|
237 |
20 |
dinesha |
end
|
238 |
|
|
else begin
|
239 |
|
|
case(state)
|
240 |
|
|
IDLE: begin
|
241 |
57 |
dinesha |
mem_wr <= 0;
|
242 |
50 |
dinesha |
// Check for Descriptor Q not empty
|
243 |
|
|
if(!desc_q_empty) begin
|
244 |
|
|
wbo_taddr <= mem_taddr;
|
245 |
|
|
wbo_addr <= {cfg_desc_baddr[15:6],desc_ptr[3:0]};
|
246 |
|
|
wbo_be <= 4'hF;
|
247 |
|
|
wbo_we <= 1'b0;
|
248 |
|
|
wbo_stb <= 1'b1;
|
249 |
|
|
wbo_cyc <= 1;
|
250 |
|
|
state <= DESC_RD;
|
251 |
|
|
desc_ptr <= desc_ptr+1;
|
252 |
20 |
dinesha |
end
|
253 |
50 |
dinesha |
end
|
254 |
|
|
DESC_RD: begin
|
255 |
|
|
// wait for web-bone ack
|
256 |
|
|
if(wbo_ack) begin
|
257 |
|
|
wbo_cyc <= 1'b0;
|
258 |
|
|
wbo_stb <= 1'b0;
|
259 |
|
|
state <= IDLE;
|
260 |
|
|
cnt <= wbo_dout[11:0];
|
261 |
|
|
mem_addr <= {wbo_dout[27:12],2'b0};
|
262 |
|
|
state <= DATA_WAIT;
|
263 |
|
|
end
|
264 |
|
|
end
|
265 |
|
|
|
266 |
|
|
DATA_WAIT: begin
|
267 |
57 |
dinesha |
mem_wr <= 0; // Reset the write for handling interburst
|
268 |
50 |
dinesha |
// check for internal memory not full and initiate
|
269 |
|
|
// the transfer
|
270 |
57 |
dinesha |
if(!(mem_full || mem_afull)) begin
|
271 |
50 |
dinesha |
wbo_taddr <= mem_taddr;
|
272 |
|
|
wbo_addr <= mem_addr[14:2];
|
273 |
|
|
wbo_stb <= 1'b1;
|
274 |
|
|
wbo_we <= 1'b0;
|
275 |
|
|
wbo_be <= 4'hF;
|
276 |
|
|
wbo_cyc <= 1'b1;
|
277 |
|
|
state <= TXFR;
|
278 |
|
|
end
|
279 |
20 |
dinesha |
end
|
280 |
|
|
TXFR: begin
|
281 |
|
|
if(wbo_ack) begin
|
282 |
57 |
dinesha |
wbo_cyc <= 1'b0;
|
283 |
|
|
wbo_stb <= 1'b0;
|
284 |
|
|
mem_addr <= mem_addr+4;
|
285 |
|
|
mem_din[7:0] <= wbo_dout[7:0]; // Write First Byte
|
286 |
|
|
tWrData <= wbo_dout[31:8];
|
287 |
|
|
mem_din[8] <= (cnt == 1) ? 1'b1 : 1'b0; // EOP generation at last transfer
|
288 |
|
|
mem_wr <= 1;
|
289 |
50 |
dinesha |
cnt <= cnt-1;
|
290 |
20 |
dinesha |
if(cnt == 1) begin
|
291 |
|
|
state <= IDLE;
|
292 |
57 |
dinesha |
end else begin
|
293 |
|
|
state <= MEM_WRITE2;
|
294 |
20 |
dinesha |
end
|
295 |
|
|
end
|
296 |
|
|
end
|
297 |
57 |
dinesha |
MEM_WRITE2: begin // Write 2nd Byte
|
298 |
|
|
if(!(mem_full || mem_afull)) begin // to handle the interburst fifo full case
|
299 |
|
|
mem_din[7:0] <= tWrData[7:0];
|
300 |
|
|
mem_din[8] <= (cnt == 1) ? 1'b1 : 1'b0; // EOP generation at last transfer
|
301 |
|
|
mem_wr <= 1;
|
302 |
|
|
cnt <= cnt-1;
|
303 |
|
|
if(cnt == 1) begin
|
304 |
|
|
state <= IDLE;
|
305 |
|
|
end else begin
|
306 |
|
|
state <= MEM_WRITE3;
|
307 |
|
|
end
|
308 |
|
|
end else begin
|
309 |
|
|
mem_wr <= 0;
|
310 |
|
|
end
|
311 |
|
|
end
|
312 |
|
|
MEM_WRITE3: begin // Write 3rd Byte
|
313 |
|
|
if(!(mem_full || mem_afull)) begin // to handle the interburst fifo full case
|
314 |
|
|
mem_din[7:0] <= tWrData[15:8];
|
315 |
|
|
mem_din[8] <= (cnt == 1) ? 1'b1 : 1'b0; // EOP generation at last transfer
|
316 |
|
|
mem_wr <= 1;
|
317 |
|
|
cnt <= cnt-1;
|
318 |
|
|
if(cnt == 1) begin
|
319 |
|
|
state <= IDLE;
|
320 |
|
|
end else begin
|
321 |
|
|
state <= MEM_WRITE4;
|
322 |
|
|
end
|
323 |
|
|
end else begin
|
324 |
|
|
mem_wr <= 0;
|
325 |
|
|
end
|
326 |
|
|
end
|
327 |
|
|
MEM_WRITE4: begin // Write 4th Byte
|
328 |
|
|
if(!(mem_full || mem_afull)) begin // to handle the interburst fifo full case
|
329 |
|
|
mem_din[7:0] <= tWrData[23:16];
|
330 |
|
|
mem_din[8] <= (cnt == 1) ? 1'b1 : 1'b0; // EOP generation at last transfer
|
331 |
|
|
mem_wr <= 1;
|
332 |
|
|
cnt <= cnt-1;
|
333 |
|
|
if(cnt == 1) begin
|
334 |
|
|
state <= IDLE;
|
335 |
|
|
end else begin
|
336 |
|
|
state <= DATA_WAIT;
|
337 |
|
|
end
|
338 |
|
|
end else begin
|
339 |
|
|
mem_wr <= 0;
|
340 |
|
|
end
|
341 |
|
|
end
|
342 |
20 |
dinesha |
endcase
|
343 |
|
|
end
|
344 |
|
|
end
|
345 |
|
|
|
346 |
|
|
endmodule
|