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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [rtl/] [noc/] [memory/] [scratchmem.sv] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2012-2022  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
module scratchmem(rst_i, clk_i, cti_i, bok_o, cs_i, cyc_i, stb_i, ack_o, we_i, adr_i, dat_i, dat_o, sp);
38
input rst_i;
39
input clk_i;
40
input [2:0] cti_i;
41
output bok_o;
42
input cs_i;
43
input cyc_i;
44
input stb_i;
45
output ack_o;
46
input we_i;
47
input [13:0] adr_i;
48
input [11:0] dat_i;
49
output reg [11:0] dat_o;
50
input [23:0] sp;
51
 
52
integer n;
53
 
54
reg [11:0] rommem [16383:0];
55
reg [13:0] radr;
56
 
57
 
58
initial begin
59
        for (n = 0; n < 16384; n = n + 1)
60
                rommem[n] <= 'h00;
61
`include "d:/cores2022/rf6809/software/a09/a09/debug/boot_rom.ver";
62
end
63
 
64
wire cs = cs_i && cyc_i && stb_i;
65
assign bok_o = cs_i;
66
reg csd = 1'b0;
67
reg wed = 1'b0;
68
reg [13:0] adrd = 16'h00;
69
reg [11:0] datid = 8'h00;
70
reg [11:0] datod = 'h00;
71
 
72
reg [2:0] cnt;
73
 
74
ack_gen #(
75
        .READ_STAGES(2),
76
        .WRITE_STAGES(1),
77
        .REGISTER_OUTPUT(1)
78
) ag1
79
(
80
        .clk_i(clk_i),
81
        .ce_i(1'b1),
82
        .i(cs && cnt != 3'b101),
83
        .we_i(we_i && cs && cnt != 3'b101),
84
        .o(ack_o),
85
        .rid_i(0),
86
        .wid_i(0),
87
        .rid_o(),
88
        .wid_o()
89
);
90
 
91
 
92
always @(posedge clk_i)
93
        csd <= cs;
94
always @(posedge clk_i)
95
        wed <= we_i;
96
always @(posedge clk_i)
97
        adrd <= adr_i;
98
always @(posedge clk_i)
99
        datid <= dat_i;
100
 
101
always @(posedge clk_i)
102
        if (cs & we_i) begin
103
                $display ("wrote to scratchmem: %h=%h", adr_i, dat_i);
104
                /*
105
                if (adr_i[14:3]==15'h3e9 && dat_i==64'h00) begin
106
                  $display("3e9=00");
107
                  $finish;
108
                end
109
                */
110
        end
111
 
112
genvar g;
113
generate begin : gRom
114
for (g = 0; g < 1; g = g + 1)
115
always @(posedge clk_i)
116
        if (csd && wed)
117
                rommem[adrd[13:0]][g*12+11:g*12] <= datid[11:0];
118
end
119
endgenerate
120
 
121
wire pe_cs;
122
edge_det u1(.rst(rst_i), .clk(clk_i), .ce(1'b1), .i(cs), .pe(pe_cs), .ne(), .ee() );
123
 
124
reg [13:0] ctr;
125
always @(posedge clk_i)
126
if (rst_i) begin
127
        cnt <= 3'd0;
128
        ctr <= 14'd0;
129
end
130
else begin
131
        if (pe_cs) begin
132
                if (cti_i==3'b000)
133
                        ctr <= adr_i[13:0];
134
                else
135
                        ctr <= adr_i[13:0] + 12'd1;
136
                cnt <= 3'b000;
137
        end
138
        else if (cs && cnt[2:0]!=3'b100 && cti_i!=3'b000) begin
139
                ctr <= ctr + 2'd1;
140
                cnt <= cnt + 3'd1;
141
        end
142
end
143
 
144
always @(posedge clk_i)
145
        radr <= pe_cs ? adr_i[13:0] : ctr;
146
 
147
reg [13:0] spr;
148
always @(posedge clk_i)
149
        spr <= sp[13:0];
150
 
151
always @(posedge clk_i)
152
if (rst_i)
153
        datod <= 12'h00;
154
else begin
155
        datod <= rommem[radr[13:0]];
156
        if (!we_i & cs)
157
                $display("read from scratchmem: %h=%h", radr, rommem[radr[13:0]]);
158
//      $display("-------------- Stack --------------");
159
//      for (n = -6; n < 8; n = n + 1) begin
160
//              $display("%c%c %h %h", n==0 ? "-": " ", n==0 ?">" : " ",spr + n, rommem[spr+n]);
161
//      end
162
end
163
 
164
always @(posedge clk_i)
165
if (rst_i)
166
        dat_o <= 'h00;
167
else begin
168
        if (cs_i)
169
                dat_o <= datod;
170
        else
171
                dat_o <= 'd0;
172
end
173
 
174
endmodule
175
 

powered by: WebSVN 2.1.0

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