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

Subversion Repositories turbo8051

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

powered by: WebSVN 2.1.0

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