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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [lib/] [bsv/] [BRAM/] [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
 
28
//One RAM.
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
//Two RAMs.
41
interface BRAM_2#(type idx_type, type data_type);
42
 
43
  method Action read_req1(idx_type idx);
44
  method Action read_req2(idx_type idx);
45
 
46
  method ActionValue#(data_type) read_resp1();
47
  method ActionValue#(data_type) read_resp2();
48
 
49
  method Action write(idx_type idx, data_type data);
50
 
51
endinterface
52
 
53
//Three RAMs.
54
interface BRAM_3#(type idx_type, type data_type);
55
 
56
  method Action read_req1(idx_type idx);
57
  method Action read_req2(idx_type idx);
58
  method Action read_req3(idx_type idx);
59
 
60
  method ActionValue#(data_type) read_resp1();
61
  method ActionValue#(data_type) read_resp2();
62
  method ActionValue#(data_type) read_resp3();
63
 
64
  method Action write(idx_type idx, data_type data);
65
 
66
endinterface
67
 
68
 
69
module mkBRAM#(Integer low, Integer high)
70
  //interface:
71
              (BRAM#(idx_type, data_type))
72
  provisos
73
          (Bits#(idx_type, idx),
74
           Bits#(data_type, data),
75
           Literal#(idx_type));
76
 
77
  BRAM#(idx_type, data_type) m <- (valueof(data) == 0) ?
78
                                  mkBRAM_Zero() :
79
                                  mkBRAM_NonZero(low, high);
80
 
81
  return m;
82
endmodule
83
 
84
import "BVI" BRAM = module mkBRAM_NonZero#(Integer low, Integer high)
85
  //interface:
86
              (BRAM#(idx_type, data_type))
87
  provisos
88
          (Bits#(idx_type, idx),
89
           Bits#(data_type, data),
90
           Literal#(idx_type));
91
 
92
  default_clock clk(CLK);
93
 
94
  parameter addr_width = valueof(idx);
95
  parameter data_width = valueof(data);
96
  parameter lo = low;
97
  parameter hi = high;
98
 
99
  method DOUT read_resp() ready(DOUT_RDY) enable(DOUT_EN);
100
 
101
  method read_req(RD_ADDR) ready(RD_RDY) enable(RD_EN);
102
  method write(WR_ADDR, WR_VAL) enable(WR_EN);
103
 
104
  schedule read_req  CF (read_resp, write);
105
  schedule read_resp CF (read_req, write);
106
  schedule write     CF (read_req, read_resp);
107
 
108
  schedule read_req  C read_req;
109
  schedule read_resp C read_resp;
110
  schedule write     C write;
111
 
112
endmodule
113
 
114
module mkBRAM_Zero
115
  //interface:
116
              (BRAM#(idx_type, data_type))
117
  provisos
118
          (Bits#(idx_type, idx),
119
           Bits#(data_type, data),
120
           Literal#(idx_type));
121
 
122
  FIFO#(data_type) q <- mkLFIFO();
123
 
124
  method Action read_req(idx_type i);
125
     q.enq(?);
126
  endmethod
127
 
128
  method Action write(idx_type i, data_type d);
129
    noAction;
130
  endmethod
131
 
132
  method ActionValue#(data_type) read_resp();
133
    q.deq();
134
    return q.first();
135
  endmethod
136
 
137
endmodule
138
 
139
module mkBRAM_Full
140
  //interface:
141
              (BRAM#(idx_type, data_type))
142
  provisos
143
          (Bits#(idx_type, idx),
144
           Bits#(data_type, data),
145
           Literal#(idx_type));
146
 
147
 
148
  BRAM#(idx_type, data_type) br <- mkBRAM(0, valueof(TExp#(idx)) - 1);
149
 
150
  return br;
151
 
152
endmodule
153
module mkBRAM_2#(Integer low, Integer high)
154
  //interface:
155
              (BRAM_2#(idx_type, data_type))
156
  provisos
157
          (Bits#(idx_type, idx),
158
           Bits#(data_type, data),
159
           Literal#(idx_type));
160
 
161
  BRAM#(idx_type, data_type) br1 <- mkBRAM(low, high);
162
  BRAM#(idx_type, data_type) br2 <- mkBRAM(low, high);
163
 
164
  method read_req1(idx) = br1.read_req(idx);
165
  method read_req2(idx) = br2.read_req(idx);
166
 
167
  method read_resp1() = br1.read_resp();
168
  method read_resp2() = br2.read_resp();
169
 
170
  method Action write(idx_type idx, data_type data);
171
 
172
    br1.write(idx, data);
173
    br2.write(idx, data);
174
 
175
  endmethod
176
 
177
endmodule
178
 
179
module mkBRAM_2_Full
180
  //interface:
181
              (BRAM_2#(idx_type, data_type))
182
  provisos
183
          (Bits#(idx_type, idx),
184
           Bits#(data_type, data),
185
           Literal#(idx_type));
186
 
187
 
188
  BRAM_2#(idx_type, data_type) br <- mkBRAM_2(0, valueof(TExp#(idx)) - 1);
189
 
190
  return br;
191
 
192
endmodule
193
 
194
module mkBRAM_3#(Integer low, Integer high)
195
  //interface:
196
              (BRAM_3#(idx_type, data_type))
197
  provisos
198
          (Bits#(idx_type, idx),
199
           Bits#(data_type, data),
200
           Literal#(idx_type));
201
 
202
  BRAM#(idx_type, data_type) br1 <- mkBRAM(low, high);
203
  BRAM#(idx_type, data_type) br2 <- mkBRAM(low, high);
204
  BRAM#(idx_type, data_type) br3 <- mkBRAM(low, high);
205
 
206
  method read_req1(idx) = br1.read_req(idx);
207
  method read_req2(idx) = br2.read_req(idx);
208
  method read_req3(idx) = br3.read_req(idx);
209
 
210
  method read_resp1() = br1.read_resp();
211
  method read_resp2() = br2.read_resp();
212
  method read_resp3() = br3.read_resp();
213
 
214
  method Action write(idx_type idx, data_type data);
215
 
216
    br1.write(idx, data);
217
    br2.write(idx, data);
218
    br3.write(idx, data);
219
 
220
  endmethod
221
 
222
endmodule
223
 
224
 
225
module mkBRAM_3_Full
226
  //interface:
227
              (BRAM_3#(idx_type, data_type))
228
  provisos
229
          (Bits#(idx_type, idx),
230
           Bits#(data_type, data),
231
           Literal#(idx_type));
232
 
233
 
234
  BRAM_3#(idx_type, data_type) br <- mkBRAM_3(0, valueof(TExp#(idx)) - 1);
235
 
236
  return br;
237
 
238
endmodule

powered by: WebSVN 2.1.0

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