OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [BlueBRAM.bsv] - Blame information for rev 100

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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