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

Subversion Repositories numbert_sort_device

[/] [numbert_sort_device/] [trunk/] [main/] [dynamic_tree.sv] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 leshabiruk
 
2 6 leshabiruk
 
3
 
4
 
5
 
6 5 leshabiruk
module Dyna_Tree ( clk, glob_com, dataIn, dataOut );
7
 
8 6 leshabiruk
parameter HBIT= 3;
9 5 leshabiruk
parameter TREE_LEVEL= 4;
10 6 leshabiruk
parameter IMRIGHT= 0;
11 5 leshabiruk
 
12
input clk;
13
input [1:0] glob_com;
14
 
15 6 leshabiruk
output TPort dataOut;
16
input  TPort dataIn;
17 5 leshabiruk
 
18
 
19 6 leshabiruk
TPort fromLeft;
20
TPort fromRight;
21 5 leshabiruk
 
22 6 leshabiruk
Cell_DT_Inner #( HBIT, IMRIGHT ) inner ( clk, glob_com, dataIn, fromLeft, fromRight, dataOut );
23
 
24 5 leshabiruk
generate
25
if ( TREE_LEVEL >0 )
26
begin
27 6 leshabiruk
        Dyna_Tree #( HBIT, TREE_LEVEL-1, 0 ) leftSubTree  ( clk, glob_com, dataOut, fromLeft );
28
        Dyna_Tree #( HBIT, TREE_LEVEL-1, 1 ) rightSubTree ( clk, glob_com, dataOut, fromRight );
29 5 leshabiruk
end
30
else
31
begin
32 6 leshabiruk
        assign fromLeft.msg =VMS_STOP;
33
        assign fromRight.msg=VMS_STOP;
34 5 leshabiruk
end
35
endgenerate
36
 
37
 
38
endmodule
39
 
40
 
41 6 leshabiruk
 
42
 
43
 
44
 
45
typedef enum bit[3:0] {         VK_EMPTY=4'h0,
46
                                                VK_DUMMY1,
47
                                                VK_DUMMY2,
48
                                                VK_DUMMY3,
49 7 leshabiruk
 
50 6 leshabiruk
                                                VK_DUMMY4,
51 7 leshabiruk
                                                VK_TRANSIT,
52 6 leshabiruk
                                                VK_APPLY,
53 7 leshabiruk
                                                VK_EOF,
54
 
55
                                                VK_K[2]= 4'h8,
56
 
57
                                                VK_S[3]= 4'd12,
58
                                                VK_DUMMY5
59 6 leshabiruk
                } VKind;
60
 
61 7 leshabiruk
function logic [1:0] CH_NUM( logic [3:0] k );
62
CH_NUM = k[1:0];
63
endfunction
64
 
65 6 leshabiruk
typedef enum bit[3:0] {         VMS_EMPTY=4'h0,
66 8 leshabiruk
                                                VMS_BUSY,
67 6 leshabiruk
                                                VMS_READY,
68 7 leshabiruk
                                                VMS_BOMB,
69
 
70 6 leshabiruk
                                                VMS_READ,
71 7 leshabiruk
                                                VMS_APPLY,
72 6 leshabiruk
                                                VMS_STOP                //      end of tree
73 5 leshabiruk
                } VMeta;
74
 
75 6 leshabiruk
typedef enum bit[1:0]{  TO_PARENT=2'h0,
76
                                                TO_CHILDREN,
77
                                                TO_LEFT,
78
                                                TO_RIGHT
79
                } VTarget;
80
 
81
typedef struct{
82
bit     [3:0] msg;
83
bit     [1:0] tgt;
84
                } TPort;
85
 
86
 
87
 
88
 
89
 
90
 
91
 
92
module Cell_DT_Inner ( clk, glob_com, i_fromParent, i_fromLeft, i_fromRight, message );
93 5 leshabiruk
parameter HBIT= 7;
94 6 leshabiruk
parameter IMRIGHT= 0;
95 5 leshabiruk
 
96
input clk;
97
input [1:0] glob_com;
98
 
99 6 leshabiruk
input  TPort i_fromParent;
100
input  TPort i_fromLeft;
101
input  TPort i_fromRight;
102 5 leshabiruk
 
103 6 leshabiruk
wire [HBIT:0] fromParent= ((IMRIGHT==0) && ( i_fromParent.tgt == TO_CHILDREN || i_fromParent.tgt == TO_LEFT )) ||
104
                                                          ((IMRIGHT==1) && ( i_fromParent.tgt == TO_CHILDREN || i_fromParent.tgt == TO_RIGHT ))
105
                                                          ? i_fromParent.msg : 4'h0;
106 5 leshabiruk
 
107 6 leshabiruk
wire [HBIT:0] fromLeft=   ( i_fromLeft.tgt == TO_PARENT  ) ? i_fromLeft.msg  : 4'h0;
108
wire [HBIT:0] fromRight=  ( i_fromRight.tgt == TO_PARENT ) ? i_fromRight.msg : 4'h0;
109
 
110 5 leshabiruk
reg [HBIT:0] value;
111 6 leshabiruk
output TPort message;
112 5 leshabiruk
VMeta        state;
113 6 leshabiruk
reg [3:0] step;
114 5 leshabiruk
 
115
always@(posedge clk )
116
begin
117 6 leshabiruk
        case( glob_com )
118
        0:                                                              //      working mode
119
        begin
120
                case( state )
121
                VMS_EMPTY:                                      //      sleeping
122 5 leshabiruk
                begin
123 7 leshabiruk
                        if ( !value )
124
                        begin   //      writing left
125
                                value <=  fromParent;//==VK_APPLY || fromParent==VK_EMPTY || fromParent==VK_K0 ? fromParent : VK_DUMMY5;                //      write self
126
                                if ( fromParent && CH_NUM( fromParent )==0 )
127
                                begin
128 8 leshabiruk
                                        message.msg <= fromParent;
129 7 leshabiruk
                                        message.tgt <= TO_PARENT;
130
                                        state       <= VMS_READY;
131
                                end
132
                        end
133 8 leshabiruk
                        else if ( CH_NUM( value )!=0 && fromLeft==0 )
134 7 leshabiruk
                        begin                                                           //      write left
135
                                message.msg <= fromParent;
136
                                message.tgt <= TO_LEFT;
137
                        end
138 8 leshabiruk
                        else if ( CH_NUM( value )==2 && fromRight==0 )
139 7 leshabiruk
                        begin                                                           //      begin writing right
140
                                message.msg <= fromParent;
141
                                message.tgt <= TO_RIGHT;
142
                        end
143
                        else
144 6 leshabiruk
                        begin
145 8 leshabiruk
                                message.msg <= VMS_BUSY;
146 6 leshabiruk
                                message.tgt <= TO_PARENT;
147 8 leshabiruk
                                state       <= VMS_BUSY;
148 6 leshabiruk
                        end
149 5 leshabiruk
                end
150 6 leshabiruk
 
151 8 leshabiruk
                VMS_BUSY:
152
                begin
153
                        if ( fromLeft && ( CH_NUM( value )==1 || fromRight ) )
154
                        begin
155
                                if ( value != VK_APPLY )
156
                                begin
157
                                        message.msg <= value;
158
                                        state       <= VMS_READY;
159
                                end
160
                                else
161
                                begin
162
                                        case (step)
163
                                        0:
164
                                        begin
165
                                                message.msg <= VMS_READ;
166
                                                message.tgt <= TO_RIGHT;
167
                                                step <= 1;
168
                                        end
169
                                        1:
170
                                        begin
171
                                                message.msg <= VMS_APPLY;
172
                                                message.tgt <= TO_LEFT;
173
                                                step <= 2;
174
                                        end
175
                                        2:
176
                                        begin
177
                                                if ( fromRight == VK_EOF )
178
                                                begin
179
                                                        step <= 3;
180
                                                        message.msg <= VK_EMPTY;
181
                                                end
182
                                                else
183
                                                begin
184
                                                        message.tgt <= TO_LEFT;
185
                                                        message.msg <= fromRight;
186
                                                end
187
                                        end
188
                                        3:
189
                                        begin
190
                                                value       <= VK_TRANSIT;
191
                                                state       <= VMS_BUSY;
192
                                                message.msg <= VMS_BOMB;
193
                                                message.tgt <= TO_RIGHT;
194
                                                step <= 0;
195
                                        end
196
                                        endcase
197
                                end
198
                        end
199
                end
200
 
201 6 leshabiruk
                VMS_READ:
202
                begin
203 7 leshabiruk
                        if ( message.msg == VK_EOF )
204 6 leshabiruk
                        begin
205 8 leshabiruk
                                message.msg <= value;           //      end read 2
206 6 leshabiruk
                                state       <= VMS_READY;
207 8 leshabiruk
                                step <= 0;
208 6 leshabiruk
                        end
209 8 leshabiruk
                        else if ( step==0 && fromLeft != VK_EOF )
210 6 leshabiruk
                        begin
211 7 leshabiruk
                                message.msg <= fromLeft;                //      transfer left
212
                                message.tgt <= TO_PARENT;
213
                        end
214
                        else if ( CH_NUM( value )==1 )
215
                        begin
216 8 leshabiruk
                                message.tgt <= TO_PARENT;
217 7 leshabiruk
                                message.msg <= VK_EOF;          //      end read 1.2
218
                        end
219 8 leshabiruk
                        else if ( step==0 )
220 7 leshabiruk
                        begin
221
                                message.msg <= VMS_READ;                //      command right
222 6 leshabiruk
                                message.tgt <= TO_RIGHT;
223 8 leshabiruk
                                step <= 1;
224 6 leshabiruk
                        end
225 7 leshabiruk
                        else if ( fromRight != VK_EOF )
226
                        begin
227
                                message.msg <= fromRight;               //      transfer right
228
                                message.tgt <= TO_PARENT;
229
                        end
230 6 leshabiruk
                        else
231 7 leshabiruk
                        begin
232
                                message.msg <= VK_EOF;          //      end read 1.3
233
                        end
234
 
235
 
236 6 leshabiruk
                end
237
 
238
                VMS_READY:
239
                begin
240
                        case( fromParent )
241 7 leshabiruk
                        VMS_BOMB:                                               //      clear
242
                        begin
243
                                message.msg <= VMS_BOMB;
244
                                message.tgt <= TO_CHILDREN;
245
                                state           <= VMS_EMPTY;
246
                                value           <= VK_EMPTY;
247
                        end
248 6 leshabiruk
                        VMS_READ:                                               //      read self
249
                        begin
250 8 leshabiruk
                                if ( CH_NUM( value )==0 )
251
                                begin                                                                   //      begin 1
252
                                        message.msg <= VK_EOF;          //      end read 1.1
253
                                end
254
                                else
255
                                begin                                                                   //      begin 2
256
                                        message.msg <= VMS_READ;        //      command left
257
                                        message.tgt <= TO_LEFT;
258
                                end
259
                                if ( value != VK_TRANSIT || step==1 )
260 7 leshabiruk
                                begin
261 8 leshabiruk
                                        state       <= VMS_READ;
262
                                        step                    <= 0;
263 7 leshabiruk
                                end
264 8 leshabiruk
                                else
265
                                        step <= 1;
266 6 leshabiruk
                        end
267 7 leshabiruk
                        VMS_APPLY:                                              //      apply string from parent to itself
268
                        begin
269
                                if ( CH_NUM( value )!=0 )
270
                                begin
271
                                        message.msg <= VMS_APPLY;
272
                                        message.tgt <= TO_CHILDREN;
273
                                end
274
                                begin
275
                                        case( value )
276
                                        VK_K0,
277
                                        VK_S0,
278
                                        VK_S1:
279
                                        begin                                                                 //        add argument
280
                                                value[1:0] <= value[1:0] +1;	//	K0 -> K1, S0 -> S1, S1 -> S2
281
                                                state      <= VMS_EMPTY;                //      WRITE
282
                                        end
283
                                        VK_K1:                                                  //      K main
284
                                        begin
285
                                                value       <= VK_TRANSIT;
286
                                                state       <= VMS_READY;
287
                                                message.msg <= VMS_BOMB;
288
                                                message.tgt <= TO_RIGHT;
289
                                        end
290
                                        VK_S2:                                                  //      S main
291
                                        begin
292
                                                state       <= VMS_APPLY;
293
                                        end
294
                                        endcase
295
                                end
296
                        end
297 6 leshabiruk
                        default:
298 8 leshabiruk
                        if ( value == VK_TRANSIT )
299 6 leshabiruk
                        begin
300 8 leshabiruk
                                message.msg <= fromLeft;
301 6 leshabiruk
                                message.tgt <= TO_PARENT;
302
                        end
303 8 leshabiruk
                        else
304
                        begin
305
                                message.msg <= value;
306
                                message.tgt <= TO_PARENT;
307
                        end
308 6 leshabiruk
                        endcase
309
                end
310 7 leshabiruk
 
311
                VMS_APPLY:
312
                if ( fromParent != VK_EOF )
313
                begin
314
                        message.msg <= fromParent;	//	Sxyz -> `(_`_xz) (_`_yz)
315
                        message.tgt <= TO_CHILDREN;
316
                end
317
                else
318
                begin
319
                        message.msg <= VK_EMPTY;
320 8 leshabiruk
                        state       <= VMS_BUSY;
321 7 leshabiruk
                        value                   <= VK_APPLY;	//	Sxyz -> _`_ (`xz) (`yz)
322
                end
323 6 leshabiruk
                endcase
324
        end
325
        default:                                                                //      reset mode
326
        begin
327
                state    <= VMS_EMPTY;
328 7 leshabiruk
                value    <= VK_EMPTY;
329 6 leshabiruk
                message.msg  <= VMS_EMPTY;
330
                step            <= 0;
331
        end
332 5 leshabiruk
        endcase
333
end
334
 
335
endmodule
336
 
337
 
338
 

powered by: WebSVN 2.1.0

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