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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [lib/] [wb_rd_mem2mem.v] - Blame information for rev 11

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

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

powered by: WebSVN 2.1.0

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