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

Subversion Repositories srdydrdy_lib

[/] [srdydrdy_lib/] [trunk/] [rtl/] [verilog/] [forks/] [sd_rrmux.v] - Blame information for rev 29

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

Line No. Rev Author Line
1 7 ghutchis
//----------------------------------------------------------------------
2 20 ghutchis
// Srdy/drdy round-robin arbiter
3 7 ghutchis
//
4 20 ghutchis
// Asserts drdy for an input and then moves to the next input.
5 7 ghutchis
//
6
// This component supports multiple round-robin modes:
7
//
8
// Mode 0 : Each input gets a single cycle, regardless of data
9
//          availability.  This mode functions like a TDM
10
//          demultiplexer.  Output flow control will cause the
11
//          component to stall, so that inputs do not miss their
12
//          turn due to flow control.
13
// Mode 1 : Each input can transmit for as long as it has data.
14
//          When input deasserts, device will begin to hunt for a
15
//          new input with data.
16
// Mode 2 : Continue to accept input until the incoming data
17 24 ghutchis
//          matches a particular "end pattern".  The end pattern
18
//          is provided on the c_rearb (re-arbitrate) input.  When
19
//          c_rearb is high, will hunt for new inputs on next clock.
20 7 ghutchis
//
21 20 ghutchis
// This component also supports two arbitration modes: slow and fast.
22
// slow rotates the grant from requestor to requestor cycle by cycle,
23
// so each requestor gets serviced at most once every #inputs cycles.
24
// This can be useful for producing a TDM-type interface, however
25
// requestors may be delayed waiting for the grant to come around even
26
// if there are no other requestors.
27
//
28
// Fast mode immediately grants the highest-priority requestor, however
29
// it is drdy-noncompliant (drdy will not be asserted until srdy is
30
// asserted).
31
//
32 7 ghutchis
// Naming convention: c = consumer, p = producer, i = internal interface
33
//----------------------------------------------------------------------
34
//  Author: Guy Hutchison
35
//
36
// This block is uncopyrighted and released into the public domain.
37
//----------------------------------------------------------------------
38
 
39
// Clocking statement for synchronous blocks.  Default is for
40
// posedge clocking and positive async reset
41
`ifndef SDLIB_CLOCKING
42
 `define SDLIB_CLOCKING posedge clk or posedge reset
43
`endif
44
 
45
// delay unit for nonblocking assigns, default is to #1
46
`ifndef SDLIB_DELAY
47
 `define SDLIB_DELAY #1
48
`endif
49
 
50 20 ghutchis
module sd_rrmux
51 7 ghutchis
  #(parameter width=8,
52
    parameter inputs=2,
53 29 ghutchis
    parameter inputs_asz=1,  // log2(inputs)
54 7 ghutchis
    parameter mode=0,
55 20 ghutchis
    parameter fast_arb=0)
56 7 ghutchis
  (
57
   input               clk,
58
   input               reset,
59
 
60
   input [(width*inputs)-1:0] c_data,
61
   input [inputs-1:0]      c_srdy,
62
   output  [inputs-1:0]    c_drdy,
63 24 ghutchis
   input                   c_rearb,  // for use with mode 2 only
64 7 ghutchis
 
65
   output reg [width-1:0]  p_data,
66 18 ghutchis
   output [inputs-1:0]     p_grant,
67 7 ghutchis
   output reg              p_srdy,
68
   input                   p_drdy
69
   );
70
 
71
  reg [inputs-1:0]    rr_state;
72
  reg [inputs-1:0]    nxt_rr_state;
73
 
74
  wire [width-1:0]     rr_mux_grid [0:inputs-1];
75 10 ghutchis
  reg                  rr_locked;
76 7 ghutchis
  genvar               i;
77
  integer              j;
78
 
79
  assign c_drdy = rr_state & {inputs{p_drdy}};
80 18 ghutchis
  assign p_grant = rr_state;
81 20 ghutchis
 
82
  function [inputs-1:0] nxt_grant;
83
    input [inputs-1:0] cur_grant;
84
    input [inputs-1:0] cur_req;
85
    reg [inputs-1:0]   msk_req;
86
    reg [inputs-1:0]   tmp_grant;
87
    begin
88
      msk_req = cur_req & ~((cur_grant - 1) | cur_grant);
89
      tmp_grant = msk_req & (~msk_req + 1);
90
 
91
      if (msk_req != 0)
92
        nxt_grant = tmp_grant;
93
      else
94
        nxt_grant = cur_req & (~cur_req + 1);
95
    end
96
  endfunction
97 7 ghutchis
 
98
  generate
99
    for (i=0; i<inputs; i=i+1)
100
      begin : grid_assign
101
        assign rr_mux_grid[i] = c_data >> (i*width);
102
      end
103
 
104
    if (mode == 2)
105
      begin : tp_gen
106 10 ghutchis
        reg nxt_rr_locked;
107 29 ghutchis
        reg selected_srdy;
108 7 ghutchis
 
109
        always @*
110
          begin
111 29 ghutchis
            if (c_rearb)
112
              nxt_rr_locked = 0;
113
            else if ((nxt_rr_state != rr_state) && (nxt_rr_state != 0))
114 7 ghutchis
              nxt_rr_locked = 1;
115 29 ghutchis
            else
116
              nxt_rr_locked = rr_locked;
117 7 ghutchis
          end
118
 
119
        always @(`SDLIB_CLOCKING)
120
          begin
121
            if (reset)
122
              rr_locked <= `SDLIB_DELAY 0;
123
            else
124
              rr_locked <= `SDLIB_DELAY nxt_rr_locked;
125
          end
126
      end // block: tp_gen
127
  endgenerate
128
 
129
  always @*
130
    begin
131
      p_data = 0;
132
      p_srdy = 0;
133
      for (j=0; j<inputs; j=j+1)
134
        if (rr_state[j])
135
          begin
136
            p_data = rr_mux_grid[j];
137
            p_srdy = c_srdy[j];
138
          end
139
    end
140
 
141
  always @*
142
    begin
143
      if ((mode ==  1) & (c_srdy & rr_state))
144
        nxt_rr_state = rr_state;
145
      else if ((mode == 0) & !p_drdy)
146
        nxt_rr_state = rr_state;
147 10 ghutchis
      else if ((mode == 2) & (rr_locked | (c_srdy & rr_state)))
148 7 ghutchis
        nxt_rr_state = rr_state;
149 20 ghutchis
      else if (fast_arb)
150
        nxt_rr_state = nxt_grant (rr_state, c_srdy);
151 7 ghutchis
      else
152
        nxt_rr_state = { rr_state[0], rr_state[inputs-1:1] };
153
    end
154
 
155
  always @(`SDLIB_CLOCKING)
156
    begin
157
      if (reset)
158
        rr_state <= `SDLIB_DELAY 1;
159
      else
160
        rr_state <= `SDLIB_DELAY nxt_rr_state;
161
    end
162
 
163
endmodule // sd_rrmux

powered by: WebSVN 2.1.0

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