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

Subversion Repositories bluespec-h264

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 jamey.hick
 
2 83 jamey.hick
// 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
 
25 3 jamey.hick
package mkSRAMMemController;
26
 
27
import MemControllerTypes::*;
28
import IMemClient::*;
29
import IMemClientBackend::*;
30
import IMemController::*;
31
import IMemScheduler::*;
32
import mkMemClient::*;
33
import SRAM::*;
34
import BlueSRAM::*;
35
import BlueBRAM::*;
36
import FIFOF::*;
37
import FIFO::*;
38
import Vector::*;
39
import ISRAMWires::*;
40
 
41
`define FIFO_SIZE 4
42
 
43
interface ISRAMMemController#(type client_number, type address_type, type data_type);
44
  interface Vector#(client_number, IMemClient#(address_type, data_type)) client_interfaces;
45
  interface ISRAMWires wires;
46
endinterface
47
 
48
 
49
module mkSRAMMemController#(IMemScheduler#(client_number, address_type) scheduler) (ISRAMMemController#(client_number, address_type, data_type))
50
    provisos
51
          (Bits#(address_type, addr_p),
52
           Bits#(data_type, data_p),
53
           Add#(addr_p, xxx, 18),
54
           Add#(data_p, yyy, 32),
55
           Bitwise#(address_type),
56
           Bitwise#(data_type),
57
           Bits#(MemReq#(address_type, data_type), mem_req_p),
58
           Literal#(address_type),
59
           Literal#(data_type),
60
           Eq#(data_type),
61
           Bounded#(address_type)
62
          );
63
 
64
  BlueSRAM#(address_type, data_type) sram <- mkBlueSRAM_Full();
65
  BlueBRAM#(address_type, data_type) bram <- mkBlueBRAM_Full();
66
 
67
  Vector#(client_number, IMemClientBackend#(address_type, data_type)) client_backends = newVector();
68
 
69
  Vector#(client_number, IMemClient#(address_type, data_type)) mem_clients = newVector();
70
 
71
  FIFO#(Bit#((TAdd#(1,TLog#(client_number))))) client_tags_fifo <- mkSizedFIFO(`FIFO_SIZE);
72
 
73
  for (Integer i = 0; i < valueof(client_number); i = i+1)
74
    begin
75
      client_backends[i] <- mkMemClient(i);
76
      mem_clients[i] = client_backends[i].client_interface;
77
    end
78
 
79
  rule send_request;
80
 
81
    Vector#(client_number, MemReqType#(address_type)) req_vec = newVector();
82
    //make a vector of the appropriate data
83
    for(int index = 0; index < fromInteger(valueof(client_number)); index = index + 1)
84
      begin
85
        if(client_backends[index].request_fifo.notEmpty())
86
          begin
87
            req_vec[index] = case(client_backends[index].request_fifo.first()) matches
88
                           tagged StoreReq .sreq: return MemReqType{ prio: client_backends[index].get_priority(),
89
                                                                              req: tagged StoreReq sreq.addr};
90
                           tagged LoadReq .lreq : return MemReqType{ prio: client_backends[index].get_priority(),
91
                                                                      req:  tagged LoadReq lreq.addr};
92
                         endcase;
93
          end
94
        else
95
          begin
96
            req_vec[index] = MemReqType{ prio:client_backends[index].get_priority(), req: tagged Nop};
97
          end
98
      end
99
 
100
 
101
  Maybe#(Bit#(TAdd#(1, TLog#(client_number)))) scheduling_result <- scheduler.choose_client(req_vec);
102
 
103
 
104
 
105
  // Throw request to SRAM
106
  if(scheduling_result matches tagged Valid .v)
107
    begin
108
      case (client_backends[v].request_fifo.first()) matches
109
        tagged StoreReq .sreq:
110
          begin
111
            $display("SRAMMemController: Write request, addr: %x data: %x, from client %d", sreq.addr, sreq.data, v);
112
            bram.write(sreq.addr, sreq.data);
113
          end
114
        tagged LoadReq .lreq:
115
          begin
116
            bram.read_req(lreq.addr);
117
            client_tags_fifo.enq(v);
118
            $display("SRAMMemController: Read request, addr: %x , from client %d", lreq.addr, v);
119
          end
120
      endcase
121
      client_backends[v].request_fifo.deq();
122
    end
123
 
124
  endrule
125
 
126
  // read response and shove it into the appropriate buffer.
127
  rule read_sram_response;
128
    Bit#((TAdd#(1, TLog#(client_number)))) target_client = client_tags_fifo.first();
129
    data_type read_result <- bram.read_resp();
130
    client_backends[target_client].enqueue_response(read_result);
131
    client_tags_fifo.deq();
132
    $display("SRAMMemController: Read response, data: %x , to client %d", read_result, target_client);
133
  endrule
134
 
135
 
136
 
137
  interface client_interfaces = mem_clients;
138
 
139
  interface ISRAMWires wires;
140
    method Bit#(18) address_out();
141
      return sram.address_out();
142
    endmethod
143
 
144
    method Bit#(32) data_O();
145
      return sram.data_out();
146
    endmethod
147
 
148
    method Action data_I(Bit#(32) data);
149
      sram.data_in(data);
150
    endmethod
151
 
152
    method Bit#(1) data_T();
153
      return sram.data_tri();
154
    endmethod
155
 
156
    method Bit#(4) we_bytes_out();
157
      return sram.we_bytes_out();
158
    endmethod
159
 
160
    method Bit#(1) we_out();
161
      return sram.we_out();
162
    endmethod
163
 
164
    method Bit#(1) ce_out();
165
      return sram.ce_out();
166
    endmethod
167
 
168
    method Bit#(1) oe_out();
169
      return sram.oe_out();
170
    endmethod
171
 
172
    method Bit#(1) cen_out();
173
      return sram.cen_out();
174
    endmethod
175
 
176
    method Bit#(1) adv_ld_out();
177
      return sram.adv_ld_out();
178
    endmethod
179
  endinterface
180
 
181
 
182
endmodule
183
endpackage

powered by: WebSVN 2.1.0

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