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 Wishbone Memory and Write to internal Memory
|
46 |
|
|
**********************************************/
|
47 |
|
|
|
48 |
|
|
module wb_rd_mem2mem (
|
49 |
|
|
|
50 |
|
|
rst_n ,
|
51 |
|
|
clk ,
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
// Master Interface Signal
|
55 |
|
|
mem_req ,
|
56 |
|
|
mem_txfr ,
|
57 |
|
|
mem_ack ,
|
58 |
|
|
mem_taddr ,
|
59 |
|
|
mem_addr ,
|
60 |
|
|
mem_full ,
|
61 |
|
|
mem_afull ,
|
62 |
|
|
mem_wr ,
|
63 |
|
|
mem_din ,
|
64 |
|
|
|
65 |
|
|
// Slave Interface Signal
|
66 |
|
|
wbo_dout ,
|
67 |
|
|
wbo_taddr ,
|
68 |
|
|
wbo_addr ,
|
69 |
|
|
wbo_be ,
|
70 |
|
|
wbo_we ,
|
71 |
|
|
wbo_ack ,
|
72 |
|
|
wbo_stb ,
|
73 |
|
|
wbo_cyc ,
|
74 |
|
|
wbo_err ,
|
75 |
|
|
wbo_rty
|
76 |
|
|
);
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
parameter D_WD = 16; // Data Width
|
80 |
|
|
parameter BE_WD = 2; // Byte Enable
|
81 |
|
|
parameter ADR_WD = 28; // Address Width
|
82 |
|
|
parameter TAR_WD = 4; // Target Width
|
83 |
|
|
|
84 |
|
|
//---------------------
|
85 |
|
|
// State Machine Parameter
|
86 |
|
|
//--------------------
|
87 |
|
|
|
88 |
|
|
parameter IDLE = 0;
|
89 |
|
|
parameter TXFR = 1;
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
//-------------------------------------------
|
93 |
|
|
// Input Declaration
|
94 |
|
|
//------------------------------------------
|
95 |
|
|
|
96 |
|
|
input clk ; // CLK_I The clock input [CLK_I] coordinates all activities
|
97 |
|
|
// for the internal logic within the WISHBONE interconnect.
|
98 |
|
|
// All WISHBONE output signals are registered at the
|
99 |
|
|
// rising edge of [CLK_I].
|
100 |
|
|
// All WISHBONE input signals must be stable before the
|
101 |
|
|
// rising edge of [CLK_I].
|
102 |
|
|
input rst_n ; // RST_I The reset input [RST_I] forces the WISHBONE interface
|
103 |
|
|
// to restart. Furthermore, all internal self-starting state
|
104 |
|
|
// machines will be forced into an initial state.
|
105 |
|
|
|
106 |
|
|
//------------------------------------------
|
107 |
|
|
// Stanard Memory Interface
|
108 |
|
|
//------------------------------------------
|
109 |
|
|
input mem_req ;
|
110 |
|
|
input [15:0] mem_txfr ;
|
111 |
|
|
output mem_ack ;
|
112 |
|
|
|
113 |
|
|
input [TAR_WD-1:0] mem_taddr ; // target address
|
114 |
|
|
input [15:0] mem_addr ; // memory address
|
115 |
|
|
input mem_full ; // memory full
|
116 |
|
|
input mem_afull ; // memory afull
|
117 |
|
|
output mem_wr ; // memory read
|
118 |
|
|
output [7:0] mem_din ; // memory read data
|
119 |
|
|
|
120 |
|
|
//------------------------------------------
|
121 |
|
|
// External Memory WB Interface
|
122 |
|
|
//------------------------------------------
|
123 |
|
|
output wbo_stb ; // STB_O The strobe output [STB_O] indicates a valid data
|
124 |
|
|
// transfer cycle. It is used to qualify various other signals
|
125 |
|
|
// on the interface such as [SEL_O(7..0)]. The SLAVE must
|
126 |
|
|
// assert either the [ACK_I], [ERR_I] or [RTY_I] signals in
|
127 |
|
|
// response to every assertion of the [STB_O] signal.
|
128 |
|
|
output wbo_we ; // WE_O The write enable output [WE_O] indicates whether the
|
129 |
|
|
// current local bus cycle is a READ or WRITE cycle. The
|
130 |
|
|
// signal is negated during READ cycles, and is asserted
|
131 |
|
|
// during WRITE cycles.
|
132 |
|
|
input wbo_ack ; // The acknowledge input [ACK_I], when asserted,
|
133 |
|
|
// indicates the termination of a normal bus cycle.
|
134 |
|
|
// Also see the [ERR_I] and [RTY_I] signal descriptions.
|
135 |
|
|
|
136 |
|
|
output [TAR_WD-1:0] wbo_taddr;
|
137 |
|
|
output [ADR_WD-1:0] wbo_addr ; // The address output array [ADR_O(63..0)] is used
|
138 |
|
|
// to pass a binary address, with the most significant
|
139 |
|
|
// address bit at the higher numbered end of the signal array.
|
140 |
|
|
// The lower array boundary is specific to the data port size.
|
141 |
|
|
// The higher array boundary is core-specific.
|
142 |
|
|
// In some cases (such as FIFO interfaces)
|
143 |
|
|
// the array may not be present on the interface.
|
144 |
|
|
|
145 |
|
|
output [BE_WD-1:0] wbo_be ; // Byte Enable
|
146 |
|
|
// SEL_O(7..0) The select output array [SEL_O(7..0)] indicates
|
147 |
|
|
// where valid data is expected on the [DAT_I(63..0)] signal
|
148 |
|
|
// array during READ cycles, and where it is placed on the
|
149 |
|
|
// [DAT_O(63..0)] signal array during WRITE cycles.
|
150 |
|
|
// Also see the [DAT_I(63..0)], [DAT_O(63..0)] and [STB_O]
|
151 |
|
|
// signal descriptions.
|
152 |
|
|
|
153 |
|
|
output wbo_cyc ; // CYC_O The cycle output [CYC_O], when asserted,
|
154 |
|
|
// indicates that a valid bus cycle is in progress.
|
155 |
|
|
// The signal is asserted for the duration of all bus cycles.
|
156 |
|
|
// For example, during a BLOCK transfer cycle there can be
|
157 |
|
|
// multiple data transfers. The [CYC_O] signal is asserted
|
158 |
|
|
// during the first data transfer, and remains asserted
|
159 |
|
|
// until the last data transfer. The [CYC_O] signal is useful
|
160 |
|
|
// for interfaces with multi-port interfaces
|
161 |
|
|
// (such as dual port memories). In these cases,
|
162 |
|
|
// the [CYC_O] signal requests use of a common bus from an
|
163 |
|
|
// arbiter. Once the arbiter grants the bus to the MASTER,
|
164 |
|
|
// it is held until [CYC_O] is negated.
|
165 |
|
|
|
166 |
|
|
input [D_WD-1:0] wbo_dout; // DAT_I(63..0) The data input array [DAT_I(63..0)] is
|
167 |
|
|
// used to pass binary data. The array boundaries are
|
168 |
|
|
// determined by the port size. Also see the [DAT_O(63..0)]
|
169 |
|
|
// and [SEL_O(7..0)] signal descriptions.
|
170 |
|
|
|
171 |
|
|
input wbo_err; // ERR_I The error input [ERR_I] indicates an abnormal
|
172 |
|
|
// cycle termination. The source of the error, and the
|
173 |
|
|
// response generated by the MASTER is defined by the IP core
|
174 |
|
|
// supplier in the WISHBONE DATASHEET. Also see the [ACK_I]
|
175 |
|
|
// and [RTY_I] signal descriptions.
|
176 |
|
|
|
177 |
|
|
input wbo_rty; // RTY_I The retry input [RTY_I] indicates that the indicates
|
178 |
|
|
// that the interface is not ready to accept or send data, and
|
179 |
|
|
// that the cycle should be retried. When and how the cycle is
|
180 |
|
|
// retried is defined by the IP core supplier in the WISHBONE
|
181 |
|
|
// DATASHEET. Also see the [ERR_I] and [RTY_I] signal
|
182 |
|
|
// descriptions.
|
183 |
|
|
|
184 |
|
|
//----------------------------------------
|
185 |
|
|
// Register Declration
|
186 |
|
|
//----------------------------------------
|
187 |
|
|
|
188 |
|
|
reg state ;
|
189 |
|
|
reg [15:0] cnt ;
|
190 |
|
|
reg [TAR_WD-1:0] wbo_taddr ;
|
191 |
|
|
reg [ADR_WD-1:0] wbo_addr ;
|
192 |
|
|
reg wbo_stb ;
|
193 |
|
|
reg wbo_we ;
|
194 |
|
|
reg [BE_WD-1:0] wbo_be ;
|
195 |
|
|
reg wbo_cyc ;
|
196 |
|
|
reg mem_ack ;
|
197 |
|
|
|
198 |
24 |
dinesha |
wire mem_wr = wbo_ack;
|
199 |
|
|
// Generate Next Address, to fix the read to address inc issue
|
200 |
|
|
wire [15:0] taddr = mem_addr+1;
|
201 |
20 |
dinesha |
|
202 |
|
|
wire [7:0] mem_din = (mem_addr[1:0] == 2'b00) ? wbo_dout[7:0] :
|
203 |
|
|
(mem_addr[1:0] == 2'b01) ? wbo_dout[15:8] :
|
204 |
|
|
(mem_addr[1:0] == 2'b10) ? wbo_dout[23:16] : wbo_dout[31:24] ;
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
always @(negedge rst_n or posedge clk) begin
|
208 |
|
|
if(rst_n == 0) begin
|
209 |
|
|
state <= IDLE;
|
210 |
|
|
wbo_taddr <= 0;
|
211 |
|
|
wbo_addr <= 0;
|
212 |
|
|
wbo_stb <= 0;
|
213 |
|
|
wbo_we <= 0;
|
214 |
|
|
wbo_be <= 0;
|
215 |
|
|
wbo_cyc <= 0;
|
216 |
|
|
mem_ack <= 0;
|
217 |
|
|
end
|
218 |
|
|
else begin
|
219 |
|
|
case(state)
|
220 |
|
|
IDLE: begin
|
221 |
|
|
if(mem_req && !mem_full) begin
|
222 |
|
|
cnt <= mem_txfr;
|
223 |
|
|
wbo_taddr <= mem_taddr;
|
224 |
|
|
wbo_addr <= mem_addr[14:2];
|
225 |
|
|
wbo_stb <= 1'b1;
|
226 |
|
|
wbo_we <= 1'b0;
|
227 |
24 |
dinesha |
wbo_be <= 1 << mem_addr[1:0];
|
228 |
20 |
dinesha |
wbo_cyc <= 1'b1;
|
229 |
|
|
mem_ack <= 1;
|
230 |
|
|
state <= TXFR;
|
231 |
|
|
end
|
232 |
|
|
end
|
233 |
|
|
TXFR: begin
|
234 |
|
|
mem_ack <= 0;
|
235 |
|
|
if(wbo_ack) begin
|
236 |
|
|
cnt <= cnt-1;
|
237 |
24 |
dinesha |
wbo_addr <= taddr[14:2];
|
238 |
|
|
wbo_be <= 1 << taddr[1:0];
|
239 |
20 |
dinesha |
if(cnt == 1) begin
|
240 |
|
|
wbo_stb <= 1'b0;
|
241 |
|
|
wbo_cyc <= 1'b0;
|
242 |
|
|
state <= IDLE;
|
243 |
|
|
end
|
244 |
|
|
else if(mem_afull) begin
|
245 |
|
|
wbo_stb <= 1'b0;
|
246 |
|
|
end
|
247 |
|
|
end else if(!mem_full) begin
|
248 |
|
|
wbo_stb <= 1'b1;
|
249 |
|
|
end
|
250 |
|
|
end
|
251 |
|
|
endcase
|
252 |
|
|
end
|
253 |
|
|
end
|
254 |
|
|
|
255 |
|
|
endmodule
|