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

Subversion Repositories apbi2c

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

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
////              Ronal Dario Celaya
30
////
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_wr_en,
97
                 input fifo_rx_f_full,
98
                 input fifo_rx_f_empty,
99
                 output [DWIDTH-1:0] fifo_rx_data_in,
100
 
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
        reg [1:0] count;
123
 
124
        //CONTROL CLOCK AND COUNTER
125
        reg [11:0] count_send_data;
126
        reg BR_CLK_O;
127
        reg SDA_OUT;
128
 
129
        //RESPONSE USED TO HOLD SIGNAL TO ACK OR NACK
130
        reg RESPONSE;
131
 
132
 
133
 
134
// TX PARAMETERS USED TO STATE MACHINE
135
 
136
localparam [5:0] TX_IDLE = 6'd0, //IDLE
137
 
138
           TX_START = 6'd1,//START BIT
139
 
140
           TX_CONTROLIN_1 = 6'd2, //START BYTE
141
           TX_CONTROLIN_2 = 6'd3,
142
           TX_CONTROLIN_3 = 6'd4,
143
           TX_CONTROLIN_4 = 6'd5,
144
           TX_CONTROLIN_5 = 6'd6,
145
           TX_CONTROLIN_6 = 6'd7,
146
           TX_CONTROLIN_7 = 6'd8,
147
           TX_CONTROLIN_8 = 6'd9, //END FIRST BYTE
148
 
149
           TX_RESPONSE_CIN =6'd10, //RESPONSE
150
 
151
           TX_ADRESS_1 = 6'd11,//START BYTE
152
           TX_ADRESS_2 = 6'd12,
153
           TX_ADRESS_3 = 6'd13,
154
           TX_ADRESS_4 = 6'd14,
155
           TX_ADRESS_5 = 6'd15,
156
           TX_ADRESS_6 = 6'd16,
157
           TX_ADRESS_7 = 6'd17,
158
           TX_ADRESS_8 = 6'd18,//END FIRST BYTE
159
 
160
           TX_RESPONSE_ADRESS =6'd19, //RESPONSE
161
 
162
           TX_DATA0_1 = 6'd20,//START BYTE
163
           TX_DATA0_2 = 6'd21,
164
           TX_DATA0_3 = 6'd22,
165
           TX_DATA0_4 = 6'd23,
166
           TX_DATA0_5 = 6'd24,
167
           TX_DATA0_6 = 6'd25,
168
           TX_DATA0_7 = 6'd26,
169
           TX_DATA0_8 = 6'd27,//END FIRST BYTE
170
 
171
           TX_RESPONSE_DATA0_1 = 6'd28,  //RESPONSE
172
 
173
           TX_DATA1_1 = 6'd29,//START BYTE
174
           TX_DATA1_2 = 6'd30,
175
           TX_DATA1_3 = 6'd31,
176
           TX_DATA1_4 = 6'd32,
177
           TX_DATA1_5 = 6'd33,
178
           TX_DATA1_6 = 6'd34,
179
           TX_DATA1_7 = 6'd35,
180
           TX_DATA1_8 = 6'd36,//END FIRST BYTE
181
 
182
           TX_RESPONSE_DATA1_1 = 6'd37,//RESPONSE
183
 
184
           TX_DELAY_BYTES = 6'd38,//USED ONLY IN ACK TO DELAY BETWEEN
185
           TX_NACK = 6'd39,//USED ONLY IN ACK TO DELAY BETWEEN BYTES
186
           TX_STOP = 6'd40;//USED TO SEND STOP BIT
187
 
188
        //STATE CONTROL 
189
        reg [5:0] state_tx;
190
        reg [5:0] next_state_tx;
191
 
192
//ASSIGN REGISTERS TO BIDIRETIONAL PORTS
193
/*
194
        TODO:
195
        We still working on verilog and we no have RX yet. So conections may change in time we are making progress on source code.
196
 
197
*/
198
assign SDA = SDA_OUT;
199
assign SCL = BR_CLK_O;
200
 
201
 
202
//COMBINATIONAL BLOCK TO TX
203
always@(*)
204
begin
205
 
206
        //THE FUN START HERE :-)
207
        //COMBINATIONAL UPDATE STATE BE CAREFUL WITH WHAT YOU MAKE HERE
208
        next_state_tx = state_tx;
209
 
210
        case(state_tx)//STATE_TX IS MORE SECURE CHANGE ONLY IF YOU KNOW WHAT ARE YOU DOING 
211
        TX_IDLE:
212
        begin
213
                //OBEYING SPEC
214
                if(DATA_CONFIG_REG[0] == 1'b0 && fifo_tx_f_full == 1'b0 && DATA_CONFIG_REG[1] == 1'b0)
215
                begin
216
                        next_state_tx = TX_IDLE;
217
                end
218
                else
219
                begin
220
                        next_state_tx = TX_START;
221
                end
222
 
223
 
224
        end
225
        TX_START://THIS IS USED TOO ALL STATE MACHINES THE COUNTER_SEND_DATA
226
        begin
227
                if(count_send_data != DATA_CONFIG_REG[13:2])
228
                begin
229
                        next_state_tx = TX_START;
230
                end
231
                else
232
                begin
233
                        next_state_tx = TX_CONTROLIN_1;
234
                end
235
 
236
        end
237
        TX_CONTROLIN_1:
238
        begin
239
                if(count_send_data != DATA_CONFIG_REG[13:2])
240
                begin
241
                        next_state_tx = TX_CONTROLIN_1;
242
                end
243
                else
244
                begin
245
                        next_state_tx = TX_CONTROLIN_2;
246
                end
247
 
248
        end
249
        TX_CONTROLIN_2:
250
        begin
251
 
252
                if(count_send_data != DATA_CONFIG_REG[13:2])
253
                begin
254
                        next_state_tx =TX_CONTROLIN_2;
255
                end
256
                else
257
                begin
258
                        next_state_tx = TX_CONTROLIN_3;
259
                end
260
 
261
        end
262
        TX_CONTROLIN_3:
263
        begin
264
 
265
                if(count_send_data != DATA_CONFIG_REG[13:2])
266
                begin
267
                        next_state_tx = TX_CONTROLIN_3;
268
                end
269
                else
270
                begin
271
                        next_state_tx = TX_CONTROLIN_4;
272
                end
273
        end
274
        TX_CONTROLIN_4:
275
        begin
276
 
277
                if(count_send_data != DATA_CONFIG_REG[13:2])
278
                begin
279
                        next_state_tx = TX_CONTROLIN_4;
280
                end
281
                else
282
                begin
283
                        next_state_tx = TX_CONTROLIN_5;
284
                end
285
        end
286
        TX_CONTROLIN_5:
287
        begin
288
 
289
                if(count_send_data != DATA_CONFIG_REG[13:2])
290
                begin
291
                        next_state_tx = TX_CONTROLIN_5;
292
                end
293
                else
294
                begin
295
                        next_state_tx = TX_CONTROLIN_6;
296
                end
297
        end
298
        TX_CONTROLIN_6:
299
        begin
300
 
301
                if(count_send_data != DATA_CONFIG_REG[13:2])
302
                begin
303
                        next_state_tx = TX_CONTROLIN_6;
304
                end
305
                else
306
                begin
307
                        next_state_tx = TX_CONTROLIN_7;
308
                end
309
        end
310
        TX_CONTROLIN_7:
311
        begin
312
 
313
                if(count_send_data != DATA_CONFIG_REG[13:2])
314
                begin
315
                        next_state_tx = TX_CONTROLIN_7;
316
                end
317
                else
318
                begin
319
                        next_state_tx = TX_CONTROLIN_8;
320
                end
321
        end
322
        TX_CONTROLIN_8:
323
        begin
324
 
325
                if(count_send_data != DATA_CONFIG_REG[13:2])
326
                begin
327
                        next_state_tx = TX_CONTROLIN_8;
328
                end
329
                else
330
                begin
331
                        next_state_tx = TX_RESPONSE_CIN;
332
                end
333
        end
334
        TX_RESPONSE_CIN:
335
        begin
336
 
337
                if(count_send_data != DATA_CONFIG_REG[13:2])
338
                begin
339
                        next_state_tx = TX_RESPONSE_CIN;
340
                end
341
                else if(RESPONSE == 1'b0)//ACK
342
                begin
343
                        next_state_tx = TX_DELAY_BYTES;
344
                end
345
                else if(RESPONSE == 1'b1)//NACK
346
                begin
347
                        next_state_tx = TX_NACK;
348
                end
349
 
350
        end
351
 
352
        //NOW SENDING ADDRESS
353
        TX_ADRESS_1:
354
        begin
355
                if(count_send_data != DATA_CONFIG_REG[13:2])
356
                begin
357
                        next_state_tx = TX_ADRESS_1;
358
                end
359
                else
360
                begin
361
                        next_state_tx = TX_ADRESS_2;
362
                end
363
        end
364
        TX_ADRESS_2:
365
        begin
366
                if(count_send_data != DATA_CONFIG_REG[13:2])
367
                begin
368
                        next_state_tx = TX_ADRESS_2;
369
                end
370
                else
371
                begin
372
                        next_state_tx = TX_ADRESS_3;
373
                end
374
        end
375
        TX_ADRESS_3:
376
        begin
377
                if(count_send_data != DATA_CONFIG_REG[13:2])
378
                begin
379
                        next_state_tx = TX_ADRESS_3;
380
                end
381
                else
382
                begin
383
                        next_state_tx = TX_ADRESS_4;
384
                end
385
        end
386
        TX_ADRESS_4:
387
        begin
388
                if(count_send_data != DATA_CONFIG_REG[13:2])
389
                begin
390
                        next_state_tx = TX_ADRESS_4;
391
                end
392
                else
393
                begin
394
                        next_state_tx = TX_ADRESS_5;
395
                end
396
        end
397
        TX_ADRESS_5:
398
        begin
399
                if(count_send_data != DATA_CONFIG_REG[13:2])
400
                begin
401
                        next_state_tx = TX_ADRESS_5;
402
                end
403
                else
404
                begin
405
                        next_state_tx = TX_ADRESS_6;
406
                end
407
        end
408
        TX_ADRESS_6:
409
        begin
410
                if(count_send_data != DATA_CONFIG_REG[13:2])
411
                begin
412
                        next_state_tx = TX_ADRESS_6;
413
                end
414
                else
415
                begin
416
                        next_state_tx = TX_ADRESS_7;
417
                end
418
        end
419
        TX_ADRESS_7:
420
        begin
421
                if(count_send_data != DATA_CONFIG_REG[13:2])
422
                begin
423
                        next_state_tx = TX_ADRESS_7;
424
                end
425
                else
426
                begin
427
                        next_state_tx = TX_ADRESS_8;
428
                end
429
        end
430
        TX_ADRESS_8:
431
        begin
432
                if(count_send_data != DATA_CONFIG_REG[13:2])
433
                begin
434
                        next_state_tx = TX_ADRESS_8;
435
                end
436
                else
437
                begin
438
                        next_state_tx = TX_RESPONSE_ADRESS;
439
                end
440
        end
441
        TX_RESPONSE_ADRESS:
442
        begin
443
                if(count_send_data != DATA_CONFIG_REG[13:2])
444
                begin
445
                        next_state_tx = TX_RESPONSE_ADRESS;
446
                end
447
                else if(RESPONSE == 1'b0)//ACK
448
                begin
449
                        next_state_tx = TX_DELAY_BYTES;
450
                end
451
                else if(RESPONSE == 1'b1)//NACK --> RESTART CONDITION AND BACK TO START BYTE AGAIN
452
                begin
453
                        next_state_tx = TX_NACK;
454
                end
455
        end
456
 
457
        //data in
458
        TX_DATA0_1:
459
        begin
460
                if(count_send_data != DATA_CONFIG_REG[13:2])
461
                begin
462
                        next_state_tx = TX_DATA0_1;
463
                end
464
                else
465
                begin
466
                        next_state_tx = TX_DATA0_2;
467
                end
468
        end
469
        TX_DATA0_2:
470
        begin
471
                if(count_send_data != DATA_CONFIG_REG[13:2])
472
                begin
473
                        next_state_tx = TX_DATA0_2;
474
                end
475
                else
476
                begin
477
                        next_state_tx = TX_DATA0_3;
478
                end
479
        end
480
        TX_DATA0_3:
481
        begin
482
                if(count_send_data != DATA_CONFIG_REG[13:2])
483
                begin
484
                        next_state_tx = TX_DATA0_3;
485
                end
486
                else
487
                begin
488
                        next_state_tx = TX_DATA0_4;
489
                end
490
        end
491
        TX_DATA0_4:
492
        begin
493
                if(count_send_data != DATA_CONFIG_REG[13:2])
494
                begin
495
                        next_state_tx = TX_DATA0_4;
496
                end
497
                else
498
                begin
499
                        next_state_tx = TX_DATA0_5;
500
                end
501
        end
502
        TX_DATA0_5:
503
        begin
504
                if(count_send_data != DATA_CONFIG_REG[13:2])
505
                begin
506
                        next_state_tx = TX_DATA0_5;
507
                end
508
                else
509
                begin
510
                        next_state_tx = TX_DATA0_6;
511
                end
512
        end
513
        TX_DATA0_6:
514
        begin
515
                if(count_send_data != DATA_CONFIG_REG[13:2])
516
                begin
517
                        next_state_tx = TX_DATA0_6;
518
                end
519
                else
520
                begin
521
                        next_state_tx = TX_DATA0_7;
522
                end
523
        end
524
        TX_DATA0_7:
525
        begin
526
                if(count_send_data != DATA_CONFIG_REG[13:2])
527
                begin
528
                        next_state_tx = TX_DATA0_7;
529
                end
530
                else
531
                begin
532
                        next_state_tx = TX_DATA0_8;
533
                end
534
        end
535
        TX_DATA0_8:
536
        begin
537
                if(count_send_data != DATA_CONFIG_REG[13:2])
538
                begin
539
                        next_state_tx = TX_DATA0_8;
540
                end
541
                else
542
                begin
543
                        next_state_tx = TX_RESPONSE_DATA0_1;
544
                end
545
        end
546
        TX_RESPONSE_DATA0_1:
547
        begin
548
                if(count_send_data != DATA_CONFIG_REG[13:2])
549
                begin
550
                        next_state_tx = TX_RESPONSE_DATA0_1;
551
                end
552
                else if(RESPONSE == 1'b0)//ACK
553
                begin
554
                        next_state_tx = TX_DELAY_BYTES;
555
                end
556
                else if(RESPONSE == 1'b1)//NACK
557
                begin
558
                        next_state_tx = TX_NACK;
559
                end
560
        end
561
 
562
        //second byte
563
        TX_DATA1_1:
564
        begin
565
                if(count_send_data != DATA_CONFIG_REG[13:2])
566
                begin
567
                        next_state_tx = TX_DATA1_1;
568
                end
569
                else
570
                begin
571
                        next_state_tx = TX_DATA1_2;
572
                end
573
        end
574
        TX_DATA1_2:
575
        begin
576
                if(count_send_data != DATA_CONFIG_REG[13:2])
577
                begin
578
                        next_state_tx = TX_DATA1_2;
579
                end
580
                else
581
                begin
582
                        next_state_tx = TX_DATA1_3;
583
                end
584
        end
585
        TX_DATA1_3:
586
        begin
587
                if(count_send_data != DATA_CONFIG_REG[13:2])
588
                begin
589
                        next_state_tx = TX_DATA1_3;
590
                end
591
                else
592
                begin
593
                        next_state_tx = TX_DATA1_4;
594
                end
595
        end
596
        TX_DATA1_4:
597
        begin
598
                if(count_send_data != DATA_CONFIG_REG[13:2])
599
                begin
600
                        next_state_tx = TX_DATA1_4;
601
                end
602
                else
603
                begin
604
                        next_state_tx = TX_DATA1_5;
605
                end
606
        end
607
        TX_DATA1_5:
608
        begin
609
                if(count_send_data != DATA_CONFIG_REG[13:2])
610
                begin
611
                        next_state_tx = TX_DATA1_5;
612
                end
613
                else
614
                begin
615
                        next_state_tx = TX_DATA1_6;
616
                end
617
        end
618
        TX_DATA1_6:
619
        begin
620
                if(count_send_data != DATA_CONFIG_REG[13:2])
621
                begin
622
                        next_state_tx = TX_DATA1_6;
623
                end
624
                else
625
                begin
626
                        next_state_tx = TX_DATA1_7;
627
                end
628
        end
629
        TX_DATA1_7:
630
        begin
631
                if(count_send_data != DATA_CONFIG_REG[13:2])
632
                begin
633
                        next_state_tx = TX_DATA1_7;
634
                end
635
                else
636
                begin
637
                        next_state_tx = TX_DATA1_8;
638
                end
639
        end
640
        TX_DATA1_8:
641
        begin
642
                if(count_send_data != DATA_CONFIG_REG[13:2])
643
                begin
644
                        next_state_tx = TX_DATA1_8;
645
                end
646
                else
647
                begin
648
                        next_state_tx = TX_RESPONSE_DATA1_1;
649
                end
650
        end
651
        TX_RESPONSE_DATA1_1:
652
        begin
653
                if(count_send_data != DATA_CONFIG_REG[13:2])
654
                begin
655
                        next_state_tx = TX_RESPONSE_DATA1_1;
656
                end
657
                else if(RESPONSE == 1'b0)//ACK
658
                begin
659
                        next_state_tx = TX_DELAY_BYTES;
660
                end
661
                else if(RESPONSE == 1'b1)//NACK
662
                begin
663
                        next_state_tx = TX_NACK;
664
                end
665
        end
666
        TX_DELAY_BYTES://THIS FORM WORKS 
667
        begin
668
 
669
 
670
                if(count_send_data != DATA_CONFIG_REG[13:2])
671
                begin
672
                        next_state_tx = TX_DELAY_BYTES;
673
                end
674
                else
675
                begin
676
 
677
                        if(count == 2'd0)
678
                        begin
679
                                next_state_tx = TX_ADRESS_1;
680
                        end
681
                        else if(count == 2'd1)
682
                        begin
683
                                next_state_tx = TX_DATA0_1;
684
                        end
685
                        else if(count == 2'd2)
686
                        begin
687
                                next_state_tx = TX_DATA1_1;
688
                        end
689
                        else if(count == 2'd3)
690
                        begin
691
                                next_state_tx = TX_STOP;
692
                        end
693
 
694
                end
695
 
696
        end
697
        TX_NACK://NOT TESTED YET !!!!
698
        begin
699
                if(count_send_data != DATA_CONFIG_REG[13:2]*2'd2)
700
                begin
701
                        next_state_tx = TX_NACK;
702
                end
703
                else
704
                begin
705
                        if(count == 2'd0)
706
                        begin
707
                                next_state_tx = TX_CONTROLIN_1;
708
                        end
709
                        else if(count == 2'd1)
710
                        begin
711
                                next_state_tx = TX_ADRESS_1;
712
                        end
713
                        else if(count == 2'd2)
714
                        begin
715
                                next_state_tx = TX_DATA0_1;
716
                        end
717
                        else if(count == 2'd3)
718
                        begin
719
                                next_state_tx = TX_DATA1_1;
720
                        end
721
                end
722
        end
723
        TX_STOP://THIS WORK
724
        begin
725
                if(count_send_data != DATA_CONFIG_REG[13:2])
726
                begin
727
                        next_state_tx = TX_STOP;
728
                end
729
                else
730
                begin
731
                        next_state_tx = TX_IDLE;
732
                end
733
        end
734
        default:
735
        begin
736
                next_state_tx = TX_IDLE;
737
        end
738
        endcase
739
 
740
 
741
end
742
//SEQUENTIAL
743
always@(posedge PCLK)
744
begin
745
 
746
        //RESET SYNC
747
        if(!PRESETn)
748
        begin
749
                //SIGNALS MUST BE RESETED
750
                count_send_data <= 12'd0;
751
                state_tx <= TX_IDLE;
752
                SDA_OUT<= 1'b1;
753
                fifo_tx_rd_en <= 1'b0;
754
                count <= 2'd0;
755
                BR_CLK_O <= 1'b1;
756
                RESPONSE<= 1'b0;
757
        end
758
        else
759
        begin
760
 
761
                // SEQUENTIAL FUN START
762
                state_tx <= next_state_tx;
763
 
764
                case(state_tx)
765
                TX_IDLE:
766
                begin
767
 
768
                        fifo_tx_rd_en <= 1'b0;
769
 
770
 
771
                        if(DATA_CONFIG_REG[0] == 1'b0 && fifo_tx_f_full == 1'b0)
772
                        begin
773
                                count_send_data <= 12'd0;
774
                                SDA_OUT<= 1'b1;
775
                                BR_CLK_O <= 1'b1;
776
                        end
777
                        else
778
                        begin
779
                                count_send_data <= count_send_data + 12'd1;
780
                                SDA_OUT<=1'b0;
781
                        end
782
 
783
                end
784
                TX_START:
785
                begin
786
 
787
                        if(count_send_data < DATA_CONFIG_REG[13:2])
788
                        begin
789
                                count_send_data <= count_send_data + 12'd1;
790
                                BR_CLK_O <= 1'b0;
791
                        end
792
                        else
793
                        begin
794
                                count_send_data <= 12'd0;
795
                                BR_CLK_O <= 1'b1;
796
                        end
797
 
798
                        if(count_send_data == DATA_CONFIG_REG[13:2]- 12'd1)
799
                        begin
800
                                SDA_OUT<=fifo_tx_data_out[0:0];
801
                        end
802
 
803
                end
804
                TX_CONTROLIN_1:
805
                begin
806
 
807
 
808
 
809
                        if(count_send_data < DATA_CONFIG_REG[13:2])
810
                        begin
811
 
812
                                count_send_data <= count_send_data + 12'd1;
813
                                SDA_OUT<=fifo_tx_data_out[0:0];
814
 
815
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
816
                                begin
817
                                        BR_CLK_O <= 1'b1;
818
                                end
819
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
820
                                begin
821
                                        BR_CLK_O <= 1'b0;
822
                                end
823
                        end
824
                        else
825
                        begin
826
                                count_send_data <= 12'd0;
827
                                BR_CLK_O <= 1'b1;
828
                                SDA_OUT<=fifo_tx_data_out[1:1];
829
                        end
830
 
831
 
832
                end
833
 
834
                TX_CONTROLIN_2:
835
                begin
836
 
837
 
838
 
839
                        if(count_send_data < DATA_CONFIG_REG[13:2])
840
                        begin
841
                                count_send_data <= count_send_data + 12'd1;
842
                                SDA_OUT<=fifo_tx_data_out[1:1];
843
 
844
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
845
                                begin
846
                                        BR_CLK_O <= 1'b1;
847
                                end
848
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
849
                                begin
850
                                        BR_CLK_O <= 1'b0;
851
                                end
852
                        end
853
                        else
854
                        begin
855
                                count_send_data <= 12'd0;
856
                                BR_CLK_O <= 1'b1;
857
                                SDA_OUT<=fifo_tx_data_out[2:2];
858
                        end
859
 
860
                end
861
 
862
                TX_CONTROLIN_3:
863
                begin
864
 
865
 
866
 
867
                        if(count_send_data < DATA_CONFIG_REG[13:2])
868
                        begin
869
                                count_send_data <= count_send_data + 12'd1;
870
                                SDA_OUT<=fifo_tx_data_out[2:2];
871
 
872
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
873
                                begin
874
                                        BR_CLK_O <= 1'b1;
875
                                end
876
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
877
                                begin
878
                                        BR_CLK_O <= 1'b0;
879
                                end
880
                        end
881
                        else
882
                        begin
883
                                count_send_data <= 12'd0;
884
                                BR_CLK_O <= 1'b1;
885
                                SDA_OUT<=fifo_tx_data_out[3:3];
886
                        end
887
 
888
 
889
 
890
                end
891
                TX_CONTROLIN_4:
892
                begin
893
 
894
 
895
 
896
                        if(count_send_data < DATA_CONFIG_REG[13:2])
897
                        begin
898
                                count_send_data <= count_send_data + 12'd1;
899
                                SDA_OUT<=fifo_tx_data_out[3:3];
900
 
901
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
902
                                begin
903
                                        BR_CLK_O <= 1'b1;
904
                                end
905
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
906
                                begin
907
                                        BR_CLK_O <= 1'b0;
908
                                end
909
                        end
910
                        else
911
                        begin
912
                                count_send_data <= 12'd0;
913
                                BR_CLK_O <= 1'b1;
914
                                SDA_OUT<=fifo_tx_data_out[4:4];
915
                        end
916
 
917
                end
918
 
919
                TX_CONTROLIN_5:
920
                begin
921
 
922
 
923
 
924
                        if(count_send_data < DATA_CONFIG_REG[13:2])
925
                        begin
926
                                count_send_data <= count_send_data + 12'd1;
927
                                SDA_OUT<=fifo_tx_data_out[4:4];
928
 
929
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
930
                                begin
931
                                        BR_CLK_O <= 1'b1;
932
                                end
933
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
934
                                begin
935
                                        BR_CLK_O <= 1'b0;
936
                                end
937
                        end
938
                        else
939
                        begin
940
                                count_send_data <= 12'd0;
941
                                BR_CLK_O <= 1'b1;
942
                                SDA_OUT<=fifo_tx_data_out[5:5];
943
                        end
944
 
945
                end
946
 
947
 
948
                TX_CONTROLIN_6:
949
                begin
950
 
951
                        if(count_send_data < DATA_CONFIG_REG[13:2])
952
                        begin
953
                                count_send_data <= count_send_data + 12'd1;
954
                                SDA_OUT<=fifo_tx_data_out[5:5];
955
 
956
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
957
                                begin
958
                                        BR_CLK_O <= 1'b1;
959
                                end
960
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
961
                                begin
962
                                        BR_CLK_O <= 1'b0;
963
                                end
964
                        end
965
                        else
966
                        begin
967
                                count_send_data <= 12'd0;
968
                                BR_CLK_O <= 1'b1;
969
                                SDA_OUT<=fifo_tx_data_out[6:6];
970
                        end
971
 
972
 
973
                end
974
 
975
                TX_CONTROLIN_7:
976
                begin
977
 
978
                        if(count_send_data < DATA_CONFIG_REG[13:2])
979
                        begin
980
                                count_send_data <= count_send_data + 12'd1;
981
                                SDA_OUT<=fifo_tx_data_out[6:6];
982
 
983
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
984
                                begin
985
                                        BR_CLK_O <= 1'b1;
986
                                end
987
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
988
                                begin
989
                                        BR_CLK_O <= 1'b0;
990
                                end
991
                        end
992
                        else
993
                        begin
994
                                count_send_data <= 12'd0;
995
                                BR_CLK_O <= 1'b1;
996
                                SDA_OUT<=fifo_tx_data_out[7:7];
997
                        end
998
 
999
 
1000
                end
1001
                TX_CONTROLIN_8:
1002
                begin
1003
 
1004
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1005
                        begin
1006
                                count_send_data <= count_send_data + 12'd1;
1007
                                SDA_OUT<=fifo_tx_data_out[7:7];
1008
 
1009
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1010
                                begin
1011
                                        BR_CLK_O <= 1'b1;
1012
                                end
1013
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1014
                                begin
1015
                                        BR_CLK_O <= 1'b0;
1016
                                end
1017
                        end
1018
                        else
1019
                        begin
1020
                                count_send_data <= 12'd0;
1021
                                BR_CLK_O <= 1'b1;
1022
                                SDA_OUT<= 1'b0;
1023
                        end
1024
 
1025
 
1026
                end
1027
                TX_RESPONSE_CIN:
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
 
1034
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1035
                                RESPONSE<= SDA;
1036
 
1037
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1038
                                begin
1039
                                        BR_CLK_O <= 1'b1;
1040
                                end
1041
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1042
                                begin
1043
                                        BR_CLK_O <= 1'b0;
1044
                                end
1045
                        end
1046
                        else
1047
                        begin
1048
                                count_send_data <= 12'd0;
1049
                        end
1050
 
1051
 
1052
                end
1053
                TX_ADRESS_1:
1054
                begin
1055
 
1056
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1057
                        begin
1058
                                count_send_data <= count_send_data + 12'd1;
1059
                                SDA_OUT<=fifo_tx_data_out[8:8];
1060
 
1061
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1062
                                begin
1063
                                        BR_CLK_O <= 1'b1;
1064
                                end
1065
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1066
                                begin
1067
                                        BR_CLK_O <= 1'b0;
1068
                                end
1069
                        end
1070
                        else
1071
                        begin
1072
                                count_send_data <= 12'd0;
1073
                                BR_CLK_O <= 1'b1;
1074
                                SDA_OUT<=fifo_tx_data_out[9:9];
1075
                        end
1076
 
1077
                end
1078
                TX_ADRESS_2:
1079
                begin
1080
 
1081
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1082
                        begin
1083
                                count_send_data <= count_send_data + 12'd1;
1084
                                SDA_OUT<=fifo_tx_data_out[9:9];
1085
 
1086
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1087
                                begin
1088
                                        BR_CLK_O <= 1'b1;
1089
                                end
1090
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1091
                                begin
1092
                                        BR_CLK_O <= 1'b0;
1093
                                end
1094
                        end
1095
                        else
1096
                        begin
1097
                                count_send_data <= 12'd0;
1098
                                BR_CLK_O <= 1'b1;
1099
                                SDA_OUT<=fifo_tx_data_out[10:10];
1100
                        end
1101
 
1102
                end
1103
                TX_ADRESS_3:
1104
                begin
1105
 
1106
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1107
                        begin
1108
                                count_send_data <= count_send_data + 12'd1;
1109
                                SDA_OUT<=fifo_tx_data_out[10:10];
1110
 
1111
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1112
                                begin
1113
                                        BR_CLK_O <= 1'b1;
1114
                                end
1115
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1116
                                begin
1117
                                        BR_CLK_O <= 1'b0;
1118
                                end
1119
                        end
1120
                        else
1121
                        begin
1122
                                count_send_data <= 12'd0;
1123
                                BR_CLK_O <= 1'b1;
1124
                                SDA_OUT<=fifo_tx_data_out[11:11];
1125
                        end
1126
 
1127
                end
1128
                TX_ADRESS_4:
1129
                begin
1130
 
1131
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1132
                        begin
1133
                                count_send_data <= count_send_data + 12'd1;
1134
                                SDA_OUT<=fifo_tx_data_out[11:11];
1135
 
1136
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1137
                                begin
1138
                                        BR_CLK_O <= 1'b1;
1139
                                end
1140
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1141
                                begin
1142
                                        BR_CLK_O <= 1'b0;
1143
                                end
1144
                        end
1145
                        else
1146
                        begin
1147
                                count_send_data <= 12'd0;
1148
                                BR_CLK_O <= 1'b1;
1149
                                SDA_OUT<=fifo_tx_data_out[12:12];
1150
                        end
1151
                end
1152
                TX_ADRESS_5:
1153
                begin
1154
 
1155
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1156
                        begin
1157
                                count_send_data <= count_send_data + 12'd1;
1158
                                SDA_OUT<=fifo_tx_data_out[12:12];
1159
 
1160
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1161
                                begin
1162
                                        BR_CLK_O <= 1'b1;
1163
                                end
1164
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1165
                                begin
1166
                                        BR_CLK_O <= 1'b0;
1167
                                end
1168
                        end
1169
                        else
1170
                        begin
1171
                                count_send_data <= 12'd0;
1172
                                BR_CLK_O <= 1'b1;
1173
                                SDA_OUT<=fifo_tx_data_out[13:13];
1174
                        end
1175
 
1176
 
1177
                end
1178
                TX_ADRESS_6:
1179
                begin
1180
 
1181
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1182
                        begin
1183
                                count_send_data <= count_send_data + 12'd1;
1184
                                SDA_OUT<=fifo_tx_data_out[13:13];
1185
 
1186
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1187
                                begin
1188
                                        BR_CLK_O <= 1'b1;
1189
                                end
1190
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1191
                                begin
1192
                                        BR_CLK_O <= 1'b0;
1193
                                end
1194
                        end
1195
                        else
1196
                        begin
1197
                                count_send_data <= 12'd0;
1198
                                BR_CLK_O <= 1'b1;
1199
                                SDA_OUT<=fifo_tx_data_out[14:14];
1200
                        end
1201
 
1202
                end
1203
                TX_ADRESS_7:
1204
                begin
1205
 
1206
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1207
                        begin
1208
                                count_send_data <= count_send_data + 12'd1;
1209
                                SDA_OUT<=fifo_tx_data_out[14:14];
1210
 
1211
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1212
                                begin
1213
                                        BR_CLK_O <= 1'b1;
1214
                                end
1215
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1216
                                begin
1217
                                        BR_CLK_O <= 1'b0;
1218
                                end
1219
                        end
1220
                        else
1221
                        begin
1222
                                count_send_data <= 12'd0;
1223
                                BR_CLK_O <= 1'b1;
1224
                                SDA_OUT<=fifo_tx_data_out[15:15];
1225
                        end
1226
 
1227
 
1228
                end
1229
                TX_ADRESS_8:
1230
                begin
1231
 
1232
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1233
                        begin
1234
                                count_send_data <= count_send_data + 12'd1;
1235
                                SDA_OUT<=fifo_tx_data_out[15:15];
1236
 
1237
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1238
                                begin
1239
                                        BR_CLK_O <= 1'b1;
1240
                                end
1241
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1242
                                begin
1243
                                        BR_CLK_O <= 1'b0;
1244
                                end
1245
                        end
1246
                        else
1247
                        begin
1248
                                count_send_data <= 12'd0;
1249
                                BR_CLK_O <= 1'b1;
1250
                        end
1251
 
1252
                end
1253
                TX_RESPONSE_ADRESS:
1254
                begin
1255
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1256
                        begin
1257
                                count_send_data <= count_send_data + 12'd1;
1258
 
1259
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1260
                                RESPONSE<= SDA;
1261
 
1262
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1263
                                begin
1264
                                        BR_CLK_O <= 1'b1;
1265
                                end
1266
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1267
                                begin
1268
                                        BR_CLK_O <= 1'b0;
1269
                                end
1270
                        end
1271
                        else
1272
                        begin
1273
                                count_send_data <= 12'd0;
1274
                        end
1275
 
1276
                end
1277
                TX_DATA0_1:
1278
                begin
1279
 
1280
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1281
                        begin
1282
                                count_send_data <= count_send_data + 12'd1;
1283
                                SDA_OUT<=fifo_tx_data_out[16:16];
1284
 
1285
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1286
                                begin
1287
                                        BR_CLK_O <= 1'b1;
1288
                                end
1289
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1290
                                begin
1291
                                        BR_CLK_O <= 1'b0;
1292
                                end
1293
                        end
1294
                        else
1295
                        begin
1296
                                count_send_data <= 12'd0;
1297
                                BR_CLK_O <= 1'b1;
1298
                                SDA_OUT<=fifo_tx_data_out[17:17];
1299
                        end
1300
 
1301
 
1302
                end
1303
                TX_DATA0_2:
1304
                begin
1305
 
1306
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1307
                        begin
1308
                                count_send_data <= count_send_data + 12'd1;
1309
                                SDA_OUT<=fifo_tx_data_out[17:17];
1310
 
1311
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1312
                                begin
1313
                                        BR_CLK_O <= 1'b1;
1314
                                end
1315
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1316
                                begin
1317
                                        BR_CLK_O <= 1'b0;
1318
                                end
1319
                        end
1320
                        else
1321
                        begin
1322
                                count_send_data <= 12'd0;
1323
                                BR_CLK_O <= 1'b1;
1324
                                SDA_OUT<=fifo_tx_data_out[18:18];
1325
                        end
1326
 
1327
 
1328
                end
1329
                TX_DATA0_3:
1330
                begin
1331
 
1332
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1333
                        begin
1334
                                count_send_data <= count_send_data + 12'd1;
1335
                                SDA_OUT<=fifo_tx_data_out[18:18];
1336
 
1337
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1338
                                begin
1339
                                        BR_CLK_O <= 1'b1;
1340
                                end
1341
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1342
                                begin
1343
                                        BR_CLK_O <= 1'b0;
1344
                                end
1345
                        end
1346
                        else
1347
                        begin
1348
                                count_send_data <= 12'd0;
1349
                                BR_CLK_O <= 1'b1;
1350
                                SDA_OUT<=fifo_tx_data_out[19:19];
1351
                        end
1352
 
1353
                end
1354
                TX_DATA0_4:
1355
                begin
1356
 
1357
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1358
                        begin
1359
                                count_send_data <= count_send_data + 12'd1;
1360
                                SDA_OUT<=fifo_tx_data_out[19:19];
1361
 
1362
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1363
                                begin
1364
                                        BR_CLK_O <= 1'b1;
1365
                                end
1366
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1367
                                begin
1368
                                        BR_CLK_O <= 1'b0;
1369
                                end
1370
                        end
1371
                        else
1372
                        begin
1373
                                count_send_data <= 12'd0;
1374
                                BR_CLK_O <= 1'b1;
1375
                                SDA_OUT<=fifo_tx_data_out[20:20];
1376
                        end
1377
 
1378
                end
1379
                TX_DATA0_5:
1380
                begin
1381
 
1382
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1383
                        begin
1384
                                count_send_data <= count_send_data + 12'd1;
1385
                                SDA_OUT<=fifo_tx_data_out[20:20];
1386
 
1387
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1388
                                begin
1389
                                        BR_CLK_O <= 1'b1;
1390
                                end
1391
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1392
                                begin
1393
                                        BR_CLK_O <= 1'b0;
1394
                                end
1395
                        end
1396
                        else
1397
                        begin
1398
                                count_send_data <= 12'd0;
1399
                                BR_CLK_O <= 1'b1;
1400
                                SDA_OUT<=fifo_tx_data_out[21:21];
1401
                        end
1402
 
1403
                end
1404
                TX_DATA0_6:
1405
                begin
1406
 
1407
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1408
                        begin
1409
                                count_send_data <= count_send_data + 12'd1;
1410
                                SDA_OUT<=fifo_tx_data_out[21:21];
1411
 
1412
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1413
                                begin
1414
                                        BR_CLK_O <= 1'b1;
1415
                                end
1416
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1417
                                begin
1418
                                        BR_CLK_O <= 1'b0;
1419
                                end
1420
                        end
1421
                        else
1422
                        begin
1423
                                count_send_data <= 12'd0;
1424
                                BR_CLK_O <= 1'b1;
1425
                                SDA_OUT<=fifo_tx_data_out[22:22];
1426
                        end
1427
 
1428
                end
1429
                TX_DATA0_7:
1430
                begin
1431
 
1432
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1433
                        begin
1434
                                count_send_data <= count_send_data + 12'd1;
1435
                                SDA_OUT<=fifo_tx_data_out[22:22];
1436
 
1437
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1438
                                begin
1439
                                        BR_CLK_O <= 1'b1;
1440
                                end
1441
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1442
                                begin
1443
                                        BR_CLK_O <= 1'b0;
1444
                                end
1445
                        end
1446
                        else
1447
                        begin
1448
                                count_send_data <= 12'd0;
1449
                                BR_CLK_O <= 1'b1;
1450
                                SDA_OUT<=fifo_tx_data_out[23:23];
1451
                        end
1452
 
1453
                end
1454
                TX_DATA0_8:
1455
                begin
1456
 
1457
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1458
                        begin
1459
                                count_send_data <= count_send_data + 12'd1;
1460
                                SDA_OUT<=fifo_tx_data_out[23:23];
1461
 
1462
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1463
                                begin
1464
                                        BR_CLK_O <= 1'b1;
1465
                                end
1466
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1467
                                begin
1468
                                        BR_CLK_O <= 1'b0;
1469
                                end
1470
 
1471
                        end
1472
                        else
1473
                        begin
1474
                                count_send_data <= 12'd0;
1475
                                BR_CLK_O <= 1'b1;
1476
                        end
1477
 
1478
                end
1479
                TX_RESPONSE_DATA0_1:
1480
                begin
1481
 
1482
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1483
                        begin
1484
                                count_send_data <= count_send_data + 12'd1;
1485
 
1486
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1487
                                RESPONSE<= SDA;
1488
 
1489
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1490
                                begin
1491
                                        BR_CLK_O <= 1'b1;
1492
                                end
1493
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1494
                                begin
1495
                                        BR_CLK_O <= 1'b0;
1496
                                end
1497
                        end
1498
                        else
1499
                        begin
1500
                                count_send_data <= 12'd0;
1501
                        end
1502
 
1503
                end
1504
                TX_DATA1_1:
1505
                begin
1506
 
1507
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1508
                        begin
1509
                                count_send_data <= count_send_data + 12'd1;
1510
                                SDA_OUT<=fifo_tx_data_out[24:24];
1511
 
1512
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1513
                                begin
1514
                                        BR_CLK_O <= 1'b1;
1515
                                end
1516
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1517
                                begin
1518
                                        BR_CLK_O <= 1'b0;
1519
                                end
1520
                        end
1521
                        else
1522
                        begin
1523
                                count_send_data <= 12'd0;
1524
                                BR_CLK_O <= 1'b1;
1525
                                SDA_OUT<=fifo_tx_data_out[25:25];
1526
 
1527
                        end
1528
 
1529
 
1530
                end
1531
                TX_DATA1_2:
1532
                begin
1533
 
1534
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1535
                        begin
1536
                                count_send_data <= count_send_data + 12'd1;
1537
                                SDA_OUT<=fifo_tx_data_out[25:25];
1538
 
1539
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1540
                                begin
1541
                                        BR_CLK_O <= 1'b1;
1542
                                end
1543
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1544
                                begin
1545
                                        BR_CLK_O <= 1'b0;
1546
                                end
1547
 
1548
                        end
1549
                        else
1550
                        begin
1551
                                count_send_data <= 12'd0;
1552
                                BR_CLK_O <= 1'b1;
1553
                                SDA_OUT<=fifo_tx_data_out[26:26];
1554
                        end
1555
 
1556
                end
1557
                TX_DATA1_3:
1558
                begin
1559
 
1560
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1561
                        begin
1562
                                count_send_data <= count_send_data + 12'd1;
1563
                                SDA_OUT<=fifo_tx_data_out[26:26];
1564
 
1565
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1566
                                begin
1567
                                        BR_CLK_O <= 1'b1;
1568
                                end
1569
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1570
                                begin
1571
                                        BR_CLK_O <= 1'b0;
1572
                                end
1573
 
1574
                        end
1575
                        else
1576
                        begin
1577
                                count_send_data <= 12'd0;
1578
                                BR_CLK_O <= 1'b1;
1579
                                SDA_OUT<=fifo_tx_data_out[27:27];
1580
                        end
1581
 
1582
                end
1583
                TX_DATA1_4:
1584
                begin
1585
 
1586
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1587
                        begin
1588
                                count_send_data <= count_send_data + 12'd1;
1589
                                SDA_OUT<=fifo_tx_data_out[27:27];
1590
 
1591
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1592
                                begin
1593
                                        BR_CLK_O <= 1'b1;
1594
                                end
1595
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1596
                                begin
1597
                                        BR_CLK_O <= 1'b0;
1598
                                end
1599
 
1600
                        end
1601
                        else
1602
                        begin
1603
                                count_send_data <= 12'd0;
1604
                                BR_CLK_O <= 1'b1;
1605
                                SDA_OUT<=fifo_tx_data_out[28:28];
1606
                        end
1607
 
1608
                end
1609
                TX_DATA1_5:
1610
                begin
1611
 
1612
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1613
                        begin
1614
                                count_send_data <= count_send_data + 12'd1;
1615
                                SDA_OUT<=fifo_tx_data_out[28:28];
1616
 
1617
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1618
                                begin
1619
                                        BR_CLK_O <= 1'b1;
1620
                                end
1621
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1622
                                begin
1623
                                        BR_CLK_O <= 1'b0;
1624
                                end
1625
 
1626
                        end
1627
                        else
1628
                        begin
1629
                                count_send_data <= 12'd0;
1630
                                BR_CLK_O <= 1'b1;
1631
                                SDA_OUT<=fifo_tx_data_out[29:29];
1632
                        end
1633
 
1634
                end
1635
                TX_DATA1_6:
1636
                begin
1637
 
1638
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1639
                        begin
1640
                                count_send_data <= count_send_data + 12'd1;
1641
                                SDA_OUT<=fifo_tx_data_out[29:29];
1642
 
1643
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1644
                                begin
1645
                                        BR_CLK_O <= 1'b1;
1646
                                end
1647
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1648
                                begin
1649
                                        BR_CLK_O <= 1'b0;
1650
                                end
1651
 
1652
                        end
1653
                        else
1654
                        begin
1655
                                count_send_data <= 12'd0;
1656
                                BR_CLK_O <= 1'b1;
1657
                                SDA_OUT<=fifo_tx_data_out[30:30];
1658
                        end
1659
 
1660
                end
1661
                TX_DATA1_7:
1662
                begin
1663
 
1664
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1665
                        begin
1666
                                count_send_data <= count_send_data + 12'd1;
1667
                                SDA_OUT<=fifo_tx_data_out[30:30];
1668
 
1669
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1670
                                begin
1671
                                        BR_CLK_O <= 1'b1;
1672
                                end
1673
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1674
                                begin
1675
                                        BR_CLK_O <= 1'b0;
1676
                                end
1677
 
1678
                        end
1679
                        else
1680
                        begin
1681
                                count_send_data <= 12'd0;
1682
                                BR_CLK_O <= 1'b1;
1683
                                SDA_OUT<=fifo_tx_data_out[31:31];
1684
                        end
1685
 
1686
 
1687
                end
1688
                TX_DATA1_8:
1689
                begin
1690
 
1691
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1692
                        begin
1693
                                count_send_data <= count_send_data + 12'd1;
1694
                                SDA_OUT<=fifo_tx_data_out[31:31];
1695
 
1696
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1697
                                begin
1698
                                        BR_CLK_O <= 1'b1;
1699
                                end
1700
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1701
                                begin
1702
                                        BR_CLK_O <= 1'b0;
1703
                                end
1704
 
1705
                        end
1706
                        else
1707
                        begin
1708
                                count_send_data <= 12'd0;
1709
                                BR_CLK_O <= 1'b1;
1710
                        end
1711
 
1712
                end
1713
                TX_RESPONSE_DATA1_1:
1714
                begin
1715
                        //fifo_tx_rd_en <= 1'b1;
1716
 
1717
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1718
                        begin
1719
                                count_send_data <= count_send_data + 12'd1;
1720
 
1721
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1722
                                RESPONSE<= SDA;
1723
 
1724
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
1725
                                begin
1726
                                        BR_CLK_O <= 1'b1;
1727
                                end
1728
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1729
                                begin
1730
                                        BR_CLK_O <= 1'b0;
1731
                                end
1732
                        end
1733
                        else
1734
                        begin
1735
                                count_send_data <= 12'd0;
1736
                                fifo_tx_rd_en <= 1'b1;
1737
                        end
1738
 
1739
                end
1740
                TX_DELAY_BYTES:
1741
                begin
1742
 
1743
                        fifo_tx_rd_en <= 1'b0;
1744
 
1745
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1746
                        begin
1747
 
1748
                                count_send_data <= count_send_data + 12'd1;
1749
                                BR_CLK_O <= 1'b0;
1750
                                SDA_OUT<=1'b0;
1751
                        end
1752
                        else
1753
                        begin
1754
 
1755
 
1756
                                if(count == 2'd0)
1757
                                begin
1758
                                        count <= count + 2'd1;
1759
                                        BR_CLK_O <= 1'b1;
1760
                                        SDA_OUT<=fifo_tx_data_out[8:8];
1761
                                end
1762
                                else if(count == 2'd1)
1763
                                begin
1764
                                        count <= count + 2'd1;
1765
                                        BR_CLK_O <= 1'b1;
1766
                                        SDA_OUT<=fifo_tx_data_out[16:16];
1767
                                end
1768
                                else if(count == 2'd2)
1769
                                begin
1770
                                        count <= count + 2'd1;
1771
                                        BR_CLK_O <= 1'b1;
1772
                                        SDA_OUT<=fifo_tx_data_out[24:24];
1773
                                end
1774
                                else if(count == 2'd3)
1775
                                begin
1776
                                        BR_CLK_O <= 1'b1;
1777
                                        count <= 2'd0;
1778
                                end
1779
 
1780
                                count_send_data <= 12'd0;
1781
 
1782
                        end
1783
 
1784
                end
1785
                //THIS BLOCK MUST BE CHECKED WITH CARE
1786
                TX_NACK:// MORE A RESTART 
1787
                begin
1788
                        fifo_tx_rd_en <= 1'b0;
1789
 
1790
                        if(count_send_data < DATA_CONFIG_REG[13:2]*2'd2)
1791
                        begin
1792
                                count_send_data <= count_send_data + 12'd1;
1793
 
1794
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
1795
                                begin
1796
                                        SDA_OUT<=1'b0;
1797
                                end
1798
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1799
                                begin
1800
                                        SDA_OUT<=1'b1;
1801
                                end
1802
                                else if(count_send_data  == DATA_CONFIG_REG[13:2]*2'd2)
1803
                                begin
1804
                                        SDA_OUT<=1'b0;
1805
                                end
1806
 
1807
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
1808
                                begin
1809
                                        BR_CLK_O <= 1'b1;
1810
                                end
1811
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1812
                                begin
1813
                                        BR_CLK_O <= 1'b0;
1814
                                end
1815
                                else if(count_send_data < DATA_CONFIG_REG[13:2]*2'd2)
1816
                                begin
1817
                                        BR_CLK_O <= 1'b1;
1818
                                end
1819
 
1820
                        end
1821
                        else
1822
                        begin
1823
                                count_send_data <= 12'd0;
1824
 
1825
                                if(count == 2'd0)
1826
                                begin
1827
                                        count <= 2'd0;
1828
                                        BR_CLK_O <= 1'b1;
1829
                                        SDA_OUT<=fifo_tx_data_out[0:0];
1830
                                end
1831
                                else if(count == 2'd1)
1832
                                begin
1833
                                        count <= 2'd1;
1834
                                        BR_CLK_O <= 1'b1;
1835
                                        SDA_OUT<=fifo_tx_data_out[8:8];
1836
                                end
1837
                                else if(count == 2'd2)
1838
                                begin
1839
                                        count <= 2'd2;
1840
                                        BR_CLK_O <= 1'b1;
1841
                                        SDA_OUT<=fifo_tx_data_out[16:16];
1842
                                end
1843
                                else if(count == 2'd3)
1844
                                begin
1845
                                        BR_CLK_O <= 1'b1;
1846
                                        count <= 2'd3;
1847
                                        SDA_OUT<=fifo_tx_data_out[24:24];
1848
                                end
1849
 
1850
 
1851
                        end
1852
                end
1853
                TX_STOP:
1854
                begin
1855
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1856
                        begin
1857
                                count_send_data <= count_send_data + 12'd1;
1858
 
1859
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
1860
                                begin
1861
                                        SDA_OUT<=1'b0;
1862
                                end
1863
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1864
                                begin
1865
                                        SDA_OUT<=1'b1;
1866
                                end
1867
                        end
1868
                        else
1869
                        begin
1870
                                count_send_data <= 12'd0;
1871
                        end
1872
                end
1873
                default:
1874
                begin
1875
                        fifo_tx_rd_en <= 1'b0;
1876
                        count_send_data <= 12'd4095;
1877
                end
1878
                endcase
1879
 
1880
        end
1881
 
1882
 
1883
end
1884
 
1885
 
1886
 
1887
endmodule

powered by: WebSVN 2.1.0

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