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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [lib/] [wb_rd_mem2mem.v] - Blame information for rev 50

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 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 50 dinesha
parameter IDLE      = 0;
99
parameter DESC_RD   = 1;
100
parameter DATA_WAIT = 2;
101
parameter TXFR      = 3;
102 20 dinesha
 
103
 
104
//-------------------------------------------
105
// Input Declaration
106
//------------------------------------------
107
 
108
input               clk         ;  // CLK_I The clock input [CLK_I] coordinates all activities 
109
                                   // for the internal logic within the WISHBONE interconnect. 
110
                                   // All WISHBONE output signals are registered at the 
111
                                   // rising edge of [CLK_I]. 
112
                                   // All WISHBONE input signals must be stable before the 
113
                                    // rising edge of [CLK_I]. 
114
input               rst_n       ;  // RST_I The reset input [RST_I] forces the WISHBONE interface 
115
                                   // to restart. Furthermore, all internal self-starting state 
116
                                   // machines will be forced into an initial state. 
117
 
118 50 dinesha
//---------------------------------
119
// Descriptor Interface
120
//---------------------------------
121
input [15:6]   cfg_desc_baddr    ;  // descriptor Base Address
122
input          desc_q_empty      ;
123
 
124 20 dinesha
//------------------------------------------
125
// Stanard Memory Interface
126
//------------------------------------------
127
 
128
input [TAR_WD-1:0]  mem_taddr   ; // target address 
129
input               mem_full    ; // memory full
130
input               mem_afull   ; // memory afull 
131 50 dinesha
output              mem_wr      ; // memory Write
132
output  [8:0]       mem_din     ; // memory read data
133 20 dinesha
 
134
//------------------------------------------
135
// External Memory WB Interface
136
//------------------------------------------
137
output              wbo_stb  ; // STB_O The strobe output [STB_O] indicates a valid data 
138
                               // transfer cycle. It is used to qualify various other signals 
139
                               // on the interface such as [SEL_O(7..0)]. The SLAVE must 
140
                               // assert either the [ACK_I], [ERR_I] or [RTY_I] signals in 
141
                               // response to every assertion of the [STB_O] signal. 
142
output              wbo_we   ; // WE_O The write enable output [WE_O] indicates whether the 
143
                               // current local bus cycle is a READ or WRITE cycle. The 
144
                               // signal is negated during READ cycles, and is asserted 
145
                               // during WRITE cycles. 
146
input               wbo_ack  ; // The acknowledge input [ACK_I], when asserted, 
147
                               // indicates the termination of a normal bus cycle. 
148
                               // Also see the [ERR_I] and [RTY_I] signal descriptions. 
149
 
150
output [TAR_WD-1:0] wbo_taddr;
151
output [ADR_WD-1:0] wbo_addr ; // The address output array [ADR_O(63..0)] is used 
152
                               // to pass a binary address, with the most significant 
153
                               // address bit at the higher numbered end of the signal array. 
154
                               // The lower array boundary is specific to the data port size. 
155
                               // The higher array boundary is core-specific. 
156
                               // In some cases (such as FIFO interfaces) 
157
                               // the array may not be present on the interface. 
158
 
159
output [BE_WD-1:0] wbo_be     ; // Byte Enable 
160
                               // SEL_O(7..0) The select output array [SEL_O(7..0)] indicates 
161
                               // where valid data is expected on the [DAT_I(63..0)] signal 
162
                               // array during READ cycles, and where it is placed on the 
163
                               // [DAT_O(63..0)] signal array during WRITE cycles. 
164
                               // Also see the [DAT_I(63..0)], [DAT_O(63..0)] and [STB_O] 
165
                               // signal descriptions.
166
 
167
output            wbo_cyc    ; // CYC_O The cycle output [CYC_O], when asserted, 
168
                               // indicates that a valid bus cycle is in progress. 
169
                               // The signal is asserted for the duration of all bus cycles. 
170
                               // For example, during a BLOCK transfer cycle there can be 
171
                               // multiple data transfers. The [CYC_O] signal is asserted 
172
                               // during the first data transfer, and remains asserted 
173
                               // until the last data transfer. The [CYC_O] signal is useful 
174
                               // for interfaces with multi-port interfaces 
175
                               // (such as dual port memories). In these cases, 
176
                               // the [CYC_O] signal requests use of a common bus from an 
177
                               // arbiter. Once the arbiter grants the bus to the MASTER, 
178
                               // it is held until [CYC_O] is negated. 
179
 
180
input [D_WD-1:0] wbo_dout;     // DAT_I(63..0) The data input array [DAT_I(63..0)] is 
181
                              // used to pass binary data. The array boundaries are 
182
                              // determined by the port size. Also see the [DAT_O(63..0)] 
183
                              // and [SEL_O(7..0)] signal descriptions. 
184
 
185
input             wbo_err; // ERR_I The error input [ERR_I] indicates an abnormal 
186
                           // cycle termination. The source of the error, and the 
187
                           // response generated by the MASTER is defined by the IP core 
188
                           // supplier in the WISHBONE DATASHEET. Also see the [ACK_I] 
189
                           // and [RTY_I] signal descriptions. 
190
 
191
input             wbo_rty; // RTY_I The retry input [RTY_I] indicates that the indicates 
192
                           // that the interface is not ready to accept or send data, and 
193
                           // that the cycle should be retried. When and how the cycle is 
194
                           // retried is defined by the IP core supplier in the WISHBONE 
195
                           // DATASHEET. Also see the [ERR_I] and [RTY_I] signal 
196
                           // descriptions. 
197
 
198
//----------------------------------------
199
// Register Declration
200
//----------------------------------------
201
 
202 50 dinesha
reg  [1:0]          state       ;
203 20 dinesha
reg  [15:0]         cnt         ;
204
reg  [TAR_WD-1:0]   wbo_taddr   ;
205
reg  [ADR_WD-1:0]   wbo_addr    ;
206
reg                 wbo_stb     ;
207
reg                 wbo_we      ;
208
reg  [BE_WD-1:0]    wbo_be      ;
209
reg                 wbo_cyc     ;
210 50 dinesha
reg [15:0]          mem_addr    ;
211 20 dinesha
 
212 50 dinesha
wire           mem_wr       = (state == TXFR) ? wbo_ack: 1'b0 ;
213
 
214 24 dinesha
// Generate Next Address, to fix the read to address inc issue
215
wire [15:0]    taddr   = mem_addr+1;
216 20 dinesha
 
217 50 dinesha
assign mem_din[7:0]  = (mem_addr[1:0] == 2'b00) ? wbo_dout[7:0] :
218
                       (mem_addr[1:0] == 2'b01) ? wbo_dout[15:8] :
219
                       (mem_addr[1:0] == 2'b10) ? wbo_dout[23:16] : wbo_dout[31:24]  ;
220 20 dinesha
 
221 50 dinesha
assign mem_din[8]    = (cnt == 1) ? 1'b1 : 1'b0; // EOP generation at last transfer
222 20 dinesha
 
223 50 dinesha
reg [3:0]   desc_ptr;
224
 
225 20 dinesha
always @(negedge rst_n or posedge clk) begin
226
   if(rst_n == 0) begin
227
      state       <= IDLE;
228
      wbo_taddr   <= 0;
229
      wbo_addr    <= 0;
230
      wbo_stb     <= 0;
231
      wbo_we      <= 0;
232
      wbo_be      <= 0;
233
      wbo_cyc     <= 0;
234 50 dinesha
      desc_ptr    <= 0;
235
      mem_addr    <= 0;
236 20 dinesha
   end
237
   else begin
238
      case(state)
239
         IDLE: begin
240 50 dinesha
            // Check for Descriptor Q not empty
241
            if(!desc_q_empty) begin
242
               wbo_taddr   <= mem_taddr;
243
               wbo_addr  <= {cfg_desc_baddr[15:6],desc_ptr[3:0]};
244
               wbo_be    <= 4'hF;
245
               wbo_we    <= 1'b0;
246
               wbo_stb   <= 1'b1;
247
               wbo_cyc   <= 1;
248
               state     <= DESC_RD;
249
               desc_ptr  <= desc_ptr+1;
250 20 dinesha
            end
251 50 dinesha
        end
252
       DESC_RD: begin
253
          // wait for web-bone ack
254
          if(wbo_ack) begin
255
              wbo_cyc   <= 1'b0;
256
              wbo_stb   <= 1'b0;
257
              state     <= IDLE;
258
              cnt       <= wbo_dout[11:0];
259
              mem_addr  <= {wbo_dout[27:12],2'b0};
260
              state     <= DATA_WAIT;
261
          end
262
       end
263
 
264
         DATA_WAIT: begin
265
            // check for internal memory not full and initiate
266
            // the transfer
267
            if(!mem_full) begin
268
                wbo_taddr   <= mem_taddr;
269
                wbo_addr    <= mem_addr[14:2];
270
                wbo_stb     <= 1'b1;
271
                wbo_we      <= 1'b0;
272
                wbo_be      <= 4'hF;
273
                wbo_cyc     <= 1'b1;
274
                state       <= TXFR;
275
            end
276 20 dinesha
         end
277
         TXFR: begin
278
            if(wbo_ack) begin
279 50 dinesha
               mem_addr     <= mem_addr+1;
280
               cnt          <= cnt-1;
281
               wbo_addr     <= taddr[14:2];
282
               wbo_be       <= 4'hF;
283 20 dinesha
               if(cnt == 1) begin
284
                  wbo_stb   <= 1'b0;
285
                  wbo_cyc   <= 1'b0;
286
                  state     <= IDLE;
287
               end
288 50 dinesha
               else if(mem_afull) begin // to handle the interburst fifo  full case
289
                  wbo_cyc   <= 1'b0;
290 20 dinesha
                  wbo_stb   <= 1'b0;
291
               end
292 50 dinesha
            end else if(!mem_full) begin // to handle interbust fifo full cases
293
                wbo_cyc     <= 1'b1;
294
                wbo_stb     <= 1'b1;
295 20 dinesha
            end
296
         end
297
      endcase
298
   end
299
end
300
 
301
endmodule

powered by: WebSVN 2.1.0

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