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

Subversion Repositories thor

[/] [thor/] [trunk/] [bench/] [scratchmem.v] - Blame information for rev 23

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

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2013  Robert Finch, Stratford
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@opencores.org
6
//       ||
7
//
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
// ============================================================================
23
//
24
module scratchmem(rst_i, clk_i, cyc_i, stb_i, ack_o, we_i, sel_i, adr_i, dat_i, dat_o);
25
parameter DBW=64;
26
input rst_i;
27
input clk_i;
28
input cyc_i;
29
input stb_i;
30
output ack_o;
31
input we_i;
32
input [DBW/8-1:0] sel_i;
33
input [DBW-1:0] adr_i;
34
input [DBW-1:0] dat_i;
35
output [DBW-1:0] dat_o;
36
reg [DBW-1:0] dat_o;
37
 
38
integer n;
39
 
40
reg [7:0] smemA [2047:0];
41
reg [7:0] smemB [2047:0];
42
reg [7:0] smemC [2047:0];
43
reg [7:0] smemD [2047:0];
44
generate
45
begin
46
if (DBW==64) begin
47
        reg [7:0] smemE [2047:0];
48
        reg [7:0] smemF [2047:0];
49
        reg [7:0] smemG [2047:0];
50
        reg [7:0] smemH [2047:0];
51
 
52
        initial begin
53
        for (n = 0; n < 2048; n = n + 1)
54
        begin
55
                smemA[n] = 0;
56
                smemB[n] = 0;
57
                smemC[n] = 0;
58
                smemD[n] = 0;
59
                smemE[n] = 0;
60
                smemF[n] = 0;
61
                smemG[n] = 0;
62
                smemH[n] = 0;
63
        end
64
        end
65
end
66
else begin
67
        initial begin
68
        for (n = 0; n < 2048; n = n + 1)
69
        begin
70
                smemA[n] = 0;
71
                smemB[n] = 0;
72
                smemC[n] = 0;
73
                smemD[n] = 0;
74
        end
75
        end
76
end
77
end
78
endgenerate
79
reg [13:3] radr;
80
 
81
 
82
wire cs = cyc_i && stb_i && adr_i[59:16]==44'h0000;
83
 
84
reg rdy,rdy1;
85
always @(posedge clk_i)
86
begin
87
        rdy1 <= cs;
88
        rdy <= rdy1 & cs;
89
end
90
assign ack_o = cs ? (we_i ? 1'b1 : rdy) : 1'b0;
91
 
92
 
93
always @(posedge clk_i)
94
        if (cs & we_i)
95
                $display ("wrote to scratchmem: %h=%h", adr_i, dat_i);
96
generate
97
begin
98
if (DBW==64) begin
99
always @(posedge clk_i)
100
        if (cs & we_i & sel_i[0])
101
                smemA[adr_i[13:3]] <= dat_i[7:0];
102
always @(posedge clk_i)
103
        if (cs & we_i & sel_i[1])
104
                smemB[adr_i[13:3]] <= dat_i[15:8];
105
always @(posedge clk_i)
106
        if (cs & we_i & sel_i[2])
107
                smemC[adr_i[13:3]] <= dat_i[23:16];
108
always @(posedge clk_i)
109
        if (cs & we_i & sel_i[3])
110
                smemD[adr_i[13:3]] <= dat_i[31:24];
111
//always @(posedge clk_i)
112
//      if (cs & we_i & sel_i[4])
113
//              smemE[adr_i[13:3]] <= dat_i[39:32];
114
//always @(posedge clk_i)
115
//      if (cs & we_i & sel_i[5])
116
//              smemF[adr_i[13:3]] <= dat_i[47:40];
117
//always @(posedge clk_i)
118
//      if (cs & we_i & sel_i[6])
119
//              smemG[adr_i[13:3]] <= dat_i[55:48];
120
//always @(posedge clk_i)
121
//      if (cs & we_i & sel_i[7])
122
//              smemH[adr_i[13:3]] <= dat_i[63:56];
123
end
124
else begin
125
always @(posedge clk_i)
126
        if (cs & we_i & sel_i[0])
127
                smemA[adr_i[12:2]] <= dat_i[7:0];
128
always @(posedge clk_i)
129
        if (cs & we_i & sel_i[1])
130
                smemB[adr_i[12:2]] <= dat_i[15:8];
131
always @(posedge clk_i)
132
        if (cs & we_i & sel_i[2])
133
                smemC[adr_i[12:2]] <= dat_i[23:16];
134
always @(posedge clk_i)
135
        if (cs & we_i & sel_i[3])
136
                smemD[adr_i[12:2]] <= dat_i[31:24];
137
end
138
end
139
endgenerate
140
 
141
wire pe_cs;
142
edge_det u1(.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(cs), .pe(pe_cs), .ne(), .ee() );
143
 
144
reg [13:3] ctr;
145
always @(posedge clk_i)
146
        if (pe_cs) begin
147
                if (DBW==64)
148
                        ctr <= adr_i[13:3] + 12'd1;
149
                else
150
                        ctr <= adr_i[12:2] + 12'd1;
151
        end
152
        else if (cs)
153
                ctr <= ctr + 12'd1;
154
 
155
always @(posedge clk_i)
156
        if (DBW==64)
157
                radr <= pe_cs ? adr_i[13:3] : ctr;
158
        else
159
                radr <= pe_cs ? adr_i[12:2] : ctr;
160
 
161
//assign dat_o = cs ? {smemH[radr],smemG[radr],smemF[radr],smemE[radr],
162
//                              smemD[radr],smemC[radr],smemB[radr],smemA[radr]} : 64'd0;
163
 
164
always @(posedge clk_i)
165
if (cs) begin
166
//      if (DBW==64)
167
//              dat_o <= {smemH[radr],smemG[radr],smemF[radr],smemE[radr],
168
//                                      smemD[radr],smemC[radr],smemB[radr],smemA[radr]};
169
//      else
170
                dat_o <= {smemD[radr],smemC[radr],smemB[radr],smemA[radr]};
171
//      if (!we_i)
172
//              $display("read from scratchmem: %h=%h", radr, {smemH[radr],smemG[radr],smemF[radr],smemE[radr],
173
//                              smemD[radr],smemC[radr],smemB[radr],smemA[radr]});
174
end
175
else
176
        dat_o <= {DBW{1'd0}};
177
 
178
endmodule

powered by: WebSVN 2.1.0

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