1 |
48 |
alirezamon |
// ==================================================================
|
2 |
|
|
// >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
|
3 |
|
|
// ------------------------------------------------------------------
|
4 |
|
|
// Copyright (c) 2006-2011 by Lattice Semiconductor Corporation
|
5 |
|
|
// ALL RIGHTS RESERVED
|
6 |
|
|
// ------------------------------------------------------------------
|
7 |
|
|
//
|
8 |
|
|
// IMPORTANT: THIS FILE IS AUTO-GENERATED BY THE LATTICEMICO SYSTEM.
|
9 |
|
|
//
|
10 |
|
|
// Permission:
|
11 |
|
|
//
|
12 |
|
|
// Lattice Semiconductor grants permission to use this code
|
13 |
|
|
// pursuant to the terms of the Lattice Semiconductor Corporation
|
14 |
|
|
// Open Source License Agreement.
|
15 |
|
|
//
|
16 |
|
|
// Disclaimer:
|
17 |
|
|
//
|
18 |
|
|
// Lattice Semiconductor provides no warranty regarding the use or
|
19 |
|
|
// functionality of this code. It is the user's responsibility to
|
20 |
|
|
// verify the user's design for consistency and functionality through
|
21 |
|
|
// the use of formal verification methods.
|
22 |
|
|
//
|
23 |
|
|
// --------------------------------------------------------------------
|
24 |
|
|
//
|
25 |
|
|
// Lattice Semiconductor Corporation
|
26 |
|
|
// 5555 NE Moore Court
|
27 |
|
|
// Hillsboro, OR 97214
|
28 |
|
|
// U.S.A
|
29 |
|
|
//
|
30 |
|
|
// TEL: 1-800-Lattice (USA and Canada)
|
31 |
|
|
// 503-286-8001 (other locations)
|
32 |
|
|
//
|
33 |
|
|
// web: http://www.latticesemi.com/
|
34 |
|
|
// email: techsupport@latticesemi.com
|
35 |
|
|
//
|
36 |
|
|
// --------------------------------------------------------------------
|
37 |
|
|
// FILE DETAILS
|
38 |
|
|
// Project : LatticeMico32
|
39 |
|
|
// File : lm32_ram.v
|
40 |
|
|
// Title : Pseudo dual-port RAM.
|
41 |
|
|
// Version : 6.1.17
|
42 |
|
|
// : Initial Release
|
43 |
|
|
// Version : 7.0SP2, 3.0
|
44 |
|
|
// : No Change
|
45 |
|
|
// Version : 3.1
|
46 |
|
|
// : Options added to select EBRs (True-DP, Psuedo-DP, DQ, or
|
47 |
|
|
// : Distributed RAM).
|
48 |
|
|
// Version : 3.2
|
49 |
|
|
// : EBRs use SYNC resets instead of ASYNC resets.
|
50 |
|
|
// Version : 3.5
|
51 |
|
|
// : Added read-after-write hazard resolution when using true
|
52 |
|
|
// : dual-port EBRs
|
53 |
|
|
// =============================================================================
|
54 |
|
|
|
55 |
|
|
`include "lm32_include.v"
|
56 |
|
|
|
57 |
|
|
/////////////////////////////////////////////////////
|
58 |
|
|
// Module interface
|
59 |
|
|
/////////////////////////////////////////////////////
|
60 |
|
|
|
61 |
|
|
module lm32_ram (
|
62 |
|
|
// ----- Inputs -------
|
63 |
|
|
read_clk,
|
64 |
|
|
write_clk,
|
65 |
|
|
reset,
|
66 |
|
|
enable_read,
|
67 |
|
|
read_address,
|
68 |
|
|
enable_write,
|
69 |
|
|
write_address,
|
70 |
|
|
write_data,
|
71 |
|
|
write_enable,
|
72 |
|
|
// ----- Outputs -------
|
73 |
|
|
read_data
|
74 |
|
|
);
|
75 |
|
|
|
76 |
|
|
/*----------------------------------------------------------------------
|
77 |
|
|
Parameters
|
78 |
|
|
----------------------------------------------------------------------*/
|
79 |
|
|
parameter data_width = 1; // Width of the data ports
|
80 |
|
|
parameter address_width = 1; // Width of the address ports
|
81 |
|
|
parameter init_file = "NONE"; // Initialization file
|
82 |
|
|
|
83 |
|
|
/*----------------------------------------------------------------------
|
84 |
|
|
Inputs
|
85 |
|
|
----------------------------------------------------------------------*/
|
86 |
|
|
input read_clk; // Read clock
|
87 |
|
|
input write_clk; // Write clock
|
88 |
|
|
input reset; // Reset
|
89 |
|
|
|
90 |
|
|
input enable_read; // Access enable
|
91 |
|
|
input [address_width-1:0] read_address; // Read/write address
|
92 |
|
|
input enable_write; // Access enable
|
93 |
|
|
input [address_width-1:0] write_address;// Read/write address
|
94 |
|
|
input [data_width-1:0] write_data; // Data to write to specified address
|
95 |
|
|
input write_enable; // Write enable
|
96 |
|
|
|
97 |
|
|
/*----------------------------------------------------------------------
|
98 |
|
|
Outputs
|
99 |
|
|
----------------------------------------------------------------------*/
|
100 |
|
|
output [data_width-1:0] read_data; // Data read from specified addess
|
101 |
|
|
wire [data_width-1:0] read_data;
|
102 |
|
|
|
103 |
|
|
/*----------------------------------------------------------------------
|
104 |
|
|
Internal nets and registers
|
105 |
|
|
----------------------------------------------------------------------*/
|
106 |
|
|
reg [data_width-1:0] mem[0:(1<<address_width)-1]; // The RAM
|
107 |
|
|
reg [address_width-1:0] ra; // Registered read address
|
108 |
|
|
|
109 |
|
|
/*----------------------------------------------------------------------
|
110 |
|
|
Combinational Logic
|
111 |
|
|
----------------------------------------------------------------------*/
|
112 |
|
|
// Read port
|
113 |
|
|
assign read_data = mem[ra];
|
114 |
|
|
|
115 |
|
|
/*----------------------------------------------------------------------
|
116 |
|
|
Sequential Logic
|
117 |
|
|
----------------------------------------------------------------------*/
|
118 |
|
|
// Write port
|
119 |
|
|
always @(posedge write_clk)
|
120 |
|
|
if ((write_enable == `TRUE) && (enable_write == `TRUE))
|
121 |
|
|
mem[write_address] <= write_data;
|
122 |
|
|
|
123 |
|
|
// Register read address for use on next cycle
|
124 |
|
|
always @(posedge read_clk)
|
125 |
|
|
if (enable_read)
|
126 |
|
|
ra <= read_address;
|
127 |
|
|
|
128 |
|
|
/*----------------------------------------------------------------------
|
129 |
|
|
Initialization
|
130 |
|
|
----------------------------------------------------------------------*/
|
131 |
|
|
generate
|
132 |
|
|
if (init_file != "NONE")
|
133 |
|
|
begin
|
134 |
|
|
initial $readmemh(init_file, mem);
|
135 |
|
|
end
|
136 |
|
|
endgenerate
|
137 |
|
|
|
138 |
|
|
endmodule
|