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

Subversion Repositories turbo8051

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

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

powered by: WebSVN 2.1.0

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