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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [memocodeDesignContest2008/] [sort/] [BRAM_v/] [BRAM.bsv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kfleming
//----------------------------------------------------------------------//
2
// The MIT License
3
//
4
// Copyright (c) 2008 Alfred Man Cheuk Ng, mcn02@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
 
27
// import standard library
28
import FIFOF::*;
29
import RWire::*;
30
 
31
//////////////////////////////////////////////////////////////////////////
32
// unguarded bram interface
33
 
34
interface UGBRAM#(type idx_type, type data_type);
35
  (* always_ready *) method Action    read_req(idx_type idx);
36
                     method data_type read_resp();
37
  (* always_ready *) method Action    write(idx_type idx, data_type data);
38
endinterface
39
 
40
//////////////////////////////////////////////////////////////////////////
41
// guarded bram interface
42
 
43
interface BRAM#(type idx_type, type data_type);
44
  method Action                  read_req(idx_type idx);
45
  method ActionValue#(data_type) read_resp();
46
  method Action                  write(idx_type idx, data_type data);
47
endinterface
48
 
49
 
50
//////////////////////////////////////////////////////////////////////////
51
// unguarded bram implementations
52
 
53
// the ugbram verilog suggest a bypass one already
54
import "BVI" UGBRAM = module mkUGBRAM#(Integer low, Integer high)
55
                         (UGBRAM#(idx_type, data_type))
56
    provisos
57
            (Bits#(idx_type, idx),
58
             Bits#(data_type, data),
59
             Literal#(idx_type));
60
 
61
    default_clock clk(CLK);
62
    default_reset rst(RST_N);
63
 
64
    parameter addr_width = valueOf(idx);
65
    parameter data_width = valueOf(data);
66
    parameter lo = low;
67
    parameter hi = high;
68
 
69
    method read_req(READ_A_ADDR) enable(READ_A_ADDR_EN);
70
    method READ_A_DATA read_resp() ready(READ_A_DATA_RDY);
71
    method write(WRITE_B_ADDR, WRITE_B_DATA) enable(WRITE_B_EN);
72
 
73
    schedule read_req CF (read_resp, write);
74
    schedule read_req C read_req;
75
    schedule read_resp CF (read_req, write);
76
    schedule read_resp CF read_resp;
77
    schedule write CF (read_req, read_resp);
78
    schedule write C write;
79
 
80
endmodule
81
 
82
module mkUGBRAM_Full(UGBRAM#(idx_type, data_type))
83
    provisos
84
            (Bits#(idx_type, idx),
85
             Bits#(data_type, data),
86
             Literal#(idx_type));
87
 
88
    UGBRAM#(idx_type, data_type) bram <- mkUGBRAM(0, valueOf(TExp#(idx)) - 1);
89
    return bram;
90
endmodule
91
 
92
// bypassUGBRAM = if write req and read req to the same addr, read the new data
93
module mkBypassUGBRAM_Full
94
  //interface:
95
              (UGBRAM#(idx_type, data_type))
96
  provisos
97
          (Bits#(idx_type, idx),
98
           Bits#(data_type, data),
99
           Literal#(idx_type),
100
           Eq#(idx_type));
101
 
102
   UGBRAM#(idx_type, data_type) bram <- mkUGBRAM(0, valueOf(TExp#(idx)) - 1);
103
   return bram;
104
 
105
//    Reg#(Maybe#(data_type))       resp    <- mkReg(tagged Invalid);
106
//    UGBRAM#(idx_type, data_type)  br      <- mkUGBRAM_Full;
107
//    RWire#(idx_type)              wr_addr <- mkRWire;
108
//    RWire#(data_type)             wr_data <- mkRWire;
109
//    RWire#(idx_type)              rd_addr <- mkRWire;
110
 
111
//    rule checkBypass(True);
112
//       if (isValid(wr_addr.wget) &&
113
//           isValid(rd_addr.wget) &&
114
//           fromMaybe(?,wr_addr.wget) == fromMaybe(?,rd_addr.wget))
115
//          resp <= wr_data.wget;
116
//       else
117
//          resp <= tagged Invalid;
118
 
119
//       $display("%m checkBypass write_en: %d, write_addr: %d, write_data: %d, read_en: %d, read_addr: %d, bypass: %d",
120
//                isValid(wr_addr.wget), fromMaybe(?,wr_addr.wget), wr_data.wget,
121
//                isValid(rd_addr.wget), fromMaybe(?,rd_addr.wget),
122
//                fromMaybe(?,wr_addr.wget) == fromMaybe(?,rd_addr.wget));
123
 
124
//    endrule
125
 
126
//    rule checkReadResp(True);
127
//       let br_resp = br.read_resp;
128
//       let res = fromMaybe(br_resp,resp);
129
//       $display("%m bram resp: %d, resp: %d, actual resp: %d",br_resp,resp,res);
130
//    endrule
131
 
132
//    method Action read_req(idx_type idx);
133
//       br.read_req(idx);
134
//       rd_addr.wset(idx);
135
//    endmethod
136
 
137
//    method data_type read_resp();
138
//       let br_resp = br.read_resp;
139
//       let res = fromMaybe(br_resp,resp);
140
//       return res;
141
//    endmethod
142
 
143
//    method Action write(idx_type idx, data_type data);
144
//       br.write(idx,data);
145
//       wr_addr.wset(idx);
146
//       wr_data.wset(data);
147
//    endmethod
148
 
149
endmodule
150
 
151
//////////////////////////////////////////////////////////////////////////
152
// guarded bram implementations
153
 
154
// there is no point to make bypassBRAM if it is guarded because
155
// the BRAM is assumed to have unknown latency
156
module mkBRAM#(Integer low, Integer high)
157
   (BRAM#(idx_type,data_type))
158
   provisos (Bits#(idx_type, idx),
159
             Bits#(data_type, data),
160
             Literal#(idx_type));
161
 
162
   UGBRAM#(idx_type,data_type) ugbram <- mkUGBRAM(low,high);
163
   FIFOF#(data_type)            rdataQ <- mkSizedFIFOF(2);
164
 
165
   rule getResp(True);
166
      let resp = ugbram.read_resp;
167
      rdataQ.enq(resp);
168
   endrule
169
 
170
   method Action read_req(idx_type addr) if (rdataQ.notFull);
171
      ugbram.read_req(addr);
172
   endmethod
173
 
174
   method ActionValue#(data_type) read_resp();
175
      rdataQ.deq;
176
      return rdataQ.first;
177
   endmethod
178
 
179
   method Action write(idx_type addr, data_type data);
180
      ugbram.write(addr,data);
181
   endmethod
182
 
183
endmodule
184
 
185
 

powered by: WebSVN 2.1.0

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