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

Subversion Repositories spacewiresystemc

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

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 37 redbear
localparam [6:0] tx_spw_start              = 7'b0000000,
62
                 tx_spw_null               = 7'b0000001,
63
                 tx_spw_fct                = 7'b0000010,
64
                 tx_spw_null_c             = 7'b0000100,
65
                 tx_spw_fct_c              = 7'b0001000,
66
                 tx_spw_data_c             = 7'b0010000,
67 39 redbear
                 tx_spw_data_c_0           = 7'b0100000,
68
                 tx_spw_time_code_c        = 7'b1000000;
69 5 redbear
 
70
localparam [5:0] NULL     = 6'b000001,
71
                 FCT      = 6'b000010,
72
                 EOP      = 6'b000100,
73
                 EEP      = 6'b001000,
74
                 DATA     = 6'b010000,
75
                 TIMEC    = 6'b100000;
76
 
77 25 redbear
 
78
localparam [7:0] null_s = 8'b01110100;
79
localparam [2:0] fct_s  = 3'b100;
80
localparam [3:0] eop_s  = 4'b0101;
81
localparam [3:0] eep_s  = 4'b0110;
82
localparam [13:0] timecode_ss    = 14'b01110000000000;
83
 
84
 
85
 
86 37 redbear
        reg [6:0] state_tx;
87
        reg [6:0] next_state_tx;
88 5 redbear
 
89 37 redbear
        reg  [2:0] state_fct_send;
90
        reg  [2:0] next_state_fct_send;
91
 
92
        reg  [2:0] state_fct_receive;
93
        reg  [2:0] next_state_fct_receive;
94
 
95 38 redbear
        reg  [2:0] state_data_fifo;
96
        reg  [2:0] next_state_data_fifo;
97
 
98 5 redbear
        reg [13:0] timecode_s;
99
 
100
        reg [5:0]  last_type;
101
        reg [8:0]  txdata_flagctrl_tx_last;
102 36 redbear
        reg [8:0]  tx_data_in;
103 39 redbear
        reg [8:0]  tx_data_in_0;
104
        reg process_data;
105
        reg process_data_0;
106
        reg last_process_data;
107 38 redbear
 
108 5 redbear
        reg [7:0]  last_timein_control_flag_tx;
109 36 redbear
        reg [7:0]  tx_tcode_in;
110
        reg tcode_rdy_trnsp;
111 5 redbear
 
112
        reg [2:0] fct_send;
113
        reg [2:0] fct_flag;
114 6 redbear
 
115
        reg [5:0] fct_counter_receive;
116
 
117 37 redbear
        reg block_decrement;
118
        reg char_sent;
119
 
120
        reg fct_sent;
121
 
122 5 redbear
        reg last_tx_dout;
123
        reg last_tx_sout;
124
 
125 33 redbear
        reg tx_dout;
126
        reg tx_sout;
127
 
128
        reg tx_dout_null;
129
        reg tx_dout_fct;
130
        reg tx_dout_timecode;
131
        reg tx_dout_data;
132
 
133 5 redbear
        reg [3:0] global_counter_transfer;
134
 
135
 
136 13 redbear
 
137 39 redbear
always@(posedge pclk_tx or negedge enable_tx)
138 5 redbear
begin
139 39 redbear
        if(!enable_tx)
140
        begin
141
                tx_dout <= 1'b0;
142
        end
143
        else
144
        begin
145 37 redbear
                case(state_tx)
146
                tx_spw_start:
147
                begin
148 39 redbear
                        if(send_null_tx && enable_tx)
149
                        begin
150
                                tx_dout <= !(null_s[6]^null_s[0]^null_s[1]);
151
                        end
152
                        else
153
                        begin
154
                                tx_dout <= 1'b0;
155
                        end
156 37 redbear
                end
157
                tx_spw_null,tx_spw_null_c:
158
                begin
159
                         if(last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
160
                         begin
161 39 redbear
                                tx_dout <= !(null_s[6]^null_s[0]^null_s[1]);
162 37 redbear
                         end
163
                         else if(last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
164
                         begin
165 39 redbear
                                tx_dout <= !(null_s[6]^fct_s[0]^fct_s[1]);
166 37 redbear
                         end
167
                         else if(last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
168
                         begin
169 39 redbear
                                tx_dout <= !(null_s[6]^eop_s[0]^eop_s[1]);
170 37 redbear
                         end
171
                         else if(last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
172
                         begin
173 39 redbear
                                tx_dout <= !(null_s[6]^eep_s[0]^eep_s[1]);
174 37 redbear
                         end
175
                         else if(last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
176
                         begin
177 39 redbear
                                tx_dout <=  !(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]);
178 37 redbear
                         end
179
                         else if(last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
180
                         begin
181 39 redbear
                                tx_dout <=  !(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]);
182 37 redbear
                         end
183
                         else if(global_counter_transfer[3:0] == 4'd1)
184
                         begin
185 39 redbear
                                tx_dout <= null_s[6];
186 37 redbear
                         end
187
                         else if(global_counter_transfer[3:0] == 4'd2)
188
                         begin
189 39 redbear
                                tx_dout <= null_s[5];
190 37 redbear
                         end
191
                         else if(global_counter_transfer[3:0] == 4'd3)
192
                         begin
193 39 redbear
                                tx_dout <= null_s[4];
194 37 redbear
                         end
195
                         else if(global_counter_transfer[3:0] == 4'd4)
196
                         begin
197 39 redbear
                                tx_dout <= null_s[3];
198 37 redbear
                         end
199
                         else if(global_counter_transfer[3:0] == 4'd5)
200
                         begin
201 39 redbear
                                tx_dout <= null_s[2];
202 37 redbear
                         end
203
                         else if(global_counter_transfer[3:0] == 4'd6)
204
                         begin
205 39 redbear
                                tx_dout <= null_s[1];
206 37 redbear
                         end
207
                         else if(global_counter_transfer[3:0] == 4'd7)
208
                         begin
209 39 redbear
                                tx_dout <= null_s[0];
210 37 redbear
                         end
211
                end
212
                tx_spw_fct,tx_spw_fct_c:
213
                begin
214
                         if(last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
215
                         begin
216 39 redbear
                                tx_dout <= !(fct_s[2]^null_s[0]^null_s[1]);
217 37 redbear
                         end
218
                         else if(last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
219
                         begin
220 39 redbear
                                tx_dout <= !(fct_s[2]^fct_s[0]^fct_s[1]);
221 37 redbear
                         end
222
                         else if(last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
223
                         begin
224 39 redbear
                                tx_dout <= !(fct_s[2]^eop_s[0]^eop_s[1]);
225 37 redbear
                         end
226
                         else if(last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
227
                         begin
228 39 redbear
                                tx_dout <= !(fct_s[2]^eep_s[0]^eep_s[1]);
229 37 redbear
                         end
230
                         else if (last_type == DATA && global_counter_transfer[3:0] == 4'd0)
231
                         begin
232 39 redbear
                                tx_dout <= !(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]);
233 37 redbear
                         end
234
                         else if(last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
235
                         begin
236 39 redbear
                                tx_dout <= !(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]);
237 37 redbear
                         end
238
                         else if(global_counter_transfer[3:0] == 4'd1)
239
                         begin
240 39 redbear
                                tx_dout <= fct_s[2];
241 37 redbear
                         end
242
                         else if(global_counter_transfer[3:0] == 4'd2)
243
                         begin
244 39 redbear
                                tx_dout <= fct_s[1];
245 37 redbear
                         end
246
                         else if(global_counter_transfer[3:0] == 4'd3)
247
                         begin
248 39 redbear
                                tx_dout <= fct_s[0];
249 37 redbear
                         end
250
                end
251
                tx_spw_data_c:
252
                begin
253
                        if(!tx_data_in[8] && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
254
                         begin
255 39 redbear
                                tx_dout <= !(tx_data_in[8]^null_s[0]^null_s[1]);
256 37 redbear
                         end
257
                         else if(!tx_data_in[8] && last_type == FCT && global_counter_transfer[3:0] == 4'd0)
258
                         begin
259 39 redbear
                                tx_dout <= !(tx_data_in[8]^fct_s[0]^fct_s[1]);
260 37 redbear
                         end
261
                         else if(!tx_data_in[8] && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
262
                         begin
263 39 redbear
                                tx_dout <= !(tx_data_in[8]^eop_s[0]^eop_s[1]);
264 37 redbear
                         end
265
                         else if(!tx_data_in[8] && last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
266
                         begin
267 39 redbear
                                tx_dout <= !(tx_data_in[8]^eep_s[0]^eep_s[1]);
268 37 redbear
                         end
269
                         else if(!tx_data_in[8] && last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
270
                         begin
271 39 redbear
                                tx_dout <= !(tx_data_in[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]);
272 37 redbear
                         end
273
                         else if(!tx_data_in[8] && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
274
                         begin
275 39 redbear
                                tx_dout <= !(tx_data_in[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]);
276 37 redbear
                         end
277
                         else if(tx_data_in[8]  && tx_data_in[1:0] == 2'b00 && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
278
                         begin
279 39 redbear
                                tx_dout <= !(eop_s[2]^null_s[0]^null_s[1]);
280 37 redbear
                         end
281
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b00 && last_type == FCT   && global_counter_transfer[3:0] == 4'd0)
282
                         begin
283 39 redbear
                                tx_dout <= !(eop_s[2]^fct_s[0]^fct_s[1]);
284 37 redbear
                         end
285
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b00 && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
286
                         begin
287 39 redbear
                                tx_dout <= !(eop_s[2]^eop_s[0]^eop_s[1]);
288 37 redbear
                         end
289
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b00 && last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
290
                         begin
291 39 redbear
                                tx_dout <= !(eop_s[2]^eep_s[0]^eep_s[1]);
292 37 redbear
                         end
293
                         else if(tx_data_in[8]  && tx_data_in[1:0] == 2'b00 && last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
294
                         begin
295 39 redbear
                                tx_dout <= !(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]);
296 37 redbear
                         end
297
                         else if(tx_data_in[8]  && tx_data_in[1:0] == 2'b00 && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
298
                         begin
299 39 redbear
                                tx_dout <= !(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]);
300 37 redbear
                         end
301
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b01 && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
302
                         begin
303 39 redbear
                                tx_dout <= !(eep_s[2]^null_s[0]^null_s[1]);
304 37 redbear
                         end
305
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b01 && last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
306
                         begin
307 39 redbear
                                tx_dout <= !(eep_s[2]^fct_s[0]^fct_s[1]);
308 37 redbear
                         end
309
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b01 && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
310
                         begin
311 39 redbear
                                tx_dout <= !(eep_s[2]^eop_s[0]^eop_s[1]);
312 37 redbear
                         end
313
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b01 && last_type == EEP && global_counter_transfer[3:0] == 4'd0)
314
                         begin
315 39 redbear
                                tx_dout <= !(eep_s[2]^eep_s[0]^eep_s[1]);
316 37 redbear
                         end
317
                         else if(tx_data_in[8]  && tx_data_in[1:0] == 2'b01 && last_type == DATA && global_counter_transfer[3:0] == 4'd0)
318
                         begin
319 39 redbear
                                tx_dout <= !(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]);
320 37 redbear
                         end
321
                         else if(tx_data_in[8]  &&  tx_data_in[1:0] == 2'b01 && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
322
                         begin
323 39 redbear
                                tx_dout <= !(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]);
324 37 redbear
                         end
325
                         else if(!tx_data_in[8] &&  global_counter_transfer[3:0] == 4'd1)
326
                         begin
327 39 redbear
                                tx_dout <= tx_data_in[8];
328 37 redbear
                         end
329
                         else if(!tx_data_in[8] && global_counter_transfer[3:0] == 4'd2)
330
                         begin
331 39 redbear
                                tx_dout <= tx_data_in[0];
332 37 redbear
                         end
333
                         else if(!tx_data_in[8] &&  global_counter_transfer[3:0] == 4'd3)
334
                         begin
335 39 redbear
                                tx_dout <= tx_data_in[1];
336 37 redbear
                         end
337
                         else if(!tx_data_in[8] && global_counter_transfer[3:0] == 4'd4)
338
                         begin
339 39 redbear
                                tx_dout <= tx_data_in[2];
340 37 redbear
                         end
341
                         else if(!tx_data_in[8]  && global_counter_transfer[3:0] == 4'd5)
342
                         begin
343 39 redbear
                                tx_dout <= tx_data_in[3];
344 37 redbear
                         end
345
                         else if(!tx_data_in[8]  && global_counter_transfer[3:0] == 4'd6)
346
                         begin
347 39 redbear
                                tx_dout <= tx_data_in[4];
348 37 redbear
                         end
349
                         else if(!tx_data_in[8]  && global_counter_transfer[3:0] == 4'd7)
350
                         begin
351 39 redbear
                                tx_dout <= tx_data_in[5];
352 37 redbear
                         end
353
                         else if(!tx_data_in[8] &&  global_counter_transfer[3:0] == 4'd8)
354
                         begin
355 39 redbear
                                tx_dout <= tx_data_in[6];
356 37 redbear
                         end
357
                         else if(!tx_data_in[8] &&  global_counter_transfer[3:0] == 4'd9)
358
                         begin
359 39 redbear
                                tx_dout <= tx_data_in[7];
360 37 redbear
                         end
361
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd1)
362
                         begin
363 39 redbear
                                tx_dout <= eep_s[2];
364 37 redbear
                         end
365
                         else if( tx_data_in[8] && tx_data_in[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd2)
366
                         begin
367 39 redbear
                                tx_dout <= eep_s[1];
368 37 redbear
                         end
369
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd3)
370
                         begin
371 39 redbear
                                tx_dout <= eep_s[0];
372 37 redbear
                         end
373
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd1)
374
                         begin
375 39 redbear
                                tx_dout <= eop_s[2];
376 37 redbear
                         end
377
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd2)
378
                         begin
379 39 redbear
                                tx_dout <= eop_s[1];
380 37 redbear
                         end
381
                         else if(tx_data_in[8] && tx_data_in[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd3)
382
                         begin
383 39 redbear
                                tx_dout <= eop_s[0];
384 37 redbear
                         end
385
                end
386 39 redbear
                tx_spw_data_c_0:
387
                begin
388
                        if(!tx_data_in_0[8] && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
389
                         begin
390
                                tx_dout <= !(tx_data_in_0[8]^null_s[0]^null_s[1]);
391
                         end
392
                         else if(!tx_data_in_0[8] && last_type == FCT && global_counter_transfer[3:0] == 4'd0)
393
                         begin
394
                                tx_dout <= !(tx_data_in_0[8]^fct_s[0]^fct_s[1]);
395
                         end
396
                         else if(!tx_data_in_0[8] && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
397
                         begin
398
                                tx_dout <= !(tx_data_in_0[8]^eop_s[0]^eop_s[1]);
399
                         end
400
                         else if(!tx_data_in_0[8] && last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
401
                         begin
402
                                tx_dout <= !(tx_data_in_0[8]^eep_s[0]^eep_s[1]);
403
                         end
404
                         else if(!tx_data_in_0[8] && last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
405
                         begin
406
                                tx_dout <= !(tx_data_in_0[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]);
407
                         end
408
                         else if(!tx_data_in_0[8] && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
409
                         begin
410
                                tx_dout <= !(tx_data_in_0[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]);
411
                         end
412
                         else if(tx_data_in_0[8]  && tx_data_in_0[1:0] == 2'b00 && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
413
                         begin
414
                                tx_dout <= !(eop_s[2]^null_s[0]^null_s[1]);
415
                         end
416
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b00 && last_type == FCT   && global_counter_transfer[3:0] == 4'd0)
417
                         begin
418
                                tx_dout <= !(eop_s[2]^fct_s[0]^fct_s[1]);
419
                         end
420
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b00 && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
421
                         begin
422
                                tx_dout <= !(eop_s[2]^eop_s[0]^eop_s[1]);
423
                         end
424
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b00 && last_type == EEP  && global_counter_transfer[3:0] == 4'd0)
425
                         begin
426
                                tx_dout <= !(eop_s[2]^eep_s[0]^eep_s[1]);
427
                         end
428
                         else if(tx_data_in_0[8]  && tx_data_in_0[1:0] == 2'b00 && last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
429
                         begin
430
                                tx_dout <= !(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]);
431
                         end
432
                         else if(tx_data_in_0[8]  && tx_data_in_0[1:0] == 2'b00 && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
433
                         begin
434
                                tx_dout <= !(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]);
435
                         end
436
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
437
                         begin
438
                                tx_dout <= !(eep_s[2]^null_s[0]^null_s[1]);
439
                         end
440
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && last_type == FCT  && global_counter_transfer[3:0] == 4'd0)
441
                         begin
442
                                tx_dout <= !(eep_s[2]^fct_s[0]^fct_s[1]);
443
                         end
444
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && last_type == EOP  && global_counter_transfer[3:0] == 4'd0)
445
                         begin
446
                                tx_dout <= !(eep_s[2]^eop_s[0]^eop_s[1]);
447
                         end
448
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && last_type == EEP && global_counter_transfer[3:0] == 4'd0)
449
                         begin
450
                                tx_dout <= !(eep_s[2]^eep_s[0]^eep_s[1]);
451
                         end
452
                         else if(tx_data_in_0[8]  && tx_data_in_0[1:0] == 2'b01 && last_type == DATA && global_counter_transfer[3:0] == 4'd0)
453
                         begin
454
                                tx_dout <= !(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]);
455
                         end
456
                         else if(tx_data_in_0[8]  &&  tx_data_in_0[1:0] == 2'b01 && last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
457
                         begin
458
                                tx_dout <= !(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]);
459
                         end
460
                         else if(!tx_data_in_0[8] &&  global_counter_transfer[3:0] == 4'd1)
461
                         begin
462
                                tx_dout <= tx_data_in_0[8];
463
                         end
464
                         else if(!tx_data_in_0[8] && global_counter_transfer[3:0] == 4'd2)
465
                         begin
466
                                tx_dout <= tx_data_in_0[0];
467
                         end
468
                         else if(!tx_data_in_0[8] &&  global_counter_transfer[3:0] == 4'd3)
469
                         begin
470
                                tx_dout <= tx_data_in_0[1];
471
                         end
472
                         else if(!tx_data_in_0[8] && global_counter_transfer[3:0] == 4'd4)
473
                         begin
474
                                tx_dout <= tx_data_in_0[2];
475
                         end
476
                         else if(!tx_data_in_0[8]  && global_counter_transfer[3:0] == 4'd5)
477
                         begin
478
                                tx_dout <= tx_data_in_0[3];
479
                         end
480
                         else if(!tx_data_in_0[8]  && global_counter_transfer[3:0] == 4'd6)
481
                         begin
482
                                tx_dout <= tx_data_in_0[4];
483
                         end
484
                         else if(!tx_data_in_0[8]  && global_counter_transfer[3:0] == 4'd7)
485
                         begin
486
                                tx_dout <= tx_data_in_0[5];
487
                         end
488
                         else if(!tx_data_in_0[8] &&  global_counter_transfer[3:0] == 4'd8)
489
                         begin
490
                                tx_dout <= tx_data_in_0[6];
491
                         end
492
                         else if(!tx_data_in_0[8] &&  global_counter_transfer[3:0] == 4'd9)
493
                         begin
494
                                tx_dout <= tx_data_in_0[7];
495
                         end
496
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd1)
497
                         begin
498
                                tx_dout <= eep_s[2];
499
                         end
500
                         else if( tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd2)
501
                         begin
502
                                tx_dout <= eep_s[1];
503
                         end
504
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b01 && global_counter_transfer[3:0] == 4'd3)
505
                         begin
506
                                tx_dout <= eep_s[0];
507
                         end
508
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd1)
509
                         begin
510
                                tx_dout <= eop_s[2];
511
                         end
512
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd2)
513
                         begin
514
                                tx_dout <= eop_s[1];
515
                         end
516
                         else if(tx_data_in_0[8] && tx_data_in_0[1:0] == 2'b00 && global_counter_transfer[3:0] == 4'd3)
517
                         begin
518
                                tx_dout <= eop_s[0];
519
                         end
520
                end
521 37 redbear
                tx_spw_time_code_c:
522
                begin
523
                         if(last_type == NULL  && global_counter_transfer[3:0] == 4'd0)
524
                         begin
525 39 redbear
                                tx_dout <= !(timecode_s[12]^null_s[0]^null_s[1]);
526 37 redbear
                         end
527
                         else if(last_type == FCT   && global_counter_transfer[3:0] == 4'd0)
528
                         begin
529 39 redbear
                                tx_dout <= !(timecode_s[12]^fct_s[0]^fct_s[1]);
530 37 redbear
                         end
531
                         else if (last_type == EOP   && global_counter_transfer[3:0] == 4'd0)
532
                         begin
533 39 redbear
                                tx_dout <= !(timecode_s[12]^eop_s[0]^eop_s[1]);
534 37 redbear
                         end
535
                         else if( last_type == EEP   && global_counter_transfer[3:0] == 4'd0)
536
                         begin
537 39 redbear
                                tx_dout <= !(timecode_s[12]^eep_s[0]^eep_s[1]);
538 37 redbear
                         end
539
                         else if( last_type == DATA  && global_counter_transfer[3:0] == 4'd0)
540
                         begin
541 39 redbear
                                tx_dout <= !(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]);
542 37 redbear
                         end
543
                         else if( last_type == TIMEC && global_counter_transfer[3:0] == 4'd0)
544
                         begin
545 39 redbear
                                tx_dout <= !(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]);
546 37 redbear
                         end
547
                         else if( global_counter_transfer[3:0] == 4'd1)
548
                         begin
549 39 redbear
                                tx_dout <= timecode_s[12];
550 37 redbear
                         end
551
                         else if( global_counter_transfer[3:0] == 4'd2)
552
                         begin
553 39 redbear
                                tx_dout <= timecode_s[11];
554 37 redbear
                         end
555
                         else if( global_counter_transfer[3:0] == 4'd3)
556
                         begin
557 39 redbear
                                tx_dout <= timecode_s[10];
558 37 redbear
                         end
559
                         else if( global_counter_transfer[3:0] == 4'd4)
560
                         begin
561 39 redbear
                                tx_dout <= timecode_s[9];
562 37 redbear
                         end
563
                         else if( global_counter_transfer[3:0] == 4'd5)
564
                         begin
565 39 redbear
                                tx_dout <= timecode_s[8];
566 37 redbear
                         end
567
                         else if( global_counter_transfer[3:0] == 4'd6)
568
                         begin
569 39 redbear
                                tx_dout <= timecode_s[0];
570 37 redbear
                         end
571
                         else if( global_counter_transfer[3:0] == 4'd7)
572
                         begin
573 39 redbear
                                tx_dout <= timecode_s[1];
574 37 redbear
                         end
575
                         else if( global_counter_transfer[3:0] == 4'd8)
576
                         begin
577 39 redbear
                                tx_dout <= timecode_s[2];
578 37 redbear
                         end
579
                         else if(global_counter_transfer[3:0] == 4'd9)
580
                         begin
581 39 redbear
                                tx_dout <= timecode_s[3];
582 37 redbear
                         end
583
                         else if(global_counter_transfer[3:0] == 4'd10)
584
                         begin
585 39 redbear
                                tx_dout <= timecode_s[4];
586 37 redbear
                         end
587
                         else if(global_counter_transfer[3:0] == 4'd11)
588
                         begin
589 39 redbear
                                tx_dout <= timecode_s[5];
590 37 redbear
                         end
591
                         else if( global_counter_transfer[3:0] == 4'd12)
592
                         begin
593 39 redbear
                                tx_dout <= timecode_s[6];
594 37 redbear
                         end
595
                         else if(global_counter_transfer[3:0] == 4'd13)
596
                         begin
597 39 redbear
                                tx_dout <= timecode_s[7];
598 37 redbear
                         end
599
                end
600
                default:
601
                begin
602
                end
603
                endcase
604 39 redbear
        end
605 5 redbear
end
606 33 redbear
 
607 5 redbear
//strobe
608
always@(*)
609
begin
610
 
611 36 redbear
        tx_sout = last_tx_sout;
612
 
613 37 redbear
        if(tx_dout == last_tx_dout)
614 5 redbear
        begin
615
                tx_sout = !last_tx_sout;
616
        end
617 37 redbear
        else if(tx_dout != last_tx_dout)
618 5 redbear
        begin
619
                tx_sout = last_tx_sout;
620 33 redbear
        end
621 5 redbear
end
622
 
623 17 redbear
always@(*)
624 5 redbear
begin
625 37 redbear
        next_state_fct_send = state_fct_send;
626 17 redbear
 
627 37 redbear
        case(state_fct_send)
628
        3'd0:
629 5 redbear
        begin
630 37 redbear
                if(send_fct_now)
631 15 redbear
                begin
632 37 redbear
                        next_state_fct_send = 3'd1;
633 17 redbear
                end
634 37 redbear
                else if(fct_sent)
635 17 redbear
                begin
636 37 redbear
                        next_state_fct_send = 3'd3;
637 15 redbear
                end
638 37 redbear
                else
639
                        next_state_fct_send = 3'd0;
640 5 redbear
        end
641 37 redbear
        3'd1:
642
        begin
643 39 redbear
                next_state_fct_send = 3'd2;
644 37 redbear
        end
645
        3'd2:
646
        begin
647
                if(send_fct_now)
648
                begin
649
                        next_state_fct_send = 3'd2;
650
                end
651
                else
652
                begin
653
                        next_state_fct_send = 3'd0;
654
                end
655
        end
656
        3'd3:
657
        begin
658 39 redbear
                next_state_fct_send = 3'd4;
659 37 redbear
        end
660
        3'd4:
661
        begin
662
                if(fct_sent)
663
                begin
664
                        next_state_fct_send = 3'd4;
665
                end
666
                else
667
                begin
668
                        next_state_fct_send = 3'd0;
669
                end
670
        end
671
        default:
672
        begin
673
                next_state_fct_send = 3'd0;
674
        end
675
        endcase
676 5 redbear
end
677
 
678 37 redbear
always@(posedge pclk_tx or negedge enable_tx)
679 5 redbear
begin
680 37 redbear
        if(!enable_tx)
681
        begin
682
                fct_flag <= 3'd7;
683
                state_fct_send<= 3'd0;
684
        end
685
        else
686
        begin
687
                state_fct_send <= next_state_fct_send;
688 5 redbear
 
689 37 redbear
                case(state_fct_send)
690
                3'd0:
691 19 redbear
                begin
692 37 redbear
                        fct_flag <= fct_flag;
693 6 redbear
                end
694 37 redbear
                3'd1:
695 6 redbear
                begin
696 39 redbear
                        if(fct_flag < 3'd7)
697 37 redbear
                                fct_flag <= fct_flag + 3'd1;
698 19 redbear
                        else
699 37 redbear
                                fct_flag <= fct_flag;
700 6 redbear
                end
701 37 redbear
                3'd2:
702
                begin
703
                        fct_flag <= fct_flag;
704
                end
705
                3'd3:
706
                begin
707 39 redbear
                        if(fct_flag > 3'd0)
708 37 redbear
                                fct_flag <= fct_flag - 3'd1;
709
                        else
710
                                fct_flag <= fct_flag;
711
                end
712
                3'd4:
713
                begin
714
                        fct_flag <= fct_flag;
715
                end
716
                default:
717
                begin
718
                        fct_flag <= fct_flag;
719
                end
720
                endcase
721 5 redbear
        end
722
end
723
 
724 37 redbear
 
725 36 redbear
always@(*)
726
begin
727 37 redbear
        next_state_fct_receive = state_fct_receive;
728 5 redbear
 
729 37 redbear
        case(state_fct_receive)
730
        3'd0:
731 36 redbear
        begin
732 37 redbear
                if(gotfct_tx)
733
                begin
734
                        next_state_fct_receive = 3'd1;
735
                end
736
                else if(char_sent)
737
                begin
738
                        next_state_fct_receive = 3'd3;
739
                end
740
                else
741
                        next_state_fct_receive = 3'd0;
742 36 redbear
        end
743 37 redbear
        3'd1:
744 36 redbear
        begin
745 39 redbear
 
746
                next_state_fct_receive = 3'd2;
747 36 redbear
        end
748 37 redbear
        3'd2:
749 36 redbear
        begin
750 37 redbear
                if(gotfct_tx)
751
                begin
752
                        next_state_fct_receive = 3'd2;
753
                end
754
                else
755
                begin
756
                        next_state_fct_receive = 3'd0;
757
                end
758 36 redbear
        end
759 37 redbear
        3'd3:
760 36 redbear
        begin
761 39 redbear
                next_state_fct_receive = 3'd4;
762 36 redbear
        end
763 37 redbear
        3'd4:
764
        begin
765
                if(char_sent)
766
                begin
767
                        next_state_fct_receive = 3'd4;
768
                end
769
                else
770
                begin
771
                        next_state_fct_receive = 3'd0;
772
                end
773
        end
774
        default:
775
        begin
776
                next_state_fct_receive = 3'd0;
777
        end
778
        endcase
779 36 redbear
end
780
 
781 37 redbear
 
782
always@(posedge pclk_tx or negedge enable_tx)
783 5 redbear
begin
784 37 redbear
        if(!enable_tx)
785
        begin
786
                fct_counter_receive<= 6'd0;
787
                state_fct_receive <= 3'd0;
788
        end
789
        else
790
        begin
791 5 redbear
 
792 37 redbear
                state_fct_receive <= next_state_fct_receive;
793 5 redbear
 
794 37 redbear
                case(state_fct_receive)
795
                3'd0:
796
                begin
797
                        fct_counter_receive <= fct_counter_receive;
798
                end
799
                3'd1:
800
                begin
801 39 redbear
                        if(fct_counter_receive < 6'd48)
802 37 redbear
                        begin
803 39 redbear
                                fct_counter_receive <= fct_counter_receive + 6'd8;
804 37 redbear
                        end
805
                        else
806 39 redbear
                        begin
807
                                fct_counter_receive <= fct_counter_receive + 6'd7;
808
                        end
809 37 redbear
                end
810
                3'd2:
811
                begin
812
                        fct_counter_receive <= fct_counter_receive;
813
                end
814
                3'd3:
815
                begin
816 39 redbear
                        if(fct_counter_receive == 6'd0)
817
                                fct_counter_receive <= fct_counter_receive;
818 37 redbear
                        else
819 39 redbear
                                fct_counter_receive <= fct_counter_receive - 6'd1;
820 37 redbear
                end
821
                3'd4:
822
                begin
823
                        fct_counter_receive <= fct_counter_receive;
824
                end
825
                default:
826
                begin
827
                        fct_counter_receive <= fct_counter_receive;
828
                end
829
                endcase
830
        end
831
end
832 5 redbear
 
833 37 redbear
always@(*)
834
begin
835 17 redbear
        next_state_tx = state_tx;
836
 
837 5 redbear
        case(state_tx)
838
        tx_spw_start:
839
        begin
840
                if(send_null_tx && enable_tx)
841
                begin
842 36 redbear
                        next_state_tx = tx_spw_null;
843 5 redbear
                end
844
                else
845
                begin
846
                        next_state_tx = tx_spw_start;
847
                end
848
        end
849
        tx_spw_null:
850
        begin
851 37 redbear
                if(send_null_tx && send_fct_tx && enable_tx)
852 5 redbear
                begin
853 37 redbear
                        if(global_counter_transfer == 4'd7)
854
                                next_state_tx = tx_spw_fct;
855 38 redbear
                        else
856
                                next_state_tx = tx_spw_null;
857 5 redbear
                end
858 37 redbear
                else
859
                        next_state_tx = tx_spw_null;
860 5 redbear
        end
861 37 redbear
        tx_spw_fct:
862 5 redbear
        begin
863 38 redbear
                if(send_fct_tx && global_counter_transfer == 4'd3)
864 5 redbear
                begin
865 38 redbear
                        if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
866 5 redbear
                        begin
867 38 redbear
                                next_state_tx = tx_spw_time_code_c;
868
                        end
869
                        else if(fct_flag > 3'd0 && !send_fct_now)
870
                        begin
871
                                next_state_tx = tx_spw_fct;
872 5 redbear
                        end
873 38 redbear
                        else
874
                        begin
875
                                next_state_tx = tx_spw_null_c;
876
                        end
877 5 redbear
                end
878 38 redbear
                else
879
                        next_state_tx = tx_spw_fct;
880 5 redbear
        end
881 37 redbear
        tx_spw_null_c:
882 5 redbear
        begin
883 37 redbear
                if(global_counter_transfer == 4'd7)
884 5 redbear
                begin
885 37 redbear
                        if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
886
                        begin
887
                                next_state_tx = tx_spw_time_code_c;
888
                        end
889
                        else if(fct_flag > 3'd0 && !send_fct_now)
890
                        begin
891
                                next_state_tx = tx_spw_fct_c;
892
                        end
893 39 redbear
                        else if(process_data && !gotfct_tx && fct_counter_receive > 6'd0)
894 37 redbear
                        begin
895
                                next_state_tx = tx_spw_data_c;
896
                        end
897 39 redbear
                        else if(process_data_0 && !gotfct_tx && fct_counter_receive > 6'd0)
898
                        begin
899
                                next_state_tx = tx_spw_data_c_0;
900
                        end
901 37 redbear
                        else
902
                        begin
903
                                next_state_tx = tx_spw_null_c;
904
                        end
905
                end
906
                else
907 5 redbear
                begin
908 37 redbear
                        next_state_tx = tx_spw_null_c;
909 5 redbear
                end
910 37 redbear
        end
911
        tx_spw_fct_c:
912
        begin
913
                if(global_counter_transfer == 4'd3)
914 5 redbear
                begin
915 37 redbear
                        if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
916
                        begin
917
                                next_state_tx = tx_spw_time_code_c;
918
                        end
919
                        else
920
                        begin
921
                                next_state_tx = tx_spw_null_c;
922
                        end
923 5 redbear
                end
924 37 redbear
                else
925 8 redbear
                begin
926 37 redbear
                        next_state_tx = tx_spw_fct_c;
927 8 redbear
                end
928 5 redbear
        end
929 37 redbear
        tx_spw_data_c:
930
        begin
931
 
932
                if(!tx_data_in[8])
933
                begin
934
                        if(global_counter_transfer == 4'd9)
935
                        begin
936
                                if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
937
                                begin
938
                                        next_state_tx = tx_spw_time_code_c;
939
                                end
940
                                else if(fct_flag > 3'd0 && !send_fct_now)
941
                                begin
942
                                        next_state_tx = tx_spw_fct_c;
943
                                end
944 39 redbear
                                else if(process_data_0 && !gotfct_tx && fct_counter_receive > 6'd0)
945 38 redbear
                                begin
946 39 redbear
                                        next_state_tx = tx_spw_data_c_0;
947 38 redbear
                                end
948 37 redbear
                                else
949
                                begin
950
                                        next_state_tx = tx_spw_null_c;
951
                                end
952
                        end
953
                        else
954
                                next_state_tx = tx_spw_data_c;
955
                end
956
                else if(tx_data_in[8])
957
                begin
958
                        if(global_counter_transfer == 4'd3)
959
                        begin
960
                                if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
961
                                begin
962
                                        next_state_tx = tx_spw_time_code_c;
963
                                end
964
                                else if(fct_flag > 3'd0 && !send_fct_now)
965
                                begin
966
                                        next_state_tx = tx_spw_fct_c;
967
                                end
968
                                else
969
                                begin
970
                                        next_state_tx = tx_spw_null_c;
971
                                end
972
                        end
973
                        else
974
                                next_state_tx = tx_spw_data_c;
975
                end
976
 
977
 
978
        end
979 39 redbear
        tx_spw_data_c_0:
980
        begin
981
 
982
                if(!tx_data_in_0[8])
983
                begin
984
                        if(global_counter_transfer == 4'd9)
985
                        begin
986
                                if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
987
                                begin
988
                                        next_state_tx = tx_spw_time_code_c;
989
                                end
990
                                else if(fct_flag > 3'd0 && !send_fct_now)
991
                                begin
992
                                        next_state_tx = tx_spw_fct_c;
993
                                end
994
                                else if(process_data && !gotfct_tx && fct_counter_receive > 6'd0)
995
                                begin
996
                                        next_state_tx = tx_spw_data_c;
997
                                end
998
                                else
999
                                begin
1000
                                        next_state_tx = tx_spw_null_c;
1001
                                end
1002
                        end
1003
                        else
1004
                                next_state_tx = tx_spw_data_c_0;
1005
                end
1006
                else if(tx_data_in_0[8])
1007
                begin
1008
                        if(global_counter_transfer == 4'd3)
1009
                        begin
1010
                                if(tickin_tx && !ready_tx_timecode && tcode_rdy_trnsp)
1011
                                begin
1012
                                        next_state_tx = tx_spw_time_code_c;
1013
                                end
1014
                                else if(fct_flag > 3'd0 && !send_fct_now)
1015
                                begin
1016
                                        next_state_tx = tx_spw_fct_c;
1017
                                end
1018
                                else
1019
                                begin
1020
                                        next_state_tx = tx_spw_null_c;
1021
                                end
1022
                        end
1023
                        else
1024
                                next_state_tx = tx_spw_data_c_0;
1025
                end
1026
 
1027
 
1028
        end
1029 37 redbear
        tx_spw_time_code_c:
1030
        begin
1031
                if(global_counter_transfer == 4'd13)
1032
                begin
1033
                        if(fct_flag > 3'd0 && !send_fct_now)
1034
                        begin
1035
                                next_state_tx = tx_spw_fct_c;
1036
                        end
1037 39 redbear
                        else if(process_data && !gotfct_tx && fct_counter_receive > 6'd0 )
1038 37 redbear
                        begin
1039
                                next_state_tx = tx_spw_data_c;
1040
                        end
1041 39 redbear
                        else if(process_data_0 && !gotfct_tx && fct_counter_receive > 6'd0)
1042
                        begin
1043
                                next_state_tx = tx_spw_data_c_0;
1044
                        end
1045 37 redbear
                        else
1046
                        begin
1047
                                next_state_tx = tx_spw_null_c;
1048
                        end
1049
                end
1050
                else
1051
                begin
1052
                        next_state_tx = tx_spw_time_code_c;
1053
                end
1054
        end
1055
        default:
1056
        begin
1057
                next_state_tx = tx_spw_start;
1058
        end
1059 5 redbear
        endcase
1060
end
1061
 
1062 33 redbear
 
1063 25 redbear
always@(posedge pclk_tx or negedge enable_tx)
1064 5 redbear
begin
1065
        if(!enable_tx)
1066
        begin
1067 25 redbear
 
1068
                timecode_s    <= 14'b01110000000000;
1069 6 redbear
 
1070 13 redbear
                ready_tx_data     <= 1'b0;
1071
                ready_tx_timecode <= 1'b0;
1072 8 redbear
 
1073 5 redbear
                last_type  <= NULL;
1074
 
1075
                global_counter_transfer <= 4'd0;
1076 38 redbear
                txdata_flagctrl_tx_last <= 9'd0;
1077
                tx_data_in <= 9'd0;
1078 39 redbear
                tx_data_in_0 <= 9'd0;
1079
 
1080
                process_data   <= 1'b0;
1081
                process_data_0 <= 1'b0;
1082
 
1083 5 redbear
                last_timein_control_flag_tx <= 8'd0;
1084 6 redbear
 
1085 37 redbear
                char_sent<= 1'b0;
1086
                fct_sent <= 1'b0;
1087 6 redbear
 
1088 5 redbear
                last_tx_dout      <= 1'b0;
1089
                last_tx_sout      <= 1'b0;
1090 33 redbear
 
1091 5 redbear
                state_tx <= tx_spw_start;
1092 17 redbear
 
1093 36 redbear
                tx_dout_e <= 1'b0;
1094
                tx_sout_e <= 1'b0;
1095
 
1096
                tx_tcode_in     <= 8'd0;
1097
                tcode_rdy_trnsp <= 1'b0;
1098
 
1099 5 redbear
        end
1100
        else
1101
        begin
1102
                state_tx <= next_state_tx;
1103 36 redbear
 
1104 37 redbear
                case(state_tx)
1105
                tx_spw_start:
1106
                begin
1107 39 redbear
 
1108
                        if(send_null_tx && enable_tx)
1109
                        begin
1110
                                global_counter_transfer <= global_counter_transfer + 4'd1;
1111
                        end
1112
                        else
1113
                        begin
1114
                                global_counter_transfer <= 4'd0;
1115
                        end
1116
 
1117 37 redbear
                end
1118
                tx_spw_null:
1119
                begin
1120 5 redbear
 
1121 37 redbear
                        last_tx_dout <= tx_dout;
1122
                        last_tx_sout <= tx_sout;
1123 36 redbear
 
1124 39 redbear
                        tx_dout_e <= tx_dout;
1125
                        tx_sout_e <= tx_sout;
1126 6 redbear
 
1127 37 redbear
 
1128 38 redbear
                        if(tickin_tx && global_counter_transfer == 4'd5)
1129 36 redbear
                        begin
1130
                                tx_tcode_in <= timecode_tx_i;
1131
                                tcode_rdy_trnsp <= 1'b1;
1132
                        end
1133
                        else
1134
                                tx_tcode_in <= tx_tcode_in;
1135
 
1136 34 redbear
 
1137 36 redbear
                        if(global_counter_transfer == 4'd7)
1138 5 redbear
                        begin
1139 36 redbear
                                last_type  <= NULL;
1140
                                global_counter_transfer <= 4'd0;
1141 5 redbear
                        end
1142 38 redbear
                        else
1143 5 redbear
                        begin
1144 36 redbear
                                last_type  <= last_type;
1145 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
1146
                        end
1147
                end
1148 37 redbear
                tx_spw_fct:
1149 5 redbear
                begin
1150 8 redbear
 
1151 37 redbear
                        last_tx_dout <= tx_dout;
1152
                        last_tx_sout <= tx_sout;
1153 25 redbear
 
1154 39 redbear
                        tx_dout_e <= tx_dout;
1155
                        tx_sout_e <= tx_sout;
1156 6 redbear
 
1157 34 redbear
                        if(global_counter_transfer == 4'd3)
1158
                        begin
1159 36 redbear
                                last_type  <=FCT;
1160
                                global_counter_transfer <= 4'd0;
1161 37 redbear
                                fct_sent <= 1'b0;
1162 34 redbear
                        end
1163
                        else
1164
                        begin
1165 37 redbear
                                if(fct_flag > 3'd0)
1166
                                        fct_sent <=  1'b1;
1167 19 redbear
                                else
1168 37 redbear
                                        fct_sent <= fct_sent;
1169 38 redbear
 
1170 36 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
1171 5 redbear
                        end
1172
                end
1173 37 redbear
                tx_spw_null_c:
1174 5 redbear
                begin
1175 33 redbear
 
1176 37 redbear
                        last_tx_dout <= tx_dout;
1177
                        last_tx_sout <= tx_sout;
1178
 
1179 39 redbear
                        tx_dout_e <= tx_dout;
1180
                        tx_sout_e <= tx_sout;
1181
 
1182 38 redbear
                        if(global_counter_transfer == 4'd7)
1183 36 redbear
                        begin
1184 39 redbear
                                fct_sent <=  1'b0;
1185 38 redbear
                                last_type  <= NULL;
1186
                                global_counter_transfer <= 4'd0;
1187 17 redbear
                        end
1188
                        else
1189 13 redbear
                        begin
1190 39 redbear
 
1191
                                if(process_data_0)
1192
                                begin
1193
                                        process_data_0 <= process_data_0;
1194
                                end
1195
                                else
1196
                                begin
1197
                                        if(txwrite_tx)
1198
                                        begin
1199
                                                tx_data_in     <= data_tx_i;
1200
                                                process_data   <= 1'b1;
1201
                                        end
1202
                                        else
1203
                                        begin
1204
                                                tx_data_in     <= tx_data_in;
1205
                                                process_data   <= 1'b0;
1206
                                        end
1207
                                        process_data_0 <= 1'b0;
1208
                                end
1209
 
1210 37 redbear
                                char_sent <= 1'b0;
1211
                                fct_sent <=  1'b0;
1212
                                ready_tx_timecode <= 1'b0;
1213
                                last_type  <= last_type;
1214
                                global_counter_transfer <= global_counter_transfer + 4'd1;
1215 19 redbear
                        end
1216 37 redbear
                end
1217
                tx_spw_fct_c:
1218
                begin
1219 6 redbear
 
1220 37 redbear
                        last_tx_dout <= tx_dout;
1221
                        last_tx_sout <= tx_sout;
1222
 
1223 39 redbear
                        tx_dout_e <= tx_dout;
1224
                        tx_sout_e <= tx_sout;
1225 37 redbear
 
1226
                        if(global_counter_transfer == 4'd3)
1227
                        begin
1228
                                char_sent <= 1'b0;
1229
                                last_type  <=FCT;
1230
                                fct_sent <=  1'b0;
1231
                                global_counter_transfer <= 4'd0;
1232 5 redbear
                        end
1233
                        else
1234
                        begin
1235 39 redbear
                                char_sent <= 1'b0;
1236
                                process_data   <= process_data;
1237
                                process_data_0 <= process_data_0;
1238 37 redbear
 
1239 39 redbear
                                fct_sent <=  1'b1;
1240
 
1241 37 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
1242 5 redbear
                        end
1243
                end
1244 37 redbear
                tx_spw_data_c:
1245 5 redbear
                begin
1246 6 redbear
 
1247 37 redbear
                        last_tx_dout <= tx_dout;
1248
                        last_tx_sout <= tx_sout;
1249
 
1250 39 redbear
                        tx_dout_e <= tx_dout;
1251
                        tx_sout_e <= tx_sout;
1252 37 redbear
 
1253 36 redbear
                        if(!tx_data_in[8])
1254 5 redbear
                        begin
1255 8 redbear
 
1256
                                if(global_counter_transfer == 4'd9)
1257
                                begin
1258 39 redbear
                                        fct_sent <=  1'b0;
1259 37 redbear
                                        char_sent <= 1'b1;
1260 36 redbear
                                        last_type  <= DATA;
1261
                                        global_counter_transfer <= 4'd0;
1262 8 redbear
                                end
1263 17 redbear
                                else
1264
                                begin
1265 38 redbear
 
1266 39 redbear
                                        if(global_counter_transfer < 4'd3)
1267 38 redbear
                                        begin
1268 39 redbear
                                                ready_tx_data <= 1'b1;
1269 38 redbear
                                        end
1270
                                        else
1271 39 redbear
                                        begin
1272
                                                fct_sent <=  1'b0;
1273
                                                ready_tx_data <= 1'b0;
1274 38 redbear
 
1275 39 redbear
                                                if(global_counter_transfer == 4'd3)
1276
                                                begin
1277
                                                        txdata_flagctrl_tx_last <= tx_data_in;
1278
                                                end
1279
                                                else
1280
                                                        txdata_flagctrl_tx_last <= txdata_flagctrl_tx_last;
1281 38 redbear
 
1282 39 redbear
                                                if(txwrite_tx)
1283
                                                begin
1284
                                                        tx_data_in_0 <= data_tx_i;
1285
                                                        process_data_0 <= 1'b1;
1286
                                                end
1287
                                                else
1288
                                                begin
1289
                                                        tx_data_in_0 <= tx_data_in_0;
1290
                                                        process_data_0 <= 1'b0;
1291
                                                end
1292
                                        end
1293
 
1294
                                        process_data <= 1'b0;
1295
                                        char_sent <= 1'b0;
1296
                                        ready_tx_timecode <= 1'b0;
1297
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
1298
 
1299
                                 end
1300
 
1301
                        end
1302
                        else if(tx_data_in[8])
1303
                        begin
1304
 
1305
                                if(global_counter_transfer == 4'd3)
1306
                                begin
1307
                                        char_sent <= 1'b1;
1308
                                        fct_sent <=  1'b0;
1309
                                        if(tx_data_in[1:0] == 2'b00)
1310 38 redbear
                                        begin
1311 39 redbear
                                                last_type  <=EOP;
1312
                                        end
1313
                                        else if(tx_data_in[1:0] == 2'b01)
1314
                                        begin
1315
                                                last_type  <=EEP;
1316
                                        end
1317
 
1318
                                        ready_tx_data <= 1'b0;
1319
                                        global_counter_transfer <= 4'd0;
1320
                                end
1321
                                else
1322
                                begin
1323
                                        fct_sent <=  1'b0;
1324
                                        char_sent <= 1'b0;
1325
                                        process_data   <= 1'b0;
1326
                                        process_data_0 <= 1'b0;
1327
                                        txdata_flagctrl_tx_last <= txdata_flagctrl_tx_last;
1328
                                        ready_tx_data <= 1'b1;
1329
                                        ready_tx_timecode <= 1'b0;
1330
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
1331
                                end
1332
                        end
1333
 
1334
                end
1335
                tx_spw_data_c_0:
1336
                begin
1337
 
1338
                        last_tx_dout <= tx_dout;
1339
                        last_tx_sout <= tx_sout;
1340
 
1341
                        tx_dout_e <= tx_dout;
1342
                        tx_sout_e <= tx_sout;
1343
 
1344
                        if(!tx_data_in_0[8])
1345
                        begin
1346
 
1347
                                if(global_counter_transfer == 4'd9)
1348
                                begin
1349
                                        fct_sent <=  1'b0;
1350
                                        char_sent <= 1'b1;
1351
                                        last_type  <= DATA;
1352
                                        global_counter_transfer <= 4'd0;
1353
                                end
1354
                                else
1355
                                begin
1356
 
1357
                                        if(global_counter_transfer < 4'd3)
1358
                                        begin
1359 38 redbear
                                                ready_tx_data <= 1'b1;
1360
                                        end
1361
                                        else
1362 39 redbear
                                        begin
1363 38 redbear
                                                ready_tx_data <= 1'b0;
1364
 
1365 39 redbear
                                                if(global_counter_transfer == 4'd3)
1366
                                                begin
1367
                                                        txdata_flagctrl_tx_last <= tx_data_in_0;
1368
                                                end
1369
                                                else
1370
                                                        txdata_flagctrl_tx_last <= txdata_flagctrl_tx_last;
1371
 
1372
                                                if(txwrite_tx)
1373
                                                begin
1374
                                                        tx_data_in     <= data_tx_i;
1375
                                                        process_data   <= 1'b1;
1376
                                                end
1377
                                                else
1378
                                                begin
1379
                                                        tx_data_in     <= tx_data_in;
1380
                                                        process_data   <= 1'b0;
1381
                                                end
1382
                                        end
1383
 
1384
                                        fct_sent <=  1'b0;
1385
                                        process_data_0 <= 1'b0;
1386 38 redbear
                                        char_sent <= 1'b0;
1387 36 redbear
                                        ready_tx_timecode <= 1'b0;
1388
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
1389 8 redbear
 
1390 38 redbear
                                 end
1391 36 redbear
 
1392 5 redbear
                        end
1393 39 redbear
                        else if(tx_data_in_0[8])
1394 5 redbear
                        begin
1395 8 redbear
 
1396
                                if(global_counter_transfer == 4'd3)
1397
                                begin
1398 39 redbear
                                        fct_sent <=  1'b0;
1399 37 redbear
                                        char_sent <= 1'b1;
1400 36 redbear
 
1401 39 redbear
                                        if(tx_data_in_0[1:0] == 2'b00)
1402 36 redbear
                                        begin
1403
                                                last_type  <=EOP;
1404
                                        end
1405 39 redbear
                                        else if(tx_data_in_0[1:0] == 2'b01)
1406 36 redbear
                                        begin
1407
                                                last_type  <=EEP;
1408
                                        end
1409
 
1410 38 redbear
                                        ready_tx_data <= 1'b0;
1411 36 redbear
                                        global_counter_transfer <= 4'd0;
1412 8 redbear
                                end
1413 17 redbear
                                else
1414
                                begin
1415 39 redbear
                                        fct_sent <=  1'b0;
1416
                                        process_data   <= 1'b0;
1417
                                        process_data_0 <= 1'b0;
1418 34 redbear
                                        txdata_flagctrl_tx_last <= txdata_flagctrl_tx_last;
1419 38 redbear
                                        ready_tx_data <= 1'b1;
1420 36 redbear
                                        ready_tx_timecode <= 1'b0;
1421 39 redbear
                                        char_sent <= 1'b0;
1422 36 redbear
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
1423 8 redbear
                                end
1424 5 redbear
                        end
1425 8 redbear
 
1426 5 redbear
                end
1427 37 redbear
                tx_spw_time_code_c:
1428
                begin
1429 39 redbear
 
1430 37 redbear
                        last_tx_dout <= tx_dout;
1431
                        last_tx_sout <= tx_sout;
1432
 
1433 39 redbear
                        tx_dout_e <= tx_dout;
1434
                        tx_sout_e <= tx_sout;
1435
 
1436
 
1437 37 redbear
                        if(global_counter_transfer == 4'd13)
1438
                        begin
1439 39 redbear
                                fct_sent <=  1'b0;
1440 37 redbear
                                ready_tx_timecode <= 1'b1;
1441
                                global_counter_transfer <= 4'd0;
1442
                        end
1443
                        else
1444
                        begin
1445 39 redbear
                                if(process_data_0)
1446
                                begin
1447
 
1448
                                        process_data_0 <= process_data_0;
1449
                                end
1450
                                else
1451
                                begin
1452
                                        if(txwrite_tx)
1453
                                        begin
1454
                                                tx_data_in     <= data_tx_i;
1455
                                                process_data   <= 1'b1;
1456
                                        end
1457
                                        else
1458
                                        begin
1459
                                                tx_data_in     <= tx_data_in;
1460
                                                process_data   <= 1'b0;
1461
                                        end
1462
                                        process_data_0 <= 1'b0;
1463
                                end
1464
                                fct_sent <=  1'b0;
1465
                                char_sent <= 1'b0;
1466 37 redbear
                                ready_tx_timecode <= 1'b0;
1467
                                global_counter_transfer <= global_counter_transfer + 4'd1;
1468
                        end
1469
 
1470
 
1471
                        if(global_counter_transfer != 4'd13)
1472
                        begin
1473
 
1474
                                timecode_s <= {timecode_ss[13:10],2'd2,tx_tcode_in[7:0]};
1475
                        end
1476
                        else
1477
                        begin
1478
                                last_timein_control_flag_tx <= tx_tcode_in;
1479
                                last_type  <= TIMEC;
1480
                        end
1481
 
1482
                end
1483
                default:
1484
                begin
1485 39 redbear
                        fct_sent <=  1'b0;
1486
                        char_sent <= 1'b0;
1487 37 redbear
                        last_type               <= last_type;
1488
                        global_counter_transfer <= global_counter_transfer;
1489
                        tx_dout_e               <= tx_dout_e;
1490
                        tx_sout_e               <= tx_sout_e;
1491
                end
1492
                endcase
1493 5 redbear
        end
1494
end
1495
 
1496
endmodule

powered by: WebSVN 2.1.0

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