Line 20... |
Line 20... |
|
|
***********************************************************************************/
|
***********************************************************************************/
|
/*
|
/*
|
The memory unit has all the memory related modules for THEIA.
|
The memory unit has all the memory related modules for THEIA.
|
There a 3 memories in the core:
|
There a 3 memories in the core:
|
DMEM: The data memory, it is a R/W RAM, stores the data locations.
|
DMEM: The data memory, it is a R/W dual channel RAM, stores the data locations.
|
IMEM: The instruction memory, R/W RAM, stores user shaders.
|
IMEM: The instruction memory, R/W dual channel RAM, stores user shaders.
|
IROM: RO instruction memory, stores default shaders and other internal code.
|
IROM: RO instruction memory, stores default shaders and other internal code.
|
|
I use two ROMs with the same data, so that simulates dual channel.
|
This unit also has a Control register.
|
This unit also has a Control register.
|
*/
|
*/
|
|
`define USER_CODE_ENABLED 2
|
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
module MemoryUnit
|
module MemoryUnit
|
(
|
(
|
input wire Clock,
|
input wire Clock,
|
input wire Reset,
|
input wire Reset,
|
input wire iDataWriteEnable,
|
input wire iDataWriteEnable,
|
input wire iInstructionWriteEnable,
|
input wire iInstructionWriteEnable,
|
input wire [`ROM_ADDRESS_WIDTH-1:0] iInstructionReadAddress,
|
input wire [`ROM_ADDRESS_WIDTH-1:0] iInstructionReadAddress1,
|
|
input wire [`ROM_ADDRESS_WIDTH-1:0] iInstructionReadAddress2,
|
input wire [`ROM_ADDRESS_WIDTH-1:0] iInstructionWriteAddress,
|
input wire [`ROM_ADDRESS_WIDTH-1:0] iInstructionWriteAddress,
|
output wire [`INSTRUCTION_WIDTH-1:0] oInstruction,
|
output wire [`INSTRUCTION_WIDTH-1:0] oInstruction1,
|
|
output wire [`INSTRUCTION_WIDTH-1:0] oInstruction2,
|
input wire [`INSTRUCTION_WIDTH-1:0] iInstruction,
|
input wire [`INSTRUCTION_WIDTH-1:0] iInstruction,
|
input wire[`DATA_ADDRESS_WIDTH-1:0] iDataReadAddress1,
|
input wire[`DATA_ADDRESS_WIDTH-1:0] iDataReadAddress1,
|
input wire[`DATA_ROW_WIDTH-1:0] oData1,
|
input wire[`DATA_ROW_WIDTH-1:0] oData1,
|
input wire[`DATA_ADDRESS_WIDTH-1:0] iDataReadAddress2,
|
input wire[`DATA_ADDRESS_WIDTH-1:0] iDataReadAddress2,
|
input wire[`DATA_ROW_WIDTH-1:0] oData2,
|
input wire[`DATA_ROW_WIDTH-1:0] oData2,
|
Line 48... |
Line 52... |
output wire[15:0] oControlRegister
|
output wire[15:0] oControlRegister
|
|
|
);
|
);
|
|
|
wire [`ROM_ADDRESS_WIDTH-1:0] wROMInstructionAddress,wRAMInstructionAddress;
|
wire [`ROM_ADDRESS_WIDTH-1:0] wROMInstructionAddress,wRAMInstructionAddress;
|
wire [`INSTRUCTION_WIDTH-1:0] wIMEM2_IMUX__DataOut,wIROM2_IMUX__DataOut;
|
wire [`INSTRUCTION_WIDTH-1:0] wIMEM2_IMUX__DataOut1,wIMEM2_IMUX__DataOut2,
|
|
wIROM2_IMUX__DataOut1,wIROM2_IMUX__DataOut2;
|
|
|
|
|
assign oInstruction = (iInstructionReadAddress[`ROM_ADDRESS_WIDTH-1] == 1) ?
|
wire wInstructionSelector;
|
wIMEM2_IMUX__DataOut : wIROM2_IMUX__DataOut;
|
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1
|
|
(
|
|
.Clock(Clock),
|
|
.Reset(Reset),
|
|
.Enable( 1'b1 ),
|
|
.D( iInstructionReadAddress1[`ROM_ADDRESS_WIDTH-1] ),
|
|
.Q( wInstructionSelector )
|
|
);
|
|
|
|
assign oInstruction1 = (wInstructionSelector == 1) ?
|
|
wIMEM2_IMUX__DataOut1 : wIROM2_IMUX__DataOut1;
|
|
|
|
|
|
assign oInstruction2 = (wInstructionSelector == 1) ?
|
|
wIMEM2_IMUX__DataOut2 : wIROM2_IMUX__DataOut2;
|
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
/*
|
/*
|
Data memory.
|
Data memory.
|
*/
|
*/
|
RAM_DATA DMEM
|
RAM_128_ROW_DUAL_READ_PORT # (`DATA_ROW_WIDTH,`DATA_ADDRESS_WIDTH) DMEM
|
(
|
(
|
.Clock( Clock ),
|
.Clock( Clock ),
|
.iWriteEnable( iDataWriteEnable ),
|
.iWriteEnable( iDataWriteEnable ),
|
.iReadAddress0( iDataReadAddress1 ),
|
.iReadAddress0( iDataReadAddress1 ),
|
.iReadAddress1( iDataReadAddress2 ),
|
.iReadAddress1( iDataReadAddress2 ),
|
Line 73... |
Line 91... |
);
|
);
|
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
/*
|
/*
|
Instruction memory.
|
Instruction memory.
|
*/
|
*/
|
RAM_INST IMEM
|
RAM_128_ROW_DUAL_READ_PORT # (`INSTRUCTION_WIDTH,`ROM_ADDRESS_WIDTH) IMEM
|
(
|
(
|
.Clock( Clock ),
|
.Clock( Clock ),
|
.iWriteEnable( iInstructionWriteEnable ),
|
.iWriteEnable( iInstructionWriteEnable ),
|
.iReadAddress( iInstructionReadAddress ),
|
.iReadAddress0( {1'b0,iInstructionReadAddress1[`ROM_ADDRESS_WIDTH-2:0]} ),
|
|
.iReadAddress1( {1'b0,iInstructionReadAddress2[`ROM_ADDRESS_WIDTH-2:0]} ),
|
.iWriteAddress( iInstructionWriteAddress ),
|
.iWriteAddress( iInstructionWriteAddress ),
|
.iDataIn( iInstruction ),
|
.iDataIn( iInstruction ),
|
.oDataOut( wIMEM2_IMUX__DataOut )
|
.oDataOut0( wIMEM2_IMUX__DataOut1 ),
|
|
.oDataOut1( wIMEM2_IMUX__DataOut2 )
|
|
|
);
|
);
|
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
/*
|
/*
|
Default code stored in ROM.
|
Default code stored in ROM.
|
*/
|
*/
|
|
wire [`INSTRUCTION_WIDTH-1:0] wRomDelay1,wRomDelay2;
|
|
//In real world ROM will take at least 1 clock cycle,
|
|
//since ROMs are not syhtethizable, I won't hurt to put
|
|
//this delay
|
|
|
|
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_WIDTH ) FFDA
|
|
(
|
|
.Clock(Clock),
|
|
.Reset(Reset),
|
|
.Enable(1'b1),
|
|
.D(wRomDelay1),
|
|
.Q(wIROM2_IMUX__DataOut1 )
|
|
);
|
|
|
|
|
|
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_WIDTH ) FFDB
|
|
(
|
|
.Clock(Clock),
|
|
.Reset(Reset),
|
|
.Enable(1'b1),
|
|
.D(wRomDelay2),
|
|
.Q(wIROM2_IMUX__DataOut2 )
|
|
);
|
|
|
|
//The reason I put two ROMs is because I need to read 2 different Instruction
|
|
//addresses at the same time (branch-taken and branch-not-taken) and not sure
|
|
//hpw to write dual read channel ROM this way...
|
|
|
ROM IROM
|
ROM IROM
|
(
|
(
|
.Address( iInstructionReadAddress ),
|
.Address( {1'b0,iInstructionReadAddress1[`ROM_ADDRESS_WIDTH-2:0]} ),
|
.I( wIROM2_IMUX__DataOut )
|
.I( wRomDelay1 )
|
|
);
|
|
|
|
ROM IROM2
|
|
(
|
|
.Address( {1'b0,iInstructionReadAddress2[`ROM_ADDRESS_WIDTH-2:0]} ),
|
|
.I( wRomDelay2 )
|
);
|
);
|
//--------------------------------------------------------
|
//--------------------------------------------------------
|
ControlRegister CR
|
ControlRegister CR
|
(
|
(
|
.Clock( Clock ),
|
.Clock( Clock ),
|