1 |
147 |
lanttu |
/******************************************************************************
|
2 |
|
|
* License Agreement *
|
3 |
|
|
* *
|
4 |
|
|
* Copyright (c) 1991-2009 Altera Corporation, San Jose, California, USA. *
|
5 |
|
|
* All rights reserved. *
|
6 |
|
|
* *
|
7 |
|
|
* Any megafunction design, and related net list (encrypted or decrypted), *
|
8 |
|
|
* support information, device programming or simulation file, and any other *
|
9 |
|
|
* associated documentation or information provided by Altera or a partner *
|
10 |
|
|
* under Altera's Megafunction Partnership Program may be used only to *
|
11 |
|
|
* program PLD devices (but not masked PLD devices) from Altera. Any other *
|
12 |
|
|
* use of such megafunction design, net list, support information, device *
|
13 |
|
|
* programming or simulation file, or any other related documentation or *
|
14 |
|
|
* information is prohibited for any other purpose, including, but not *
|
15 |
|
|
* limited to modification, reverse engineering, de-compiling, or use with *
|
16 |
|
|
* any other silicon devices, unless such use is explicitly licensed under *
|
17 |
|
|
* a separate agreement with Altera or a megafunction partner. Title to *
|
18 |
|
|
* the intellectual property, including patents, copyrights, trademarks, *
|
19 |
|
|
* trade secrets, or maskworks, embodied in any such megafunction design, *
|
20 |
|
|
* net list, support information, device programming or simulation file, or *
|
21 |
|
|
* any other related documentation or information provided by Altera or a *
|
22 |
|
|
* megafunction partner, remains with Altera, the megafunction partner, or *
|
23 |
|
|
* their respective licensors. No other licenses, including any licenses *
|
24 |
|
|
* needed under any third party's intellectual property, are provided herein.*
|
25 |
|
|
* Copying or modifying any file, or portion thereof, to which this notice *
|
26 |
|
|
* is attached violates this copyright. *
|
27 |
|
|
* *
|
28 |
|
|
* THIS FILE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
|
29 |
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
|
30 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
|
31 |
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
|
32 |
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
|
33 |
|
|
* FROM, OUT OF OR IN CONNECTION WITH THIS FILE OR THE USE OR OTHER DEALINGS *
|
34 |
|
|
* IN THIS FILE. *
|
35 |
|
|
* *
|
36 |
|
|
* This agreement shall be governed in all respects by the laws of the State *
|
37 |
|
|
* of California and by the laws of the United States of America. *
|
38 |
|
|
* *
|
39 |
|
|
******************************************************************************/
|
40 |
|
|
|
41 |
|
|
/******************************************************************************
|
42 |
|
|
* *
|
43 |
|
|
* This module chipselects reads and writes to the sram, with 2-cycle *
|
44 |
|
|
* read latency and one cycle write latency. *
|
45 |
|
|
* *
|
46 |
|
|
******************************************************************************/
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
module sram_0 (
|
50 |
|
|
// Inputs
|
51 |
|
|
clk,
|
52 |
|
|
reset,
|
53 |
|
|
|
54 |
|
|
address,
|
55 |
|
|
byteenable,
|
56 |
|
|
read,
|
57 |
|
|
write,
|
58 |
|
|
writedata,
|
59 |
|
|
|
60 |
|
|
// Bi-Directional
|
61 |
|
|
SRAM_DQ,
|
62 |
|
|
|
63 |
|
|
// Outputs
|
64 |
|
|
readdata,
|
65 |
|
|
|
66 |
|
|
SRAM_ADDR,
|
67 |
|
|
SRAM_LB_N,
|
68 |
|
|
SRAM_UB_N,
|
69 |
|
|
SRAM_CE_N,
|
70 |
|
|
SRAM_OE_N,
|
71 |
|
|
SRAM_WE_N
|
72 |
|
|
);
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
/*****************************************************************************
|
76 |
|
|
* Parameter Declarations *
|
77 |
|
|
*****************************************************************************/
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
/*****************************************************************************
|
81 |
|
|
* Port Declarations *
|
82 |
|
|
*****************************************************************************/
|
83 |
|
|
// Inputs
|
84 |
|
|
input clk;
|
85 |
|
|
input reset;
|
86 |
|
|
|
87 |
|
|
input [17:0] address;
|
88 |
|
|
input [1:0] byteenable;
|
89 |
|
|
input read;
|
90 |
|
|
input write;
|
91 |
|
|
input [15:0] writedata;
|
92 |
|
|
|
93 |
|
|
// Bi-Directional
|
94 |
|
|
inout [15:0] SRAM_DQ; // SRAM Data bus 16 Bits
|
95 |
|
|
|
96 |
|
|
// Outputs
|
97 |
|
|
output reg [15:0] readdata;
|
98 |
|
|
|
99 |
|
|
output reg [17:0] SRAM_ADDR; // SRAM Address bus 18 Bits
|
100 |
|
|
output reg SRAM_LB_N; // SRAM Low-byte Data Mask
|
101 |
|
|
output reg SRAM_UB_N; // SRAM High-byte Data Mask
|
102 |
|
|
output reg SRAM_CE_N; // SRAM Chip chipselect
|
103 |
|
|
output reg SRAM_OE_N; // SRAM Output chipselect
|
104 |
|
|
output reg SRAM_WE_N; // SRAM Write chipselect
|
105 |
|
|
|
106 |
|
|
/*****************************************************************************
|
107 |
|
|
* Internal Wires and Registers Declarations *
|
108 |
|
|
*****************************************************************************/
|
109 |
|
|
|
110 |
|
|
// Internal Wires
|
111 |
|
|
|
112 |
|
|
// Internal Registers
|
113 |
|
|
reg is_write;
|
114 |
|
|
reg [15: 0] writedata_reg;
|
115 |
|
|
|
116 |
|
|
// State Machine Registers
|
117 |
|
|
|
118 |
|
|
/*****************************************************************************
|
119 |
|
|
* Finite State Machine(s) *
|
120 |
|
|
*****************************************************************************/
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
/*****************************************************************************
|
124 |
|
|
* Sequential logic *
|
125 |
|
|
*****************************************************************************/
|
126 |
|
|
|
127 |
|
|
// Output Registers
|
128 |
|
|
always @(posedge clk)
|
129 |
|
|
begin
|
130 |
|
|
if (reset)
|
131 |
|
|
begin
|
132 |
|
|
readdata <= 16'h0000;
|
133 |
|
|
|
134 |
|
|
SRAM_ADDR <= 18'h00000;
|
135 |
|
|
SRAM_LB_N <= 1'b1;
|
136 |
|
|
SRAM_UB_N <= 1'b1;
|
137 |
|
|
SRAM_CE_N <= 1'b1;
|
138 |
|
|
SRAM_OE_N <= 1'b1;
|
139 |
|
|
SRAM_WE_N <= 1'b1;
|
140 |
|
|
end
|
141 |
|
|
else
|
142 |
|
|
begin
|
143 |
|
|
readdata <= SRAM_DQ;
|
144 |
|
|
|
145 |
|
|
SRAM_ADDR <= address;
|
146 |
|
|
SRAM_LB_N <= ~(byteenable[0] & (read | write));
|
147 |
|
|
SRAM_UB_N <= ~(byteenable[1] & (read | write));
|
148 |
|
|
SRAM_CE_N <= ~(read | write);
|
149 |
|
|
SRAM_OE_N <= ~read;
|
150 |
|
|
SRAM_WE_N <= ~write;
|
151 |
|
|
end
|
152 |
|
|
end
|
153 |
|
|
|
154 |
|
|
// Internal Registers
|
155 |
|
|
always @(posedge clk)
|
156 |
|
|
begin
|
157 |
|
|
if (reset)
|
158 |
|
|
is_write <= 1'b0;
|
159 |
|
|
else
|
160 |
|
|
is_write <= write;
|
161 |
|
|
end
|
162 |
|
|
|
163 |
|
|
always @(posedge clk)
|
164 |
|
|
begin
|
165 |
|
|
if (reset)
|
166 |
|
|
writedata_reg <= 16'h0000;
|
167 |
|
|
else
|
168 |
|
|
writedata_reg <= writedata;
|
169 |
|
|
end
|
170 |
|
|
|
171 |
|
|
/*****************************************************************************
|
172 |
|
|
* Combinational logic *
|
173 |
|
|
*****************************************************************************/
|
174 |
|
|
|
175 |
|
|
// Output Assignments
|
176 |
|
|
assign SRAM_DQ = (is_write) ? writedata_reg : 16'hzzzz;
|
177 |
|
|
|
178 |
|
|
// Internal Assignments
|
179 |
|
|
|
180 |
|
|
/*****************************************************************************
|
181 |
|
|
* Internal Modules *
|
182 |
|
|
*****************************************************************************/
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
endmodule
|
186 |
|
|
|