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

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [src_fpga/] [mkPriorityRoundRobinMemScheduler.bsv] - Blame information for rev 83

Go to most recent revision | 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
//This is a simple round robin memory scheduler.  It's kind of bad because it's a CAM, but hey, don't have so many clients
25
 
26
package mkPriorityRoundRobinMemScheduler;
27
 
28
 
29
import MemControllerTypes::*;
30
import IMemScheduler::*;
31
import Vector::*;
32
 
33
module mkPriorityRoundRobinMemScheduler  (IMemScheduler#(number_clients, address_type))
34
      provisos
35
          (Bits#(address_type, addr_p),
36
           Eq#(address_type),
37
           Bits#(MemReqType#(address_type), mem_req_type_p),
38
           Eq#(MemReqType#(address_type))
39
           );
40
  Reg#(Bit#((TAdd#(1, TLog#(number_clients))))) first_index <- mkReg(0);
41
 
42
  function Bit#(TAdd#(1, TLog#(number_clients))) next_index ( Bit#(TAdd#(1, TLog#(number_clients))) curr_index );
43
   next_index = (curr_index < fromInteger(valueof(number_clients) - 1)) ? (curr_index + 1):(0);
44
  endfunction: next_index
45
 
46
  function Bit#(TAdd#(1, TLog#(number_clients))) prev_index ( Bit#(TAdd#(1, TLog#(number_clients))) curr_index );
47
   prev_index = (curr_index > 0) ? (curr_index - 1):(fromInteger(valueof(number_clients) - 1));
48
  endfunction: prev_index
49
 
50
  method ActionValue#(Maybe#(Bit#(TAdd#(1, TLog#(number_clients))))) choose_client(Vector#(number_clients, MemReqType#(address_type)) req_vec);
51
    Maybe#(Bit#(TAdd#(1,(TLog#(number_clients))))) target_index = tagged Invalid;
52
    PRIORITY_LEVEL prio = 0; //The lowest priority
53
 
54
    // Loop through command indicies backwards... this enables us to get the highest priority
55
    // command.
56
    for(Bit#((TAdd#(1, TLog#(number_clients)))) curr_index = prev_index(first_index), int count = 0;
57
        count < fromInteger(valueof(number_clients));
58
        curr_index = prev_index(curr_index), count = count + 1)
59
      begin
60
        if(req_vec[curr_index].req != tagged Nop)
61
          begin
62
            if(target_index matches tagged Valid .op )
63
              begin
64
                if(req_vec[curr_index].prio >= prio)
65
                  begin
66
                    target_index = tagged Valid curr_index;
67
                    prio = req_vec[curr_index].prio;
68
                  end
69
              end
70
            else
71
              begin
72
                target_index = tagged Valid curr_index;
73
                prio = req_vec[curr_index].prio;
74
              end
75
          end
76
      end
77
    // set the next "high priority" index.
78
    if(target_index matches tagged Valid .v)
79
      begin
80
        first_index <= next_index(v);
81
      end
82
    return target_index;
83
  endmethod
84
endmodule
85
 
86
endpackage

powered by: WebSVN 2.1.0

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