1 |
46 |
simont |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// 8051 data ram ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the 8051 cores project ////
|
6 |
|
|
//// http://www.opencores.org/cores/8051/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// data ram ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// To Do: ////
|
12 |
|
|
//// nothing ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// Author(s): ////
|
15 |
|
|
//// - Simon Teran, simont@opencores.org ////
|
16 |
|
|
//// ////
|
17 |
|
|
//////////////////////////////////////////////////////////////////////
|
18 |
|
|
//// ////
|
19 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
20 |
|
|
//// ////
|
21 |
|
|
//// This source file may be used and distributed without ////
|
22 |
|
|
//// restriction provided that this copyright statement is not ////
|
23 |
|
|
//// removed from the file and that any derivative work contains ////
|
24 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// This source file is free software; you can redistribute it ////
|
27 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
28 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
29 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
30 |
|
|
//// later version. ////
|
31 |
|
|
//// ////
|
32 |
|
|
//// This source is distributed in the hope that it will be ////
|
33 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
34 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
35 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
36 |
|
|
//// details. ////
|
37 |
|
|
//// ////
|
38 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
39 |
|
|
//// Public License along with this source; if not, download it ////
|
40 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
41 |
|
|
//// ////
|
42 |
|
|
//////////////////////////////////////////////////////////////////////
|
43 |
|
|
//
|
44 |
|
|
// CVS Revision History
|
45 |
|
|
//
|
46 |
|
|
// $Log: not supported by cvs2svn $
|
47 |
|
|
//
|
48 |
|
|
|
49 |
|
|
// synopsys translate_off
|
50 |
|
|
`include "oc8051_timescale.v"
|
51 |
|
|
// synopsys translate_on
|
52 |
|
|
|
53 |
|
|
`include "oc8051_defines.v"
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
module oc8051_ram_top (clk, rst, rd_addr, rd_data, wr_addr, bit_addr, wr_data, wr, bit_data_in, bit_data_out);
|
57 |
|
|
//
|
58 |
|
|
// clk (in) clock
|
59 |
|
|
// rd_addr (in) read addres [oc8051_ram_rd_sel.out]
|
60 |
|
|
// rd_data (out) read data [oc8051_ram_sel.in_ram]
|
61 |
|
|
// wr_addr (in) write addres [oc8051_ram_wr_sel.out]
|
62 |
|
|
// bit_addr (in) bit addresable instruction [oc8051_decoder.bit_addr -r]
|
63 |
|
|
// wr_data (in) write data [oc8051_alu.des1]
|
64 |
|
|
// wr (in) write [oc8051_decoder.wr -r]
|
65 |
|
|
// bit_data_in (in) bit data input [oc8051_alu.desCy]
|
66 |
|
|
// bit_data_out (out) bit data output [oc8051_ram_sel.bit_in]
|
67 |
|
|
//
|
68 |
|
|
|
69 |
|
|
input clk, wr, bit_addr, bit_data_in, rst;
|
70 |
|
|
input [7:0] rd_addr, wr_addr, wr_data;
|
71 |
|
|
output bit_data_out;
|
72 |
|
|
output [7:0] rd_data;
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
// rd_addr_m read address modified
|
76 |
|
|
// wr_addr_m write address modified
|
77 |
|
|
// wr_data_m write data modified
|
78 |
|
|
reg [7:0] rd_addr_m, wr_addr_m, wr_data_m;
|
79 |
|
|
|
80 |
|
|
// bit_addr_r bit addresable instruction (registerd)
|
81 |
|
|
reg bit_addr_r;
|
82 |
|
|
reg [2:0] bit_select;
|
83 |
|
|
|
84 |
|
|
assign bit_data_out = rd_data[bit_select];
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
oc8051_ram oc8051_ram1(.clk(clk), .rst(rst), .rd_addr(rd_addr_m), .rd_data(rd_data), .wr_addr(wr_addr_m),
|
89 |
|
|
.wr_data(wr_data_m), .wr(wr));
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
always @(posedge clk or posedge rst)
|
93 |
|
|
if (rst) begin
|
94 |
|
|
bit_addr_r <= #1 1'b0;
|
95 |
|
|
bit_select <= #1 3'b0;
|
96 |
|
|
end else begin
|
97 |
|
|
bit_addr_r <= #1 bit_addr;
|
98 |
|
|
bit_select <= #1 rd_addr[2:0];
|
99 |
|
|
end
|
100 |
|
|
|
101 |
|
|
always @(rd_addr or bit_addr)
|
102 |
|
|
begin
|
103 |
|
|
case ({bit_addr, rd_addr[7]})
|
104 |
|
|
2'b10: rd_addr_m = {4'b0010, rd_addr[6:3]};
|
105 |
|
|
2'b11: rd_addr_m = {1'b1, rd_addr[6:3], 3'b000};
|
106 |
|
|
default: rd_addr_m = rd_addr;
|
107 |
|
|
endcase
|
108 |
|
|
end
|
109 |
|
|
|
110 |
|
|
always @(wr_addr or bit_addr_r)
|
111 |
|
|
begin
|
112 |
|
|
casex ({bit_addr_r, wr_addr[7]})
|
113 |
|
|
2'b10: wr_addr_m = {4'b0010, wr_addr[6:3]};
|
114 |
|
|
2'b11: wr_addr_m = {1'b1, wr_addr[6:3], 3'b000};
|
115 |
|
|
default: wr_addr_m = wr_addr;
|
116 |
|
|
endcase
|
117 |
|
|
end
|
118 |
|
|
|
119 |
|
|
always @(rd_data or bit_select or bit_data_in or wr_data or bit_addr_r)
|
120 |
|
|
begin
|
121 |
|
|
if (bit_addr_r) begin
|
122 |
|
|
case (bit_select)
|
123 |
|
|
3'b000: wr_data_m = {rd_data[7:1], bit_data_in};
|
124 |
|
|
3'b001: wr_data_m = {rd_data[7:2], bit_data_in, rd_data[0]};
|
125 |
|
|
3'b010: wr_data_m = {rd_data[7:3], bit_data_in, rd_data[1:0]};
|
126 |
|
|
3'b011: wr_data_m = {rd_data[7:4], bit_data_in, rd_data[2:0]};
|
127 |
|
|
3'b100: wr_data_m = {rd_data[7:5], bit_data_in, rd_data[3:0]};
|
128 |
|
|
3'b101: wr_data_m = {rd_data[7:6], bit_data_in, rd_data[4:0]};
|
129 |
|
|
3'b110: wr_data_m = {rd_data[7], bit_data_in, rd_data[5:0]};
|
130 |
|
|
default: wr_data_m = {bit_data_in, rd_data[6:0]};
|
131 |
|
|
endcase
|
132 |
|
|
end else
|
133 |
|
|
wr_data_m = wr_data;
|
134 |
|
|
end
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
|
138 |
|
|
endmodule
|