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

Subversion Repositories spacewiresystemc

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

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
                output reg tx_dout,
54
                output reg tx_sout,
55
                //
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
        reg [2:0] state_tx;
74
        reg [2:0] next_state_tx;
75
 
76
        reg [7:0]  null_s;
77
        reg [3:0]  fct_s;
78
        reg [3:0]  eop_s;
79
        reg [3:0]  eep_s;
80
        reg [13:0] timecode_s;
81
 
82
        reg [5:0]  last_type;
83
        reg [8:0]  txdata_flagctrl_tx_last;
84
        reg [7:0]  last_timein_control_flag_tx;
85
 
86
        reg first_time;
87
 
88 8 redbear
        reg hold_null;
89
        reg hold_fct;
90
        reg hold_data;
91
        reg hold_time_code;
92
 
93 5 redbear
        reg enable_null;
94
        reg enable_fct;
95
        reg enable_n_char;
96
        reg enable_time_code;
97
 
98
        reg [2:0] fct_send;
99 6 redbear
        reg [2:0] fct_send_last;
100 5 redbear
        reg [2:0] fct_flag;
101 6 redbear
 
102 5 redbear
        reg [5:0] fct_counter;
103 6 redbear
        reg [5:0] fct_counter_receive;
104
 
105 5 redbear
        reg last_tx_dout;
106
        reg last_tx_sout;
107
 
108 17 redbear
        reg block_sum;
109
 
110 5 redbear
        reg [3:0] global_counter_transfer;
111
 
112
 
113 13 redbear
 
114 5 redbear
always@(*)
115
begin
116
        tx_dout = 1'b0;
117
 
118
         if(!enable_tx)
119
         begin
120
                tx_dout = 1'b0;
121
         end
122
         else if( enable_null & first_time  & global_counter_transfer == 4'd0)
123
         begin
124
                tx_dout = null_s[7];
125
         end
126
         else if( enable_null & !first_time & last_type == NULL  & global_counter_transfer == 4'd0)
127
         begin
128
                tx_dout = !(null_s[6]^null_s[0]^null_s[1]);
129
         end
130
         else if( enable_null & !first_time & last_type == FCT   & global_counter_transfer == 4'd0)
131
         begin
132
                tx_dout = !(null_s[6]^fct_s[0]^fct_s[1]);
133
         end
134
         else if( enable_null & !first_time & last_type == EOP   & global_counter_transfer == 4'd0)
135
         begin
136
                tx_dout = !(null_s[6]^eop_s[0]^eop_s[1]);
137
         end
138
         else if( enable_null & !first_time & last_type == EEP   & global_counter_transfer == 4'd0)
139
         begin
140
                tx_dout = !(null_s[6]^eep_s[0]^eep_s[1]);
141
         end
142
         else if( enable_null & !first_time & last_type == DATA  & global_counter_transfer == 4'd0)
143
         begin
144
                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]);
145
         end
146
         else if( enable_null & !first_time & last_type == TIMEC & global_counter_transfer == 4'd0)
147
         begin
148
                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]);
149
         end
150
         else if( enable_null & !first_time & global_counter_transfer == 4'd1)
151
         begin
152
                tx_dout = null_s[6];
153
         end
154
         else if( enable_null & !first_time & global_counter_transfer == 4'd2)
155
         begin
156
                tx_dout = null_s[5];
157
         end
158
         else if( enable_null & !first_time & global_counter_transfer == 4'd3)
159
         begin
160
                tx_dout = null_s[4];
161
         end
162
         else if( enable_null & !first_time & global_counter_transfer == 4'd4)
163
         begin
164
                tx_dout = null_s[3];
165
         end
166
         else if( enable_null & !first_time & global_counter_transfer == 4'd5)
167
         begin
168
                tx_dout = null_s[2];
169
         end
170
         else if( enable_null & !first_time & global_counter_transfer == 4'd6)
171
         begin
172
                tx_dout = null_s[1];
173
         end
174
         else if( enable_null & !first_time & global_counter_transfer == 4'd7)
175
         begin
176
                tx_dout = null_s[0];
177
         end
178
         else if( enable_fct  & !first_time & last_type == NULL  & global_counter_transfer == 4'd0)
179
         begin
180
                tx_dout = !(fct_s[2]^null_s[0]^null_s[1]);
181
         end
182
         else if( enable_fct  & !first_time & last_type == FCT   & global_counter_transfer == 4'd0)
183
         begin
184
                tx_dout = !(fct_s[2]^fct_s[0]^fct_s[1]);
185
         end
186
         else if( enable_fct  & !first_time & last_type == EOP   & global_counter_transfer == 4'd0)
187
         begin
188
                tx_dout = !(fct_s[2]^eop_s[0]^eop_s[1]);
189
         end
190
         else if( enable_fct  & !first_time & last_type == EEP   & global_counter_transfer == 4'd0)
191
         begin
192
                tx_dout = !(fct_s[2]^eep_s[0]^eep_s[1]);
193
         end
194
         else if ( enable_fct  & !first_time & last_type == DATA  & global_counter_transfer == 4'd0)
195
         begin
196
                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]);
197
         end
198
         else if( enable_fct  & !first_time & last_type == TIMEC & global_counter_transfer == 4'd0)
199
         begin
200
                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]);
201
         end
202
         else if( enable_fct  & !first_time & global_counter_transfer == 4'd1)
203
         begin
204
                tx_dout = fct_s[2];
205
         end
206
         else if( enable_fct  & !first_time & global_counter_transfer == 4'd2)
207
         begin
208
                tx_dout = fct_s[1];
209
         end
210
         else if( enable_fct  & !first_time & global_counter_transfer == 4'd3)
211
         begin
212
                tx_dout = fct_s[0];
213
         end
214
         else if( enable_time_code & !first_time & last_type == NULL  & global_counter_transfer == 4'd0)
215
         begin
216
                tx_dout = !(timecode_s[12]^null_s[0]^null_s[1]);
217
         end
218
         else if( enable_time_code & !first_time & last_type == FCT   & global_counter_transfer == 4'd0)
219
         begin
220
                tx_dout = !(timecode_s[12]^fct_s[0]^fct_s[1]);
221
         end
222
         else if ( enable_time_code & !first_time & last_type == EOP   & global_counter_transfer == 4'd0)
223
         begin
224
                tx_dout = !(timecode_s[12]^eop_s[0]^eop_s[1]);
225
         end
226
         else if( enable_time_code & !first_time & last_type == EEP   & global_counter_transfer == 4'd0)
227
         begin
228
                tx_dout = !(timecode_s[12]^eep_s[0]^eep_s[1]);
229
         end
230
         else if( enable_time_code & !first_time & last_type == DATA  & global_counter_transfer == 4'd0)
231
         begin
232
                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]);
233
         end
234
         else if( enable_time_code & !first_time & last_type == TIMEC & global_counter_transfer == 4'd0)
235
         begin
236
                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]);
237
         end
238
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd1)
239
         begin
240
                tx_dout = timecode_s[12];
241
         end
242
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd2)
243
         begin
244
                tx_dout = timecode_s[11];
245
         end
246
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd3)
247
         begin
248
                tx_dout = timecode_s[10];
249
         end
250
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd4)
251
         begin
252
                tx_dout = timecode_s[9];
253
         end
254
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd5)
255
         begin
256
                tx_dout = timecode_s[8];
257
         end
258
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd6)
259
         begin
260 13 redbear
                tx_dout = timecode_s[0];
261 5 redbear
         end
262
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd7)
263
         begin
264 13 redbear
                tx_dout = timecode_s[1];
265 5 redbear
         end
266
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd8)
267
         begin
268 13 redbear
                tx_dout = timecode_s[2];
269 5 redbear
         end
270
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd9)
271
         begin
272 13 redbear
                tx_dout = timecode_s[3];
273 5 redbear
         end
274
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd10)
275
         begin
276 13 redbear
                tx_dout = timecode_s[4];
277 5 redbear
         end
278
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd11)
279
         begin
280 13 redbear
                tx_dout = timecode_s[5];
281 5 redbear
         end
282
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd12)
283
         begin
284 13 redbear
                tx_dout = timecode_s[6];
285 5 redbear
         end
286
         else if( enable_time_code & !first_time & global_counter_transfer == 4'd13)
287
         begin
288 13 redbear
                tx_dout = timecode_s[7];
289 5 redbear
         end
290 8 redbear
         else if( enable_n_char   & !data_tx_i[8] & !first_time & last_type == NULL  & global_counter_transfer == 4'd0)
291 5 redbear
         begin
292
                tx_dout = !(data_tx_i[8]^null_s[0]^null_s[1]);
293
         end
294 8 redbear
         else if( enable_n_char   & !data_tx_i[8] & !first_time & last_type == FCT   & global_counter_transfer == 4'd0)
295 5 redbear
         begin
296
                tx_dout = !(data_tx_i[8]^fct_s[0]^fct_s[1]);
297
         end
298 8 redbear
         else if( enable_n_char   & !data_tx_i[8] & !first_time & last_type == EOP   & global_counter_transfer == 4'd0)
299 5 redbear
         begin
300
                tx_dout = !(data_tx_i[8]^eop_s[0]^eop_s[1]);
301
         end
302 8 redbear
         else if( enable_n_char   & !data_tx_i[8] & !first_time & last_type == EEP   & global_counter_transfer == 4'd0)
303 5 redbear
         begin
304
                tx_dout = !(data_tx_i[8]^eep_s[0]^eep_s[1]);
305
         end
306 8 redbear
         else if( enable_n_char   & !data_tx_i[8] & !first_time & last_type == DATA  & global_counter_transfer == 4'd0)
307 5 redbear
         begin
308
                tx_dout = !(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]);
309
         end
310 8 redbear
         else if( enable_n_char   & !data_tx_i[8] & !first_time & last_type == TIMEC & global_counter_transfer == 4'd0)
311 5 redbear
         begin
312
                tx_dout = !(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]);
313
         end
314 8 redbear
         else if( enable_n_char   & data_tx_i[8]  & data_tx_i[1:0] == 2'b00 &  !first_time & last_type == NULL  & global_counter_transfer == 4'd0)
315 5 redbear
         begin
316 8 redbear
                tx_dout = !(eop_s[3]^null_s[0]^null_s[1]);
317
         end
318
         else if( enable_n_char   & !data_tx_i[8] & data_tx_i[1:0] == 2'b00 & !first_time & last_type == FCT   & global_counter_transfer == 4'd0)
319
         begin
320
                tx_dout = !(eop_s[3]^fct_s[0]^fct_s[1]);
321
         end
322
         else if( enable_n_char   & !data_tx_i[8] & data_tx_i[1:0] == 2'b00 & !first_time & last_type == EOP   & global_counter_transfer == 4'd0)
323
         begin
324
                tx_dout = !(eop_s[3]^eop_s[0]^eop_s[1]);
325
         end
326
         else if( enable_n_char   & !data_tx_i[8] & data_tx_i[1:0] == 2'b00 & !first_time & last_type == EEP   & global_counter_transfer == 4'd0)
327
         begin
328
                tx_dout = !(eop_s[3]^eep_s[0]^eep_s[1]);
329
         end
330
         else if( enable_n_char   & !data_tx_i[8]  & data_tx_i[1:0] == 2'b00 & !first_time & last_type == DATA  & global_counter_transfer == 4'd0)
331
         begin
332
                tx_dout = !(eop_s[3]^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]);
333
         end
334
         else if( enable_n_char   & !data_tx_i[8]  & data_tx_i[1:0] == 2'b00 & !first_time & last_type == TIMEC & global_counter_transfer == 4'd0)
335
         begin
336
                tx_dout = !(eop_s[3]^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]);
337
         end
338
         else if( enable_n_char    &  data_tx_i[8] & data_tx_i[1:0] == 2'b00 & !first_time & global_counter_transfer == 4'd1)
339
         begin
340
                tx_dout = eop_s[2];
341
         end
342
         else if( enable_n_char    &  data_tx_i[8] & data_tx_i[1:0] == 2'b00 & !first_time & global_counter_transfer == 4'd2)
343
         begin
344
                tx_dout = eop_s[1];
345
         end
346
         else if( enable_n_char    &  data_tx_i[8] & data_tx_i[1:0] == 2'b00 & !first_time & global_counter_transfer == 4'd3)
347
         begin
348
                tx_dout = eop_s[0];
349
         end
350
         else if( enable_n_char   & data_tx_i[8]  & data_tx_i[1:0] == 2'b01 &  !first_time & last_type == NULL  & global_counter_transfer == 4'd0)
351
         begin
352
                tx_dout = !(eep_s[3]^null_s[0]^null_s[1]);
353
         end
354
         else if( enable_n_char   & !data_tx_i[8] & data_tx_i[1:0] == 2'b01 & !first_time & last_type == FCT   & global_counter_transfer == 4'd0)
355
         begin
356
                tx_dout = !(eep_s[3]^fct_s[0]^fct_s[1]);
357
         end
358
         else if( enable_n_char   & !data_tx_i[8] & data_tx_i[1:0] == 2'b01 & !first_time & last_type == EOP   & global_counter_transfer == 4'd0)
359
         begin
360
                tx_dout = !(eep_s[3]^eop_s[0]^eop_s[1]);
361
         end
362
         else if( enable_n_char   & !data_tx_i[8] & data_tx_i[1:0] == 2'b01 & !first_time & last_type == EEP   & global_counter_transfer == 4'd0)
363
         begin
364
                tx_dout = !(eep_s[3]^eep_s[0]^eep_s[1]);
365
         end
366
         else if( enable_n_char   & !data_tx_i[8]  & data_tx_i[1:0] == 2'b01 & !first_time & last_type == DATA  & global_counter_transfer == 4'd0)
367
         begin
368
                tx_dout = !(eep_s[3]^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]);
369
         end
370
         else if( enable_n_char   & !data_tx_i[8]  & data_tx_i[1:0] == 2'b01 & !first_time & last_type == TIMEC & global_counter_transfer == 4'd0)
371
         begin
372
                tx_dout = !(eep_s[3]^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]);
373
         end
374
         else if( enable_n_char   & !data_tx_i[8] & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd1)
375
         begin
376 5 redbear
                tx_dout = data_tx_i[8];
377
         end
378
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd2)
379
         begin
380
                tx_dout = data_tx_i[0];
381
         end
382
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd3)
383
         begin
384
                tx_dout = data_tx_i[1];
385
         end
386
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd4)
387
         begin
388
                tx_dout = data_tx_i[2];
389
         end
390
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd5)
391
         begin
392
                tx_dout = data_tx_i[3];
393
         end
394
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd6)
395
         begin
396
                tx_dout = data_tx_i[4];
397
         end
398
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd7)
399
         begin
400
                tx_dout = data_tx_i[5];
401
         end
402
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd8)
403
         begin
404
                tx_dout = data_tx_i[6];
405
         end
406
         else if( enable_n_char    & !data_tx_i[8] & !first_time & global_counter_transfer == 4'd9)
407
         begin
408
                tx_dout = data_tx_i[7];
409
         end
410
         else if( enable_n_char    &  data_tx_i[8] & data_tx_i[1:0] == 2'b01 & !first_time & global_counter_transfer == 4'd1)
411
         begin
412
                tx_dout = eep_s[2];
413
         end
414
         else if( enable_n_char    &  data_tx_i[8] & data_tx_i[1:0] == 2'b01 & !first_time & global_counter_transfer == 4'd2)
415
         begin
416
                tx_dout = eep_s[1];
417
         end
418
         else if( enable_n_char    &  data_tx_i[8] & data_tx_i[1:0] == 2'b01 & !first_time & global_counter_transfer == 4'd3)
419
         begin
420
                tx_dout = eep_s[0];
421
         end
422
end
423
 
424
//strobe
425
always@(*)
426
begin
427
        tx_sout = 1'b0;
428
 
429
        if(!enable_tx)
430
        begin
431
                tx_sout = 1'b0;
432
        end
433 13 redbear
        else if((enable_null | enable_fct | enable_n_char | enable_time_code) && tx_dout == last_tx_dout)
434 5 redbear
        begin
435
                tx_sout = !last_tx_sout;
436
        end
437 13 redbear
        else if((enable_null | enable_fct | enable_n_char | enable_time_code) && tx_dout != last_tx_dout)
438 5 redbear
        begin
439
                tx_sout = last_tx_sout;
440 12 redbear
        end
441
 
442 5 redbear
end
443
 
444 17 redbear
always@(*)
445 5 redbear
begin
446 17 redbear
        fct_counter = 6'd0;
447
 
448
        if(gotfct_tx)
449 5 redbear
        begin
450 17 redbear
                if(block_sum)
451 15 redbear
                begin
452 17 redbear
 
453
                end
454
                else
455
                begin
456
                        if(fct_counter_receive < 6'd48)
457 15 redbear
                        begin
458 17 redbear
                                fct_counter = fct_counter_receive + 6'd8;
459 15 redbear
                        end
460
                        else
461
                        begin
462 17 redbear
                                fct_counter = fct_counter_receive + 6'd7;
463
 
464 15 redbear
                        end
465
                end
466 5 redbear
        end
467
end
468
 
469
//slots open in our side
470
always@(posedge send_fct_now or negedge enable_tx)
471
begin
472
 
473
        if(!enable_tx)
474
        begin
475
                fct_send <= {3{1'b1}};
476
        end
477
        else
478
        begin
479 6 redbear
 
480
                if(fct_send == 3'd7)
481
                begin
482
                        fct_send <= 3'd1;
483
                end
484
                else
485
                begin
486
                        fct_send <= fct_send + 3'd1;
487
                end
488 5 redbear
        end
489
 
490
end
491
 
492
 
493
always@(*)
494
begin
495
 
496
 
497
        enable_null      = 1'b0;
498
        enable_fct       = 1'b0;
499
        enable_n_char    = 1'b0;
500
        enable_time_code = 1'b0;
501
 
502 17 redbear
        next_state_tx = state_tx;
503
 
504 5 redbear
        case(state_tx)
505
        tx_spw_start:
506
        begin
507
                if(send_null_tx && enable_tx)
508
                begin
509 12 redbear
                        //if(!hold_null)
510 5 redbear
                                next_state_tx = tx_spw_null;
511
 
512 12 redbear
                        //enable_null = 1'b1;
513 5 redbear
                end
514
                else
515
                begin
516
                        next_state_tx = tx_spw_start;
517
                end
518
        end
519
        tx_spw_null:
520
        begin
521
                enable_null = 1'b1;
522
 
523 8 redbear
                if(!hold_null)
524 5 redbear
                begin
525
                        if(send_null_tx && send_fct_tx && enable_tx)
526
                                next_state_tx = tx_spw_null_fct;
527
                        else
528
                                next_state_tx = tx_spw_null;
529
                end
530
 
531
        end
532
        tx_spw_null_fct:
533
        begin
534
 
535
                enable_null   = 1'b1;
536
 
537 8 redbear
                if(send_fct_tx && fct_flag > 0  && !hold_null)
538 5 redbear
                begin
539 8 redbear
                        next_state_tx = tx_spw_null_fct;
540 5 redbear
                        enable_null = 1'b0;
541 8 redbear
                        enable_fct  = 1'b1;
542 5 redbear
                end
543
                else
544
                begin
545
                        enable_fct = 1'b0;
546 17 redbear
                        if(send_fct_tx && fct_counter_receive > 6'd0)
547 5 redbear
                        begin
548 12 redbear
                                //if(global_counter_transfer == 4'd7)
549
                                        next_state_tx =  tx_spw_full;
550 5 redbear
                        end
551
 
552
                end
553
        end
554
        tx_spw_full:
555
        begin
556 8 redbear
                if(tickin_tx && !hold_null && !hold_fct && !hold_data)
557 5 redbear
                begin
558 6 redbear
                        enable_time_code = 1'b1;
559 5 redbear
                end
560 8 redbear
                else if(fct_flag > 3'd0 && !hold_null && !hold_time_code && !hold_data)
561 5 redbear
                begin
562 6 redbear
                        enable_fct  = 1'b1;
563 5 redbear
                end
564 17 redbear
                else if((txwrite_tx && fct_counter_receive > 6'd0 && !hold_null && !hold_time_code && !hold_fct) == 1'b1 )
565 5 redbear
                begin
566 8 redbear
                        enable_n_char = 1'b1;
567 5 redbear
                end
568 17 redbear
                else
569 8 redbear
                begin
570
                        enable_null = 1'b1;
571
                end
572 5 redbear
        end
573
        endcase
574
 
575
end
576
 
577
always@(posedge pclk_tx)
578
begin
579
        if(!enable_tx)
580
        begin
581 13 redbear
                null_s        <= 8'h74;
582
                fct_s         <= 4'h4;
583
                eop_s         <= 4'h5;
584
                eep_s         <= 4'h6;
585
                timecode_s    <= 14'b01110000000000;
586 5 redbear
 
587 13 redbear
                fct_flag      <= 3'd0;
588 6 redbear
                fct_send_last <= 3'd0;
589
 
590 13 redbear
                first_time        <= 1'b1;
591
                ready_tx_data     <= 1'b0;
592
                ready_tx_timecode <= 1'b0;
593 8 redbear
 
594
                hold_null       <= 1'b0;
595
                hold_fct        <= 1'b0;
596
                hold_data       <= 1'b0;
597
                hold_time_code  <= 1'b0;
598
 
599 5 redbear
                last_type  <= NULL;
600
 
601
                global_counter_transfer <= 4'd0;
602
                txdata_flagctrl_tx_last <= 9'd0;
603
                last_timein_control_flag_tx <= 8'd0;
604 6 redbear
 
605
                fct_counter_receive <= 6'd0;
606 17 redbear
 
607
                block_sum  <= 1'b0;
608 6 redbear
 
609 5 redbear
                last_tx_dout      <= 1'b0;
610
                last_tx_sout      <= 1'b0;
611
                state_tx <= tx_spw_start;
612 17 redbear
 
613 5 redbear
        end
614
        else
615
        begin
616
 
617
                state_tx <= next_state_tx;
618
                last_tx_dout <= tx_dout;
619
                last_tx_sout <= tx_sout;
620
 
621
                if(enable_null)
622
                begin
623 6 redbear
 
624 8 redbear
                        ready_tx_data <= 1'b0;
625 13 redbear
                        ready_tx_timecode <= 1'b0;
626 8 redbear
 
627 17 redbear
                        if(gotfct_tx && !block_sum)
628
                        begin
629 15 redbear
                                fct_counter_receive <= fct_counter;
630 17 redbear
                                block_sum<= 1'b1;
631
                        end
632
                        else if(!gotfct_tx)
633
                        begin
634
                                block_sum<= 1'b0;
635
                        end
636
                        else
637
                                block_sum <= block_sum;
638
 
639 6 redbear
                        //
640
                        if(fct_send_last != fct_send)
641
                        begin
642
                                if(fct_send == 3'd1 && fct_send_last == 3'd7)
643
                                begin
644
                                        fct_flag <= fct_flag + 3'd1;
645
                                end
646
                                else
647
                                begin
648
                                        fct_flag <= fct_flag + (fct_send - fct_send_last);
649
                                end
650
 
651
                                fct_send_last <= fct_send;
652
                        end
653
 
654 5 redbear
                        if(first_time)
655
                        begin
656
                                first_time <= 1'b0;
657 8 redbear
                                hold_null <= 1'b1;
658 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
659
                        end
660
                        else if(global_counter_transfer != 4'd7)
661
                        begin
662 8 redbear
                                hold_null <= 1'b1;
663 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
664
                        end
665
                        else
666
                        begin
667 8 redbear
                                hold_null <= 1'b0;
668 5 redbear
                                global_counter_transfer <= 4'd0;
669
                        end
670
                end
671
                else if(enable_fct)
672
                begin
673 8 redbear
 
674
                        ready_tx_data <= 1'b0;
675 13 redbear
                        ready_tx_timecode <= 1'b0;
676 8 redbear
 
677 17 redbear
                        if(gotfct_tx && !block_sum)
678
                        begin
679 15 redbear
                                fct_counter_receive <= fct_counter;
680 17 redbear
                                block_sum<= 1'b1;
681
                        end
682
                        else if(!gotfct_tx)
683
                        begin
684
                                block_sum<= 1'b0;
685
                        end
686
                        else
687
                                block_sum <= block_sum;
688 6 redbear
 
689
 
690 5 redbear
                        if(global_counter_transfer != 4'd3)
691
                        begin
692 8 redbear
                                hold_fct <= 1'b1;
693 5 redbear
                                global_counter_transfer <= global_counter_transfer + 4'd1;
694
                        end
695
                        else
696
                        begin
697 8 redbear
                                hold_fct <= 1'b0;
698 5 redbear
                                global_counter_transfer <= 4'd0;
699 6 redbear
                                fct_flag <= fct_flag - 3'd1;
700 5 redbear
                        end
701
                end
702
                else if(enable_time_code)
703
                begin
704 8 redbear
 
705
                        ready_tx_data <= 1'b0;
706
 
707 17 redbear
                        if(gotfct_tx && !block_sum)
708
                        begin
709 15 redbear
                                fct_counter_receive <= fct_counter;
710 17 redbear
                                block_sum<= 1'b1;
711
                        end
712
                        else if(!gotfct_tx)
713
                        begin
714
                                block_sum<= 1'b0;
715
                        end
716
                        else
717
                                block_sum <= block_sum;
718 15 redbear
 
719
 
720 13 redbear
                        if(global_counter_transfer == 4'd13)
721
                        begin
722
                                ready_tx_timecode <= 1'b1;
723
                        end
724 6 redbear
                        //
725
                        if(fct_send_last != fct_send)
726
                        begin
727
                                if(fct_send == 3'd1 && fct_send_last == 3'd7)
728
                                begin
729
                                        fct_flag <= fct_flag + 3'd1;
730
                                end
731
                                else
732
                                begin
733
                                        fct_flag <= fct_flag + (fct_send - fct_send_last);
734
                                end
735
 
736
                                fct_send_last <= fct_send;
737
                        end
738
 
739 5 redbear
                        if(global_counter_transfer < 4'd13)
740
                        begin
741
                                global_counter_transfer <= global_counter_transfer + 4'd1;
742 13 redbear
                                timecode_s <= {timecode_s[13:10],2'd2,timecode_tx_i[7:0]};
743 5 redbear
                        end
744
                        else
745
                        begin
746 13 redbear
                                last_timein_control_flag_tx <= timecode_tx_i;
747 5 redbear
                                global_counter_transfer <= 4'd0;
748
                        end
749
                end
750
                else if(enable_n_char)
751
                begin
752 8 redbear
 
753 13 redbear
                        ready_tx_timecode <= 1'b0;
754
 
755 15 redbear
                        //if(fct_counter > 6'd0)
756
                        //      fct_counter_receive <= fct_counter;
757 6 redbear
                        //
758
                        if(fct_send_last != fct_send)
759
                        begin
760
                                if(fct_send == 3'd1 && fct_send_last == 3'd7)
761
                                begin
762
                                        fct_flag <= fct_flag + 3'd1;
763
                                end
764
                                else
765
                                begin
766
                                        fct_flag <= fct_flag + (fct_send - fct_send_last);
767
                                end
768
 
769
                                fct_send_last <= fct_send;
770
                        end
771
 
772 8 redbear
                        if(!data_tx_i[8])
773 5 redbear
                        begin
774 8 redbear
 
775
                                if(global_counter_transfer == 4'd9)
776
                                begin
777
                                        ready_tx_data <= 1'b1;
778
                                end
779 17 redbear
                                else
780
                                begin
781
                                        ready_tx_data <= 1'b0;
782
                                end
783 8 redbear
 
784
                                if(global_counter_transfer != 4'd9)
785
                                begin
786
                                        hold_data <= 1'b1;
787
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
788
                                        txdata_flagctrl_tx_last <= data_tx_i;
789 17 redbear
 
790
                                        if(gotfct_tx && !block_sum)
791
                                        begin
792
                                                fct_counter_receive <= fct_counter;
793
                                                block_sum<= 1'b1;
794
                                        end
795
                                        else if(!gotfct_tx)
796
                                        begin
797
                                                block_sum<= 1'b0;
798
                                        end
799
                                        else
800
                                                block_sum <= block_sum;
801 8 redbear
                                end
802
                                else
803
                                begin
804
                                        hold_data <= 1'b0;
805
                                        global_counter_transfer <= 4'd0;
806 15 redbear
                                        fct_counter_receive <= fct_counter_receive - 6'd1;
807 8 redbear
                                end
808
 
809 5 redbear
                        end
810 8 redbear
                        else if(data_tx_i[8])
811 5 redbear
                        begin
812 8 redbear
 
813
                                if(global_counter_transfer == 4'd3)
814
                                begin
815
                                        ready_tx_data <= 1'b1;
816
                                end
817 17 redbear
                                else
818
                                begin
819
                                        ready_tx_data <= 1'b0;
820
                                end
821 8 redbear
 
822
                                if(global_counter_transfer != 4'd3)
823
                                begin
824
                                        hold_data <= 1'b1;
825
                                        global_counter_transfer <= global_counter_transfer + 4'd1;
826
                                        txdata_flagctrl_tx_last <= data_tx_i;
827 17 redbear
 
828
                                        if(gotfct_tx && !block_sum)
829
                                        begin
830
                                                fct_counter_receive <= fct_counter;
831
                                                block_sum<= 1'b1;
832
                                        end
833
                                        else if(!gotfct_tx)
834
                                        begin
835
                                                block_sum<= 1'b0;
836
                                        end
837
                                        else
838
                                                block_sum <= block_sum;
839 8 redbear
                                end
840
                                else
841
                                begin
842 15 redbear
 
843 8 redbear
                                        hold_data <= 1'b0;
844
                                        global_counter_transfer <= 4'd0;
845 15 redbear
                                        fct_counter_receive <= fct_counter_receive - 6'd1;
846 8 redbear
                                end
847 5 redbear
                        end
848 8 redbear
 
849 5 redbear
                end
850
 
851
        end
852
end
853
 
854
endmodule

powered by: WebSVN 2.1.0

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