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

Subversion Repositories spacewiresystemc

[/] [spacewiresystemc/] [trunk/] [rtl/] [RTL_VB/] [tx_spw.v] - Blame information for rev 34

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 redbear
//+FHDR------------------------------------------------------------------------
2
//Copyright (c) 2013 Latin Group American Integhrated Circuit, Inc. All rights reserved
3
//GLADIC Open Source RTL
4
//-----------------------------------------------------------------------------
5
//FILE NAME      :
6
//DEPARTMENT     : IC Design / Verification
7
//AUTHOR         : Felipe Fernandes da Costa
8
//AUTHOR’S EMAIL :
9
//-----------------------------------------------------------------------------
10
//RELEASE HISTORY
11
//VERSION DATE AUTHOR DESCRIPTION
12
//1.0 YYYY-MM-DD name
13
//-----------------------------------------------------------------------------
14
//KEYWORDS : General file searching keywords, leave blank if none.
15
//-----------------------------------------------------------------------------
16
//PURPOSE  : ECSS_E_ST_50_12C_31_july_2008
17
//-----------------------------------------------------------------------------
18
//PARAMETERS
19
//PARAM NAME            RANGE   : DESCRIPTION : DEFAULT : UNITS
20
//e.g.DATA_WIDTH        [32,16] : width of the DATA : 32:
21
//-----------------------------------------------------------------------------
22
//REUSE ISSUES
23
//Reset Strategy        :
24
//Clock Domains         :
25
//Critical Timing       :
26
//Test Features         :
27
//Asynchronous I/F      :
28
//Scan Methodology      :
29
//Instantiations        :
30
//Synthesizable (y/n)   :
31
//Other                 :
32
//-FHDR------------------------------------------------------------------------
33
 
34
`timescale 1ns/1ns
35
 
36
module TX_SPW (
37
                input pclk_tx,
38
                //
39
                input [8:0] data_tx_i,
40
                input txwrite_tx,
41
                //
42
                input [7:0] timecode_tx_i,
43
                input tickin_tx,
44
                //
45
                input enable_tx,
46
                input send_null_tx,
47
                input send_fct_tx,
48
 
49
                //
50
                input gotfct_tx,
51
                input send_fct_now,
52
                //
53 33 redbear
                output reg tx_dout_e,
54
                output reg tx_sout_e,
55 5 redbear
                //
56 8 redbear
                output  reg ready_tx_data,
57 13 redbear
                output  reg ready_tx_timecode
58 5 redbear
 
59
                );
60
 
61
localparam [2:0] tx_spw_start     = 3'b000,
62
                 tx_spw_null      = 3'b001,
63
                 tx_spw_null_fct  = 3'b010,
64
                 tx_spw_full      = 3'b100;
65
 
66
localparam [5:0] NULL     = 6'b000001,
67
                 FCT      = 6'b000010,
68
                 EOP      = 6'b000100,
69
                 EEP      = 6'b001000,
70
                 DATA     = 6'b010000,
71
                 TIMEC    = 6'b100000;
72
 
73 25 redbear
 
74
localparam [7:0] null_s = 8'b01110100;
75
localparam [2:0] fct_s  = 3'b100;
76
localparam [3:0] eop_s  = 4'b0101;
77
localparam [3:0] eep_s  = 4'b0110;
78
localparam [13:0] timecode_ss    = 14'b01110000000000;
79
 
80
 
81
 
82 5 redbear
        reg [2:0] state_tx;
83
        reg [2:0] next_state_tx;
84
 
85 25 redbear
        //reg [7:0]  null_s;
86
        //reg [2:0]  fct_s;
87
        //reg [3:0]  eop_s;
88
        //reg [3:0]  eep_s;
89 5 redbear
        reg [13:0] timecode_s;
90
 
91
        reg [5:0]  last_type;
92
        reg [8:0]  txdata_flagctrl_tx_last;
93
        reg [7:0]  last_timein_control_flag_tx;
94
 
95
        reg first_time;
96
 
97 8 redbear
        reg hold_null;
98
        reg hold_fct;
99
        reg hold_data;
100
        reg hold_time_code;
101
 
102 5 redbear
        reg enable_null;
103
        reg enable_fct;
104
        reg enable_n_char;
105
        reg enable_time_code;
106
 
107
        reg [2:0] fct_send;
108
        reg [2:0] fct_flag;
109 6 redbear
 
110 5 redbear
        reg [5:0] fct_counter;
111 6 redbear
        reg [5:0] fct_counter_receive;
112
 
113 5 redbear
        reg last_tx_dout;
114
        reg last_tx_sout;
115
 
116 33 redbear
        reg tx_dout;
117
        reg tx_sout;
118
 
119
        reg tx_dout_null;
120
        reg tx_dout_fct;
121
        reg tx_dout_timecode;
122
        reg tx_dout_data;
123
 
124 17 redbear
        reg block_sum;
125 19 redbear
        reg block_sum_fct_send;
126 17 redbear
 
127 5 redbear
        reg [3:0] global_counter_transfer;
128
 
129 33 redbear
always@(*)
130
begin
131
        tx_dout_null = 1'b0;
132 5 redbear
 
133 33 redbear
         if(enable_null)
134
         begin
135
                 if(first_time  && global_counter_transfer[3:0] == 4'd0)
136
                 begin
137
                        tx_dout_null = null_s[7];
138
                 end
139
                 else if(last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
140
                 begin
141
                        tx_dout_null = !(null_s[6]^null_s[0]^null_s[1]);
142
                 end
143
                 else if(last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
144
                 begin
145
                        tx_dout_null = !(null_s[6]^fct_s[0]^fct_s[1]);
146
                 end
147
                 else if(last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
148
                 begin
149
                        tx_dout_null = !(null_s[6]^eop_s[0]^eop_s[1]);
150
                 end
151
                 else if(last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
152
                 begin
153
                        tx_dout_null = !(null_s[6]^eep_s[0]^eep_s[1]);
154
                 end
155
                 else if(last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
156
                 begin
157
                        tx_dout_null =  !(null_s[6]^txdata_flagctrl_tx_last[0]^txdata_flagctrl_tx_last[1]^txdata_flagctrl_tx_last[2]^txdata_flagctrl_tx_last[3]^ txdata_flagctrl_tx_last[4]^txdata_flagctrl_tx_last[5]^txdata_flagctrl_tx_last[6]^txdata_flagctrl_tx_last[7]);
158
                 end
159
                 else if(last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
160
                 begin
161
                        tx_dout_null =  !(null_s[6]^last_timein_control_flag_tx[7]^last_timein_control_flag_tx[6]^last_timein_control_flag_tx[5]^last_timein_control_flag_tx[4]^last_timein_control_flag_tx[3]^last_timein_control_flag_tx[2]^last_timein_control_flag_tx[1]^last_timein_control_flag_tx[0]);
162
                 end
163
                 else if(global_counter_transfer[3:0] == 4'd1)
164
                 begin
165
                        tx_dout_null = null_s[6];
166
                 end
167
                 else if(global_counter_transfer[3:0] == 4'd2)
168
                 begin
169
                        tx_dout_null = null_s[5];
170
                 end
171
                 else if(global_counter_transfer[3:0] == 4'd3)
172
                 begin
173
                        tx_dout_null = null_s[4];
174
                 end
175
                 else if(global_counter_transfer[3:0] == 4'd4)
176
                 begin
177
                        tx_dout_null = null_s[3];
178
                 end
179
                 else if(global_counter_transfer[3:0] == 4'd5)
180
                 begin
181
                        tx_dout_null = null_s[2];
182
                 end
183
                 else if(global_counter_transfer[3:0] == 4'd6)
184
                 begin
185
                        tx_dout_null = null_s[1];
186
                 end
187
                 else if(global_counter_transfer[3:0] == 4'd7)
188
                 begin
189
                        tx_dout_null = null_s[0];
190
                 end
191
        end
192
end
193 13 redbear
 
194 33 redbear
 
195 5 redbear
always@(*)
196
begin
197
 
198 33 redbear
        tx_dout_fct = 1'b0;
199
 
200
        if(enable_fct)
201
        begin
202
 
203
                 if(last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
204
                 begin
205
                        tx_dout_fct = !(fct_s[2]^null_s[0]^null_s[1]);
206
                 end
207
                 else if(last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
208
                 begin
209
                        tx_dout_fct = !(fct_s[2]^fct_s[0]^fct_s[1]);
210
                 end
211
                 else if(last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
212
                 begin
213
                        tx_dout_fct = !(fct_s[2]^eop_s[0]^eop_s[1]);
214
                 end
215
                 else if(last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
216
                 begin
217
                        tx_dout_fct = !(fct_s[2]^eep_s[0]^eep_s[1]);
218
                 end
219
                 else if (last_type == DATA && global_counter_transfer[3:0] == 4'd0)
220
                 begin
221
                        tx_dout_fct = !(fct_s[2]^txdata_flagctrl_tx_last[0]^txdata_flagctrl_tx_last[1]^txdata_flagctrl_tx_last[2]^txdata_flagctrl_tx_last[3]^ txdata_flagctrl_tx_last[4]^txdata_flagctrl_tx_last[5]^txdata_flagctrl_tx_last[6]^txdata_flagctrl_tx_last[7]);
222
                 end
223
                 else if(last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
224
                 begin
225
                        tx_dout_fct = !(fct_s[2]^last_timein_control_flag_tx[7]^last_timein_control_flag_tx[6]^last_timein_control_flag_tx[5]^last_timein_control_flag_tx[4]^last_timein_control_flag_tx[3]^last_timein_control_flag_tx[2]^last_timein_control_flag_tx[1]^last_timein_control_flag_tx[0]);
226
                 end
227
                 else if(global_counter_transfer[3:0] == 4'd1)
228
                 begin
229
                        tx_dout_fct = fct_s[2];
230
                 end
231
                 else if(global_counter_transfer[3:0] == 4'd2)
232
                 begin
233
                        tx_dout_fct = fct_s[1];
234
                 end
235
                 else if(global_counter_transfer[3:0] == 4'd3)
236
                 begin
237
                        tx_dout_fct = fct_s[0];
238
                 end
239
 
240
        end
241 5 redbear
end
242 33 redbear
 
243
always@(*)
244
begin
245
        tx_dout_timecode = 1'b0;
246
 
247
        if(enable_time_code)
248
        begin
249
                 if(last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
250
                 begin
251
                        tx_dout_timecode = !(timecode_s[12]^null_s[0]^null_s[1]);
252
                 end
253
                 else if(last_type == FCT   && global_counter_transfer[3:0] == 4'd0)
254
                 begin
255
                        tx_dout_timecode = !(timecode_s[12]^fct_s[0]^fct_s[1]);
256
                 end
257
                 else if (last_type == EOP   && global_counter_transfer[3:0] == 4'd0)
258
                 begin
259
                        tx_dout_timecode = !(timecode_s[12]^eop_s[0]^eop_s[1]);
260
                 end
261
                 else if( last_type == EEP   && global_counter_transfer[3:0] == 4'd0)
262
                 begin
263
                        tx_dout_timecode = !(timecode_s[12]^eep_s[0]^eep_s[1]);
264
                 end
265
                 else if( last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
266
                 begin
267
                        tx_dout_timecode = !(timecode_s[12]^txdata_flagctrl_tx_last[0]^txdata_flagctrl_tx_last[1]^txdata_flagctrl_tx_last[2]^txdata_flagctrl_tx_last[3]^ txdata_flagctrl_tx_last[4]^txdata_flagctrl_tx_last[5]^txdata_flagctrl_tx_last[6]^txdata_flagctrl_tx_last[7]);
268
                 end
269
                 else if( last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
270
                 begin
271
                        tx_dout_timecode = !(timecode_s[12]^last_timein_control_flag_tx[7]^last_timein_control_flag_tx[6]^last_timein_control_flag_tx[5]^last_timein_control_flag_tx[4]^last_timein_control_flag_tx[3]^last_timein_control_flag_tx[2]^last_timein_control_flag_tx[1]^last_timein_control_flag_tx[0]);
272
                 end
273
                 else if( global_counter_transfer[3:0] == 4'd1)
274
                 begin
275
                        tx_dout_timecode = timecode_s[12];
276
                 end
277
                 else if( global_counter_transfer[3:0] == 4'd2)
278
                 begin
279
                        tx_dout_timecode = timecode_s[11];
280
                 end
281
                 else if( global_counter_transfer[3:0] == 4'd3)
282
                 begin
283
                        tx_dout_timecode = timecode_s[10];
284
                 end
285
                 else if( global_counter_transfer[3:0] == 4'd4)
286
                 begin
287
                        tx_dout_timecode = timecode_s[9];
288
                 end
289
                 else if( global_counter_transfer[3:0] == 4'd5)
290
                 begin
291
                        tx_dout_timecode = timecode_s[8];
292
                 end
293
                 else if( global_counter_transfer[3:0] == 4'd6)
294
                 begin
295
                        tx_dout_timecode = timecode_s[0];
296
                 end
297
                 else if( global_counter_transfer[3:0] == 4'd7)
298
                 begin
299
                        tx_dout_timecode = timecode_s[1];
300
                 end
301
                 else if( global_counter_transfer[3:0] == 4'd8)
302
                 begin
303
                        tx_dout_timecode = timecode_s[2];
304
                 end
305
                 else if(global_counter_transfer[3:0] == 4'd9)
306
                 begin
307
                        tx_dout_timecode = timecode_s[3];
308
                 end
309
                 else if(global_counter_transfer[3:0] == 4'd10)
310
                 begin
311
                        tx_dout_timecode = timecode_s[4];
312
                 end
313
                 else if(global_counter_transfer[3:0] == 4'd11)
314
                 begin
315
                        tx_dout_timecode = timecode_s[5];
316
                 end
317
                 else if( global_counter_transfer[3:0] == 4'd12)
318
                 begin
319
                        tx_dout_timecode = timecode_s[6];
320
                 end
321
                 else if(global_counter_transfer[3:0] == 4'd13)
322
                 begin
323
                        tx_dout_timecode = timecode_s[7];
324
                 end
325
        end
326
end
327
 
328
always@(*)
329
begin
330
        tx_dout_data = 1'b0;
331
 
332
        if(enable_n_char)
333
        begin
334
                if(!data_tx_i[8] && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
335
                 begin
336
                        tx_dout_data = !(data_tx_i[8]^null_s[0]^null_s[1]);
337
                 end
338
                 else if(!data_tx_i[8] && last_type == FCT && global_counter_transfer[3:0] == 4'd0)
339
                 begin
340
                        tx_dout_data = !(data_tx_i[8]^fct_s[0]^fct_s[1]);
341
                 end
342
                 else if(!data_tx_i[8] && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
343
                 begin
344
                        tx_dout_data = !(data_tx_i[8]^eop_s[0]^eop_s[1]);
345
                 end
346
                 else if(!data_tx_i[8] && last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
347
                 begin
348
                        tx_dout_data = !(data_tx_i[8]^eep_s[0]^eep_s[1]);
349
                 end
350
                 else if(!data_tx_i[8] && last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
351
                 begin
352
                        tx_dout_data = !(data_tx_i[8]^txdata_flagctrl_tx_last[0]^txdata_flagctrl_tx_last[1]^txdata_flagctrl_tx_last[2]^txdata_flagctrl_tx_last[3]^ txdata_flagctrl_tx_last[4]^txdata_flagctrl_tx_last[5]^txdata_flagctrl_tx_last[6]^txdata_flagctrl_tx_last[7]);
353
                 end
354
                 else if(!data_tx_i[8] && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
355
                 begin
356
                        tx_dout_data = !(data_tx_i[8]^last_timein_control_flag_tx[7]^last_timein_control_flag_tx[6]^last_timein_control_flag_tx[5]^last_timein_control_flag_tx[4]^last_timein_control_flag_tx[3]^last_timein_control_flag_tx[2]^last_timein_control_flag_tx[1]^last_timein_control_flag_tx[0]);
357
                 end
358
                 else if(data_tx_i[8]  && data_tx_i[1:0] == 2'b00 && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
359
                 begin
360
                        tx_dout_data = !(eop_s[2]^null_s[0]^null_s[1]);
361
                 end
362
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b00 && last_type == FCT   && global_counter_transfer[3:0] == 4'd0)
363
                 begin
364
                        tx_dout_data = !(eop_s[2]^fct_s[0]^fct_s[1]);
365
                 end
366
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b00 && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
367
                 begin
368
                        tx_dout_data = !(eop_s[2]^eop_s[0]^eop_s[1]);
369
                 end
370
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b00 && last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
371
                 begin
372
                        tx_dout_data = !(eop_s[2]^eep_s[0]^eep_s[1]);
373
                 end
374
                 else if(data_tx_i[8]  && data_tx_i[1:0] == 2'b00 && last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
375
                 begin
376
                        tx_dout_data = !(eop_s[2]^txdata_flagctrl_tx_last[0]^txdata_flagctrl_tx_last[1]^txdata_flagctrl_tx_last[2]^txdata_flagctrl_tx_last[3]^ txdata_flagctrl_tx_last[4]^txdata_flagctrl_tx_last[5]^txdata_flagctrl_tx_last[6]^txdata_flagctrl_tx_last[7]);
377
                 end
378
                 else if(data_tx_i[8]  && data_tx_i[1:0] == 2'b00 && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
379
                 begin
380
                        tx_dout_data = !(eop_s[2]^last_timein_control_flag_tx[7]^last_timein_control_flag_tx[6]^last_timein_control_flag_tx[5]^last_timein_control_flag_tx[4]^last_timein_control_flag_tx[3]^last_timein_control_flag_tx[2]^last_timein_control_flag_tx[1]^last_timein_control_flag_tx[0]);
381
                 end
382
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b01 && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
383
                 begin
384
                        tx_dout_data = !(eep_s[2]^null_s[0]^null_s[1]);
385
                 end
386
                 else if(data_tx_i[8] & data_tx_i[1:0] == 2'b01 && last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
387
                 begin
388
                        tx_dout_data = !(eep_s[2]^fct_s[0]^fct_s[1]);
389
                 end
390
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b01 && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
391
                 begin
392
                        tx_dout_data = !(eep_s[2]^eop_s[0]^eop_s[1]);
393
                 end
394
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b01 && last_type == EEP && global_counter_transfer[3:0] == 4'd0)
395
                 begin
396
                        tx_dout_data = !(eep_s[2]^eep_s[0]^eep_s[1]);
397
                 end
398
                 else if(data_tx_i[8]  && data_tx_i[1:0] == 2'b01 && last_type == DATA && global_counter_transfer[3:0] == 4'd0)
399
                 begin
400
                        tx_dout_data = !(eep_s[2]^txdata_flagctrl_tx_last[0]^txdata_flagctrl_tx_last[1]^txdata_flagctrl_tx_last[2]^txdata_flagctrl_tx_last[3]^ txdata_flagctrl_tx_last[4]^txdata_flagctrl_tx_last[5]^txdata_flagctrl_tx_last[6]^txdata_flagctrl_tx_last[7]);
401
                 end
402
                 else if(data_tx_i[8]  &&  data_tx_i[1:0] == 2'b01 && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
403
                 begin
404
                        tx_dout_data = !(eep_s[2]^last_timein_control_flag_tx[7]^last_timein_control_flag_tx[6]^last_timein_control_flag_tx[5]^last_timein_control_flag_tx[4]^last_timein_control_flag_tx[3]^last_timein_control_flag_tx[2]^last_timein_control_flag_tx[1]^last_timein_control_flag_tx[0]);
405
                 end
406
                 else if(!data_tx_i[8] &&  global_counter_transfer[3:0] == 4'd1)
407
                 begin
408
                        tx_dout_data = data_tx_i[8];
409
                 end
410
                 else if(!data_tx_i[8] && global_counter_transfer[3:0] == 4'd2)
411
                 begin
412
                        tx_dout_data = data_tx_i[0];
413
                 end
414
                 else if(!data_tx_i[8] &&  global_counter_transfer[3:0] == 4'd3)
415
                 begin
416
                        tx_dout_data = data_tx_i[1];
417
                 end
418
                 else if( !data_tx_i[8] && global_counter_transfer[3:0] == 4'd4)
419
                 begin
420
                        tx_dout_data = data_tx_i[2];
421
                 end
422
                 else if(!data_tx_i[8]  && global_counter_transfer[3:0] == 4'd5)
423
                 begin
424
                        tx_dout_data = data_tx_i[3];
425
                 end
426
                 else if(!data_tx_i[8]  && global_counter_transfer[3:0] == 4'd6)
427
                 begin
428
                        tx_dout_data = data_tx_i[4];
429
                 end
430
                 else if(!data_tx_i[8]  && global_counter_transfer[3:0] == 4'd7)
431
                 begin
432
                        tx_dout_data = data_tx_i[5];
433
                 end
434
                 else if(!data_tx_i[8] &&  global_counter_transfer[3:0] == 4'd8)
435
                 begin
436
                        tx_dout_data = data_tx_i[6];
437
                 end
438
                 else if(!data_tx_i[8] &&  global_counter_transfer[3:0] == 4'd9)
439
                 begin
440
                        tx_dout_data = data_tx_i[7];
441
                 end
442
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd1)
443
                 begin
444
                        tx_dout_data = eep_s[2];
445
                 end
446
                 else if( data_tx_i[8] && data_tx_i[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd2)
447
                 begin
448
                        tx_dout_data = eep_s[1];
449
                 end
450
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd3)
451
                 begin
452
                        tx_dout_data = eep_s[0];
453
                 end
454
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd1)
455
                 begin
456
                        tx_dout_data = eop_s[2];
457
                 end
458
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd2)
459
                 begin
460
                        tx_dout_data = eop_s[1];
461
                 end
462
                 else if(data_tx_i[8] && data_tx_i[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd3)
463
                 begin
464
                        tx_dout_data = eop_s[0];
465
                 end
466
        end
467
end
468 5 redbear
 
469
//strobe
470
always@(*)
471
begin
472
        tx_sout = 1'b0;
473
 
474
        if(!enable_tx)
475
        begin
476
                tx_sout = 1'b0;
477
        end
478 33 redbear
        else if((enable_null | enable_fct | enable_n_char | enable_time_code) & tx_dout == last_tx_dout)
479 5 redbear
        begin
480
                tx_sout = !last_tx_sout;
481
        end
482 33 redbear
        else if((enable_null | enable_fct | enable_n_char | enable_time_code) & tx_dout != last_tx_dout)
483 5 redbear
        begin
484
                tx_sout = last_tx_sout;
485 33 redbear
        end
486 5 redbear
end
487
 
488 17 redbear
always@(*)
489 5 redbear
begin
490 17 redbear
        fct_counter = 6'd0;
491
 
492
        if(gotfct_tx)
493 5 redbear
        begin
494 17 redbear
                if(block_sum)
495 15 redbear
                begin
496 17 redbear
 
497
                end
498
                else
499
                begin
500
                        if(fct_counter_receive < 6'd48)
501 15 redbear
                        begin
502 17 redbear
                                fct_counter = fct_counter_receive + 6'd8;
503 15 redbear
                        end
504
                        else
505
                        begin
506 17 redbear
                                fct_counter = fct_counter_receive + 6'd7;
507
 
508 15 redbear
                        end
509
                end
510 5 redbear
        end
511
end
512
 
513
//slots open in our side
514 19 redbear
always@(*)
515 5 redbear
begin
516
 
517 19 redbear
        fct_send = {3{1'b0}};
518
 
519
        if(send_fct_now)
520 5 redbear
        begin
521 19 redbear
                if(block_sum_fct_send)
522
                begin
523 6 redbear
 
524
                end
525
                else
526
                begin
527 19 redbear
                        if(fct_flag == 3'd7)
528
                        begin
529
                                fct_send = 3'd0;
530
                        end
531
                        else
532
                        begin
533
                                fct_send = fct_flag + 3'd1;
534
 
535
                        end
536 6 redbear
                end
537 5 redbear
        end
538
end
539
 
540
 
541
always@(*)
542
begin
543
 
544
 
545
        enable_null      = 1'b0;
546
        enable_fct       = 1'b0;
547
        enable_n_char    = 1'b0;
548
        enable_time_code = 1'b0;
549
 
550 17 redbear
        next_state_tx = state_tx;
551
 
552 5 redbear
        case(state_tx)
553
        tx_spw_start:
554
        begin
555
                if(send_null_tx && enable_tx)
556
                begin
557 12 redbear
                        //if(!hold_null)
558 5 redbear
                                next_state_tx = tx_spw_null;
559
 
560 12 redbear
                        //enable_null = 1'b1;
561 5 redbear
                end
562
                else
563
                begin
564
                        next_state_tx = tx_spw_start;
565
                end
566
        end
567
        tx_spw_null:
568
        begin
569
                enable_null = 1'b1;
570
 
571 8 redbear
                if(!hold_null)
572 5 redbear
                begin
573
                        if(send_null_tx && send_fct_tx && enable_tx)
574
                                next_state_tx = tx_spw_null_fct;
575
                        else
576
                                next_state_tx = tx_spw_null;
577
                end
578
 
579
        end
580
        tx_spw_null_fct:
581
        begin
582
 
583
                enable_null   = 1'b1;
584
 
585 8 redbear
                if(send_fct_tx && fct_flag > 0  && !hold_null)
586 5 redbear
                begin
587 8 redbear
                        next_state_tx = tx_spw_null_fct;
588 5 redbear
                        enable_null = 1'b0;
589 8 redbear
                        enable_fct  = 1'b1;
590 5 redbear
                end
591
                else
592
                begin
593
                        enable_fct = 1'b0;
594 17 redbear
                        if(send_fct_tx && fct_counter_receive > 6'd0)
595 5 redbear
                        begin
596 12 redbear
                                //if(global_counter_transfer == 4'd7)
597
                                        next_state_tx =  tx_spw_full;
598 5 redbear
                        end
599
 
600
                end
601
        end
602
        tx_spw_full:
603
        begin
604 8 redbear
                if(tickin_tx && !hold_null && !hold_fct && !hold_data)
605 5 redbear
                begin
606 6 redbear
                        enable_time_code = 1'b1;
607 5 redbear
                end
608 8 redbear
                else if(fct_flag > 3'd0 && !hold_null && !hold_time_code && !hold_data)
609 5 redbear
                begin
610 6 redbear
                        enable_fct  = 1'b1;
611 5 redbear
                end
612 34 redbear
                else if((txwrite_tx && !ready_tx_data && fct_counter_receive > 6'd0 && !hold_null && !hold_time_code && !hold_fct) == 1'b1 )
613 5 redbear
                begin
614 8 redbear
                        enable_n_char = 1'b1;
615 5 redbear
                end
616 17 redbear
                else
617 8 redbear
                begin
618
                        enable_null = 1'b1;
619
                end
620 5 redbear
        end
621
        endcase
622
 
623
end
624
 
625 33 redbear
 
626
always@(*)
627
begin
628
 
629
        tx_dout = 1'b0;
630
 
631
        if(enable_null)
632
        begin
633
                tx_dout = tx_dout_null;
634
        end
635
        else if(enable_fct)
636
        begin
637
                tx_dout = tx_dout_fct;
638
        end
639
        else if(enable_time_code)
640
        begin
641
                tx_dout = tx_dout_timecode;
642
        end
643
        else if(enable_n_char)
644
        begin
645
                tx_dout = tx_dout_data;
646
        end
647
end
648
 
649
 
650 25 redbear
always@(posedge pclk_tx or negedge enable_tx)
651 5 redbear
begin
652
        if(!enable_tx)
653
        begin
654 33 redbear
                tx_dout_e <= 1'b0;
655
                tx_sout_e <= 1'b0;
656
        end
657
        else
658
        begin
659
                if(enable_null)
660
                begin
661
                        tx_dout_e <= tx_dout;
662
                        tx_sout_e <= tx_sout;
663
                end
664
                else if(enable_fct)
665
                begin
666
                        tx_dout_e <= tx_dout;
667
                        tx_sout_e <= tx_sout;
668
                end
669
                else if(enable_time_code)
670
                begin
671
                        tx_dout_e <= tx_dout;
672
                        tx_sout_e <= tx_sout;
673
                end
674
                else if(enable_n_char)
675
                begin
676
                        tx_dout_e <= tx_dout;
677
                        tx_sout_e <= tx_sout;
678
                end
679
        end
680
end
681 25 redbear
 
682 33 redbear
always@(posedge pclk_tx or negedge enable_tx)
683
begin
684
        if(!enable_tx)
685
        begin
686
 
687 25 redbear
                timecode_s    <= 14'b01110000000000;
688 19 redbear
                fct_flag      <= 3'd7;
689 6 redbear
 
690 13 redbear
                first_time        <= 1'b1;
691
                ready_tx_data     <= 1'b0;
692
                ready_tx_timecode <= 1'b0;
693 8 redbear
 
694
                hold_null       <= 1'b0;
695
                hold_fct        <= 1'b0;
696
                hold_data       <= 1'b0;
697
                hold_time_code  <= 1'b0;
698
 
699 5 redbear
                last_type  <= NULL;
700
 
701
                global_counter_transfer <= 4'd0;
702
                txdata_flagctrl_tx_last <= 9'd0;
703
                last_timein_control_flag_tx <= 8'd0;
704 6 redbear
 
705
                fct_counter_receive <= 6'd0;
706 17 redbear
 
707
                block_sum  <= 1'b0;
708 19 redbear
                block_sum_fct_send <= 1'b0;
709 6 redbear
 
710 5 redbear
                last_tx_dout      <= 1'b0;
711
                last_tx_sout      <= 1'b0;
712 33 redbear
 
713 5 redbear
                state_tx <= tx_spw_start;
714 17 redbear
 
715 5 redbear
        end
716
        else
717
        begin
718 25 redbear
 
719 5 redbear
                state_tx <= next_state_tx;
720
                last_tx_dout <= tx_dout;
721
                last_tx_sout <= tx_sout;
722
 
723
                if(enable_null)
724
                begin
725 6 redbear
 
726 34 redbear
                        //ready_tx_data <= 1'b0;
727 13 redbear
                        ready_tx_timecode <= 1'b0;
728 25 redbear
                        //hold_null     <= 1'b0;
729
                        hold_fct        <= 1'b0;
730
                        hold_data       <= 1'b0;
731
                        hold_time_code  <= 1'b0;
732
 
733 19 redbear
                        //
734 17 redbear
                        if(gotfct_tx && !block_sum)
735
                        begin
736 15 redbear
                                fct_counter_receive <= fct_counter;
737 17 redbear
                                block_sum<= 1'b1;
738
                        end
739
                        else if(!gotfct_tx)
740
                        begin
741
                                block_sum<= 1'b0;
742
                        end
743
                        else
744
                                block_sum <= block_sum;
745 6 redbear
                        //
746 19 redbear
                        if(send_fct_now && !block_sum_fct_send)
747 6 redbear
                        begin
748 19 redbear
                                fct_flag <= fct_send;
749
                                block_sum_fct_send<= 1'b1;
750 6 redbear
                        end
751 19 redbear
                        else if(!send_fct_now)
752
                        begin
753
                                block_sum_fct_send<= 1'b0;
754
                        end
755
                        else
756
                                block_sum_fct_send <= block_sum_fct_send;
757 6 redbear
 
758 34 redbear
                        if(global_counter_transfer == 4'd7)
759
                        begin
760
                                hold_null <= 1'b0;
761
                        end
762
                        else
763
                        begin
764
                                hold_null <= 1'b1;
765
                        end
766
 
767 5 redbear
                        if(first_time)
768
                        begin
769
                                first_time <= 1'b0;
770 34 redbear
                                //hold_null  <= 1'b1;
771 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
772
                        end
773
                        else if(global_counter_transfer != 4'd7)
774
                        begin
775 34 redbear
                                //hold_null  <= 1'b1;
776 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
777
                        end
778
                        else
779
                        begin
780 34 redbear
                                //hold_null <= 1'b0;
781
                                ready_tx_data <= 1'b0;
782 25 redbear
                                last_type  <= NULL;
783 5 redbear
                                global_counter_transfer <= 4'd0;
784
                        end
785
                end
786
                else if(enable_fct)
787
                begin
788 34 redbear
                        //ready_tx_data <= 1'b0;
789 13 redbear
                        ready_tx_timecode <= 1'b0;
790 8 redbear
 
791 25 redbear
                        hold_null       <= 1'b0;
792
                        //hold_fct      <= 1'b0;
793
                        hold_data       <= 1'b0;
794
                        hold_time_code  <= 1'b0;
795
 
796
 
797 17 redbear
                        if(gotfct_tx && !block_sum)
798
                        begin
799 15 redbear
                                fct_counter_receive <= fct_counter;
800 17 redbear
                                block_sum<= 1'b1;
801
                        end
802
                        else if(!gotfct_tx)
803
                        begin
804
                                block_sum<= 1'b0;
805
                        end
806
                        else
807
                                block_sum <= block_sum;
808 6 redbear
 
809 34 redbear
                        if(global_counter_transfer == 4'd2)
810
                                ready_tx_data <= 1'b0;
811
                        else
812
                                ready_tx_data <= ready_tx_data;
813 6 redbear
 
814 34 redbear
                        if(global_counter_transfer == 4'd3)
815
                        begin
816
                                hold_fct <= 1'b0;
817
                        end
818
                        else
819
                        begin
820
                                hold_fct <= 1'b1;
821
                        end
822
 
823 5 redbear
                        if(global_counter_transfer != 4'd3)
824
                        begin
825 34 redbear
                                //hold_fct <= 1'b1;
826 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
827 19 redbear
                                //
828
                                if(send_fct_now && !block_sum_fct_send)
829
                                begin
830
                                        fct_flag <= fct_send;
831
                                        block_sum_fct_send<= 1'b1;
832
                                end
833
                                else if(!send_fct_now)
834
                                begin
835
                                        block_sum_fct_send<= 1'b0;
836
                                end
837
                                else
838
                                        block_sum_fct_send <= block_sum_fct_send;
839 5 redbear
                        end
840
                        else
841
                        begin
842 34 redbear
                                //hold_fct <= 1'b0;
843 5 redbear
                                global_counter_transfer <= 4'd0;
844 6 redbear
                                fct_flag <= fct_flag - 3'd1;
845 25 redbear
                                last_type  <=FCT;
846 5 redbear
                        end
847
                end
848
                else if(enable_time_code)
849
                begin
850 33 redbear
 
851 25 redbear
                        hold_null       <= 1'b0;
852
                        hold_fct        <= 1'b0;
853
                        hold_data       <= 1'b0;
854
                        //hold_time_code        <= 1'b0;
855
 
856 34 redbear
                        //ready_tx_data <= 1'b0;
857 8 redbear
 
858 17 redbear
                        if(gotfct_tx && !block_sum)
859
                        begin
860 15 redbear
                                fct_counter_receive <= fct_counter;
861 17 redbear
                                block_sum<= 1'b1;
862
                        end
863
                        else if(!gotfct_tx)
864
                        begin
865
                                block_sum<= 1'b0;
866
                        end
867
                        else
868
                                block_sum <= block_sum;
869 15 redbear
 
870 13 redbear
                        if(global_counter_transfer == 4'd13)
871
                        begin
872
                                ready_tx_timecode <= 1'b1;
873
                        end
874 19 redbear
 
875 34 redbear
                        if(global_counter_transfer == 4'd13)
876
                        begin
877
                                hold_time_code <= 1'b0;
878
                        end
879
                        else
880
                        begin
881
                                hold_time_code <= 1'b0;
882
                        end
883
 
884 6 redbear
                        //
885 19 redbear
                        if(send_fct_now && !block_sum_fct_send)
886 6 redbear
                        begin
887 19 redbear
                                fct_flag <= fct_send;
888
                                block_sum_fct_send<= 1'b1;
889 6 redbear
                        end
890 19 redbear
                        else if(!send_fct_now)
891
                        begin
892
                                block_sum_fct_send<= 1'b0;
893
                        end
894
                        else
895
                                block_sum_fct_send <= block_sum_fct_send;
896 6 redbear
 
897 34 redbear
                        if(global_counter_transfer != 4'd13)
898 5 redbear
                        begin
899
                                global_counter_transfer <= global_counter_transfer + 4'd1;
900 25 redbear
                                timecode_s <= {timecode_ss[13:10],2'd2,timecode_tx_i[7:0]};
901 5 redbear
                        end
902
                        else
903
                        begin
904 34 redbear
                                ready_tx_data <= 1'b0;
905 13 redbear
                                last_timein_control_flag_tx <= timecode_tx_i;
906 5 redbear
                                global_counter_transfer <= 4'd0;
907 25 redbear
                                last_type  <= TIMEC;
908 5 redbear
                        end
909
                end
910
                else if(enable_n_char)
911
                begin
912 13 redbear
                        ready_tx_timecode <= 1'b0;
913 25 redbear
                        hold_null       <= 1'b0;
914
                        hold_fct        <= 1'b0;
915
                        //hold_data     <= 1'b0;
916
                        hold_time_code  <= 1'b0;
917
 
918 6 redbear
                        //
919 19 redbear
                        if(send_fct_now && !block_sum_fct_send)
920 6 redbear
                        begin
921 19 redbear
                                fct_flag <= fct_send;
922
                                block_sum_fct_send<= 1'b1;
923 6 redbear
                        end
924 19 redbear
                        else if(!send_fct_now)
925
                        begin
926
                                block_sum_fct_send<= 1'b0;
927
                        end
928
                        else
929
                                block_sum_fct_send <= block_sum_fct_send;
930 6 redbear
 
931 8 redbear
                        if(!data_tx_i[8])
932 5 redbear
                        begin
933 8 redbear
 
934
                                if(global_counter_transfer == 4'd9)
935
                                begin
936 34 redbear
                                        hold_data <= 1'b0;
937 8 redbear
                                        ready_tx_data <= 1'b1;
938
                                end
939 17 redbear
                                else
940
                                begin
941
                                        ready_tx_data <= 1'b0;
942 34 redbear
                                        hold_data <= 1'b1;
943 17 redbear
                                end
944 8 redbear
 
945
                                if(global_counter_transfer != 4'd9)
946
                                begin
947 34 redbear
 
948 8 redbear
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
949
                                        txdata_flagctrl_tx_last <= data_tx_i;
950 17 redbear
 
951
                                        if(gotfct_tx && !block_sum)
952
                                        begin
953
                                                fct_counter_receive <= fct_counter;
954
                                                block_sum<= 1'b1;
955
                                        end
956
                                        else if(!gotfct_tx)
957
                                        begin
958
                                                block_sum<= 1'b0;
959
                                        end
960
                                        else
961
                                                block_sum <= block_sum;
962 8 redbear
                                end
963
                                else
964
                                begin
965
                                        global_counter_transfer <= 4'd0;
966 15 redbear
                                        fct_counter_receive <= fct_counter_receive - 6'd1;
967 25 redbear
                                        last_type  <= DATA;
968 8 redbear
                                end
969
 
970 5 redbear
                        end
971 8 redbear
                        else if(data_tx_i[8])
972 5 redbear
                        begin
973 8 redbear
 
974
                                if(global_counter_transfer == 4'd3)
975
                                begin
976 34 redbear
                                        hold_data <= 1'b0;
977 8 redbear
                                        ready_tx_data <= 1'b1;
978
                                end
979 17 redbear
                                else
980
                                begin
981 34 redbear
                                        hold_data <= 1'b1;
982 17 redbear
                                        ready_tx_data <= 1'b0;
983
                                end
984 8 redbear
 
985
                                if(global_counter_transfer != 4'd3)
986
                                begin
987 34 redbear
 
988 8 redbear
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
989 34 redbear
                                        txdata_flagctrl_tx_last <= txdata_flagctrl_tx_last;
990 17 redbear
 
991
                                        if(gotfct_tx && !block_sum)
992
                                        begin
993
                                                fct_counter_receive <= fct_counter;
994
                                                block_sum<= 1'b1;
995
                                        end
996
                                        else if(!gotfct_tx)
997
                                        begin
998
                                                block_sum<= 1'b0;
999
                                        end
1000
                                        else
1001
                                                block_sum <= block_sum;
1002 8 redbear
                                end
1003
                                else
1004
                                begin
1005
                                        global_counter_transfer <= 4'd0;
1006 15 redbear
                                        fct_counter_receive <= fct_counter_receive - 6'd1;
1007 34 redbear
 
1008
                                        if(data_tx_i[1:0] == 2'b00)
1009
                                        begin
1010
                                                last_type  <=EOP;
1011
                                        end
1012
                                        else if(data_tx_i[1:0] == 2'b01)
1013
                                        begin
1014
                                                last_type  <=EEP;
1015
                                        end
1016 8 redbear
                                end
1017 5 redbear
                        end
1018 8 redbear
 
1019 5 redbear
                end
1020
 
1021
        end
1022
end
1023
 
1024
endmodule

powered by: WebSVN 2.1.0

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