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 21

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
//          matches a particular "end pattern".  The trigger pattern
18
//          is when (c_data & eod_mask) == eod_pattern.  Once
19
//          trigger pattern is seen, begin hunting for new input.
20
//
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
    parameter mode=0,
54
    parameter eod_pattern=0,
55 20 ghutchis
    parameter eod_mask=0,
56
    parameter fast_arb=0)
57 7 ghutchis
  (
58
   input               clk,
59
   input               reset,
60
 
61
   input [(width*inputs)-1:0] c_data,
62
   input [inputs-1:0]      c_srdy,
63
   output  [inputs-1:0]    c_drdy,
64
 
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
  reg [$clog2(inputs)-1:0] data_ind;
75
 
76
  wire [width-1:0]     rr_mux_grid [0:inputs-1];
77 10 ghutchis
  reg                  rr_locked;
78 7 ghutchis
  genvar               i;
79
  integer              j;
80
  wire                 trig_pattern;
81
 
82
  assign c_drdy = rr_state & {inputs{p_drdy}};
83 18 ghutchis
  assign p_grant = rr_state;
84 20 ghutchis
 
85
  function [inputs-1:0] nxt_grant;
86
    input [inputs-1:0] cur_grant;
87
    input [inputs-1:0] cur_req;
88
    reg [inputs-1:0]   msk_req;
89
    reg [inputs-1:0]   tmp_grant;
90
    begin
91
      msk_req = cur_req & ~((cur_grant - 1) | cur_grant);
92
      tmp_grant = msk_req & (~msk_req + 1);
93
 
94
      if (msk_req != 0)
95
        nxt_grant = tmp_grant;
96
      else
97
        nxt_grant = cur_req & (~cur_req + 1);
98
    end
99
  endfunction
100 7 ghutchis
 
101
  generate
102
    for (i=0; i<inputs; i=i+1)
103
      begin : grid_assign
104
        assign rr_mux_grid[i] = c_data >> (i*width);
105
      end
106
 
107
    if (mode == 2)
108
      begin : tp_gen
109 10 ghutchis
        reg nxt_rr_locked;
110 7 ghutchis
 
111
        assign trig_pattern = (rr_mux_grid[data_ind] & eod_mask) == eod_pattern;
112
        always @*
113
          begin
114
            data_ind = 0;
115
            for (j=0; j<inputs; j=j+1)
116
              if (rr_state[j])
117
                data_ind = j;
118
 
119
            nxt_rr_locked = rr_locked;
120
 
121
            if ((c_srdy & rr_state) & (!rr_locked))
122
              nxt_rr_locked = 1;
123
            else if ((c_srdy & rr_state) & p_drdy & trig_pattern )
124
              nxt_rr_locked = 0;
125
          end
126
 
127
        always @(`SDLIB_CLOCKING)
128
          begin
129
            if (reset)
130
              rr_locked <= `SDLIB_DELAY 0;
131
            else
132
              rr_locked <= `SDLIB_DELAY nxt_rr_locked;
133
          end
134
      end // block: tp_gen
135
    else
136
      begin : ntp_gen
137
        assign trig_pattern = 1'b0;
138
      end
139
  endgenerate
140
 
141
  always @*
142
    begin
143
      p_data = 0;
144
      p_srdy = 0;
145
      for (j=0; j<inputs; j=j+1)
146
        if (rr_state[j])
147
          begin
148
            p_data = rr_mux_grid[j];
149
            p_srdy = c_srdy[j];
150
          end
151
    end
152
 
153
  always @*
154
    begin
155
      if ((mode ==  1) & (c_srdy & rr_state))
156
        nxt_rr_state = rr_state;
157
      else if ((mode == 0) & !p_drdy)
158
        nxt_rr_state = rr_state;
159 10 ghutchis
      else if ((mode == 2) & (rr_locked | (c_srdy & rr_state)))
160 7 ghutchis
        nxt_rr_state = rr_state;
161 20 ghutchis
      else if (fast_arb)
162
        nxt_rr_state = nxt_grant (rr_state, c_srdy);
163 7 ghutchis
      else
164
        nxt_rr_state = { rr_state[0], rr_state[inputs-1:1] };
165
    end
166
 
167
  always @(`SDLIB_CLOCKING)
168
    begin
169
      if (reset)
170
        rr_state <= `SDLIB_DELAY 1;
171
      else
172
        rr_state <= `SDLIB_DELAY nxt_rr_state;
173
    end
174
 
175
endmodule // sd_rrmux

powered by: WebSVN 2.1.0

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