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

Subversion Repositories Aquarius

[/] [Aquarius/] [trunk/] [verilog/] [memory.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 thorn_aitc
//======================================================
2
// Aquarius Project
3
//    SuperH-2 ISA Compatible RISC CPU
4
//------------------------------------------------------
5
// Module      : Memory (ROM/RAM) in MCU 
6
//------------------------------------------------------
7
// File        : memory.v
8
// Library     : none
9
// Description : 16KB Memory Module in MCU
10
//               lower 8KB has fixed code (rom.v)
11
// Simulator   : Icarus Verilog (Cygwin)
12
// Synthesizer : Xilinx XST (Windows XP)
13
// Author      : Thorn Aitch
14
//------------------------------------------------------
15
// Revision Number : 1
16
// Date of Change  : 15th August 2002
17
// Creator         : Thorn Aitch
18
// Description     : Initial Design                               
19
//------------------------------------------------------
20
// Revision Number : 2
21
// Date of Change  : 30th April 2003
22
// Modifier        : Thorn Aitch
23
// Description     : Release Version 1.0
24
//======================================================
25
// Copyright (C) 2002-2003, Thorn Aitch
26
//
27
// Designs can be altered while keeping list of
28
// modifications "the same as in GNU" No money can
29
// be earned by selling the designs themselves, but
30
// anyone can get money by selling the implementation
31
// of the design, such as ICs based on some cores, 
32
// boards based on some schematics or Layouts, and
33
// even GUI interfaces to text mode drivers.
34
// "The same as GPL SW" Any update to the design
35
// should be documented and returned to the design. 
36
// Any derivative work based on the IP should be free
37
// under OpenIP License. Derivative work means any
38
// update, change or improvement on the design. 
39
// Any work based on the design can be either made
40
// free under OpenIP license or protected by any other
41
// license. Work based on the design means any work uses
42
// the OpenIP Licensed core as a building black without
43
// changing anything on it with any other blocks to
44
// produce larger design.  There is NO WARRANTY on the
45
// functionality or performance of the design on the
46
// real hardware implementation.
47
// On the other hand, the SuperH-2 ISA (Instruction Set
48
// Architecture) executed by Aquarius is rigidly
49
// the property of Renesas Corp. Then you have all 
50
// responsibility to judge if there are not any 
51
// infringements to Renesas's rights regarding your 
52
// Aquarius adoption into your design. 
53
// By adopting Aquarius, the user assumes all 
54
// responsibility for its use.
55
// This project may cause any damages around you, for 
56
// example, loss of properties, data, money, profits,
57
// life, or business etc. By adopting this source, 
58
// the user assumes all responsibility for its use.
59
//======================================================
60
 
61
`include "timescale.v"
62
`include "defines.v"
63
 
64
//*************************************************
65
// Module Definition
66
//*************************************************
67
module memory (
68
               CLK,
69
               CE, WE, SEL,
70
               ADR, DATI, DATO
71
           );
72
 
73
//-------------------
74
// Module I/O Signals
75
//-------------------
76
    input CLK;           // clock
77
    input CE;            // chip enable
78
    input WE;            // write enable (read = 0, write = 1)
79
    input [3:0]SEL;      // data valid position
80
    input [13:0] ADR;    // address
81
    input [31:0] DATI;   // write data
82
    output [31:0] DATO;  // read data
83
 
84
//-----------------
85
// Internal Signals
86
//-----------------
87
    reg    [7:0] RAM0HH [0:511];
88
    reg    [7:0] RAM0HL [0:511];
89
    reg    [7:0] RAM0LH [0:511];
90
    reg    [7:0] RAM0LL [0:511];
91
    reg    [7:0] RAM1HH [0:511];
92
    reg    [7:0] RAM1HL [0:511];
93
    reg    [7:0] RAM1LH [0:511];
94
    reg    [7:0] RAM1LL [0:511];
95
    reg    [7:0] RAM2HH [0:511];
96
    reg    [7:0] RAM2HL [0:511];
97
    reg    [7:0] RAM2LH [0:511];
98
    reg    [7:0] RAM2LL [0:511];
99
    reg    [7:0] RAM3HH [0:511];
100
    reg    [7:0] RAM3HL [0:511];
101
    reg    [7:0] RAM3LH [0:511];
102
    reg    [7:0] RAM3LL [0:511];
103
 
104
    wire   [31:0] DATO;
105
    wire   [31:0] DATOUT0;
106
    wire   [31:0] DATOUT1;
107
    wire   [31:0] DATOUT2;
108
    wire   [31:0] DATOUT3;
109
    wire   [31:0] DATROM;
110
 
111
    reg    [8:0] ADR_RD;
112
    reg    [3:0] CERAM;
113
    reg    CEROM;
114
 
115
//--------------
116
// ROM Operation
117
//--------------
118
    always @(ADR or CE)
119
    begin
120
        case ({CE, ADR[13]})
121
            4'b1_0:  CEROM <= 1'b1;
122
            default: CEROM <= 1'b0;
123
        endcase
124
    end
125
 
126
    rom ROM(
127
        .CLK(CLK), .CE(CEROM), .WE(WE), .SEL(SEL),
128
        .ADR(ADR[12:0]), .DATI(DATO), .DATO(DATROM)
129
    );
130
 
131
//--------------
132
// RAM Operation
133
//--------------
134
    always @(ADR or CE)
135
    begin
136
        case ({CE, ADR[13:11]})
137
            4'b1_100: CERAM <= 4'b0001;
138
            4'b1_101: CERAM <= 4'b0010;
139
            4'b1_110: CERAM <= 4'b0100;
140
            4'b1_111: CERAM <= 4'b1000;
141
            default: CERAM <= 4'b0000;
142
        endcase
143
    end
144
 
145
    always @(negedge CLK) begin
146
        if (CERAM[0] & WE & SEL[3]) RAM0HH[ADR[10:2]] <= DATI[31:24];
147
        if (CERAM[0] & WE & SEL[2]) RAM0HL[ADR[10:2]] <= DATI[23:16];
148
        if (CERAM[0] & WE & SEL[1]) RAM0LH[ADR[10:2]] <= DATI[15: 8];
149
        if (CERAM[0] & WE & SEL[0]) RAM0LL[ADR[10:2]] <= DATI[ 7: 0];
150
        if (CERAM[1] & WE & SEL[3]) RAM1HH[ADR[10:2]] <= DATI[31:24];
151
        if (CERAM[1] & WE & SEL[2]) RAM1HL[ADR[10:2]] <= DATI[23:16];
152
        if (CERAM[1] & WE & SEL[1]) RAM1LH[ADR[10:2]] <= DATI[15: 8];
153
        if (CERAM[1] & WE & SEL[0]) RAM1LL[ADR[10:2]] <= DATI[ 7: 0];
154
        if (CERAM[2] & WE & SEL[3]) RAM2HH[ADR[10:2]] <= DATI[31:24];
155
        if (CERAM[2] & WE & SEL[2]) RAM2HL[ADR[10:2]] <= DATI[23:16];
156
        if (CERAM[2] & WE & SEL[1]) RAM2LH[ADR[10:2]] <= DATI[15: 8];
157
        if (CERAM[2] & WE & SEL[0]) RAM2LL[ADR[10:2]] <= DATI[ 7: 0];
158
        if (CERAM[3] & WE & SEL[3]) RAM3HH[ADR[10:2]] <= DATI[31:24];
159
        if (CERAM[3] & WE & SEL[2]) RAM3HL[ADR[10:2]] <= DATI[23:16];
160
        if (CERAM[3] & WE & SEL[1]) RAM3LH[ADR[10:2]] <= DATI[15: 8];
161
        if (CERAM[3] & WE & SEL[0]) RAM3LL[ADR[10:2]] <= DATI[ 7: 0];
162
        ADR_RD <= ADR[10:2];
163
    end
164
 
165
    assign DATOUT0[31:24] = (CERAM[0]) ? RAM0HH[ADR_RD] : 8'h00;
166
    assign DATOUT0[23:16] = (CERAM[0]) ? RAM0HL[ADR_RD] : 8'h00;
167
    assign DATOUT0[15: 8] = (CERAM[0]) ? RAM0LH[ADR_RD] : 8'h00;
168
    assign DATOUT0[ 7: 0] = (CERAM[0]) ? RAM0LL[ADR_RD] : 8'h00;
169
    assign DATOUT1[31:24] = (CERAM[1]) ? RAM1HH[ADR_RD] : 8'h00;
170
    assign DATOUT1[23:16] = (CERAM[1]) ? RAM1HL[ADR_RD] : 8'h00;
171
    assign DATOUT1[15: 8] = (CERAM[1]) ? RAM1LH[ADR_RD] : 8'h00;
172
    assign DATOUT1[ 7: 0] = (CERAM[1]) ? RAM1LL[ADR_RD] : 8'h00;
173
    assign DATOUT2[31:24] = (CERAM[2]) ? RAM2HH[ADR_RD] : 8'h00;
174
    assign DATOUT2[23:16] = (CERAM[2]) ? RAM2HL[ADR_RD] : 8'h00;
175
    assign DATOUT2[15: 8] = (CERAM[2]) ? RAM2LH[ADR_RD] : 8'h00;
176
    assign DATOUT2[ 7: 0] = (CERAM[2]) ? RAM2LL[ADR_RD] : 8'h00;
177
    assign DATOUT3[31:24] = (CERAM[3]) ? RAM3HH[ADR_RD] : 8'h00;
178
    assign DATOUT3[23:16] = (CERAM[3]) ? RAM3HL[ADR_RD] : 8'h00;
179
    assign DATOUT3[15: 8] = (CERAM[3]) ? RAM3LH[ADR_RD] : 8'h00;
180
    assign DATOUT3[ 7: 0] = (CERAM[3]) ? RAM3LL[ADR_RD] : 8'h00;
181
 
182
    assign DATO = DATOUT0 | DATOUT1 | DATOUT2 | DATOUT3 | DATROM;
183
 
184
//======================================================
185
  endmodule
186
//======================================================

powered by: WebSVN 2.1.0

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