forked from pConst/basic_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathround_robin_enc.sv
executable file
·79 lines (65 loc) · 2.2 KB
/
round_robin_enc.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//------------------------------------------------------------------------------
// round_robin_enc.sv
// Konstantin Pavlov, [email protected]
//------------------------------------------------------------------------------
// INFO -------------------------------------------------------------------------
// Round robin combinational encoder to select only one bit from the input bus.
// In contrast to priority encoder, it features cyclically changing priority
// pointer inside, so every input bit (on aaverage) has equal chance
// to get to the output
//
// This module is meant to be as simple as possible. It is possible to make
// more efficient, but complicated circuit
//
// See also priority_enc.sv
// See also round_robin_performance_enc.sv
//
/* --- INSTANTIATION TEMPLATE BEGIN ---
round_robin_enc #(
.WIDTH( 32 )
) RE1 (
.clk( clk ),
.nrst( nrst ),
.id( ),
.od_valid( ),
.od_filt( ),
.od_bin( )
);
--- INSTANTIATION TEMPLATE END ---*/
module round_robin_enc #( parameter
WIDTH = 32,
WIDTH_W = $clogb2(WIDTH)
)(
input clk, // clock
input nrst, // inversed reset, synchronous
input [WIDTH-1:0] id, // input data bus
output logic od_valid, // output valid (some bits are active)
output logic [WIDTH-1:0] od_filt, // filtered data (only one priority bit active)
output logic [WIDTH_W-1:0] od_bin // priority bit binary index
);
// current bit selector
logic [WIDTH_W-1:0] priority_bit = '0;
always_ff @(posedge clk) begin
if( ~nrst ) begin
priority_bit[WIDTH_W-1:0] <= '0;
end else begin
if( priority_bit[WIDTH_W-1:0] == WIDTH-1 ) begin
priority_bit[WIDTH_W-1:0] <= '0;
end else begin
priority_bit[WIDTH_W-1:0] <= priority_bit[WIDTH_W-1:0] + 1'b1;
end // if
end // if nrst
end
always_comb begin
if( id[priority_bit[WIDTH_W-1:0]] ) begin
od_valid = id[priority_bit[WIDTH_W-1:0]];
od_filt[WIDTH-1:0] = 1'b1 << priority_bit[WIDTH_W-1:0];
od_bin[WIDTH_W-1:0] = priority_bit[WIDTH_W-1:0];
end else begin
od_valid = 1'b0;
od_filt[WIDTH-1:0] = '0;
od_bin[WIDTH_W-1:0] = '0;
end
end
`include "clogb2.svh"
endmodule