source: vis_dev/vis-2.1/examples/treearbiter/8-arbit.v @ 14

Last change on this file since 14 was 11, checked in by cecile, 13 years ago

Add vis

File size: 6.3 KB
RevLine 
[11]1/**************************************************************************
2
3  This is a simple tree arbiter, adapted from Dills' thesis p 89.
4  There are four processors which
5  share a single resource. A token defines which processor has the
6  resource. The arbiter cells have two children and one parent.
7  An arbiter can request the token, release it, etc.
8
9  Adnan Aziz
10  July 10, 1996
11  UT Austin
12
13***************************************************************************/ 
14
15/*
16 * Symbolic variables.
17 *
18 */
19typedef enum {myTRUE, myFALSE} boolean;
20typedef enum {idle, request, lock, release} handShakeType;
21
22/*
23 * The inteconnections between the processors and the cells.
24 *
25 */
26module main( clk );
27input clk;
28
29boolean wire xa, ya, sa; 
30handShakeType wire xr, yr, sr;
31
32boolean wire constTRUE;
33
34
35assign sa = myFALSE;
36assign constTRUE = myTRUE;
37
38arbitCell F0(  clk, constTRUE, xr,  yr,  xa,  ya, sr, sa );
39fourCells G1( clk, xa, xr );
40fourCells G2( clk, ya, yr );
41
42endmodule
43
44
45module fourCells( clk, sa, sr );
46input clk;
47input sa;
48output sr;
49
50boolean       wire ua1, ua2, ua3, ua4, xa, ya, sa;
51handShakeType wire ur1, ur2, ur3, ur4, xr, yr, sr;
52
53wire[0:1] procChoice;
54
55boolean wire constTRUE, constFALSE;
56
57assign constTRUE  = myTRUE;
58assign constFALSE = myFALSE;
59
60arbitCell C0 ( clk, constFALSE,  xr,  yr,  xa,  ya,  sr, sa );
61arbitCell C1 ( clk, constFALSE, ur1, ur2, ua1, ua2, xr, xa );
62arbitCell C2 ( clk, constFALSE, ur3, ur4, ua3, ua4, yr, ya ); 
63
64procModel P1( clk, ua1, ur1 ); 
65procModel P2( clk, ua2, ur2 ); 
66procModel P3( clk, ua3, ur3 ); 
67procModel P4( clk, ua4, ur4 ); 
68
69endmodule
70
71
72/*
73 * The arbiter cell has two inputs from children and two outputs to chidren.
74 * One input from parent, and one output to parent. The latch holdToken corresponds
75 * to whether the cell holds the token. The latches prevLeft and prevRight are
76 * used to keep track of which way the token went last, to impart fairness
77 * in the scheduling of the children.
78 *
79 */
80
81
82/*
83 * Add comments
84 */
85module procModel(clk, ack, req );
86input clk;
87input ack;
88output req;
89
90boolean wire ack;
91handShakeType wire req;
92wire randChoice;
93
94assign req = procState;
95assign randChoice = $ND(0,1);
96
97handShakeType reg procState;
98
99initial procState = idle;
100
101always @(posedge clk) begin
102   
103    if ( procState == idle  && (randChoice == 1) )
104        begin 
105            procState = request;
106        end
107    else if ( procState == request && ack == myTRUE )
108        begin 
109            procState = lock;
110        end
111    else if (  procState == lock && (randChoice == 1 ) ) 
112        begin 
113            procState = release;
114        end
115    else if ( procState == release )
116        begin
117            procState = idle;
118        end
119end
120
121endmodule
122
123
124
125module arbitCell(clk, topCell, urLeft, urRight, uaLeft, uaRight, xr, xa);
126input clk;
127input topCell, urLeft, urRight, xa;
128output uaLeft, uaRight, xr;
129
130boolean       wire topCell, uaLeft, uaRight, xa; 
131handShakeType wire urLeft, urRight, xr; 
132
133boolean wire uaLeft, uaRight;
134
135boolean reg prevLeft, prevRight;
136initial prevLeft = myFALSE;
137initial prevRight = myTRUE;
138
139boolean reg processedLeft, processedRight;
140initial processedLeft = myFALSE;
141initial processedRight = myFALSE;
142
143boolean wire mustGiveParent; /* essentially a macro for checking if must release the token to parent */
144assign mustGiveParent = ( processedLeft == myTRUE ) && ( processedRight == myTRUE ) 
145                                              && ( !( topCell == myTRUE ) ) ? myTRUE : myFALSE;
146
147boolean reg holdToken;
148initial holdToken = topCell;
149
150boolean wire childOwns; /* essentially a macro for checking if a descendant owns the token */
151assign childOwns = ( urLeft == lock || urRight == lock ) ? myTRUE : myFALSE;
152
153boolean wire giveChild; /* essentially a macro for checking if a child is being given the token */
154assign giveChild = ( uaLeft == myTRUE  || uaRight == myTRUE ) ? myTRUE : myFALSE;
155
156/*
157 * Condition under which the token is given to the left child
158 * Must own token, have request from left, and either no request from right or if there is
159 * a request from the right it, should be lefts turn (since right went the last time
160 *
161 */
162assign uaLeft = ( !( mustGiveParent == myTRUE ) && ( holdToken == myTRUE && urLeft == request 
163                    && ( ! ( urRight == request ) || prevRight == myTRUE ) ) ) ? myTRUE : myFALSE;
164
165/*
166 * same as above for right
167 *
168 */
169assign uaRight = ( !( mustGiveParent == myTRUE ) && ( holdToken == myTRUE && urRight == request 
170                    && ( ! ( urLeft == request ) || prevLeft == myTRUE ) ) ) ? myTRUE : myFALSE;
171
172/*
173 * signal to parent:
174 *
175 *   1. request if dont own the token,
176 *   2. lock if descendant has locked the token
177 *   3. release if child has released token
178 *   4. idle otherwise
179 *
180 */
181assign xr = ( holdToken == myFALSE  &&  ( urLeft == request || urRight == request ) )
182                ? request :
183                    ( childOwns == myTRUE )
184                     ? lock :
185                      ( holdToken == myTRUE && ( ( ( mustGiveParent == myTRUE ) ||
186                                                   ! ( ( urLeft == request || urRight == request ) ) )
187                        && !( topCell == myTRUE ) ) )
188                          ? release : idle;
189
190always @(posedge clk) begin
191
192/*
193 * keep track of whether we hold the token or not
194 *
195 */
196
197    if ( xa == myTRUE )
198        begin
199            holdToken = myTRUE;
200        end
201    else if ( giveChild == myTRUE )
202        begin 
203            holdToken = myFALSE;
204        end
205    else if ( urLeft == release  || urRight == release )
206        begin 
207            holdToken = myTRUE;
208        end
209   else if ( xr == release )
210        begin 
211            holdToken = myFALSE;
212        end
213
214/*
215 * keep track of which child got the token last
216 *
217 */
218   if ( uaLeft == myTRUE ) 
219       begin
220           prevLeft  = myTRUE;
221           prevRight = myFALSE;
222       end
223    else if ( uaRight == myTRUE )
224       begin
225           prevLeft  = myFALSE;
226           prevRight = myTRUE;
227       end
228
229/*
230 * child has finished processing the token
231 *
232 */
233
234   if ( urLeft == release )
235     begin
236        processedLeft = myTRUE;
237     end
238   else if ( urRight == release )
239      begin
240        processedRight = myTRUE;
241      end
242/*
243 * if we have given the token to both children, must now give it up
244 *
245 */
246   else if ( ( processedLeft == myTRUE ) && ( processedRight == myTRUE ) )
247        begin
248            processedLeft = myFALSE;
249            processedRight = myFALSE;
250        end
251         
252end
253
254endmodule
Note: See TracBrowser for help on using the repository browser.