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

Subversion Repositories apbi2c

[/] [apbi2c/] [trunk/] [rtl/] [module_i2c.v] - Blame information for rev 11

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

Line No. Rev Author Line
1 2 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    TOP I2C BLOCK to I2C Core
5
////
6
////
7
////
8
//// This file is part of the APB to I2C project
9
////
10
//// http://www.opencores.org/cores/apbi2c/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// apbi2c_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29 4 redbear
////              Ronal Dario Celaya ,rcelaya.dario@gmail.com
30 2 redbear
////
31
///////////////////////////////////////////////////////////////// 
32
////
33
////
34
//// Copyright (C) 2009 Authors and OPENCORES.ORG
35
////
36
////
37
////
38
//// This source file may be used and distributed without
39
////
40
//// restriction provided that this copyright statement is not
41
////
42
//// removed from the file and that any derivative work contains
43
//// the original copyright notice and the associated disclaimer.
44
////
45
////
46
//// This source file is free software; you can redistribute it
47
////
48
//// and/or modify it under the terms of the GNU Lesser General
49
////
50
//// Public License as published by the Free Software Foundation;
51
//// either version 2.1 of the License, or (at your option) any
52
////
53
//// later version.
54
////
55
////
56
////
57
//// This source is distributed in the hope that it will be
58
////
59
//// useful, but WITHOUT ANY WARRANTY; without even the implied
60
////
61
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
62
////
63
//// PURPOSE. See the GNU Lesser General Public License for more
64
//// details.
65
////
66
////
67
////
68
//// You should have received a copy of the GNU Lesser General
69
////
70
//// Public License along with this source; if not, download it
71
////
72
//// from http://www.opencores.org/lgpl.shtml
73
////
74
////
75
///////////////////////////////////////////////////////////////////
76
 
77
 
78
`timescale 1ns/1ps //timescale 
79
 
80
module module_i2c#(
81
                        //THIS IS USED ONLY LIKE PARAMETER TO BEM CONFIGURABLE
82
                        parameter integer DWIDTH = 32,
83
                        parameter integer AWIDTH = 14
84
                )
85
                (
86
                //I2C INTERFACE WITH ANOTHER BLOCKS
87
                 input PCLK,
88
                 input PRESETn,
89
 
90
                //INTERFACE WITH FIFO TRANSMISSION
91
                 input fifo_tx_f_full,
92
                 input fifo_tx_f_empty,
93
                 input [DWIDTH-1:0] fifo_tx_data_out,
94
 
95
                //INTERFACE WITH FIFO RECEIVER
96
                 input fifo_rx_f_full,
97
                 input fifo_rx_f_empty,
98 6 redbear
                 output reg fifo_rx_wr_en,
99
                 output reg [DWIDTH-1:0] fifo_rx_data_in,
100 2 redbear
 
101
                //INTERFACE WITH REGISTER CONFIGURATION
102
                 input [AWIDTH-1:0] DATA_CONFIG_REG,
103
 
104
                //INTERFACE TO APB AND READ FOR FIFO TX
105
                 output reg fifo_tx_rd_en,
106
                 output TX_EMPTY,
107
                 output RX_EMPTY,
108
                 output ERROR,
109
 
110
                //I2C BI DIRETIONAL PORTS
111
                inout SDA,
112
                inout SCL
113
 
114
 
115
                 );
116
 
117
//THIS IS USED TO GENERATE INTERRUPTIONS
118
assign TX_EMPTY = (fifo_tx_f_empty == 1'b1)? 1'b1:1'b0;
119
assign RX_EMPTY = (fifo_rx_f_empty == 1'b1)? 1'b1:1'b0;
120
 
121
        //THIS COUNT IS USED TO CONTROL DATA ACCROSS FSM        
122 6 redbear
        reg [1:0] count_tx;
123 2 redbear
        //CONTROL CLOCK AND COUNTER
124
        reg [11:0] count_send_data;
125
        reg BR_CLK_O;
126
        reg SDA_OUT;
127
 
128
        //RESPONSE USED TO HOLD SIGNAL TO ACK OR NACK
129
        reg RESPONSE;
130
 
131
// TX PARAMETERS USED TO STATE MACHINE
132
 
133
localparam [5:0] TX_IDLE = 6'd0, //IDLE
134
 
135
           TX_START = 6'd1,//START BIT
136
 
137
           TX_CONTROLIN_1 = 6'd2, //START BYTE
138
           TX_CONTROLIN_2 = 6'd3,
139
           TX_CONTROLIN_3 = 6'd4,
140
           TX_CONTROLIN_4 = 6'd5,
141
           TX_CONTROLIN_5 = 6'd6,
142
           TX_CONTROLIN_6 = 6'd7,
143
           TX_CONTROLIN_7 = 6'd8,
144
           TX_CONTROLIN_8 = 6'd9, //END FIRST BYTE
145
 
146
           TX_RESPONSE_CIN =6'd10, //RESPONSE
147
 
148
           TX_ADRESS_1 = 6'd11,//START BYTE
149
           TX_ADRESS_2 = 6'd12,
150
           TX_ADRESS_3 = 6'd13,
151
           TX_ADRESS_4 = 6'd14,
152
           TX_ADRESS_5 = 6'd15,
153
           TX_ADRESS_6 = 6'd16,
154
           TX_ADRESS_7 = 6'd17,
155
           TX_ADRESS_8 = 6'd18,//END FIRST BYTE
156
 
157
           TX_RESPONSE_ADRESS =6'd19, //RESPONSE
158
 
159
           TX_DATA0_1 = 6'd20,//START BYTE
160
           TX_DATA0_2 = 6'd21,
161
           TX_DATA0_3 = 6'd22,
162
           TX_DATA0_4 = 6'd23,
163
           TX_DATA0_5 = 6'd24,
164
           TX_DATA0_6 = 6'd25,
165
           TX_DATA0_7 = 6'd26,
166
           TX_DATA0_8 = 6'd27,//END FIRST BYTE
167
 
168
           TX_RESPONSE_DATA0_1 = 6'd28,  //RESPONSE
169
 
170
           TX_DATA1_1 = 6'd29,//START BYTE
171
           TX_DATA1_2 = 6'd30,
172
           TX_DATA1_3 = 6'd31,
173
           TX_DATA1_4 = 6'd32,
174
           TX_DATA1_5 = 6'd33,
175
           TX_DATA1_6 = 6'd34,
176
           TX_DATA1_7 = 6'd35,
177
           TX_DATA1_8 = 6'd36,//END FIRST BYTE
178
 
179
           TX_RESPONSE_DATA1_1 = 6'd37,//RESPONSE
180
 
181
           TX_DELAY_BYTES = 6'd38,//USED ONLY IN ACK TO DELAY BETWEEN
182
           TX_NACK = 6'd39,//USED ONLY IN ACK TO DELAY BETWEEN BYTES
183
           TX_STOP = 6'd40;//USED TO SEND STOP BIT
184
 
185
        //STATE CONTROL 
186
        reg [5:0] state_tx;
187
        reg [5:0] next_state_tx;
188
 
189
//ASSIGN REGISTERS TO BIDIRETIONAL PORTS
190 11 redbear
assign SDA = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?SDA_OUT:1'b0;
191
assign SCL = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?BR_CLK_O:1'b0;
192 2 redbear
 
193 4 redbear
//STANDARD ERROR
194
assign ERROR = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b1)?1'b1:1'b0;
195 2 redbear
 
196
//COMBINATIONAL BLOCK TO TX
197
always@(*)
198
begin
199
 
200
        //THE FUN START HERE :-)
201
        //COMBINATIONAL UPDATE STATE BE CAREFUL WITH WHAT YOU MAKE HERE
202
        next_state_tx = state_tx;
203
 
204
        case(state_tx)//STATE_TX IS MORE SECURE CHANGE ONLY IF YOU KNOW WHAT ARE YOU DOING 
205
        TX_IDLE:
206
        begin
207
                //OBEYING SPEC
208
                if(DATA_CONFIG_REG[0] == 1'b0 && fifo_tx_f_full == 1'b0 && DATA_CONFIG_REG[1] == 1'b0)
209
                begin
210
                        next_state_tx = TX_IDLE;
211
                end
212 4 redbear
                else if(DATA_CONFIG_REG[0] == 1'b1 && fifo_tx_f_full == 1'b1 && DATA_CONFIG_REG[1] == 1'b1)
213 2 redbear
                begin
214 4 redbear
                        next_state_tx = TX_IDLE;
215
                end
216
                else if(DATA_CONFIG_REG[0] == 1'b1 && fifo_tx_f_full == 1'b1 && DATA_CONFIG_REG[1] == 1'b0)
217
                begin
218 2 redbear
                        next_state_tx = TX_START;
219
                end
220
 
221
 
222
        end
223
        TX_START://THIS IS USED TOO ALL STATE MACHINES THE COUNTER_SEND_DATA
224
        begin
225
                if(count_send_data != DATA_CONFIG_REG[13:2])
226
                begin
227
                        next_state_tx = TX_START;
228
                end
229
                else
230
                begin
231
                        next_state_tx = TX_CONTROLIN_1;
232
                end
233
 
234
        end
235
        TX_CONTROLIN_1:
236
        begin
237
                if(count_send_data != DATA_CONFIG_REG[13:2])
238
                begin
239
                        next_state_tx = TX_CONTROLIN_1;
240
                end
241
                else
242
                begin
243
                        next_state_tx = TX_CONTROLIN_2;
244
                end
245
 
246
        end
247
        TX_CONTROLIN_2:
248
        begin
249
 
250
                if(count_send_data != DATA_CONFIG_REG[13:2])
251
                begin
252
                        next_state_tx =TX_CONTROLIN_2;
253
                end
254
                else
255
                begin
256
                        next_state_tx = TX_CONTROLIN_3;
257
                end
258
 
259
        end
260
        TX_CONTROLIN_3:
261
        begin
262
 
263
                if(count_send_data != DATA_CONFIG_REG[13:2])
264
                begin
265
                        next_state_tx = TX_CONTROLIN_3;
266
                end
267
                else
268
                begin
269
                        next_state_tx = TX_CONTROLIN_4;
270
                end
271
        end
272
        TX_CONTROLIN_4:
273
        begin
274
 
275
                if(count_send_data != DATA_CONFIG_REG[13:2])
276
                begin
277
                        next_state_tx = TX_CONTROLIN_4;
278
                end
279
                else
280
                begin
281
                        next_state_tx = TX_CONTROLIN_5;
282
                end
283
        end
284
        TX_CONTROLIN_5:
285
        begin
286
 
287
                if(count_send_data != DATA_CONFIG_REG[13:2])
288
                begin
289
                        next_state_tx = TX_CONTROLIN_5;
290
                end
291
                else
292
                begin
293
                        next_state_tx = TX_CONTROLIN_6;
294
                end
295
        end
296
        TX_CONTROLIN_6:
297
        begin
298
 
299
                if(count_send_data != DATA_CONFIG_REG[13:2])
300
                begin
301
                        next_state_tx = TX_CONTROLIN_6;
302
                end
303
                else
304
                begin
305
                        next_state_tx = TX_CONTROLIN_7;
306
                end
307
        end
308
        TX_CONTROLIN_7:
309
        begin
310
 
311
                if(count_send_data != DATA_CONFIG_REG[13:2])
312
                begin
313
                        next_state_tx = TX_CONTROLIN_7;
314
                end
315
                else
316
                begin
317
                        next_state_tx = TX_CONTROLIN_8;
318
                end
319
        end
320
        TX_CONTROLIN_8:
321
        begin
322
 
323
                if(count_send_data != DATA_CONFIG_REG[13:2])
324
                begin
325
                        next_state_tx = TX_CONTROLIN_8;
326
                end
327
                else
328
                begin
329
                        next_state_tx = TX_RESPONSE_CIN;
330
                end
331
        end
332
        TX_RESPONSE_CIN:
333
        begin
334
 
335
                if(count_send_data != DATA_CONFIG_REG[13:2])
336
                begin
337
                        next_state_tx = TX_RESPONSE_CIN;
338
                end
339
                else if(RESPONSE == 1'b0)//ACK
340
                begin
341
                        next_state_tx = TX_DELAY_BYTES;
342
                end
343
                else if(RESPONSE == 1'b1)//NACK
344
                begin
345
                        next_state_tx = TX_NACK;
346
                end
347
 
348
        end
349
 
350
        //NOW SENDING ADDRESS
351
        TX_ADRESS_1:
352
        begin
353
                if(count_send_data != DATA_CONFIG_REG[13:2])
354
                begin
355
                        next_state_tx = TX_ADRESS_1;
356
                end
357
                else
358
                begin
359
                        next_state_tx = TX_ADRESS_2;
360
                end
361
        end
362
        TX_ADRESS_2:
363
        begin
364
                if(count_send_data != DATA_CONFIG_REG[13:2])
365
                begin
366
                        next_state_tx = TX_ADRESS_2;
367
                end
368
                else
369
                begin
370
                        next_state_tx = TX_ADRESS_3;
371
                end
372
        end
373
        TX_ADRESS_3:
374
        begin
375
                if(count_send_data != DATA_CONFIG_REG[13:2])
376
                begin
377
                        next_state_tx = TX_ADRESS_3;
378
                end
379
                else
380
                begin
381
                        next_state_tx = TX_ADRESS_4;
382
                end
383
        end
384
        TX_ADRESS_4:
385
        begin
386
                if(count_send_data != DATA_CONFIG_REG[13:2])
387
                begin
388
                        next_state_tx = TX_ADRESS_4;
389
                end
390
                else
391
                begin
392
                        next_state_tx = TX_ADRESS_5;
393
                end
394
        end
395
        TX_ADRESS_5:
396
        begin
397
                if(count_send_data != DATA_CONFIG_REG[13:2])
398
                begin
399
                        next_state_tx = TX_ADRESS_5;
400
                end
401
                else
402
                begin
403
                        next_state_tx = TX_ADRESS_6;
404
                end
405
        end
406
        TX_ADRESS_6:
407
        begin
408
                if(count_send_data != DATA_CONFIG_REG[13:2])
409
                begin
410
                        next_state_tx = TX_ADRESS_6;
411
                end
412
                else
413
                begin
414
                        next_state_tx = TX_ADRESS_7;
415
                end
416
        end
417
        TX_ADRESS_7:
418
        begin
419
                if(count_send_data != DATA_CONFIG_REG[13:2])
420
                begin
421
                        next_state_tx = TX_ADRESS_7;
422
                end
423
                else
424
                begin
425
                        next_state_tx = TX_ADRESS_8;
426
                end
427
        end
428
        TX_ADRESS_8:
429
        begin
430
                if(count_send_data != DATA_CONFIG_REG[13:2])
431
                begin
432
                        next_state_tx = TX_ADRESS_8;
433
                end
434
                else
435
                begin
436
                        next_state_tx = TX_RESPONSE_ADRESS;
437
                end
438
        end
439
        TX_RESPONSE_ADRESS:
440
        begin
441
                if(count_send_data != DATA_CONFIG_REG[13:2])
442
                begin
443
                        next_state_tx = TX_RESPONSE_ADRESS;
444
                end
445
                else if(RESPONSE == 1'b0)//ACK
446
                begin
447
                        next_state_tx = TX_DELAY_BYTES;
448
                end
449
                else if(RESPONSE == 1'b1)//NACK --> RESTART CONDITION AND BACK TO START BYTE AGAIN
450
                begin
451
                        next_state_tx = TX_NACK;
452
                end
453
        end
454
 
455
        //data in
456
        TX_DATA0_1:
457
        begin
458
                if(count_send_data != DATA_CONFIG_REG[13:2])
459
                begin
460
                        next_state_tx = TX_DATA0_1;
461
                end
462
                else
463
                begin
464
                        next_state_tx = TX_DATA0_2;
465
                end
466
        end
467
        TX_DATA0_2:
468
        begin
469
                if(count_send_data != DATA_CONFIG_REG[13:2])
470
                begin
471
                        next_state_tx = TX_DATA0_2;
472
                end
473
                else
474
                begin
475
                        next_state_tx = TX_DATA0_3;
476
                end
477
        end
478
        TX_DATA0_3:
479
        begin
480
                if(count_send_data != DATA_CONFIG_REG[13:2])
481
                begin
482
                        next_state_tx = TX_DATA0_3;
483
                end
484
                else
485
                begin
486
                        next_state_tx = TX_DATA0_4;
487
                end
488
        end
489
        TX_DATA0_4:
490
        begin
491
                if(count_send_data != DATA_CONFIG_REG[13:2])
492
                begin
493
                        next_state_tx = TX_DATA0_4;
494
                end
495
                else
496
                begin
497
                        next_state_tx = TX_DATA0_5;
498
                end
499
        end
500
        TX_DATA0_5:
501
        begin
502
                if(count_send_data != DATA_CONFIG_REG[13:2])
503
                begin
504
                        next_state_tx = TX_DATA0_5;
505
                end
506
                else
507
                begin
508
                        next_state_tx = TX_DATA0_6;
509
                end
510
        end
511
        TX_DATA0_6:
512
        begin
513
                if(count_send_data != DATA_CONFIG_REG[13:2])
514
                begin
515
                        next_state_tx = TX_DATA0_6;
516
                end
517
                else
518
                begin
519
                        next_state_tx = TX_DATA0_7;
520
                end
521
        end
522
        TX_DATA0_7:
523
        begin
524
                if(count_send_data != DATA_CONFIG_REG[13:2])
525
                begin
526
                        next_state_tx = TX_DATA0_7;
527
                end
528
                else
529
                begin
530
                        next_state_tx = TX_DATA0_8;
531
                end
532
        end
533
        TX_DATA0_8:
534
        begin
535
                if(count_send_data != DATA_CONFIG_REG[13:2])
536
                begin
537
                        next_state_tx = TX_DATA0_8;
538
                end
539
                else
540
                begin
541
                        next_state_tx = TX_RESPONSE_DATA0_1;
542
                end
543
        end
544
        TX_RESPONSE_DATA0_1:
545
        begin
546
                if(count_send_data != DATA_CONFIG_REG[13:2])
547
                begin
548
                        next_state_tx = TX_RESPONSE_DATA0_1;
549
                end
550
                else if(RESPONSE == 1'b0)//ACK
551
                begin
552
                        next_state_tx = TX_DELAY_BYTES;
553
                end
554
                else if(RESPONSE == 1'b1)//NACK
555
                begin
556
                        next_state_tx = TX_NACK;
557
                end
558
        end
559
 
560
        //second byte
561
        TX_DATA1_1:
562
        begin
563
                if(count_send_data != DATA_CONFIG_REG[13:2])
564
                begin
565
                        next_state_tx = TX_DATA1_1;
566
                end
567
                else
568
                begin
569
                        next_state_tx = TX_DATA1_2;
570
                end
571
        end
572
        TX_DATA1_2:
573
        begin
574
                if(count_send_data != DATA_CONFIG_REG[13:2])
575
                begin
576
                        next_state_tx = TX_DATA1_2;
577
                end
578
                else
579
                begin
580
                        next_state_tx = TX_DATA1_3;
581
                end
582
        end
583
        TX_DATA1_3:
584
        begin
585
                if(count_send_data != DATA_CONFIG_REG[13:2])
586
                begin
587
                        next_state_tx = TX_DATA1_3;
588
                end
589
                else
590
                begin
591
                        next_state_tx = TX_DATA1_4;
592
                end
593
        end
594
        TX_DATA1_4:
595
        begin
596
                if(count_send_data != DATA_CONFIG_REG[13:2])
597
                begin
598
                        next_state_tx = TX_DATA1_4;
599
                end
600
                else
601
                begin
602
                        next_state_tx = TX_DATA1_5;
603
                end
604
        end
605
        TX_DATA1_5:
606
        begin
607
                if(count_send_data != DATA_CONFIG_REG[13:2])
608
                begin
609
                        next_state_tx = TX_DATA1_5;
610
                end
611
                else
612
                begin
613
                        next_state_tx = TX_DATA1_6;
614
                end
615
        end
616
        TX_DATA1_6:
617
        begin
618
                if(count_send_data != DATA_CONFIG_REG[13:2])
619
                begin
620
                        next_state_tx = TX_DATA1_6;
621
                end
622
                else
623
                begin
624
                        next_state_tx = TX_DATA1_7;
625
                end
626
        end
627
        TX_DATA1_7:
628
        begin
629
                if(count_send_data != DATA_CONFIG_REG[13:2])
630
                begin
631
                        next_state_tx = TX_DATA1_7;
632
                end
633
                else
634
                begin
635
                        next_state_tx = TX_DATA1_8;
636
                end
637
        end
638
        TX_DATA1_8:
639
        begin
640
                if(count_send_data != DATA_CONFIG_REG[13:2])
641
                begin
642
                        next_state_tx = TX_DATA1_8;
643
                end
644
                else
645
                begin
646
                        next_state_tx = TX_RESPONSE_DATA1_1;
647
                end
648
        end
649
        TX_RESPONSE_DATA1_1:
650
        begin
651
                if(count_send_data != DATA_CONFIG_REG[13:2])
652
                begin
653
                        next_state_tx = TX_RESPONSE_DATA1_1;
654
                end
655
                else if(RESPONSE == 1'b0)//ACK
656
                begin
657
                        next_state_tx = TX_DELAY_BYTES;
658
                end
659
                else if(RESPONSE == 1'b1)//NACK
660
                begin
661
                        next_state_tx = TX_NACK;
662
                end
663
        end
664
        TX_DELAY_BYTES://THIS FORM WORKS 
665
        begin
666
 
667
 
668
                if(count_send_data != DATA_CONFIG_REG[13:2])
669
                begin
670
                        next_state_tx = TX_DELAY_BYTES;
671
                end
672
                else
673
                begin
674
 
675 6 redbear
                        if(count_tx == 2'd0)
676 2 redbear
                        begin
677
                                next_state_tx = TX_ADRESS_1;
678
                        end
679 6 redbear
                        else if(count_tx == 2'd1)
680 2 redbear
                        begin
681
                                next_state_tx = TX_DATA0_1;
682
                        end
683 6 redbear
                        else if(count_tx == 2'd2)
684 2 redbear
                        begin
685
                                next_state_tx = TX_DATA1_1;
686
                        end
687 6 redbear
                        else if(count_tx == 2'd3)
688 2 redbear
                        begin
689
                                next_state_tx = TX_STOP;
690
                        end
691
 
692
                end
693
 
694
        end
695
        TX_NACK://NOT TESTED YET !!!!
696
        begin
697
                if(count_send_data != DATA_CONFIG_REG[13:2]*2'd2)
698
                begin
699
                        next_state_tx = TX_NACK;
700
                end
701
                else
702
                begin
703 6 redbear
                        if(count_tx == 2'd0)
704 2 redbear
                        begin
705
                                next_state_tx = TX_CONTROLIN_1;
706
                        end
707 6 redbear
                        else if(count_tx == 2'd1)
708 2 redbear
                        begin
709
                                next_state_tx = TX_ADRESS_1;
710
                        end
711 6 redbear
                        else if(count_tx == 2'd2)
712 2 redbear
                        begin
713
                                next_state_tx = TX_DATA0_1;
714
                        end
715 6 redbear
                        else if(count_tx == 2'd3)
716 2 redbear
                        begin
717
                                next_state_tx = TX_DATA1_1;
718
                        end
719
                end
720
        end
721
        TX_STOP://THIS WORK
722
        begin
723
                if(count_send_data != DATA_CONFIG_REG[13:2])
724
                begin
725
                        next_state_tx = TX_STOP;
726
                end
727
                else
728
                begin
729
                        next_state_tx = TX_IDLE;
730
                end
731
        end
732
        default:
733
        begin
734
                next_state_tx = TX_IDLE;
735
        end
736
        endcase
737
 
738
 
739
end
740 6 redbear
//SEQUENTIAL TX
741 2 redbear
always@(posedge PCLK)
742
begin
743
 
744
        //RESET SYNC
745
        if(!PRESETn)
746
        begin
747
                //SIGNALS MUST BE RESETED
748
                count_send_data <= 12'd0;
749
                state_tx <= TX_IDLE;
750
                SDA_OUT<= 1'b1;
751
                fifo_tx_rd_en <= 1'b0;
752 6 redbear
                count_tx <= 2'd0;
753 2 redbear
                BR_CLK_O <= 1'b1;
754
                RESPONSE<= 1'b0;
755
        end
756
        else
757
        begin
758
 
759
                // SEQUENTIAL FUN START
760
                state_tx <= next_state_tx;
761
 
762
                case(state_tx)
763
                TX_IDLE:
764
                begin
765
 
766
                        fifo_tx_rd_en <= 1'b0;
767
 
768
 
769 4 redbear
                        if(DATA_CONFIG_REG[0] == 1'b0 && fifo_tx_f_full == 1'b0 && DATA_CONFIG_REG[1] == 1'b0)
770 2 redbear
                        begin
771
                                count_send_data <= 12'd0;
772
                                SDA_OUT<= 1'b1;
773
                                BR_CLK_O <= 1'b1;
774
                        end
775 4 redbear
                        else if(DATA_CONFIG_REG[0] == 1'b1 && fifo_tx_f_full == 1'b1 && DATA_CONFIG_REG[1] == 1'b0)
776 2 redbear
                        begin
777
                                count_send_data <= count_send_data + 12'd1;
778
                                SDA_OUT<=1'b0;
779 4 redbear
                        end
780
                        else if(DATA_CONFIG_REG[0] == 1'b1 && fifo_tx_f_full == 1'b1 && DATA_CONFIG_REG[1] == 1'b1)
781
                        begin
782
                                count_send_data <= 12'd0;
783
                                SDA_OUT<= 1'b1;
784
                                BR_CLK_O <= 1'b1;
785 2 redbear
                        end
786
 
787
                end
788
                TX_START:
789
                begin
790
 
791
                        if(count_send_data < DATA_CONFIG_REG[13:2])
792
                        begin
793
                                count_send_data <= count_send_data + 12'd1;
794
                                BR_CLK_O <= 1'b0;
795
                        end
796
                        else
797
                        begin
798 7 redbear
                                count_send_data <= 12'd0;
799 2 redbear
                        end
800
 
801
                        if(count_send_data == DATA_CONFIG_REG[13:2]- 12'd1)
802
                        begin
803 6 redbear
                                SDA_OUT<=fifo_tx_data_out[0:0];
804
                                count_tx <= 2'd0;
805 2 redbear
                        end
806
 
807
                end
808
                TX_CONTROLIN_1:
809
                begin
810
 
811
 
812
 
813
                        if(count_send_data < DATA_CONFIG_REG[13:2])
814
                        begin
815
 
816
                                count_send_data <= count_send_data + 12'd1;
817
                                SDA_OUT<=fifo_tx_data_out[0:0];
818
 
819 7 redbear
 
820
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
821 2 redbear
                                begin
822 7 redbear
                                        BR_CLK_O <= 1'b0;
823
                                end
824
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
825
                                begin
826 2 redbear
                                        BR_CLK_O <= 1'b1;
827
                                end
828 7 redbear
                                else
829 2 redbear
                                begin
830
                                        BR_CLK_O <= 1'b0;
831
                                end
832
                        end
833
                        else
834
                        begin
835
                                count_send_data <= 12'd0;
836
                                SDA_OUT<=fifo_tx_data_out[1:1];
837
                        end
838
 
839
 
840
                end
841
 
842
                TX_CONTROLIN_2:
843
                begin
844
 
845
 
846
 
847
                        if(count_send_data < DATA_CONFIG_REG[13:2])
848
                        begin
849
                                count_send_data <= count_send_data + 12'd1;
850
                                SDA_OUT<=fifo_tx_data_out[1:1];
851
 
852 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
853 2 redbear
                                begin
854 7 redbear
                                        BR_CLK_O <= 1'b0;
855
                                end
856
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
857
                                begin
858 2 redbear
                                        BR_CLK_O <= 1'b1;
859
                                end
860 7 redbear
                                else
861 2 redbear
                                begin
862
                                        BR_CLK_O <= 1'b0;
863 7 redbear
                                end
864 2 redbear
                        end
865
                        else
866
                        begin
867
                                count_send_data <= 12'd0;
868
                                SDA_OUT<=fifo_tx_data_out[2:2];
869
                        end
870
 
871
                end
872
 
873
                TX_CONTROLIN_3:
874
                begin
875
 
876
 
877
 
878
                        if(count_send_data < DATA_CONFIG_REG[13:2])
879
                        begin
880
                                count_send_data <= count_send_data + 12'd1;
881
                                SDA_OUT<=fifo_tx_data_out[2:2];
882
 
883 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
884 2 redbear
                                begin
885 7 redbear
                                        BR_CLK_O <= 1'b0;
886
                                end
887
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
888
                                begin
889 2 redbear
                                        BR_CLK_O <= 1'b1;
890
                                end
891 7 redbear
                                else
892 2 redbear
                                begin
893
                                        BR_CLK_O <= 1'b0;
894 7 redbear
                                end
895 2 redbear
                        end
896
                        else
897
                        begin
898
                                count_send_data <= 12'd0;
899
                                SDA_OUT<=fifo_tx_data_out[3:3];
900
                        end
901
 
902
 
903
 
904
                end
905
                TX_CONTROLIN_4:
906
                begin
907
 
908
 
909
 
910
                        if(count_send_data < DATA_CONFIG_REG[13:2])
911
                        begin
912
                                count_send_data <= count_send_data + 12'd1;
913
                                SDA_OUT<=fifo_tx_data_out[3:3];
914
 
915 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
916 2 redbear
                                begin
917 7 redbear
                                        BR_CLK_O <= 1'b0;
918
                                end
919
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
920
                                begin
921 2 redbear
                                        BR_CLK_O <= 1'b1;
922
                                end
923 7 redbear
                                else
924 2 redbear
                                begin
925
                                        BR_CLK_O <= 1'b0;
926 7 redbear
                                end
927 2 redbear
                        end
928
                        else
929
                        begin
930
                                count_send_data <= 12'd0;
931
                                SDA_OUT<=fifo_tx_data_out[4:4];
932
                        end
933
 
934
                end
935
 
936
                TX_CONTROLIN_5:
937
                begin
938
 
939
 
940
 
941
                        if(count_send_data < DATA_CONFIG_REG[13:2])
942
                        begin
943
                                count_send_data <= count_send_data + 12'd1;
944
                                SDA_OUT<=fifo_tx_data_out[4:4];
945
 
946 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
947 2 redbear
                                begin
948 7 redbear
                                        BR_CLK_O <= 1'b0;
949
                                end
950
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
951
                                begin
952 2 redbear
                                        BR_CLK_O <= 1'b1;
953
                                end
954 7 redbear
                                else
955 2 redbear
                                begin
956
                                        BR_CLK_O <= 1'b0;
957 7 redbear
                                end
958 2 redbear
                        end
959
                        else
960
                        begin
961
                                count_send_data <= 12'd0;
962
                                SDA_OUT<=fifo_tx_data_out[5:5];
963
                        end
964
 
965
                end
966
 
967
 
968
                TX_CONTROLIN_6:
969
                begin
970
 
971
                        if(count_send_data < DATA_CONFIG_REG[13:2])
972
                        begin
973
                                count_send_data <= count_send_data + 12'd1;
974
                                SDA_OUT<=fifo_tx_data_out[5:5];
975
 
976 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
977 2 redbear
                                begin
978 7 redbear
                                        BR_CLK_O <= 1'b0;
979
                                end
980
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
981
                                begin
982 2 redbear
                                        BR_CLK_O <= 1'b1;
983
                                end
984 7 redbear
                                else
985 2 redbear
                                begin
986
                                        BR_CLK_O <= 1'b0;
987
                                end
988
                        end
989
                        else
990
                        begin
991
                                count_send_data <= 12'd0;
992
                                SDA_OUT<=fifo_tx_data_out[6:6];
993
                        end
994
 
995
 
996
                end
997
 
998
                TX_CONTROLIN_7:
999
                begin
1000
 
1001
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1002
                        begin
1003
                                count_send_data <= count_send_data + 12'd1;
1004
                                SDA_OUT<=fifo_tx_data_out[6:6];
1005
 
1006 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1007 2 redbear
                                begin
1008 7 redbear
                                        BR_CLK_O <= 1'b0;
1009
                                end
1010
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1011
                                begin
1012 2 redbear
                                        BR_CLK_O <= 1'b1;
1013
                                end
1014 7 redbear
                                else
1015 2 redbear
                                begin
1016
                                        BR_CLK_O <= 1'b0;
1017
                                end
1018
                        end
1019
                        else
1020
                        begin
1021
                                count_send_data <= 12'd0;
1022
                                SDA_OUT<=fifo_tx_data_out[7:7];
1023
                        end
1024
 
1025
 
1026
                end
1027
                TX_CONTROLIN_8:
1028
                begin
1029
 
1030
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1031
                        begin
1032
                                count_send_data <= count_send_data + 12'd1;
1033
                                SDA_OUT<=fifo_tx_data_out[7:7];
1034
 
1035 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1036 2 redbear
                                begin
1037 7 redbear
                                        BR_CLK_O <= 1'b0;
1038
                                end
1039
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1040
                                begin
1041 2 redbear
                                        BR_CLK_O <= 1'b1;
1042
                                end
1043 7 redbear
                                else
1044 2 redbear
                                begin
1045
                                        BR_CLK_O <= 1'b0;
1046 7 redbear
                                end
1047 2 redbear
                        end
1048
                        else
1049
                        begin
1050
                                count_send_data <= 12'd0;
1051
                                SDA_OUT<= 1'b0;
1052
                        end
1053
 
1054
 
1055
                end
1056
                TX_RESPONSE_CIN:
1057
                begin
1058
 
1059
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1060
                        begin
1061
                                count_send_data <= count_send_data + 12'd1;
1062
 
1063
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1064
                                RESPONSE<= SDA;
1065
 
1066 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1067 2 redbear
                                begin
1068 7 redbear
                                        BR_CLK_O <= 1'b0;
1069
                                end
1070
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1071
                                begin
1072 2 redbear
                                        BR_CLK_O <= 1'b1;
1073
                                end
1074 7 redbear
                                else
1075 2 redbear
                                begin
1076
                                        BR_CLK_O <= 1'b0;
1077 7 redbear
                                end
1078 2 redbear
                        end
1079
                        else
1080
                        begin
1081
                                count_send_data <= 12'd0;
1082
                        end
1083
 
1084
 
1085
                end
1086
                TX_ADRESS_1:
1087
                begin
1088
 
1089
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1090
                        begin
1091
                                count_send_data <= count_send_data + 12'd1;
1092
                                SDA_OUT<=fifo_tx_data_out[8:8];
1093
 
1094 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1095 2 redbear
                                begin
1096 7 redbear
                                        BR_CLK_O <= 1'b0;
1097
                                end
1098
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1099
                                begin
1100 2 redbear
                                        BR_CLK_O <= 1'b1;
1101
                                end
1102 7 redbear
                                else
1103 2 redbear
                                begin
1104
                                        BR_CLK_O <= 1'b0;
1105 7 redbear
                                end
1106 2 redbear
                        end
1107
                        else
1108
                        begin
1109
                                count_send_data <= 12'd0;
1110
                                SDA_OUT<=fifo_tx_data_out[9:9];
1111
                        end
1112
 
1113
                end
1114
                TX_ADRESS_2:
1115
                begin
1116
 
1117
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1118
                        begin
1119
                                count_send_data <= count_send_data + 12'd1;
1120
                                SDA_OUT<=fifo_tx_data_out[9:9];
1121
 
1122 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1123 2 redbear
                                begin
1124 7 redbear
                                        BR_CLK_O <= 1'b0;
1125
                                end
1126
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1127
                                begin
1128 2 redbear
                                        BR_CLK_O <= 1'b1;
1129
                                end
1130 7 redbear
                                else
1131 2 redbear
                                begin
1132
                                        BR_CLK_O <= 1'b0;
1133 7 redbear
                                end
1134 2 redbear
                        end
1135
                        else
1136
                        begin
1137
                                count_send_data <= 12'd0;
1138
                                SDA_OUT<=fifo_tx_data_out[10:10];
1139
                        end
1140
 
1141
                end
1142
                TX_ADRESS_3:
1143
                begin
1144
 
1145
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1146
                        begin
1147
                                count_send_data <= count_send_data + 12'd1;
1148
                                SDA_OUT<=fifo_tx_data_out[10:10];
1149
 
1150 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1151 2 redbear
                                begin
1152 7 redbear
                                        BR_CLK_O <= 1'b0;
1153
                                end
1154
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1155
                                begin
1156 2 redbear
                                        BR_CLK_O <= 1'b1;
1157
                                end
1158 7 redbear
                                else
1159 2 redbear
                                begin
1160
                                        BR_CLK_O <= 1'b0;
1161 7 redbear
                                end
1162 2 redbear
                        end
1163
                        else
1164
                        begin
1165
                                count_send_data <= 12'd0;
1166
                                SDA_OUT<=fifo_tx_data_out[11:11];
1167
                        end
1168
 
1169
                end
1170
                TX_ADRESS_4:
1171
                begin
1172
 
1173
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1174
                        begin
1175
                                count_send_data <= count_send_data + 12'd1;
1176
                                SDA_OUT<=fifo_tx_data_out[11:11];
1177
 
1178 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1179 2 redbear
                                begin
1180 7 redbear
                                        BR_CLK_O <= 1'b0;
1181
                                end
1182
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1183
                                begin
1184 2 redbear
                                        BR_CLK_O <= 1'b1;
1185
                                end
1186 7 redbear
                                else
1187 2 redbear
                                begin
1188
                                        BR_CLK_O <= 1'b0;
1189 7 redbear
                                end
1190 2 redbear
                        end
1191
                        else
1192
                        begin
1193
                                count_send_data <= 12'd0;
1194
                                SDA_OUT<=fifo_tx_data_out[12:12];
1195
                        end
1196
                end
1197
                TX_ADRESS_5:
1198
                begin
1199
 
1200
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1201
                        begin
1202
                                count_send_data <= count_send_data + 12'd1;
1203
                                SDA_OUT<=fifo_tx_data_out[12:12];
1204
 
1205 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1206 2 redbear
                                begin
1207 7 redbear
                                        BR_CLK_O <= 1'b0;
1208
                                end
1209
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1210
                                begin
1211 2 redbear
                                        BR_CLK_O <= 1'b1;
1212
                                end
1213 7 redbear
                                else
1214 2 redbear
                                begin
1215
                                        BR_CLK_O <= 1'b0;
1216 7 redbear
                                end
1217 2 redbear
                        end
1218
                        else
1219
                        begin
1220
                                count_send_data <= 12'd0;
1221
                                SDA_OUT<=fifo_tx_data_out[13:13];
1222
                        end
1223
 
1224
 
1225
                end
1226
                TX_ADRESS_6:
1227
                begin
1228
 
1229
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1230
                        begin
1231
                                count_send_data <= count_send_data + 12'd1;
1232
                                SDA_OUT<=fifo_tx_data_out[13:13];
1233
 
1234 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1235 2 redbear
                                begin
1236 7 redbear
                                        BR_CLK_O <= 1'b0;
1237
                                end
1238
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1239
                                begin
1240 2 redbear
                                        BR_CLK_O <= 1'b1;
1241
                                end
1242 7 redbear
                                else
1243 2 redbear
                                begin
1244
                                        BR_CLK_O <= 1'b0;
1245
                                end
1246
                        end
1247
                        else
1248
                        begin
1249 7 redbear
                                count_send_data <= 12'd0;
1250 2 redbear
                                SDA_OUT<=fifo_tx_data_out[14:14];
1251
                        end
1252
 
1253
                end
1254
                TX_ADRESS_7:
1255
                begin
1256
 
1257
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1258
                        begin
1259
                                count_send_data <= count_send_data + 12'd1;
1260
                                SDA_OUT<=fifo_tx_data_out[14:14];
1261
 
1262 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1263 2 redbear
                                begin
1264 7 redbear
                                        BR_CLK_O <= 1'b0;
1265
                                end
1266
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1267
                                begin
1268 2 redbear
                                        BR_CLK_O <= 1'b1;
1269
                                end
1270 7 redbear
                                else
1271 2 redbear
                                begin
1272
                                        BR_CLK_O <= 1'b0;
1273 7 redbear
                                end
1274 2 redbear
                        end
1275
                        else
1276
                        begin
1277
                                count_send_data <= 12'd0;
1278
                                SDA_OUT<=fifo_tx_data_out[15:15];
1279
                        end
1280
 
1281
 
1282
                end
1283
                TX_ADRESS_8:
1284
                begin
1285
 
1286
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1287
                        begin
1288
                                count_send_data <= count_send_data + 12'd1;
1289
                                SDA_OUT<=fifo_tx_data_out[15:15];
1290
 
1291 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1292 2 redbear
                                begin
1293 7 redbear
                                        BR_CLK_O <= 1'b0;
1294
                                end
1295
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1296
                                begin
1297 2 redbear
                                        BR_CLK_O <= 1'b1;
1298
                                end
1299 7 redbear
                                else
1300 2 redbear
                                begin
1301
                                        BR_CLK_O <= 1'b0;
1302
                                end
1303
                        end
1304
                        else
1305
                        begin
1306
                                count_send_data <= 12'd0;
1307
                        end
1308
 
1309
                end
1310
                TX_RESPONSE_ADRESS:
1311
                begin
1312
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1313
                        begin
1314
                                count_send_data <= count_send_data + 12'd1;
1315
 
1316
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1317
                                RESPONSE<= SDA;
1318
 
1319 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1320 2 redbear
                                begin
1321 7 redbear
                                        BR_CLK_O <= 1'b0;
1322
                                end
1323
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1324
                                begin
1325 2 redbear
                                        BR_CLK_O <= 1'b1;
1326
                                end
1327 7 redbear
                                else
1328 2 redbear
                                begin
1329
                                        BR_CLK_O <= 1'b0;
1330
                                end
1331
                        end
1332
                        else
1333
                        begin
1334
                                count_send_data <= 12'd0;
1335
                        end
1336
 
1337
                end
1338
                TX_DATA0_1:
1339
                begin
1340
 
1341
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1342
                        begin
1343
                                count_send_data <= count_send_data + 12'd1;
1344
                                SDA_OUT<=fifo_tx_data_out[16:16];
1345
 
1346 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1347 2 redbear
                                begin
1348 7 redbear
                                        BR_CLK_O <= 1'b0;
1349
                                end
1350
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1351
                                begin
1352 2 redbear
                                        BR_CLK_O <= 1'b1;
1353
                                end
1354 7 redbear
                                else
1355 2 redbear
                                begin
1356
                                        BR_CLK_O <= 1'b0;
1357
                                end
1358
                        end
1359
                        else
1360
                        begin
1361
                                count_send_data <= 12'd0;
1362
                                SDA_OUT<=fifo_tx_data_out[17:17];
1363
                        end
1364
 
1365
 
1366
                end
1367
                TX_DATA0_2:
1368
                begin
1369
 
1370
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1371
                        begin
1372
                                count_send_data <= count_send_data + 12'd1;
1373
                                SDA_OUT<=fifo_tx_data_out[17:17];
1374
 
1375 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1376 2 redbear
                                begin
1377 7 redbear
                                        BR_CLK_O <= 1'b0;
1378
                                end
1379
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1380
                                begin
1381 2 redbear
                                        BR_CLK_O <= 1'b1;
1382
                                end
1383 7 redbear
                                else
1384 2 redbear
                                begin
1385
                                        BR_CLK_O <= 1'b0;
1386 7 redbear
                                end
1387 2 redbear
                        end
1388
                        else
1389
                        begin
1390
                                count_send_data <= 12'd0;
1391
                                SDA_OUT<=fifo_tx_data_out[18:18];
1392
                        end
1393
 
1394
 
1395
                end
1396
                TX_DATA0_3:
1397
                begin
1398
 
1399
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1400
                        begin
1401
                                count_send_data <= count_send_data + 12'd1;
1402
                                SDA_OUT<=fifo_tx_data_out[18:18];
1403
 
1404 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1405 2 redbear
                                begin
1406 7 redbear
                                        BR_CLK_O <= 1'b0;
1407
                                end
1408
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1409
                                begin
1410 2 redbear
                                        BR_CLK_O <= 1'b1;
1411
                                end
1412 7 redbear
                                else
1413 2 redbear
                                begin
1414
                                        BR_CLK_O <= 1'b0;
1415 7 redbear
                                end
1416 2 redbear
                        end
1417
                        else
1418
                        begin
1419
                                count_send_data <= 12'd0;
1420
                                SDA_OUT<=fifo_tx_data_out[19:19];
1421
                        end
1422
 
1423
                end
1424
                TX_DATA0_4:
1425
                begin
1426
 
1427
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1428
                        begin
1429
                                count_send_data <= count_send_data + 12'd1;
1430
                                SDA_OUT<=fifo_tx_data_out[19:19];
1431
 
1432 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1433 2 redbear
                                begin
1434 7 redbear
                                        BR_CLK_O <= 1'b0;
1435
                                end
1436
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1437
                                begin
1438 2 redbear
                                        BR_CLK_O <= 1'b1;
1439
                                end
1440 7 redbear
                                else
1441 2 redbear
                                begin
1442
                                        BR_CLK_O <= 1'b0;
1443 7 redbear
                                end
1444 2 redbear
                        end
1445
                        else
1446
                        begin
1447
                                count_send_data <= 12'd0;
1448
                                SDA_OUT<=fifo_tx_data_out[20:20];
1449
                        end
1450
 
1451
                end
1452
                TX_DATA0_5:
1453
                begin
1454
 
1455
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1456
                        begin
1457
                                count_send_data <= count_send_data + 12'd1;
1458
                                SDA_OUT<=fifo_tx_data_out[20:20];
1459
 
1460 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1461 2 redbear
                                begin
1462 7 redbear
                                        BR_CLK_O <= 1'b0;
1463
                                end
1464
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1465
                                begin
1466 2 redbear
                                        BR_CLK_O <= 1'b1;
1467
                                end
1468 7 redbear
                                else
1469 2 redbear
                                begin
1470
                                        BR_CLK_O <= 1'b0;
1471
                                end
1472
                        end
1473
                        else
1474
                        begin
1475
                                count_send_data <= 12'd0;
1476
                                SDA_OUT<=fifo_tx_data_out[21:21];
1477
                        end
1478
 
1479
                end
1480
                TX_DATA0_6:
1481
                begin
1482
 
1483
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1484
                        begin
1485
                                count_send_data <= count_send_data + 12'd1;
1486
                                SDA_OUT<=fifo_tx_data_out[21:21];
1487
 
1488 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1489 2 redbear
                                begin
1490 7 redbear
                                        BR_CLK_O <= 1'b0;
1491
                                end
1492
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1493
                                begin
1494 2 redbear
                                        BR_CLK_O <= 1'b1;
1495
                                end
1496 7 redbear
                                else
1497 2 redbear
                                begin
1498
                                        BR_CLK_O <= 1'b0;
1499
                                end
1500
                        end
1501
                        else
1502
                        begin
1503
                                count_send_data <= 12'd0;
1504
                                SDA_OUT<=fifo_tx_data_out[22:22];
1505
                        end
1506
 
1507
                end
1508
                TX_DATA0_7:
1509
                begin
1510
 
1511
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1512
                        begin
1513
                                count_send_data <= count_send_data + 12'd1;
1514
                                SDA_OUT<=fifo_tx_data_out[22:22];
1515
 
1516 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1517 2 redbear
                                begin
1518 7 redbear
                                        BR_CLK_O <= 1'b0;
1519
                                end
1520
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1521
                                begin
1522 2 redbear
                                        BR_CLK_O <= 1'b1;
1523
                                end
1524 7 redbear
                                else
1525 2 redbear
                                begin
1526
                                        BR_CLK_O <= 1'b0;
1527 7 redbear
                                end
1528 2 redbear
                        end
1529
                        else
1530
                        begin
1531
                                count_send_data <= 12'd0;
1532
                                SDA_OUT<=fifo_tx_data_out[23:23];
1533
                        end
1534
 
1535
                end
1536
                TX_DATA0_8:
1537
                begin
1538
 
1539
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1540
                        begin
1541
                                count_send_data <= count_send_data + 12'd1;
1542
                                SDA_OUT<=fifo_tx_data_out[23:23];
1543
 
1544 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1545 2 redbear
                                begin
1546 7 redbear
                                        BR_CLK_O <= 1'b0;
1547
                                end
1548
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1549
                                begin
1550 2 redbear
                                        BR_CLK_O <= 1'b1;
1551
                                end
1552 7 redbear
                                else
1553 2 redbear
                                begin
1554
                                        BR_CLK_O <= 1'b0;
1555
                                end
1556
 
1557
                        end
1558
                        else
1559
                        begin
1560
                                count_send_data <= 12'd0;
1561
                        end
1562
 
1563
                end
1564
                TX_RESPONSE_DATA0_1:
1565
                begin
1566
 
1567
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1568
                        begin
1569
                                count_send_data <= count_send_data + 12'd1;
1570
 
1571
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1572
                                RESPONSE<= SDA;
1573
 
1574 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1575 2 redbear
                                begin
1576 7 redbear
                                        BR_CLK_O <= 1'b0;
1577
                                end
1578
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1579
                                begin
1580 2 redbear
                                        BR_CLK_O <= 1'b1;
1581
                                end
1582 7 redbear
                                else
1583 2 redbear
                                begin
1584
                                        BR_CLK_O <= 1'b0;
1585 7 redbear
                                end
1586 2 redbear
                        end
1587
                        else
1588
                        begin
1589
                                count_send_data <= 12'd0;
1590
                        end
1591
 
1592
                end
1593
                TX_DATA1_1:
1594
                begin
1595
 
1596
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1597
                        begin
1598
                                count_send_data <= count_send_data + 12'd1;
1599
                                SDA_OUT<=fifo_tx_data_out[24:24];
1600
 
1601 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1602 2 redbear
                                begin
1603 7 redbear
                                        BR_CLK_O <= 1'b0;
1604
                                end
1605
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1606
                                begin
1607 2 redbear
                                        BR_CLK_O <= 1'b1;
1608
                                end
1609 7 redbear
                                else
1610 2 redbear
                                begin
1611
                                        BR_CLK_O <= 1'b0;
1612 7 redbear
                                end
1613 2 redbear
                        end
1614
                        else
1615
                        begin
1616
                                count_send_data <= 12'd0;
1617
                                SDA_OUT<=fifo_tx_data_out[25:25];
1618
 
1619
                        end
1620
 
1621
 
1622
                end
1623
                TX_DATA1_2:
1624
                begin
1625
 
1626
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1627
                        begin
1628
                                count_send_data <= count_send_data + 12'd1;
1629
                                SDA_OUT<=fifo_tx_data_out[25:25];
1630
 
1631 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1632 2 redbear
                                begin
1633 7 redbear
                                        BR_CLK_O <= 1'b0;
1634
                                end
1635
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1636
                                begin
1637 2 redbear
                                        BR_CLK_O <= 1'b1;
1638
                                end
1639 7 redbear
                                else
1640 2 redbear
                                begin
1641
                                        BR_CLK_O <= 1'b0;
1642 7 redbear
                                end
1643 2 redbear
                        end
1644
                        else
1645
                        begin
1646
                                count_send_data <= 12'd0;
1647
                                SDA_OUT<=fifo_tx_data_out[26:26];
1648
                        end
1649
 
1650
                end
1651
                TX_DATA1_3:
1652
                begin
1653
 
1654
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1655
                        begin
1656
                                count_send_data <= count_send_data + 12'd1;
1657
                                SDA_OUT<=fifo_tx_data_out[26:26];
1658
 
1659 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1660 2 redbear
                                begin
1661 7 redbear
                                        BR_CLK_O <= 1'b0;
1662
                                end
1663
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1664
                                begin
1665 2 redbear
                                        BR_CLK_O <= 1'b1;
1666
                                end
1667 7 redbear
                                else
1668 2 redbear
                                begin
1669
                                        BR_CLK_O <= 1'b0;
1670
                                end
1671
 
1672
                        end
1673
                        else
1674
                        begin
1675
                                count_send_data <= 12'd0;
1676
                                SDA_OUT<=fifo_tx_data_out[27:27];
1677
                        end
1678
 
1679
                end
1680
                TX_DATA1_4:
1681
                begin
1682
 
1683
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1684
                        begin
1685
                                count_send_data <= count_send_data + 12'd1;
1686
                                SDA_OUT<=fifo_tx_data_out[27:27];
1687
 
1688 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1689 2 redbear
                                begin
1690 7 redbear
                                        BR_CLK_O <= 1'b0;
1691
                                end
1692
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1693
                                begin
1694 2 redbear
                                        BR_CLK_O <= 1'b1;
1695
                                end
1696 7 redbear
                                else
1697 2 redbear
                                begin
1698
                                        BR_CLK_O <= 1'b0;
1699 7 redbear
                                end
1700 2 redbear
 
1701
                        end
1702
                        else
1703
                        begin
1704
                                count_send_data <= 12'd0;
1705
                                SDA_OUT<=fifo_tx_data_out[28:28];
1706
                        end
1707
 
1708
                end
1709
                TX_DATA1_5:
1710
                begin
1711
 
1712
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1713
                        begin
1714
                                count_send_data <= count_send_data + 12'd1;
1715
                                SDA_OUT<=fifo_tx_data_out[28:28];
1716
 
1717 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1718 2 redbear
                                begin
1719 7 redbear
                                        BR_CLK_O <= 1'b0;
1720
                                end
1721
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1722
                                begin
1723 2 redbear
                                        BR_CLK_O <= 1'b1;
1724
                                end
1725 7 redbear
                                else
1726 2 redbear
                                begin
1727
                                        BR_CLK_O <= 1'b0;
1728
                                end
1729
 
1730
                        end
1731
                        else
1732
                        begin
1733
                                count_send_data <= 12'd0;
1734
                                SDA_OUT<=fifo_tx_data_out[29:29];
1735
                        end
1736
 
1737
                end
1738
                TX_DATA1_6:
1739
                begin
1740
 
1741
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1742
                        begin
1743
                                count_send_data <= count_send_data + 12'd1;
1744
                                SDA_OUT<=fifo_tx_data_out[29:29];
1745
 
1746 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1747 2 redbear
                                begin
1748 7 redbear
                                        BR_CLK_O <= 1'b0;
1749
                                end
1750
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1751
                                begin
1752 2 redbear
                                        BR_CLK_O <= 1'b1;
1753
                                end
1754 7 redbear
                                else
1755 2 redbear
                                begin
1756
                                        BR_CLK_O <= 1'b0;
1757
                                end
1758
 
1759
                        end
1760
                        else
1761
                        begin
1762
                                count_send_data <= 12'd0;
1763
                                SDA_OUT<=fifo_tx_data_out[30:30];
1764
                        end
1765
 
1766
                end
1767
                TX_DATA1_7:
1768
                begin
1769
 
1770
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1771
                        begin
1772
                                count_send_data <= count_send_data + 12'd1;
1773
                                SDA_OUT<=fifo_tx_data_out[30:30];
1774
 
1775 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1776 2 redbear
                                begin
1777 7 redbear
                                        BR_CLK_O <= 1'b0;
1778
                                end
1779
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1780
                                begin
1781 2 redbear
                                        BR_CLK_O <= 1'b1;
1782
                                end
1783 7 redbear
                                else
1784 2 redbear
                                begin
1785
                                        BR_CLK_O <= 1'b0;
1786
                                end
1787
 
1788
                        end
1789
                        else
1790
                        begin
1791
                                count_send_data <= 12'd0;
1792
                                SDA_OUT<=fifo_tx_data_out[31:31];
1793
                        end
1794
 
1795
 
1796
                end
1797
                TX_DATA1_8:
1798
                begin
1799
 
1800
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1801
                        begin
1802
                                count_send_data <= count_send_data + 12'd1;
1803
                                SDA_OUT<=fifo_tx_data_out[31:31];
1804
 
1805 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1806 2 redbear
                                begin
1807 7 redbear
                                        BR_CLK_O <= 1'b0;
1808
                                end
1809
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1810
                                begin
1811 2 redbear
                                        BR_CLK_O <= 1'b1;
1812
                                end
1813 7 redbear
                                else
1814 2 redbear
                                begin
1815
                                        BR_CLK_O <= 1'b0;
1816
                                end
1817
 
1818
                        end
1819
                        else
1820
                        begin
1821
                                count_send_data <= 12'd0;
1822
                        end
1823
 
1824
                end
1825
                TX_RESPONSE_DATA1_1:
1826
                begin
1827
                        //fifo_tx_rd_en <= 1'b1;
1828
 
1829
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1830
                        begin
1831
                                count_send_data <= count_send_data + 12'd1;
1832
 
1833
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1834
                                RESPONSE<= SDA;
1835
 
1836 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1837 2 redbear
                                begin
1838 7 redbear
                                        BR_CLK_O <= 1'b0;
1839
                                end
1840
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1841
                                begin
1842 2 redbear
                                        BR_CLK_O <= 1'b1;
1843
                                end
1844 7 redbear
                                else
1845 2 redbear
                                begin
1846
                                        BR_CLK_O <= 1'b0;
1847 7 redbear
                                end
1848 2 redbear
                        end
1849
                        else
1850
                        begin
1851
                                count_send_data <= 12'd0;
1852
                                fifo_tx_rd_en <= 1'b1;
1853
                        end
1854
 
1855
                end
1856
                TX_DELAY_BYTES:
1857
                begin
1858
 
1859
                        fifo_tx_rd_en <= 1'b0;
1860
 
1861
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1862
                        begin
1863
 
1864
                                count_send_data <= count_send_data + 12'd1;
1865
                                BR_CLK_O <= 1'b0;
1866
                                SDA_OUT<=1'b0;
1867
                        end
1868
                        else
1869
                        begin
1870
 
1871
 
1872 6 redbear
                                if(count_tx == 2'd0)
1873 2 redbear
                                begin
1874 6 redbear
                                        count_tx <= count_tx + 2'd1;
1875 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[8:8];
1876
                                end
1877 6 redbear
                                else if(count_tx == 2'd1)
1878 2 redbear
                                begin
1879 6 redbear
                                        count_tx <= count_tx + 2'd1;
1880 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[16:16];
1881
                                end
1882 6 redbear
                                else if(count_tx == 2'd2)
1883 2 redbear
                                begin
1884 6 redbear
                                        count_tx <= count_tx + 2'd1;
1885 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[24:24];
1886
                                end
1887 6 redbear
                                else if(count_tx == 2'd3)
1888 2 redbear
                                begin
1889 6 redbear
                                        count_tx <= 2'd0;
1890 2 redbear
                                end
1891
 
1892
                                count_send_data <= 12'd0;
1893
 
1894
                        end
1895
 
1896
                end
1897
                //THIS BLOCK MUST BE CHECKED WITH CARE
1898
                TX_NACK:// MORE A RESTART 
1899
                begin
1900
                        fifo_tx_rd_en <= 1'b0;
1901
 
1902
                        if(count_send_data < DATA_CONFIG_REG[13:2]*2'd2)
1903
                        begin
1904
                                count_send_data <= count_send_data + 12'd1;
1905
 
1906 6 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1907 2 redbear
                                begin
1908
                                        SDA_OUT<=1'b0;
1909
                                end
1910
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1911
                                begin
1912
                                        SDA_OUT<=1'b1;
1913
                                end
1914
                                else if(count_send_data  == DATA_CONFIG_REG[13:2]*2'd2)
1915
                                begin
1916
                                        SDA_OUT<=1'b0;
1917
                                end
1918
 
1919 6 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1920 2 redbear
                                begin
1921
                                        BR_CLK_O <= 1'b1;
1922
                                end
1923
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1924
                                begin
1925
                                        BR_CLK_O <= 1'b0;
1926
                                end
1927
                                else if(count_send_data < DATA_CONFIG_REG[13:2]*2'd2)
1928
                                begin
1929
                                        BR_CLK_O <= 1'b1;
1930
                                end
1931
 
1932
                        end
1933
                        else
1934
                        begin
1935
                                count_send_data <= 12'd0;
1936
 
1937 6 redbear
                                if(count_tx == 2'd0)
1938 2 redbear
                                begin
1939 6 redbear
                                        count_tx <= 2'd0;
1940 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[0:0];
1941
                                end
1942 6 redbear
                                else if(count_tx == 2'd1)
1943 2 redbear
                                begin
1944 6 redbear
                                        count_tx <= 2'd1;
1945 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[8:8];
1946
                                end
1947 6 redbear
                                else if(count_tx == 2'd2)
1948 2 redbear
                                begin
1949 6 redbear
                                        count_tx <= 2'd2;
1950 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[16:16];
1951
                                end
1952 6 redbear
                                else if(count_tx == 2'd3)
1953 2 redbear
                                begin
1954 6 redbear
                                        count_tx <= 2'd3;
1955 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[24:24];
1956
                                end
1957
 
1958
 
1959
                        end
1960
                end
1961
                TX_STOP:
1962
                begin
1963 7 redbear
 
1964
                        BR_CLK_O <= 1'b1;
1965
 
1966 2 redbear
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1967
                        begin
1968
                                count_send_data <= count_send_data + 12'd1;
1969
 
1970
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
1971
                                begin
1972
                                        SDA_OUT<=1'b0;
1973
                                end
1974
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1975
                                begin
1976
                                        SDA_OUT<=1'b1;
1977
                                end
1978
                        end
1979
                        else
1980
                        begin
1981
                                count_send_data <= 12'd0;
1982
                        end
1983
                end
1984
                default:
1985
                begin
1986
                        fifo_tx_rd_en <= 1'b0;
1987
                        count_send_data <= 12'd4095;
1988
                end
1989
                endcase
1990
 
1991
        end
1992
 
1993
 
1994
end
1995
 
1996
 
1997 6 redbear
// RX PARAMETERS USED TO STATE MACHINE
1998 2 redbear
 
1999 6 redbear
localparam [5:0] RX_IDLE = 6'd0, //IDLE
2000
 
2001
           RX_START = 6'd1,//START BIT
2002
 
2003
           RX_CONTROLIN_1 = 6'd2, //START BYTE
2004
           RX_CONTROLIN_2 = 6'd3,
2005
           RX_CONTROLIN_3 = 6'd4,
2006
           RX_CONTROLIN_4 = 6'd5,
2007
           RX_CONTROLIN_5 = 6'd6,
2008
           RX_CONTROLIN_6 = 6'd7,
2009
           RX_CONTROLIN_7 = 6'd8,
2010
           RX_CONTROLIN_8 = 6'd9, //END FIRST BYTE
2011
 
2012
           RX_RESPONSE_CIN =6'd10, //RESPONSE
2013
 
2014
           RX_ADRESS_1 = 6'd11,//START BYTE
2015
           RX_ADRESS_2 = 6'd12,
2016
           RX_ADRESS_3 = 6'd13,
2017
           RX_ADRESS_4 = 6'd14,
2018
           RX_ADRESS_5 = 6'd15,
2019
           RX_ADRESS_6 = 6'd16,
2020
           RX_ADRESS_7 = 6'd17,
2021
           RX_ADRESS_8 = 6'd18,//END FIRST BYTE
2022
 
2023
           RX_RESPONSE_ADRESS =6'd19, //RESPONSE
2024
 
2025
           RX_DATA0_1 = 6'd20,//START BYTE
2026
           RX_DATA0_2 = 6'd21,
2027
           RX_DATA0_3 = 6'd22,
2028
           RX_DATA0_4 = 6'd23,
2029
           RX_DATA0_5 = 6'd24,
2030
           RX_DATA0_6 = 6'd25,
2031
           RX_DATA0_7 = 6'd26,
2032
           RX_DATA0_8 = 6'd27,//END FIRST BYTE
2033
 
2034
           RX_RESPONSE_DATA0_1 = 6'd28,  //RESPONSE
2035
 
2036
           RX_DATA1_1 = 6'd29,//START BYTE
2037
           RX_DATA1_2 = 6'd30,
2038
           RX_DATA1_3 = 6'd31,
2039
           RX_DATA1_4 = 6'd32,
2040
           RX_DATA1_5 = 6'd33,
2041
           RX_DATA1_6 = 6'd34,
2042
           RX_DATA1_7 = 6'd35,
2043
           RX_DATA1_8 = 6'd36,//END FIRST BYTE
2044
 
2045
           RX_RESPONSE_DATA1_1 = 6'd37,//RESPONSE
2046
 
2047
           RX_DELAY_BYTES = 6'd38,//USED ONLY IN ACK TO DELAY BETWEEN
2048
           RX_NACK = 6'd39,//USED ONLY IN ACK TO DELAY BETWEEN BYTES
2049
           RX_STOP = 6'd40;//USED TO SEND STOP BIT
2050
 
2051
        //STATE CONTROL 
2052
        reg [5:0] state_rx;
2053
        reg [5:0] next_state_rx;
2054
 
2055
        reg [11:0] count_receive_data;
2056
 
2057
        reg [1:0] count_rx;
2058
 
2059
//COMBINATIONAL BLOCK RX
2060
 
2061
always@(*)
2062
begin
2063
 
2064
 
2065
        next_state_rx = state_rx;
2066
 
2067
        case(state_rx)//STATE_RX IS MORE SECURE CHANGE ONLY IF YOU KNOW WHAT ARE YOU DOING 
2068
        RX_IDLE:
2069
        begin
2070
                //OBEYING SPEC
2071
                if(DATA_CONFIG_REG[1] == 1'b0 && DATA_CONFIG_REG[0] == 1'b0)
2072
                begin
2073
                        next_state_rx = RX_IDLE;
2074
                end
2075
                else if(DATA_CONFIG_REG[1] == 1'b1 && DATA_CONFIG_REG[0] == 1'b1)
2076
                begin
2077
                        next_state_rx = RX_IDLE;
2078
                end
2079
                else if(DATA_CONFIG_REG[1] == 1'b1 && DATA_CONFIG_REG[0] == 1'b0 && SDA == 1'b0 && SCL == 1'b1)
2080
                begin
2081
                        next_state_rx = RX_START;
2082
                end
2083
        end
2084
        RX_START:
2085
        begin
2086
 
2087
                if(SDA == 1'b0 && SCL == 1'b1)
2088
                begin
2089
                        if(count_receive_data != DATA_CONFIG_REG[13:2])
2090
                        begin
2091
                                next_state_rx = RX_START;
2092
                        end
2093
                        else
2094
                        begin
2095
                                next_state_rx = RX_CONTROLIN_1;
2096
                        end
2097
                end
2098
                else
2099
                begin
2100
                        next_state_rx = RX_IDLE;
2101
                end
2102
        end
2103
        RX_CONTROLIN_1:
2104
        begin
2105
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2106
                begin
2107
                        next_state_rx = RX_CONTROLIN_1;
2108
                end
2109
                else
2110
                begin
2111
                        next_state_rx = RX_CONTROLIN_2;
2112
                end
2113
        end
2114
        RX_CONTROLIN_2:
2115
        begin
2116
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2117
                begin
2118
                        next_state_rx = RX_CONTROLIN_2;
2119
                end
2120
                else
2121
                begin
2122
                        next_state_rx = RX_CONTROLIN_3;
2123
                end
2124
        end
2125
        RX_CONTROLIN_3:
2126
        begin
2127
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2128
                begin
2129
                        next_state_rx = RX_CONTROLIN_3;
2130
                end
2131
                else
2132
                begin
2133
                        next_state_rx = RX_CONTROLIN_4;
2134
                end
2135
        end
2136
        RX_CONTROLIN_4:
2137
        begin
2138
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2139
                begin
2140
                        next_state_rx = RX_CONTROLIN_4;
2141
                end
2142
                else
2143
                begin
2144
                        next_state_rx = RX_CONTROLIN_5;
2145
                end
2146
        end
2147
        RX_CONTROLIN_5:
2148
        begin
2149
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2150
                begin
2151
                        next_state_rx = RX_CONTROLIN_5;
2152
                end
2153
                else
2154
                begin
2155
                        next_state_rx = RX_CONTROLIN_6;
2156
                end
2157
        end
2158
        RX_CONTROLIN_6:
2159
        begin
2160
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2161
                begin
2162
                        next_state_rx = RX_CONTROLIN_6;
2163
                end
2164
                else
2165
                begin
2166
                        next_state_rx = RX_CONTROLIN_7;
2167
                end
2168
        end
2169
        RX_CONTROLIN_7:
2170
        begin
2171
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2172
                begin
2173
                        next_state_rx = RX_CONTROLIN_7;
2174
                end
2175
                else
2176
                begin
2177
                        next_state_rx = RX_CONTROLIN_8;
2178
                end
2179
        end
2180
        RX_CONTROLIN_8:
2181
        begin
2182
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2183
                begin
2184
                        next_state_rx = RX_CONTROLIN_8;
2185
                end
2186
                else
2187
                begin
2188
                        next_state_rx = RX_RESPONSE_CIN;
2189
                end
2190
        end
2191
        RX_RESPONSE_CIN:
2192
        begin
2193
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2194
                begin
2195
                        next_state_rx = RX_CONTROLIN_8;
2196
                end
2197
                else
2198
                begin
2199
                        next_state_rx = RX_RESPONSE_CIN;
2200
                end
2201
        end
2202
 
2203
        RX_ADRESS_1:
2204
        begin
2205
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2206
                begin
2207
                        next_state_rx = RX_ADRESS_1;
2208
                end
2209
                else
2210
                begin
2211
                        next_state_rx = RX_ADRESS_2;
2212
                end
2213
        end
2214
        RX_ADRESS_2:
2215
        begin
2216
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2217
                begin
2218
                        next_state_rx = RX_ADRESS_2;
2219
                end
2220
                else
2221
                begin
2222
                        next_state_rx = RX_ADRESS_3;
2223
                end
2224
        end
2225
        RX_ADRESS_3:
2226
        begin
2227
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2228
                begin
2229
                        next_state_rx = RX_ADRESS_3;
2230
                end
2231
                else
2232
                begin
2233
                        next_state_rx = RX_ADRESS_4;
2234
                end
2235
        end
2236
        RX_ADRESS_4:
2237
        begin
2238
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2239
                begin
2240
                        next_state_rx = RX_ADRESS_4;
2241
                end
2242
                else
2243
                begin
2244
                        next_state_rx = RX_ADRESS_5;
2245
                end
2246
        end
2247
        RX_ADRESS_5:
2248
        begin
2249
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2250
                begin
2251
                        next_state_rx = RX_ADRESS_5;
2252
                end
2253
                else
2254
                begin
2255
                        next_state_rx = RX_ADRESS_6;
2256
                end
2257
        end
2258
        RX_ADRESS_6:
2259
        begin
2260
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2261
                begin
2262
                        next_state_rx = RX_ADRESS_6;
2263
                end
2264
                else
2265
                begin
2266
                        next_state_rx = RX_ADRESS_7;
2267
                end
2268
        end
2269
        RX_ADRESS_7:
2270
        begin
2271
 
2272
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2273
                begin
2274
                        next_state_rx = RX_ADRESS_7;
2275
                end
2276
                else
2277
                begin
2278
                        next_state_rx = RX_ADRESS_8;
2279
                end
2280
 
2281
        end
2282
        RX_ADRESS_8:
2283
        begin
2284
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2285
                begin
2286
                        next_state_rx = RX_ADRESS_8;
2287
                end
2288
                else
2289
                begin
2290
                        next_state_rx = RX_RESPONSE_ADRESS;
2291
                end
2292
        end
2293
        RX_RESPONSE_ADRESS:
2294
        begin
2295
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2296
                begin
2297
                        next_state_rx = RX_RESPONSE_ADRESS;
2298
                end
2299
                else
2300
                begin
2301
                        next_state_rx = RX_DATA0_1;
2302
                end
2303
        end
2304
 
2305
        RX_DATA0_1:
2306
        begin
2307
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2308
                begin
2309
                        next_state_rx = RX_DATA0_1;
2310
                end
2311
                else
2312
                begin
2313
                        next_state_rx = RX_DATA0_2;
2314
                end
2315
        end
2316
        RX_DATA0_2:
2317
        begin
2318
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2319
                begin
2320
                        next_state_rx = RX_DATA0_2;
2321
                end
2322
                else
2323
                begin
2324
                        next_state_rx = RX_DATA0_3;
2325
                end
2326
        end
2327
        RX_DATA0_3:
2328
        begin
2329
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2330
                begin
2331
                        next_state_rx = RX_DATA0_3;
2332
                end
2333
                else
2334
                begin
2335
                        next_state_rx = RX_DATA0_4;
2336
                end
2337
        end
2338
        RX_DATA0_4:
2339
        begin
2340
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2341
                begin
2342
                        next_state_rx = RX_DATA0_4;
2343
                end
2344
                else
2345
                begin
2346
                        next_state_rx = RX_DATA0_5;
2347
                end
2348
        end
2349
        RX_DATA0_5:
2350
        begin
2351
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2352
                begin
2353
                        next_state_rx = RX_DATA0_5;
2354
                end
2355
                else
2356
                begin
2357
                        next_state_rx = RX_DATA0_6;
2358
                end
2359
        end
2360
        RX_DATA0_6:
2361
        begin
2362
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2363
                begin
2364
                        next_state_rx = RX_DATA0_6;
2365
                end
2366
                else
2367
                begin
2368
                        next_state_rx = RX_DATA0_7;
2369
                end
2370
        end
2371
        RX_DATA0_7:
2372
        begin
2373
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2374
                begin
2375
                        next_state_rx = RX_DATA0_7;
2376
                end
2377
                else
2378
                begin
2379
                        next_state_rx = RX_DATA0_8;
2380
                end
2381
        end
2382
        RX_DATA0_8:
2383
        begin
2384
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2385
                begin
2386
                        next_state_rx = RX_DATA0_8;
2387
                end
2388
                else
2389
                begin
2390
                        next_state_rx = RX_RESPONSE_DATA0_1;
2391
                end
2392
        end
2393
        RX_RESPONSE_DATA0_1:
2394
        begin
2395
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2396
                begin
2397
                        next_state_rx = RX_RESPONSE_DATA0_1;
2398
                end
2399
                else
2400
                begin
2401
                        next_state_rx = RX_DATA1_1;
2402
                end
2403
        end
2404
        RX_DATA1_1:
2405
        begin
2406
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2407
                begin
2408
                        next_state_rx = RX_DATA1_1;
2409
                end
2410
                else
2411
                begin
2412
                        next_state_rx = RX_DATA1_2;
2413
                end
2414
        end
2415
        RX_DATA1_2:
2416
        begin
2417
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2418
                begin
2419
                        next_state_rx = RX_DATA1_1;
2420
                end
2421
                else
2422
                begin
2423
                        next_state_rx = RX_DATA1_3;
2424
                end
2425
        end
2426
        RX_DATA1_3:
2427
        begin
2428
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2429
                begin
2430
                        next_state_rx = RX_DATA1_3;
2431
                end
2432
                else
2433
                begin
2434
                        next_state_rx = RX_DATA1_4;
2435
                end
2436
        end
2437
        RX_DATA1_4:
2438
        begin
2439
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2440
                begin
2441
                        next_state_rx = RX_DATA1_4;
2442
                end
2443
                else
2444
                begin
2445
                        next_state_rx = RX_DATA1_5;
2446
                end
2447
        end
2448
        RX_DATA1_5:
2449
        begin
2450
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2451
                begin
2452
                        next_state_rx = RX_DATA1_5;
2453
                end
2454
                else
2455
                begin
2456
                        next_state_rx = RX_DATA1_6;
2457
                end
2458
        end
2459
        RX_DATA1_6:
2460
        begin
2461
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2462
                begin
2463
                        next_state_rx = RX_DATA1_6;
2464
                end
2465
                else
2466
                begin
2467
                        next_state_rx = RX_DATA1_7;
2468
                end
2469
        end
2470
        RX_DATA1_7:
2471
        begin
2472
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2473
                begin
2474
                        next_state_rx = RX_DATA1_7;
2475
                end
2476
                else
2477
                begin
2478
                        next_state_rx = RX_DATA1_8;
2479
                end
2480
        end
2481
        RX_DATA1_8:
2482
        begin
2483
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2484
                begin
2485
                        next_state_rx = RX_DATA1_8;
2486
                end
2487
                else
2488
                begin
2489
                        next_state_rx = RX_RESPONSE_DATA1_1;
2490
                end
2491
        end
2492
        RX_RESPONSE_DATA1_1:
2493
        begin
2494
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2495
                begin
2496
                        next_state_rx = RX_RESPONSE_DATA1_1;
2497
                end
2498
                else
2499
                begin
2500
                        next_state_rx = RX_DELAY_BYTES;
2501
                end
2502
        end
2503
        RX_DELAY_BYTES:
2504
        begin
2505
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2506
                begin
2507
                        next_state_rx = RX_DELAY_BYTES;
2508
                end
2509
                else
2510
                begin
2511
 
2512
                        if(count_rx == 2'd0)
2513
                        begin
2514
                                next_state_rx = RX_ADRESS_1;
2515
                        end
2516
                        else if(count_rx == 2'd1)
2517
                        begin
2518
                                next_state_rx = RX_DATA0_1;
2519
                        end
2520
                        else if(count_rx == 2'd2)
2521
                        begin
2522
                                next_state_rx = RX_DATA1_1;
2523
                        end
2524
                        else if(count_rx == 2'd3)
2525
                        begin
2526
                                next_state_rx = RX_STOP;
2527
                        end
2528
 
2529
                end
2530
        end
2531
        RX_NACK:
2532
        begin
2533
 
2534
                        if(count_receive_data != DATA_CONFIG_REG[13:2]*2'd2)
2535
                        begin
2536
                                next_state_rx = RX_NACK;
2537
                        end
2538
                        else
2539
                        begin
2540
                                if(count_rx == 2'd0)
2541
                                begin
2542
                                        next_state_rx = RX_CONTROLIN_1;
2543
                                end
2544
                                else if(count_rx == 2'd1)
2545
                                begin
2546
                                        next_state_rx = RX_ADRESS_1;
2547
                                end
2548
                                else if(count_rx == 2'd2)
2549
                                begin
2550
                                        next_state_rx = RX_DATA0_1;
2551
                                end
2552
                                else if(count_rx == 2'd3)
2553
                                begin
2554
                                        next_state_rx = RX_DATA1_1;
2555
                                end
2556
                        end
2557
 
2558
 
2559
        end
2560
        RX_STOP:
2561
        begin
2562
 
2563
                if(count_receive_data != DATA_CONFIG_REG[13:2])
2564
                begin
2565
                        next_state_rx = RX_STOP;
2566
                end
2567
                else
2568
                begin
2569
                        next_state_rx = RX_IDLE;
2570
                end
2571
 
2572
        end
2573
        default:
2574
        begin
2575
                        next_state_rx = RX_IDLE;
2576
        end
2577
        endcase
2578
end
2579
 
2580
 
2581
//SEQUENTIAL BLOCK RX
2582
 
2583
always@(posedge PCLK)
2584
begin
2585
 
2586
        if(!PRESETn)
2587
        begin
2588
                //SIGNALS MUST BE RESETED
2589
                count_receive_data <= 12'd0;
2590
                state_rx <= RX_IDLE;
2591
                fifo_rx_wr_en <= 1'b0;
2592
                count_rx <= 2'd0;
2593
        end
2594
        else
2595
        begin
2596
 
2597
                state_rx <= next_state_rx;
2598
 
2599
                case(state_rx)//STATE_RX IS MORE SECURE CHANGE ONLY IF YOU KNOW WHAT ARE YOU DOING 
2600
                RX_IDLE:
2601
                begin
2602
                        if(SDA == 1'b0 && SCL == 1'b1)
2603
                        begin
2604
                                count_receive_data <= count_receive_data +12'd1;
2605
                        end
2606
                        else
2607
                        begin
2608
                                count_receive_data <= 12'd0;
2609
                        end
2610
                end
2611
                RX_START:
2612
                begin
2613
                        if(SDA == 1'b0 && SCL == 1'b0)
2614
                        begin
2615
                                count_receive_data <= count_receive_data +12'd1;
2616
                        end
2617
                        else
2618
                        begin
2619
                                count_receive_data <= 12'd0;
2620
                        end
2621
                end
2622
                RX_CONTROLIN_1:
2623
                begin
2624
 
2625
                end
2626
                RX_CONTROLIN_2:
2627
                begin
2628
 
2629
                end
2630
                RX_CONTROLIN_3:
2631
                begin
2632
 
2633
                end
2634
                RX_CONTROLIN_4:
2635
                begin
2636
 
2637
                end
2638
                RX_CONTROLIN_5:
2639
                begin
2640
 
2641
                end
2642
                RX_CONTROLIN_6:
2643
                begin
2644
 
2645
                end
2646
                RX_CONTROLIN_7:
2647
                begin
2648
 
2649
                end
2650
                RX_CONTROLIN_8:
2651
                begin
2652
 
2653
                end
2654
                RX_RESPONSE_CIN:
2655
                begin
2656
 
2657
                end
2658
                RX_ADRESS_1:
2659
                begin
2660
                end
2661
                RX_ADRESS_2:
2662
                begin
2663
                end
2664
                RX_ADRESS_3:
2665
                begin
2666
                end
2667
                RX_ADRESS_4:
2668
                begin
2669
                end
2670
                RX_ADRESS_5:
2671
                begin
2672
                end
2673
                RX_ADRESS_6:
2674
                begin
2675
                end
2676
                RX_ADRESS_7:
2677
                begin
2678
                end
2679
                RX_ADRESS_8:
2680
                begin
2681
                end
2682
                RX_RESPONSE_ADRESS:
2683
                begin
2684
 
2685
                end
2686
                RX_DATA0_1:
2687
                begin
2688
 
2689
                end
2690
                RX_DATA0_2:
2691
                begin
2692
 
2693
                end
2694
                RX_DATA0_3:
2695
                begin
2696
 
2697
                end
2698
                RX_DATA0_4:
2699
                begin
2700
 
2701
                end
2702
                RX_DATA0_5:
2703
                begin
2704
 
2705
                end
2706
                RX_DATA0_6:
2707
                begin
2708
 
2709
                end
2710
                RX_DATA0_7:
2711
                begin
2712
 
2713
                end
2714
                RX_DATA0_8:
2715
                begin
2716
 
2717
                end
2718
                RX_RESPONSE_DATA0_1:
2719
                begin
2720
                end
2721
 
2722
                RX_DATA1_1:
2723
                begin
2724
 
2725
                end
2726
                RX_DATA1_2:
2727
                begin
2728
 
2729
                end
2730
                RX_DATA1_3:
2731
                begin
2732
 
2733
                end
2734
                RX_DATA1_4:
2735
                begin
2736
 
2737
                end
2738
                RX_DATA1_5:
2739
                begin
2740
 
2741
                end
2742
                RX_DATA1_6:
2743
                begin
2744
 
2745
                end
2746
                RX_DATA1_7:
2747
                begin
2748
 
2749
                end
2750
                RX_DATA1_8:
2751
                begin
2752
 
2753
                end
2754
                RX_RESPONSE_DATA1_1:
2755
                begin
2756
                end
2757
                RX_DELAY_BYTES:
2758
                begin
2759
 
2760
                end
2761
                RX_NACK:
2762
                begin
2763
 
2764
 
2765
                end
2766
                RX_STOP:
2767
                begin
2768
 
2769
 
2770
                end
2771
                default:
2772
                begin
2773
                        count_receive_data <= 12'd4095;
2774
                        fifo_rx_wr_en <= 1'b0;
2775
                        count_rx <= 2'd3;
2776
                end
2777
                endcase
2778
        end
2779
end
2780
 
2781 2 redbear
endmodule

powered by: WebSVN 2.1.0

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