-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmem_for_dcache.v
88 lines (79 loc) · 1.87 KB
/
dmem_for_dcache.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Module : 256x8-bit data memory (4-Byte blocks)
Author : Isuru Nawinne
Date : 30/05/2020
Description :
This file presents a primitive data memory module for CO224 Lab 6 - Part 2
This memory allows data to be read and written as 4-Byte blocks
*/
`timescale 1ns/100ps
module data_memory(
clock,
reset,
read,
write,
address,
writedata,
readdata,
busywait
);
input clock;
input reset;
input read;
input write;
input[5:0] address;
input[31:0] writedata;
output reg [31:0] readdata;
output reg busywait;
//Declare memory array 256x8-bits
reg [7:0] memory_array [255:0];
//Detecting an incoming memory access
reg readaccess, writeaccess;
always @(read, write)
begin
busywait = (read || write)? 1 : 0;
readaccess = (read && !write)? 1 : 0;
writeaccess = (!read && write)? 1 : 0;
end
//Reading & writing
always @(posedge clock)
begin
if(readaccess)
begin
readdata[7:0] = #40 memory_array[{address,2'b00}];
readdata[15:8] = #40 memory_array[{address,2'b01}];
readdata[23:16] = #40 memory_array[{address,2'b10}];
readdata[31:24] = #40 memory_array[{address,2'b11}];
busywait = 0;
readaccess = 0;
end
if(writeaccess)
begin
memory_array[{address,2'b00}] = #40 writedata[7:0];
memory_array[{address,2'b01}] = #40 writedata[15:8];
memory_array[{address,2'b10}] = #40 writedata[23:16];
memory_array[{address,2'b11}] = #40 writedata[31:24];
busywait = 0;
writeaccess = 0;
end
end
//Reset memory
always @(posedge reset)
begin
if (reset)
begin
for (integer i=0;i<256; i=i+1)
memory_array[i] = 0;
busywait = 0;
readaccess = 0;
writeaccess = 0;
end
end
//testing - dump the values of the memory array to the gtkwave file
initial
begin
$dumpfile("cpu_wavedata.vcd");
for(integer i = 0;i<256;i++)
$dumpvars(1,memory_array[i]);
end
endmodule