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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [lib/] [bsv/] [BRAM/] [blue_sim_model/] [BRAM.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 kfleming
//----------------------------------------------------------------------//
2
// The MIT License
3
//
4
// Copyright (c) 2008 Kermin Fleming, kfleming@mit.edu
5
//
6
// Permission is hereby granted, free of charge, to any person
7
// obtaining a copy of this software and associated documentation
8
// files (the "Software"), to deal in the Software without
9
// restriction, including without limitation the rights to use,
10
// copy, modify, merge, publish, distribute, sublicense, and/or sell
11
// copies of the Software, and to permit persons to whom the
12
// Software is furnished to do so, subject to the following conditions:
13
//
14
// The above copyright notice and this permission notice shall be
15
// included in all copies or substantial portions of the Software.
16
//
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//----------------------------------------------------------------------//
26
import FIFO::*;
27
import RegFile::*;
28
 
29
interface BRAM#(type idx_type, type data_type);
30
 
31
  method Action read_req(idx_type idx);
32
 
33
  method ActionValue#(data_type) read_resp();
34
 
35
  method Action write(idx_type idx, data_type data);
36
 
37
endinterface
38
 
39
 
40
module mkBRAM#(Integer low, Integer high)
41
  //interface:
42
              (BRAM#(idx_type, data_type))
43
  provisos
44
          (Bits#(idx_type, idx),
45
           Bits#(data_type, data),
46
           Literal#(idx_type),
47
           Bounded#(idx_type));
48
 
49
  BRAM#(idx_type, data_type) m <- (valueof(data) == 0) ?
50
                                  mkBRAM_Zero() :
51
                                  mkBRAM_NonZero(low, high);
52
 
53
  return m;
54
endmodule
55
 
56
module mkBRAM_NonZero#(Integer low, Integer high)
57
  //interface:
58
              (BRAM#(idx_type, data_type))
59
  provisos
60
          (Bits#(idx_type, idx),
61
           Bits#(data_type, data),
62
           Literal#(idx_type),
63
           Bounded#(idx_type));
64
  RegFile#(idx_type, data_type) arr <- mkRegFileFull();
65
  FIFO#(data_type) outfifo <- mkSizedFIFO(8);
66
 
67
  method Action read_req(idx_type idx);
68
    outfifo.enq(arr.sub(idx));
69
  endmethod
70
 
71
  method ActionValue#(data_type) read_resp();
72
    outfifo.deq();
73
    return outfifo.first();
74
  endmethod
75
 
76
  method Action write(idx_type idx, data_type data);
77
    arr.upd(idx, data);
78
  endmethod
79
endmodule
80
 
81
module mkBRAM_Zero
82
  //interface:
83
              (BRAM#(idx_type, data_type))
84
  provisos
85
          (Bits#(idx_type, idx),
86
           Bits#(data_type, data),
87
           Literal#(idx_type));
88
 
89
  FIFO#(data_type) q <- mkSizedFIFO(8);
90
 
91
  method Action read_req(idx_type i);
92
     q.enq(?);
93
  endmethod
94
 
95
  method Action write(idx_type i, data_type d);
96
    noAction;
97
  endmethod
98
 
99
  method ActionValue#(data_type) read_resp();
100
    q.deq();
101
    return q.first();
102
  endmethod
103
 
104
endmodule
105
 
106
module mkBRAM_Full
107
  //interface:
108
              (BRAM#(idx_type, data_type))
109
  provisos
110
          (Bits#(idx_type, idx),
111
           Bits#(data_type, data),
112
           Literal#(idx_type),
113
           Bounded#(idx_type));
114
 
115
 
116
  BRAM#(idx_type, data_type) br <- mkBRAM(0, valueof(TExp#(idx)) - 1);
117
 
118
  return br;
119
 
120
endmodule

powered by: WebSVN 2.1.0

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