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