-
Notifications
You must be signed in to change notification settings - Fork 3
/
VirtualArbiter.sv
96 lines (71 loc) · 2.56 KB
/
VirtualArbiter.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package pkg_arbiter_virtualArbiter;
import pkg_arbiter_transaction::*;
import pkg_arbiter_types::*;
class VirtualArbiter;
int roundRobinIndex = NUMUNITS-1; //This is only for initialization. This is because we want first shot to analyse device 0.
function logic [NUMUNITS-1 : 0] getArbiterResponse(Transaction transaction);
logic [ADDRESSWIDTH-1 : 0] min;
int minPrioIndex = 0;
//fixed prio
//holds the priorities
logic [ADDRESSWIDTH-1 : 0] prio [NUMUNITS-1 : 0];
logic [ADDRESSWIDTH-1 : 0] tmp_prio;
logic [ADDRESSWIDTH-1 : 0] selectPrio [NUMUNITS-1 : 0];
//Initialize grant to 0
logic [NUMUNITS-1 : 0] grant;
for(int i = 0; i < NUMUNITS; i=i+1)
grant[i]=0;
//$display("VirtualArbiter : rrbit %b, received request %b", transaction.payload_roundORpriority, transaction.payload_request);
//if payload_roundORpriority == 0, round robin
if(!transaction.payload_roundORpriority) begin
//round robin
//On trouve la prochaine device a s'executer
for(int i = 1; i < NUMUNITS-1 ; i=i+1) begin
roundRobinIndex = (roundRobinIndex + 1) % NUMUNITS;
//$display("rr idx : %d", roundRobinIndex);
if (transaction.payload_request[roundRobinIndex] == 1) begin
//$display("VirtualArbiter : found RR device %d", roundRobinIndex);
break;
end
end
grant[roundRobinIndex] = 1;
end
else begin
// //On vectorise les priorites
// for (int i=0; i<NUMUNITS; i=i+1)
// begin
// for (int j=0; j<ADDRESSWIDTH; j=j+1)
// tmp_prio[j] = transaction.payload_priorit[i*ADDRESSWIDTH + j];
// prio[i] = tmp_prio;
// end
//Met aux maximum les prio des devices ne faisant pas de request
for(int i = 0; i < NUMUNITS; i=i+1)
begin
selectPrio[i] = transaction.payload_request[i] ? transaction.payload_priority[i] : NUMUNITS-1;
//$display("transactionPrio[%d] : %d", i, transaction.payload_priority[i]);
//$display("selectPrio[%d] : %d", i, selectPrio[i]);
end
// for(int i = 0; i < NUMUNITS; i=i+1)
// $display("VirutalArbiter : prio %d = %b", i, selectPrio[i]);
//Trouver la prio minimale
min = selectPrio[0];
for(int i = 0; i < NUMUNITS; i=i+1)
begin
if(selectPrio[i] < min)
min = selectPrio[i];
end
for(int i = 0; i < NUMUNITS; i=i+1)
if(selectPrio[i] == min)
begin
minPrioIndex = i;
break;
end
if(transaction.payload_request)
grant[minPrioIndex] = 1;
roundRobinIndex = minPrioIndex;
end
//$display("VirtualArbiter : returning grant %b", grant);
return grant;
endfunction
endclass
endpackage : pkg_arbiter_virtualArbiter