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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [bench/] [verilog/] [ram.v] - Blame information for rev 103

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
// 
25
// *File Name: ram.v
26
// 
27
// *Module Description:
28
//                      Scalable RAM model
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 103 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
37
//----------------------------------------------------------------------------
38 2 olivier.gi
 
39
module ram (
40
 
41
// OUTPUTs
42
    ram_dout,                      // RAM data output
43
 
44
// INPUTs
45
    ram_addr,                      // RAM address
46
    ram_cen,                       // RAM chip enable (low active)
47
    ram_clk,                       // RAM clock
48
    ram_din,                       // RAM data input
49
    ram_wen                        // RAM write enable (low active)
50
);
51
 
52
// PARAMETERs
53
//============
54 72 olivier.gi
parameter ADDR_MSB   =  6;         // MSB of the address bus
55
parameter MEM_SIZE   =  256;       // Memory size in bytes
56 2 olivier.gi
 
57
// OUTPUTs
58
//============
59
output      [15:0] ram_dout;       // RAM data output
60
 
61
// INPUTs
62
//============
63
input [ADDR_MSB:0] ram_addr;       // RAM address
64
input              ram_cen;        // RAM chip enable (low active)
65
input              ram_clk;        // RAM clock
66
input       [15:0] ram_din;        // RAM data input
67
input        [1:0] ram_wen;        // RAM write enable (low active)
68
 
69
 
70
// RAM
71
//============
72
 
73 84 olivier.gi
reg         [15:0] mem [0:(MEM_SIZE/2)-1];
74 2 olivier.gi
reg   [ADDR_MSB:0] ram_addr_reg;
75
 
76
wire        [15:0] mem_val = mem[ram_addr];
77 72 olivier.gi
 
78
 
79 2 olivier.gi
always @(posedge ram_clk)
80 72 olivier.gi
  if (~ram_cen & ram_addr<(MEM_SIZE/2))
81 2 olivier.gi
    begin
82
      if      (ram_wen==2'b00) mem[ram_addr] <= ram_din;
83
      else if (ram_wen==2'b01) mem[ram_addr] <= {ram_din[15:8], mem_val[7:0]};
84
      else if (ram_wen==2'b10) mem[ram_addr] <= {mem_val[15:8], ram_din[7:0]};
85
      ram_addr_reg <= ram_addr;
86
    end
87
 
88
assign ram_dout = mem[ram_addr_reg];
89
 
90
 
91
endmodule // ram

powered by: WebSVN 2.1.0

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