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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [tags/] [Beta_0.2/] [rtl/] [MEM/] [Unit_MEM.v] - Blame information for rev 60

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3
/**********************************************************************************
4
Theia, Ray Cast Programable graphic Processing Unit.
5
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
***********************************************************************************/
22
/*
23
The memory unit has all the memory related modules for THEIA.
24
There a 3 memories in the core:
25 60 diegovalve
DMEM: The data memory, it is a R/W dual channel RAM, stores the data locations.
26
IMEM: The instruction memory, R/W dual channel RAM, stores user shaders.
27 19 diegovalve
IROM: RO instruction memory, stores default shaders and other internal code.
28 60 diegovalve
I use two ROMs with the same data, so that simulates dual channel.
29 19 diegovalve
This unit also has a Control register.
30
*/
31 60 diegovalve
`define USER_CODE_ENABLED 2
32 19 diegovalve
//-------------------------------------------------------------------
33
module MemoryUnit
34
(
35
input wire                              Clock,
36
input wire                              Reset,
37
input wire                              iDataWriteEnable,
38
input wire                              iInstructionWriteEnable,
39 60 diegovalve
input  wire [`ROM_ADDRESS_WIDTH-1:0]    iInstructionReadAddress1,
40
input  wire [`ROM_ADDRESS_WIDTH-1:0]    iInstructionReadAddress2,
41 19 diegovalve
input wire [`ROM_ADDRESS_WIDTH-1:0]     iInstructionWriteAddress,
42 60 diegovalve
output wire [`INSTRUCTION_WIDTH-1:0]    oInstruction1,
43
output wire [`INSTRUCTION_WIDTH-1:0]    oInstruction2,
44 19 diegovalve
input wire [`INSTRUCTION_WIDTH-1:0]     iInstruction,
45
input wire[`DATA_ADDRESS_WIDTH-1:0]     iDataReadAddress1,
46
input wire[`DATA_ROW_WIDTH-1:0]         oData1,
47
input wire[`DATA_ADDRESS_WIDTH-1:0]     iDataReadAddress2,
48
input wire[`DATA_ROW_WIDTH-1:0]         oData2,
49
input wire[`DATA_ADDRESS_WIDTH-1:0]     iDataWriteAddress,
50
input wire[`DATA_ROW_WIDTH-1:0]         iData,
51
input wire[15:0]                       iControlRegister,
52
output wire[15:0]                       oControlRegister
53
 
54
);
55
 
56
wire [`ROM_ADDRESS_WIDTH-1:0] wROMInstructionAddress,wRAMInstructionAddress;
57 60 diegovalve
wire [`INSTRUCTION_WIDTH-1:0] wIMEM2_IMUX__DataOut1,wIMEM2_IMUX__DataOut2,
58
wIROM2_IMUX__DataOut1,wIROM2_IMUX__DataOut2;
59 19 diegovalve
 
60
 
61 60 diegovalve
wire wInstructionSelector;
62
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1
63
(
64
        .Clock(Clock),
65
        .Reset(Reset),
66
        .Enable( 1'b1 ),
67
        .D( iInstructionReadAddress1[`ROM_ADDRESS_WIDTH-1]  ),
68
        .Q( wInstructionSelector )
69
);
70 19 diegovalve
 
71 60 diegovalve
assign oInstruction1 = (wInstructionSelector == 1) ?
72
        wIMEM2_IMUX__DataOut1 : wIROM2_IMUX__DataOut1;
73
 
74
 
75
assign oInstruction2 = (wInstructionSelector == 1) ?
76
        wIMEM2_IMUX__DataOut2 : wIROM2_IMUX__DataOut2;
77 19 diegovalve
//-------------------------------------------------------------------
78
/*
79
Data memory.
80
*/
81 60 diegovalve
RAM_128_ROW_DUAL_READ_PORT  # (`DATA_ROW_WIDTH,`DATA_ADDRESS_WIDTH) DMEM
82 19 diegovalve
(
83
        .Clock( Clock ),
84
        .iWriteEnable( iDataWriteEnable ),
85
        .iReadAddress0( iDataReadAddress1 ),
86
        .iReadAddress1( iDataReadAddress2 ),
87
        .iWriteAddress( iDataWriteAddress ),
88
        .iDataIn( iData ),
89
        .oDataOut0( oData1 ),
90
        .oDataOut1( oData2 )
91
);
92
//-------------------------------------------------------------------
93
/*
94
Instruction memory.
95
*/
96 60 diegovalve
RAM_128_ROW_DUAL_READ_PORT  # (`INSTRUCTION_WIDTH,`ROM_ADDRESS_WIDTH) IMEM
97 19 diegovalve
(
98
        .Clock( Clock ),
99
        .iWriteEnable( iInstructionWriteEnable ),
100 60 diegovalve
        .iReadAddress0( {1'b0,iInstructionReadAddress1[`ROM_ADDRESS_WIDTH-2:0]} ),
101
        .iReadAddress1( {1'b0,iInstructionReadAddress2[`ROM_ADDRESS_WIDTH-2:0]} ),
102 19 diegovalve
        .iWriteAddress( iInstructionWriteAddress ),
103
        .iDataIn( iInstruction ),
104 60 diegovalve
        .oDataOut0( wIMEM2_IMUX__DataOut1 ),
105
        .oDataOut1( wIMEM2_IMUX__DataOut2 )
106 19 diegovalve
 
107
);
108
//-------------------------------------------------------------------
109
/*
110
 Default code stored in ROM.
111
*/
112 60 diegovalve
wire [`INSTRUCTION_WIDTH-1:0] wRomDelay1,wRomDelay2;
113
//In real world ROM will take at least 1 clock cycle,
114
//since ROMs are not syhtethizable, I won't hurt to put
115
//this delay
116
 
117
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_WIDTH ) FFDA
118
(
119
        .Clock(Clock),
120
        .Reset(Reset),
121
        .Enable(1'b1),
122
        .D(wRomDelay1),
123
        .Q(wIROM2_IMUX__DataOut1 )
124
);
125
 
126
 
127
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_WIDTH ) FFDB
128
(
129
        .Clock(Clock),
130
        .Reset(Reset),
131
        .Enable(1'b1),
132
        .D(wRomDelay2),
133
        .Q(wIROM2_IMUX__DataOut2 )
134
);
135
 
136
//The reason I put two ROMs is because I need to read 2 different Instruction 
137
//addresses at the same time (branch-taken and branch-not-taken) and not sure
138
//hpw to write dual read channel ROM this way...
139
 
140 19 diegovalve
ROM IROM
141
(
142 60 diegovalve
        .Address( {1'b0,iInstructionReadAddress1[`ROM_ADDRESS_WIDTH-2:0]} ),
143
        .I( wRomDelay1 )
144 19 diegovalve
);
145 60 diegovalve
 
146
ROM IROM2
147
(
148
        .Address( {1'b0,iInstructionReadAddress2[`ROM_ADDRESS_WIDTH-2:0]} ),
149
        .I( wRomDelay2 )
150
);
151 19 diegovalve
//--------------------------------------------------------
152
ControlRegister CR
153
(
154
        .Clock( Clock ),
155
        .Reset( Reset ),
156
        .iControlRegister( iControlRegister ),
157
        .oControlRegister( oControlRegister )
158
);
159
 
160
 
161
endmodule
162
//-------------------------------------------------------------------

powered by: WebSVN 2.1.0

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