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

Subversion Repositories apbi2c

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

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

powered by: WebSVN 2.1.0

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