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

Subversion Repositories common

[/] [common/] [trunk/] [sram_for_debugging_async.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 bbeaver
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// sram_for_debugging_async  #(NUM_ADDR_BITS, NUM_DATA_BITS)    ////
4
////                                                              ////
5
//// This file is part of the general opencores effort.           ////
6
//// <http://www.opencores.org/cores/misc/>                       ////
7
////                                                              ////
8
//// Module Description:                                          ////
9
////    An SRAM model which contains only 32 entries.             ////
10
////    This SRAM trades off time for storage.  By only storing   ////
11
////      a very few entries, this SRAM takes constant storage    ////
12
////      independent of how many address lines it exports.       ////
13
////    The limited storage means that the entries must be read   ////
14
////      soon after it is written.  If too many writes happen    ////
15
////      before an entry is read, the entry returns X's.         ////
16
////    This SRAM has 1 other debugging feature.  When a write    ////
17
////      is executed, the SRAM ;atches the bit number of the     ////
18
////      least significant bit of the address which is HIGH.     ////
19
////    The special address 0xAA00..., with the top 8 bits being  ////
20
////      8'b1010_1010, returns the stored number when read.      ////
21
////    As an example, assume that a write is done to location    ////
22
////      20'h0_0040.                                             ////
23
////    After the write, but before any other write, the user     ////
24
////      can read location 20'hC_C000.  The read returns 4'h5.   ////
25
////                                                              ////
26
//// Author(s):                                                   ////
27
//// - Anonymous                                                  ////
28
////                                                              ////
29
//////////////////////////////////////////////////////////////////////
30
////                                                              ////
31
//// Copyright (C) 2000 Anonymous and OPENCORES.ORG               ////
32
////                                                              ////
33
//// This source file may be used and distributed without         ////
34
//// restriction provided that this copyright statement is not    ////
35
//// removed from the file and that any derivative work contains  ////
36
//// the original copyright notice and the associated disclaimer. ////
37
////                                                              ////
38
//// This source file is free software; you can redistribute it   ////
39
//// and/or modify it under the terms of the GNU Lesser General   ////
40
//// Public License as published by the Free Software Foundation; ////
41
//// either version 2.1 of the License, or (at your option) any   ////
42
//// later version.                                               ////
43
////                                                              ////
44
//// This source is distributed in the hope that it will be       ////
45
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
46
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
47
//// PURPOSE. See the GNU Lesser General Public License for more  ////
48
//// details.                                                     ////
49
////                                                              ////
50
//// You should have received a copy of the GNU Lesser General    ////
51
//// Public License along with this source; if not, download it   ////
52
//// from <http://www.opencores.org/lgpl.shtml>                   ////
53
////                                                              ////
54
//////////////////////////////////////////////////////////////////////
55
//
56 32 bbeaver
// $Id: sram_for_debugging_async.v,v 1.2 2001-11-06 12:33:15 bbeaver Exp $
57 15 bbeaver
//
58
// CVS Revision History
59
//
60
// $Log: not supported by cvs2svn $
61
// Revision 1.1  2001/10/02 05:23:27  Blue Beaver
62
// no message
63
//
64
// Revision 1.3  2001/09/27 08:05:43  Blue Beaver
65
// no message
66
//
67
// Revision 1.2  2001/09/26 09:46:20  Blue Beaver
68
// no message
69
//
70
// Revision 1.1  2001/09/25 10:49:34  Blue Beaver
71
// no message
72
//
73
 
74
`timescale 1ns/1ps
75
 
76
// instantiate as "sram_for_debugging_async #(NUM_ADDR_BITS, NUM_DATA_BITS) instance ()"
77
 
78
module sram_for_debugging_async (
79
  data_out,
80
  data_in,
81
  address,
82
  read_enable,
83
  write_enable
84
);
85
  parameter NUM_ADDR_BITS = 1;
86
  parameter NUM_DATA_BITS = 1;
87
 
88
  output [NUM_DATA_BITS - 1 : 0] data_out;
89
  input  [NUM_DATA_BITS - 1 : 0] data_in;
90
  input  [NUM_ADDR_BITS - 1 : 0] address;
91
  input   read_enable;
92
  input   write_enable;
93
 
94
  reg    [NUM_DATA_BITS - 1 : 0] data_storage [31:0];  // 32 entries of SRAM storage
95
  reg    [NUM_ADDR_BITS - 1 : 0] address_storage [31:0];  // 32 entries of SRAM storage
96
  reg    [5:0] write_counter;  // enough to count to 63
97
  reg    [NUM_DATA_BITS - 1 : 0] stored_write_address;  // store bit number of address LSB set to 1
98
 
99
  integer i, j, k, l;
100
 
101
// synopsys translate_off
102
  initial
103
  begin
104
    for (i = 6'h00; i != 6'h20; i = i + 6'h01)
105
    begin
106
      address_storage[i] = {NUM_ADDR_BITS{1'bX}};
107
      data_storage[i] = {NUM_DATA_BITS{1'bX}};
108
      stored_write_address[NUM_DATA_BITS - 1 : 0] = {NUM_DATA_BITS{1'bX}};
109
      write_counter[5:0] = 6'h00;
110
    end
111
  end
112
// synopsys translate_on
113
 
114
// Write to next address, remember which LSB write address bit was ~0
115
  always @(posedge write_enable)
116
  begin
117
    address_storage[write_counter[4:0]] = address[NUM_ADDR_BITS - 1 : 0];
118
    data_storage[write_counter[4:0]] = data_in[NUM_DATA_BITS - 1 : 0];
119
    for (j = 0; j < NUM_ADDR_BITS; j = j + 1)
120
    begin
121
      if (((address[NUM_ADDR_BITS - 1 : 0] >> j) & 1'b1) != 1'b0)
122
      begin
123
        stored_write_address[NUM_DATA_BITS - 1 : 0] = j;
124
        j = NUM_ADDR_BITS + 1;  // only remember the FIRST bit set
125
      end
126
    end
127
    if (j == NUM_ADDR_BITS)  // NO bit was set
128
    begin
129
      stored_write_address[NUM_DATA_BITS - 1 : 0] = NUM_ADDR_BITS;
130
    end
131
    write_counter[5:0] = (write_counter[5:0] + 6'h01) & 6'h1F;
132
  end
133
 
134
// Starting at the newest, search back to oldest to find if the word has been written
135
  reg    [NUM_DATA_BITS - 1 : 0] data_out;
136
  reg    [4:0] read_address;
137
 
138
  always @(read_enable)
139
  begin
140
    if ((read_enable !== 1'b1) | ((^address[NUM_DATA_BITS - 1 : 0]) === 1'bX))  // no read, return X's
141
    begin
142
      data_out[NUM_DATA_BITS - 1 : 0] = {NUM_DATA_BITS{1'bX}};
143
    end
144
    else
145
    begin
146
      if ((address[NUM_ADDR_BITS - 1 : 0] >> (NUM_ADDR_BITS - 8)) == 8'hAA)  // read magic location, return Address Bit Number
147
      begin
148
        data_out[NUM_DATA_BITS - 1 : 0] = stored_write_address[NUM_DATA_BITS - 1 : 0];
149
      end
150
      else  // otherwise search history to see if the word has been written recently
151
      begin
152
        k = write_counter[5:0];
153
        for (l = k + 6'h1F;  // half way around, same as last minus 1;
154
             l >= k;  // write address not valid
155
             l = l - 1)
156
        begin
157
          read_address[4:0] = l;
158
          if (address[NUM_ADDR_BITS - 1 : 0] === address_storage[read_address[4:0]])
159
          begin
160
            data_out[NUM_DATA_BITS - 1 : 0] = data_storage[read_address[4:0]];
161
            l = k - 2;
162
          end
163
        end
164
        if (l == (k - 1))  // didn't find it at all!
165
        begin
166
          data_out[NUM_DATA_BITS - 1 : 0] = {NUM_DATA_BITS{1'bX}};
167
        end
168
      end
169
    end
170
  end
171
 
172
// synopsys translate_off
173
  initial
174
  begin
175
    if (NUM_ADDR_BITS < 8)
176
    begin
177
      $display ("*** Exiting because %m sram_for_debugging_async Number of Address bits %d < 8",
178
                   NUM_ADDR_BITS);
179
      $finish;
180
    end
181
    if (NUM_DATA_BITS < 8)
182
    begin
183
      $display ("*** Exiting because %m sram_for_debugging_async Number of Data bits %d < 8",
184
                   NUM_DATA_BITS);
185
      $finish;
186
    end
187
  end
188
// synopsys translate_on
189
endmodule
190
 
191
`define TEST_SRAM
192
`ifdef TEST_SRAM
193
module test_sram;
194
  reg    [11:0] address;
195
  reg    [8:0] data_in;
196
  reg     read_enable, write_enable;
197
  wire   [8:0] data_out;
198
 
199
  integer i;
200
 
201
  initial
202
  begin
203
    read_enable = 1'b0;
204
    write_enable = 1'b0;
205
    for (i = 0; i < 12; i = i + 1)
206
    begin
207
      # 0;
208
      address[11:0] = (12'h001 << i);
209
      data_in[8:0] = i + 4;
210
      # 0; write_enable = 1'b1;
211
      # 0; write_enable = 1'b0;
212
      # 0;
213
      address[11:0] = 12'hAA0;
214
      # 0; read_enable = 1'b1;
215
      # 0;
216
      if (data_out[8:0] !== i)
217
        $display ("*** Debug SRAM read failed %x %x", i, data_out[8:0]);
218
      # 0; read_enable = 1'b0;
219
    end
220
 
221
    for (i = 0; i < 12; i = i + 1)
222
    begin
223
      # 0;
224
      address[11:0] = (12'h001 << i);
225
      # 0; read_enable = 1'b1;
226
      # 0;
227
      if (data_out[8:0] !== (i + 4))
228
        $display ("*** Debug SRAM read failed %x %x", i, data_out[8:0]);
229
      # 0; read_enable = 1'b0;
230
    end
231
 
232
    # 0;
233
    address[11:0] = 12'hXXX;
234
    # 0; read_enable = 1'b1;
235
    # 0;
236
    if (data_out[8:0] !== 9'hXXX)
237
      $display ("*** Debug SRAM read failed %x %x", i, data_out[8:0]);
238
    # 0; read_enable = 1'b0;
239
 
240
    # 0;
241
    address[11:0] = 12'h003;
242
    # 0; read_enable = 1'b1;
243
    # 0;
244
    if (data_out[8:0] !== 9'hXXX)
245
      $display ("*** Debug SRAM read failed %x %x", i, data_out[8:0]);
246
    # 0; read_enable = 1'b0;
247
 
248
    for (i = 0; i < 32; i = i + 1)
249
    begin
250
      # 0;
251
      address[11:0] = i;
252
      data_in[8:0] = i + 32;
253
      # 0; write_enable = 1'b1;
254
      # 0; write_enable = 1'b0;
255
    end
256
 
257
    for (i = 0; i < 32; i = i + 1)
258
    begin
259
      # 0;
260
      address[11:0] = i;
261
      # 0; read_enable = 1'b1;
262
      # 0;
263
      if (data_out[8:0] !== (i + 32))
264
        $display ("*** Debug SRAM read failed %x %x", i, data_out[8:0]);
265
      # 0; read_enable = 1'b0;
266
    end
267
 
268
  end
269
 
270
sram_for_debugging_async
271
#(12,  // NUM_ADDR_BITS
272
   9   // NUM_DATA_BITS
273
 ) test_this_one (
274
  .data_out                   (data_out[8:0]),
275
  .data_in                    (data_in[8:0]),
276
  .address                    (address[11:0]),
277
  .read_enable                (read_enable),
278
  .write_enable               (write_enable)
279
);
280
 
281
endmodule
282
`endif  // TEST_SRAM
283
 

powered by: WebSVN 2.1.0

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