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 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 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
2
 
3
package mkPriorityRoundRobinMemScheduler;
4
 
5
 
6
import MemControllerTypes::*;
7
import IMemScheduler::*;
8
import Vector::*;
9
 
10
module mkPriorityRoundRobinMemScheduler  (IMemScheduler#(number_clients, address_type))
11
      provisos
12
          (Bits#(address_type, addr_p),
13
           Eq#(address_type),
14
           Bits#(MemReqType#(address_type), mem_req_type_p),
15
           Eq#(MemReqType#(address_type))
16
           );
17
  Reg#(Bit#((TAdd#(1, TLog#(number_clients))))) first_index <- mkReg(0);
18
 
19
  function Bit#(TAdd#(1, TLog#(number_clients))) next_index ( Bit#(TAdd#(1, TLog#(number_clients))) curr_index );
20
   next_index = (curr_index < fromInteger(valueof(number_clients) - 1)) ? (curr_index + 1):(0);
21
  endfunction: next_index
22
 
23
  function Bit#(TAdd#(1, TLog#(number_clients))) prev_index ( Bit#(TAdd#(1, TLog#(number_clients))) curr_index );
24
   prev_index = (curr_index > 0) ? (curr_index - 1):(fromInteger(valueof(number_clients) - 1));
25
  endfunction: prev_index
26
 
27
  method ActionValue#(Maybe#(Bit#(TAdd#(1, TLog#(number_clients))))) choose_client(Vector#(number_clients, MemReqType#(address_type)) req_vec);
28
    Maybe#(Bit#(TAdd#(1,(TLog#(number_clients))))) target_index = tagged Invalid;
29
    PRIORITY_LEVEL prio = 0; //The lowest priority
30
 
31
    // Loop through command indicies backwards... this enables us to get the highest priority
32
    // command.
33
    for(Bit#((TAdd#(1, TLog#(number_clients)))) curr_index = prev_index(first_index), int count = 0;
34
        count < fromInteger(valueof(number_clients));
35
        curr_index = prev_index(curr_index), count = count + 1)
36
      begin
37
        if(req_vec[curr_index].req != tagged Nop)
38
          begin
39
            if(target_index matches tagged Valid .op )
40
              begin
41
                if(req_vec[curr_index].prio >= prio)
42
                  begin
43
                    target_index = tagged Valid curr_index;
44
                    prio = req_vec[curr_index].prio;
45
                  end
46
              end
47
            else
48
              begin
49
                target_index = tagged Valid curr_index;
50
                prio = req_vec[curr_index].prio;
51
              end
52
          end
53
      end
54
    // set the next "high priority" index.
55
    if(target_index matches tagged Valid .v)
56
      begin
57
        first_index <= next_index(v);
58
      end
59
    return target_index;
60
  endmethod
61
endmodule
62
 
63
endpackage

powered by: WebSVN 2.1.0

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