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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [lib/] [wb_wr_mem2mem.v] - Blame information for rev 63

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

Line No. Rev Author Line
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
      Web-bone , Read from Memory and Write to WebBone External Memory
46
**********************************************/
47
 
48
module wb_wr_mem2mem (
49
 
50
              rst_n               ,
51
              clk                 ,
52
 
53
 
54
    // Master Interface Signal
55
              mem_taddr           ,
56
              mem_addr            ,
57
              mem_empty           ,
58
              mem_aempty          ,
59
              mem_rd              ,
60
              mem_dout            ,
61 50 dinesha
              mem_eop             ,
62
 
63
              cfg_desc_baddr      ,
64
              desc_req            ,
65
              desc_ack            ,
66
              desc_disccard       ,
67
              desc_data           ,
68
 
69 20 dinesha
 
70
    // Slave Interface Signal
71
              wbo_din             ,
72
              wbo_taddr           ,
73
              wbo_addr            ,
74
              wbo_be              ,
75
              wbo_we              ,
76
              wbo_ack             ,
77
              wbo_stb             ,
78
              wbo_cyc             ,
79
              wbo_err             ,
80
              wbo_rty
81
         );
82
 
83
 
84
parameter D_WD    = 16; // Data Width
85
parameter BE_WD   = 2;  // Byte Enable
86
parameter ADR_WD  = 28; // Address Width
87
parameter TAR_WD  = 4;  // Target Width
88
 
89
// State Machine
90 57 dinesha
parameter   IDLE       = 3'h0;
91
parameter   RD_BYTE1   = 3'h1;
92
parameter   RD_BYTE2   = 3'h2;
93
parameter   RD_BYTE3   = 3'h3;
94
parameter   RD_BYTE4   = 3'h4;
95
parameter   WB_XFR     = 3'h5;
96
parameter   DESC_WAIT  = 3'h6;
97
parameter   DESC_XFR   = 3'h7;
98 20 dinesha
 
99
input               clk      ;  // CLK_I The clock input [CLK_I] coordinates all activities 
100
                                // for the internal logic within the WISHBONE interconnect. 
101
                                // All WISHBONE output signals are registered at the 
102
                                // rising edge of [CLK_I]. 
103
                                // All WISHBONE input signals must be stable before the 
104
                                // rising edge of [CLK_I]. 
105
input               rst_n    ;  // RST_I The reset input [RST_I] forces the WISHBONE interface 
106
                                // to restart. Furthermore, all internal self-starting state 
107
                                // machines will be forced into an initial state. 
108
 
109
//------------------------------------------
110
// Stanard Memory Interface
111
//------------------------------------------
112
input [TAR_WD-1:0]  mem_taddr;  // target address 
113
input [15:0]        mem_addr;   // memory address 
114
input               mem_empty;  // memory empty 
115
input               mem_aempty; // memory empty 
116
output              mem_rd;     // memory read
117
input  [7:0]        mem_dout;   // memory read data
118 50 dinesha
input               mem_eop;    // Last Transfer indication
119 20 dinesha
 
120 50 dinesha
//----------------------------------------
121
// Discriptor defination
122
//----------------------------------------
123
input              desc_req;    // descriptor request
124
output             desc_ack;    // descriptor ack
125
input              desc_disccard;// descriptor discard
126
input [15:6]       cfg_desc_baddr;  // descriptor memory base address
127
input [31:0]       desc_data;   // descriptor data
128
 
129 20 dinesha
//------------------------------------------
130
// External Memory WB Interface
131
//------------------------------------------
132
output [TAR_WD-1:0] wbo_taddr ;
133
output              wbo_stb  ; // STB_O The strobe output [STB_O] indicates a valid data 
134
                               // transfer cycle. It is used to qualify various other signals 
135
                               // on the interface such as [SEL_O(7..0)]. The SLAVE must 
136
                               // assert either the [ACK_I], [ERR_I] or [RTY_I] signals in 
137
                               // response to every assertion of the [STB_O] signal. 
138
output              wbo_we   ; // WE_O The write enable output [WE_O] indicates whether the 
139
                               // current local bus cycle is a READ or WRITE cycle. The 
140
                               // signal is negated during READ cycles, and is asserted 
141
                               // during WRITE cycles. 
142
input               wbo_ack  ; // The acknowledge input [ACK_I], when asserted, 
143
                               // indicates the termination of a normal bus cycle. 
144
                               // Also see the [ERR_I] and [RTY_I] signal descriptions. 
145
 
146
output [ADR_WD-1:0] wbo_addr  ; // The address output array [ADR_O(63..0)] is used 
147
                               // to pass a binary address, with the most significant 
148
                               // address bit at the higher numbered end of the signal array. 
149
                               // The lower array boundary is specific to the data port size. 
150
                               // The higher array boundary is core-specific. 
151
                               // In some cases (such as FIFO interfaces) 
152
                               // the array may not be present on the interface. 
153
 
154
output [BE_WD-1:0] wbo_be     ; // Byte Enable 
155
                               // SEL_O(7..0) The select output array [SEL_O(7..0)] indicates 
156
                               // where valid data is expected on the [DAT_I(63..0)] signal 
157
                               // array during READ cycles, and where it is placed on the 
158
                               // [DAT_O(63..0)] signal array during WRITE cycles. 
159
                               // Also see the [DAT_I(63..0)], [DAT_O(63..0)] and [STB_O] 
160
                               // signal descriptions.
161
 
162
output            wbo_cyc    ; // CYC_O The cycle output [CYC_O], when asserted, 
163
                               // indicates that a valid bus cycle is in progress. 
164
                               // The signal is asserted for the duration of all bus cycles. 
165
                               // For example, during a BLOCK transfer cycle there can be 
166
                               // multiple data transfers. The [CYC_O] signal is asserted 
167
                               // during the first data transfer, and remains asserted 
168
                               // until the last data transfer. The [CYC_O] signal is useful 
169
                               // for interfaces with multi-port interfaces 
170
                               // (such as dual port memories). In these cases, 
171
                               // the [CYC_O] signal requests use of a common bus from an 
172
                               // arbiter. Once the arbiter grants the bus to the MASTER, 
173
                               // it is held until [CYC_O] is negated. 
174
 
175
output [D_WD-1:0] wbo_din;     // DAT_I(63..0) The data input array [DAT_I(63..0)] is 
176
                               // used to pass binary data. The array boundaries are 
177
                               // determined by the port size. Also see the [DAT_O(63..0)] 
178
                               // and [SEL_O(7..0)] signal descriptions. 
179
 
180
input             wbo_err; // ERR_I The error input [ERR_I] indicates an abnormal 
181
                           // cycle termination. The source of the error, and the 
182
                           // response generated by the MASTER is defined by the IP core 
183
                           // supplier in the WISHBONE DATASHEET. Also see the [ACK_I] 
184
                           // and [RTY_I] signal descriptions. 
185
 
186
input             wbo_rty; // RTY_I The retry input [RTY_I] indicates that the indicates 
187
                           // that the interface is not ready to accept or send data, and 
188
                           // that the cycle should be retried. When and how the cycle is 
189
                           // retried is defined by the IP core supplier in the WISHBONE 
190
                           // DATASHEET. Also see the [ERR_I] and [RTY_I] signal 
191
                           // descriptions. 
192
 
193
//-------------------------------------------
194
// Register Dec
195
//-------------------------------------------
196
 
197
reg [TAR_WD-1:0]     wbo_taddr ;
198
reg [ADR_WD-1:0]     wbo_addr  ;
199
reg                  wbo_stb   ;
200
reg                  wbo_we    ;
201
reg [BE_WD-1:0]      wbo_be    ;
202
reg                  wbo_cyc   ;
203
reg [D_WD-1:0]       wbo_din   ;
204 57 dinesha
reg [2:0]            state     ;
205 20 dinesha
 
206 50 dinesha
reg                  mem_rd    ;
207
reg [3:0]            desc_ptr  ; // descriptor pointer, in 32 bit mode
208
reg                  mem_eop_l ; // delayed eop signal
209
reg                  desc_ack  ; // delayed eop signal
210 20 dinesha
 
211 57 dinesha
reg  [23:0]  tWrData; // Temp 24 Bit Data
212 20 dinesha
always @(negedge rst_n or posedge clk) begin
213
   if(rst_n == 0) begin
214
      wbo_taddr <= 0;
215
      wbo_addr  <= 0;
216
      wbo_stb   <= 0;
217
      wbo_we    <= 0;
218
      wbo_be    <= 0;
219
      wbo_cyc   <= 0;
220
      wbo_din   <= 0;
221 24 dinesha
      mem_rd    <= 0;
222 50 dinesha
      desc_ptr  <= 0;
223
      mem_eop_l <= 0;
224
      desc_ack  <= 0;
225 57 dinesha
      tWrData   <= 0;
226 20 dinesha
      state     <= IDLE;
227
   end
228
   else begin
229
      case(state)
230
       IDLE: begin
231 50 dinesha
          desc_ack <= 0;
232 20 dinesha
          if(!mem_empty) begin
233 57 dinesha
             mem_rd         <= 1;
234
             mem_eop_l      <= 0;
235
             tWrData[7:0]   <= mem_dout[7:0];
236
             state          <= RD_BYTE1;
237
          end
238
       end
239
       RD_BYTE1: begin // End of First Transfer
240
          if(mem_rd && mem_eop) begin
241
             mem_rd    <= 0;
242
             mem_eop_l <= mem_eop;
243 20 dinesha
             wbo_taddr <= mem_taddr;
244
             wbo_addr  <= mem_addr[14:2];
245
             wbo_stb   <= 1'b1;
246
             wbo_we    <= 1'b1;
247 57 dinesha
             wbo_be    <= 4'h1; // Assigned Aligned 32bit address
248
             wbo_din   <= {24'h0,mem_dout[7:0]};
249 20 dinesha
             wbo_cyc   <= 1;
250 57 dinesha
             state     <= WB_XFR;
251
          end else if(!(mem_empty || (mem_rd && mem_aempty))) begin
252
             mem_rd    <= 1;
253
             state     <= RD_BYTE2;
254
          end else begin
255
             mem_rd    <= 0;
256
          end
257
          if(mem_rd) begin
258
             tWrData[7:0]   <= mem_dout[7:0];
259
          end
260
       end
261
 
262
       RD_BYTE2: begin // End of Second Transfer
263
          if(mem_rd && mem_eop) begin
264
             mem_rd    <= 0;
265 50 dinesha
             mem_eop_l <= mem_eop;
266 57 dinesha
             wbo_taddr <= mem_taddr;
267
             wbo_addr  <= mem_addr[14:2];
268
             wbo_stb   <= 1'b1;
269
             wbo_we    <= 1'b1;
270
             wbo_be    <= 4'h3; // Assigned Aligned 32bit address
271
             wbo_din   <= {16'h0,mem_dout[7:0],tWrData[7:0]};
272
             wbo_cyc   <= 1;
273
             state     <= WB_XFR;
274
          end else if(!(mem_empty || (mem_rd && mem_aempty))) begin
275 24 dinesha
             mem_rd    <= 1;
276 57 dinesha
             state     <= RD_BYTE3;
277
          end else begin
278
             mem_rd    <= 0;
279 20 dinesha
          end
280 57 dinesha
          if(mem_rd) begin
281
             tWrData[15:8]   <= mem_dout[7:0];
282
          end
283 20 dinesha
       end
284 57 dinesha
 
285
 
286
       RD_BYTE3: begin // End of Third Transfer
287
          if(mem_rd && mem_eop) begin
288
             mem_rd    <= 0;
289 50 dinesha
             mem_eop_l <= mem_eop;
290 57 dinesha
             wbo_taddr <= mem_taddr;
291 24 dinesha
             wbo_addr  <= mem_addr[14:2];
292 57 dinesha
             wbo_stb   <= 1'b1;
293
             wbo_we    <= 1'b1;
294
             wbo_be    <= 4'h7; // Assigned Aligned 32bit address
295
             wbo_din   <= {8'h0,mem_dout[7:0],tWrData[15:0]};
296
             wbo_cyc   <= 1;
297
             state     <= WB_XFR;
298
          end else if(!(mem_empty || (mem_rd && mem_aempty))) begin
299
             mem_rd    <= 1;
300
             state     <= RD_BYTE4;
301
          end else begin
302
             mem_rd    <= 0;
303
          end
304
          if(mem_rd) begin
305
             tWrData[23:16]   <= mem_dout[7:0];
306
          end
307
       end
308
 
309
       RD_BYTE4: begin // End of Fourth Transfer
310
             mem_rd    <= 0;
311
             mem_eop_l <= mem_eop;
312
             wbo_taddr <= mem_taddr;
313
             wbo_addr  <= mem_addr[14:2];
314
             wbo_stb   <= 1'b1;
315
             wbo_we    <= 1'b1;
316
             wbo_be    <= 4'hF; // Assigned Aligned 32bit address
317
             wbo_din   <= {mem_dout[7:0],tWrData[23:0]};
318
             wbo_cyc   <= 1;
319
             state     <= WB_XFR;
320
       end
321
 
322
       WB_XFR: begin
323
          if(wbo_ack) begin
324
             wbo_stb   <= 0;
325
             wbo_cyc   <= 0;
326 50 dinesha
             if(mem_eop_l) begin
327 57 dinesha
                state     <= DESC_WAIT;
328 24 dinesha
             end else begin
329 57 dinesha
                state     <= IDLE; // Next Byte
330 20 dinesha
             end
331
          end
332
       end
333 57 dinesha
 
334
 
335 50 dinesha
       DESC_WAIT: begin
336
          if(desc_req) begin
337
             desc_ack    <= 1;
338
             if(desc_disccard) begin // if the Desc is discarded
339
                state     <= IDLE;
340
             end
341
             else begin
342
                wbo_addr  <= {cfg_desc_baddr[15:6],desc_ptr[3:0]}; // Each Transfer is 32bit
343
                wbo_be    <= 4'hF;
344
                wbo_din   <= desc_data;
345
                wbo_we    <= 1'b1;
346
                wbo_stb   <= 1'b1;
347
                wbo_cyc   <= 1;
348
                state     <= DESC_XFR;
349
                desc_ptr  <= desc_ptr+1;
350
             end
351
          end
352
       end
353
       DESC_XFR: begin
354
           desc_ack <= 0;
355
          if(wbo_ack) begin
356
              wbo_stb   <= 1'b0;
357
              wbo_cyc   <= 1'b0;
358
              state     <= IDLE;
359
          end
360
       end
361
 
362 20 dinesha
      endcase
363
   end
364
end
365
 
366
 
367
 
368
endmodule

powered by: WebSVN 2.1.0

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