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

Subversion Repositories apbi2c

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

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

Line No. Rev Author Line
1 2 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    TOP I2C BLOCK to I2C Core
5
////
6
////
7
////
8
//// This file is part of the APB to I2C project
9
////
10
//// http://www.opencores.org/cores/apbi2c/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// apbi2c_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29 4 redbear
////              Ronal Dario Celaya ,rcelaya.dario@gmail.com
30 2 redbear
////
31
///////////////////////////////////////////////////////////////// 
32
////
33
////
34
//// Copyright (C) 2009 Authors and OPENCORES.ORG
35
////
36
////
37
////
38
//// This source file may be used and distributed without
39
////
40
//// restriction provided that this copyright statement is not
41
////
42
//// removed from the file and that any derivative work contains
43
//// the original copyright notice and the associated disclaimer.
44
////
45
////
46
//// This source file is free software; you can redistribute it
47
////
48
//// and/or modify it under the terms of the GNU Lesser General
49
////
50
//// Public License as published by the Free Software Foundation;
51
//// either version 2.1 of the License, or (at your option) any
52
////
53
//// later version.
54
////
55
////
56
////
57
//// This source is distributed in the hope that it will be
58
////
59
//// useful, but WITHOUT ANY WARRANTY; without even the implied
60
////
61
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
62
////
63
//// PURPOSE. See the GNU Lesser General Public License for more
64
//// details.
65
////
66
////
67
////
68
//// You should have received a copy of the GNU Lesser General
69
////
70
//// Public License along with this source; if not, download it
71
////
72
//// from http://www.opencores.org/lgpl.shtml
73
////
74
////
75
///////////////////////////////////////////////////////////////////
76
 
77
 
78
`timescale 1ns/1ps //timescale 
79
 
80
module module_i2c#(
81
                        //THIS IS USED ONLY LIKE PARAMETER TO BEM CONFIGURABLE
82
                        parameter integer DWIDTH = 32,
83
                        parameter integer AWIDTH = 14
84
                )
85
                (
86
                //I2C INTERFACE WITH ANOTHER BLOCKS
87
                 input PCLK,
88
                 input PRESETn,
89
 
90
                //INTERFACE WITH FIFO TRANSMISSION
91
                 input fifo_tx_f_full,
92
                 input fifo_tx_f_empty,
93
                 input [DWIDTH-1:0] fifo_tx_data_out,
94
 
95
                //INTERFACE WITH FIFO RECEIVER
96
                 input fifo_rx_f_full,
97
                 input fifo_rx_f_empty,
98 6 redbear
                 output reg fifo_rx_wr_en,
99
                 output reg [DWIDTH-1:0] fifo_rx_data_in,
100 2 redbear
 
101
                //INTERFACE WITH REGISTER CONFIGURATION
102
                 input [AWIDTH-1:0] DATA_CONFIG_REG,
103
 
104
                //INTERFACE TO APB AND READ FOR FIFO TX
105
                 output reg fifo_tx_rd_en,
106
                 output TX_EMPTY,
107
                 output RX_EMPTY,
108
                 output ERROR,
109
 
110
                //I2C BI DIRETIONAL PORTS
111
                inout SDA,
112
                inout SCL
113
 
114
 
115
                 );
116
 
117
//THIS IS USED TO GENERATE INTERRUPTIONS
118
assign TX_EMPTY = (fifo_tx_f_empty == 1'b1)? 1'b1:1'b0;
119
assign RX_EMPTY = (fifo_rx_f_empty == 1'b1)? 1'b1:1'b0;
120
 
121
        //THIS COUNT IS USED TO CONTROL DATA ACCROSS FSM        
122 6 redbear
        reg [1:0] count_tx;
123 2 redbear
        //CONTROL CLOCK AND COUNTER
124
        reg [11:0] count_send_data;
125
        reg BR_CLK_O;
126
        reg SDA_OUT;
127
 
128
        //RESPONSE USED TO HOLD SIGNAL TO ACK OR NACK
129
        reg RESPONSE;
130
 
131
// TX PARAMETERS USED TO STATE MACHINE
132
 
133 19 redbear
localparam [5:0] RX_TX_IDLE = 6'd0, //IDLE
134 2 redbear
 
135 19 redbear
           RX_TX_START = 6'd1,//START BIT
136 2 redbear
 
137 19 redbear
           RX_TX_CONTROLIN_1 = 6'd2, //START BYTE
138
           RX_TX_CONTROLIN_2 = 6'd3,
139
           RX_TX_CONTROLIN_3 = 6'd4,
140
           RX_TX_CONTROLIN_4 = 6'd5,
141
           RX_TX_CONTROLIN_5 = 6'd6,
142
           RX_TX_CONTROLIN_6 = 6'd7,
143
           RX_TX_CONTROLIN_7 = 6'd8,
144
           RX_TX_CONTROLIN_8 = 6'd9, //END FIRST BYTE
145 2 redbear
 
146 19 redbear
           RX_TX_RESPONSE_CIN =6'd10, //RESPONSE
147 2 redbear
 
148 19 redbear
           RX_TX_ADRESS_1 = 6'd11,//START BYTE
149
           RX_TX_ADRESS_2 = 6'd12,
150
           RX_TX_ADRESS_3 = 6'd13,
151
           RX_TX_ADRESS_4 = 6'd14,
152
           RX_TX_ADRESS_5 = 6'd15,
153
           RX_TX_ADRESS_6 = 6'd16,
154
           RX_TX_ADRESS_7 = 6'd17,
155
           RX_TX_ADRESS_8 = 6'd18,//END FIRST BYTE
156 2 redbear
 
157 19 redbear
           RX_TX_RESPONSE_ADRESS =6'd19, //RESPONSE
158 2 redbear
 
159 19 redbear
           RX_TX_DATA0_1 = 6'd20,//START BYTE
160
           RX_TX_DATA0_2 = 6'd21,
161
           RX_TX_DATA0_3 = 6'd22,
162
           RX_TX_DATA0_4 = 6'd23,
163
           RX_TX_DATA0_5 = 6'd24,
164
           RX_TX_DATA0_6 = 6'd25,
165
           RX_TX_DATA0_7 = 6'd26,
166
           RX_TX_DATA0_8 = 6'd27,//END FIRST BYTE
167 2 redbear
 
168 19 redbear
           RX_TX_RESPONSE_DATA0_1 = 6'd28,  //RESPONSE
169 2 redbear
 
170 19 redbear
           RX_TX_DATA1_1 = 6'd29,//START BYTE
171
           RX_TX_DATA1_2 = 6'd30,
172
           RX_TX_DATA1_3 = 6'd31,
173
           RX_TX_DATA1_4 = 6'd32,
174
           RX_TX_DATA1_5 = 6'd33,
175
           RX_TX_DATA1_6 = 6'd34,
176
           RX_TX_DATA1_7 = 6'd35,
177
           RX_TX_DATA1_8 = 6'd36,//END FIRST BYTE
178 2 redbear
 
179 19 redbear
           RX_TX_RESPONSE_DATA1_1 = 6'd37,//RESPONSE
180 2 redbear
 
181 19 redbear
           RX_TX_DELAY_BYTES = 6'd38,//USED ONLY IN ACK TO DELAY BETWEEN
182
           RX_TX_NACK = 6'd39,//USED ONLY IN ACK TO DELAY BETWEEN BYTES
183
           RX_TX_STOP = 6'd40;//USED TO SEND STOP BIT
184 2 redbear
 
185
        //STATE CONTROL 
186 19 redbear
        reg [5:0] state_tx_rx;
187
        reg [5:0] next_state_tx_rx;
188 2 redbear
 
189
//ASSIGN REGISTERS TO BIDIRETIONAL PORTS
190 11 redbear
assign SDA = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?SDA_OUT:1'b0;
191
assign SCL = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?BR_CLK_O:1'b0;
192 2 redbear
 
193 4 redbear
//STANDARD ERROR
194
assign ERROR = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b1)?1'b1:1'b0;
195 2 redbear
 
196
//COMBINATIONAL BLOCK TO TX
197
always@(*)
198
begin
199
 
200
        //THE FUN START HERE :-)
201
        //COMBINATIONAL UPDATE STATE BE CAREFUL WITH WHAT YOU MAKE HERE
202 19 redbear
        next_state_tx_rx = state_tx_rx;
203 2 redbear
 
204 19 redbear
        case(state_tx_rx)//state_tx_rx IS MORE SECURE CHANGE ONLY IF YOU KNOW WHAT ARE YOU DOING 
205
        RX_TX_IDLE:
206 2 redbear
        begin
207
                //OBEYING SPEC
208 18 redbear
                if(DATA_CONFIG_REG[0] == 1'b0 && (fifo_tx_f_full == 1'b1 || fifo_tx_f_empty == 1'b0) && DATA_CONFIG_REG[1] == 1'b0)
209 2 redbear
                begin
210 19 redbear
                        next_state_tx_rx = RX_TX_IDLE;
211 2 redbear
                end
212 18 redbear
                else if(DATA_CONFIG_REG[0] == 1'b1 && (fifo_tx_f_full == 1'b1 || fifo_tx_f_empty == 1'b0) && DATA_CONFIG_REG[1] == 1'b1)
213 2 redbear
                begin
214 19 redbear
                        next_state_tx_rx = RX_TX_IDLE;
215 4 redbear
                end
216 18 redbear
                else if(DATA_CONFIG_REG[0] == 1'b1 && (fifo_tx_f_full == 1'b1 || fifo_tx_f_empty == 1'b0) && DATA_CONFIG_REG[1] == 1'b0)
217 4 redbear
                begin
218 19 redbear
                        next_state_tx_rx = RX_TX_START;
219 2 redbear
                end
220
 
221
 
222
        end
223 19 redbear
        RX_TX_START://THIS IS USED TOO ALL STATE MACHINES THE COUNTER_SEND_DATA
224 2 redbear
        begin
225
                if(count_send_data != DATA_CONFIG_REG[13:2])
226
                begin
227 19 redbear
                        next_state_tx_rx = RX_TX_START;
228 2 redbear
                end
229
                else
230
                begin
231 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_1;
232 2 redbear
                end
233
 
234
        end
235 19 redbear
        RX_TX_CONTROLIN_1:
236 2 redbear
        begin
237
                if(count_send_data != DATA_CONFIG_REG[13:2])
238
                begin
239 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_1;
240 2 redbear
                end
241
                else
242
                begin
243 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_2;
244 2 redbear
                end
245
 
246
        end
247 19 redbear
        RX_TX_CONTROLIN_2:
248 2 redbear
        begin
249
 
250
                if(count_send_data != DATA_CONFIG_REG[13:2])
251
                begin
252 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_2;
253 2 redbear
                end
254
                else
255
                begin
256 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_3;
257 2 redbear
                end
258
 
259
        end
260 19 redbear
        RX_TX_CONTROLIN_3:
261 2 redbear
        begin
262
 
263
                if(count_send_data != DATA_CONFIG_REG[13:2])
264
                begin
265 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_3;
266 2 redbear
                end
267
                else
268
                begin
269 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_4;
270 2 redbear
                end
271
        end
272 19 redbear
        RX_TX_CONTROLIN_4:
273 2 redbear
        begin
274
 
275
                if(count_send_data != DATA_CONFIG_REG[13:2])
276
                begin
277 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_4;
278 2 redbear
                end
279
                else
280
                begin
281 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_5;
282 2 redbear
                end
283
        end
284 19 redbear
        RX_TX_CONTROLIN_5:
285 2 redbear
        begin
286
 
287
                if(count_send_data != DATA_CONFIG_REG[13:2])
288
                begin
289 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_5;
290 2 redbear
                end
291
                else
292
                begin
293 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_6;
294 2 redbear
                end
295
        end
296 19 redbear
        RX_TX_CONTROLIN_6:
297 2 redbear
        begin
298
 
299
                if(count_send_data != DATA_CONFIG_REG[13:2])
300
                begin
301 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_6;
302 2 redbear
                end
303
                else
304
                begin
305 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_7;
306 2 redbear
                end
307
        end
308 19 redbear
        RX_TX_CONTROLIN_7:
309 2 redbear
        begin
310
 
311
                if(count_send_data != DATA_CONFIG_REG[13:2])
312
                begin
313 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_7;
314 2 redbear
                end
315
                else
316
                begin
317 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_8;
318 2 redbear
                end
319
        end
320 19 redbear
        RX_TX_CONTROLIN_8:
321 2 redbear
        begin
322
 
323
                if(count_send_data != DATA_CONFIG_REG[13:2])
324
                begin
325 19 redbear
                        next_state_tx_rx = RX_TX_CONTROLIN_8;
326 2 redbear
                end
327
                else
328
                begin
329 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_CIN;
330 2 redbear
                end
331
        end
332 19 redbear
        RX_TX_RESPONSE_CIN:
333 2 redbear
        begin
334
 
335
                if(count_send_data != DATA_CONFIG_REG[13:2])
336
                begin
337 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_CIN;
338 2 redbear
                end
339
                else if(RESPONSE == 1'b0)//ACK
340
                begin
341 19 redbear
                        next_state_tx_rx = RX_TX_DELAY_BYTES;
342 2 redbear
                end
343
                else if(RESPONSE == 1'b1)//NACK
344
                begin
345 19 redbear
                        next_state_tx_rx = RX_TX_NACK;
346 2 redbear
                end
347
 
348
        end
349
 
350
        //NOW SENDING ADDRESS
351 19 redbear
        RX_TX_ADRESS_1:
352 2 redbear
        begin
353
                if(count_send_data != DATA_CONFIG_REG[13:2])
354
                begin
355 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_1;
356 2 redbear
                end
357
                else
358
                begin
359 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_2;
360 2 redbear
                end
361
        end
362 19 redbear
        RX_TX_ADRESS_2:
363 2 redbear
        begin
364
                if(count_send_data != DATA_CONFIG_REG[13:2])
365
                begin
366 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_2;
367 2 redbear
                end
368
                else
369
                begin
370 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_3;
371 2 redbear
                end
372
        end
373 19 redbear
        RX_TX_ADRESS_3:
374 2 redbear
        begin
375
                if(count_send_data != DATA_CONFIG_REG[13:2])
376
                begin
377 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_3;
378 2 redbear
                end
379
                else
380
                begin
381 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_4;
382 2 redbear
                end
383
        end
384 19 redbear
        RX_TX_ADRESS_4:
385 2 redbear
        begin
386
                if(count_send_data != DATA_CONFIG_REG[13:2])
387
                begin
388 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_4;
389 2 redbear
                end
390
                else
391
                begin
392 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_5;
393 2 redbear
                end
394
        end
395 19 redbear
        RX_TX_ADRESS_5:
396 2 redbear
        begin
397
                if(count_send_data != DATA_CONFIG_REG[13:2])
398
                begin
399 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_5;
400 2 redbear
                end
401
                else
402
                begin
403 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_6;
404 2 redbear
                end
405
        end
406 19 redbear
        RX_TX_ADRESS_6:
407 2 redbear
        begin
408
                if(count_send_data != DATA_CONFIG_REG[13:2])
409
                begin
410 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_6;
411 2 redbear
                end
412
                else
413
                begin
414 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_7;
415 2 redbear
                end
416
        end
417 19 redbear
        RX_TX_ADRESS_7:
418 2 redbear
        begin
419
                if(count_send_data != DATA_CONFIG_REG[13:2])
420
                begin
421 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_7;
422 2 redbear
                end
423
                else
424
                begin
425 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_8;
426 2 redbear
                end
427
        end
428 19 redbear
        RX_TX_ADRESS_8:
429 2 redbear
        begin
430
                if(count_send_data != DATA_CONFIG_REG[13:2])
431
                begin
432 19 redbear
                        next_state_tx_rx = RX_TX_ADRESS_8;
433 2 redbear
                end
434
                else
435
                begin
436 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_ADRESS;
437 2 redbear
                end
438
        end
439 19 redbear
        RX_TX_RESPONSE_ADRESS:
440 2 redbear
        begin
441
                if(count_send_data != DATA_CONFIG_REG[13:2])
442
                begin
443 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_ADRESS;
444 2 redbear
                end
445
                else if(RESPONSE == 1'b0)//ACK
446
                begin
447 19 redbear
                        next_state_tx_rx = RX_TX_DELAY_BYTES;
448 2 redbear
                end
449
                else if(RESPONSE == 1'b1)//NACK --> RESTART CONDITION AND BACK TO START BYTE AGAIN
450
                begin
451 19 redbear
                        next_state_tx_rx = RX_TX_NACK;
452 2 redbear
                end
453
        end
454
 
455
        //data in
456 19 redbear
        RX_TX_DATA0_1:
457 2 redbear
        begin
458
                if(count_send_data != DATA_CONFIG_REG[13:2])
459
                begin
460 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_1;
461 2 redbear
                end
462
                else
463
                begin
464 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_2;
465 2 redbear
                end
466
        end
467 19 redbear
        RX_TX_DATA0_2:
468 2 redbear
        begin
469
                if(count_send_data != DATA_CONFIG_REG[13:2])
470
                begin
471 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_2;
472 2 redbear
                end
473
                else
474
                begin
475 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_3;
476 2 redbear
                end
477
        end
478 19 redbear
        RX_TX_DATA0_3:
479 2 redbear
        begin
480
                if(count_send_data != DATA_CONFIG_REG[13:2])
481
                begin
482 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_3;
483 2 redbear
                end
484
                else
485
                begin
486 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_4;
487 2 redbear
                end
488
        end
489 19 redbear
        RX_TX_DATA0_4:
490 2 redbear
        begin
491
                if(count_send_data != DATA_CONFIG_REG[13:2])
492
                begin
493 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_4;
494 2 redbear
                end
495
                else
496
                begin
497 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_5;
498 2 redbear
                end
499
        end
500 19 redbear
        RX_TX_DATA0_5:
501 2 redbear
        begin
502
                if(count_send_data != DATA_CONFIG_REG[13:2])
503
                begin
504 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_5;
505 2 redbear
                end
506
                else
507
                begin
508 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_6;
509 2 redbear
                end
510
        end
511 19 redbear
        RX_TX_DATA0_6:
512 2 redbear
        begin
513
                if(count_send_data != DATA_CONFIG_REG[13:2])
514
                begin
515 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_6;
516 2 redbear
                end
517
                else
518
                begin
519 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_7;
520 2 redbear
                end
521
        end
522 19 redbear
        RX_TX_DATA0_7:
523 2 redbear
        begin
524
                if(count_send_data != DATA_CONFIG_REG[13:2])
525
                begin
526 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_7;
527 2 redbear
                end
528
                else
529
                begin
530 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_8;
531 2 redbear
                end
532
        end
533 19 redbear
        RX_TX_DATA0_8:
534 2 redbear
        begin
535
                if(count_send_data != DATA_CONFIG_REG[13:2])
536
                begin
537 19 redbear
                        next_state_tx_rx = RX_TX_DATA0_8;
538 2 redbear
                end
539
                else
540
                begin
541 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_DATA0_1;
542 2 redbear
                end
543
        end
544 19 redbear
        RX_TX_RESPONSE_DATA0_1:
545 2 redbear
        begin
546
                if(count_send_data != DATA_CONFIG_REG[13:2])
547
                begin
548 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_DATA0_1;
549 2 redbear
                end
550
                else if(RESPONSE == 1'b0)//ACK
551
                begin
552 19 redbear
                        next_state_tx_rx = RX_TX_DELAY_BYTES;
553 2 redbear
                end
554
                else if(RESPONSE == 1'b1)//NACK
555
                begin
556 19 redbear
                        next_state_tx_rx = RX_TX_NACK;
557 2 redbear
                end
558
        end
559
 
560
        //second byte
561 19 redbear
        RX_TX_DATA1_1:
562 2 redbear
        begin
563
                if(count_send_data != DATA_CONFIG_REG[13:2])
564
                begin
565 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_1;
566 2 redbear
                end
567
                else
568
                begin
569 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_2;
570 2 redbear
                end
571
        end
572 19 redbear
        RX_TX_DATA1_2:
573 2 redbear
        begin
574
                if(count_send_data != DATA_CONFIG_REG[13:2])
575
                begin
576 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_2;
577 2 redbear
                end
578
                else
579
                begin
580 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_3;
581 2 redbear
                end
582
        end
583 19 redbear
        RX_TX_DATA1_3:
584 2 redbear
        begin
585
                if(count_send_data != DATA_CONFIG_REG[13:2])
586
                begin
587 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_3;
588 2 redbear
                end
589
                else
590
                begin
591 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_4;
592 2 redbear
                end
593
        end
594 19 redbear
        RX_TX_DATA1_4:
595 2 redbear
        begin
596
                if(count_send_data != DATA_CONFIG_REG[13:2])
597
                begin
598 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_4;
599 2 redbear
                end
600
                else
601
                begin
602 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_5;
603 2 redbear
                end
604
        end
605 19 redbear
        RX_TX_DATA1_5:
606 2 redbear
        begin
607
                if(count_send_data != DATA_CONFIG_REG[13:2])
608
                begin
609 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_5;
610 2 redbear
                end
611
                else
612
                begin
613 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_6;
614 2 redbear
                end
615
        end
616 19 redbear
        RX_TX_DATA1_6:
617 2 redbear
        begin
618
                if(count_send_data != DATA_CONFIG_REG[13:2])
619
                begin
620 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_6;
621 2 redbear
                end
622
                else
623
                begin
624 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_7;
625 2 redbear
                end
626
        end
627 19 redbear
        RX_TX_DATA1_7:
628 2 redbear
        begin
629
                if(count_send_data != DATA_CONFIG_REG[13:2])
630
                begin
631 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_7;
632 2 redbear
                end
633
                else
634
                begin
635 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_8;
636 2 redbear
                end
637
        end
638 19 redbear
        RX_TX_DATA1_8:
639 2 redbear
        begin
640
                if(count_send_data != DATA_CONFIG_REG[13:2])
641
                begin
642 19 redbear
                        next_state_tx_rx = RX_TX_DATA1_8;
643 2 redbear
                end
644
                else
645
                begin
646 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_DATA1_1;
647 2 redbear
                end
648
        end
649 19 redbear
        RX_TX_RESPONSE_DATA1_1:
650 2 redbear
        begin
651
                if(count_send_data != DATA_CONFIG_REG[13:2])
652
                begin
653 19 redbear
                        next_state_tx_rx = RX_TX_RESPONSE_DATA1_1;
654 2 redbear
                end
655
                else if(RESPONSE == 1'b0)//ACK
656
                begin
657 19 redbear
                        next_state_tx_rx = RX_TX_DELAY_BYTES;
658 2 redbear
                end
659
                else if(RESPONSE == 1'b1)//NACK
660
                begin
661 19 redbear
                        next_state_tx_rx = RX_TX_NACK;
662 2 redbear
                end
663
        end
664 19 redbear
        RX_TX_DELAY_BYTES://THIS FORM WORKS 
665 2 redbear
        begin
666
 
667
 
668
                if(count_send_data != DATA_CONFIG_REG[13:2])
669
                begin
670 19 redbear
                        next_state_tx_rx = RX_TX_DELAY_BYTES;
671 2 redbear
                end
672
                else
673
                begin
674
 
675 6 redbear
                        if(count_tx == 2'd0)
676 2 redbear
                        begin
677 19 redbear
                                next_state_tx_rx = RX_TX_ADRESS_1;
678 2 redbear
                        end
679 6 redbear
                        else if(count_tx == 2'd1)
680 2 redbear
                        begin
681 19 redbear
                                next_state_tx_rx = RX_TX_DATA0_1;
682 2 redbear
                        end
683 6 redbear
                        else if(count_tx == 2'd2)
684 2 redbear
                        begin
685 19 redbear
                                next_state_tx_rx = RX_TX_DATA1_1;
686 2 redbear
                        end
687 6 redbear
                        else if(count_tx == 2'd3)
688 2 redbear
                        begin
689 19 redbear
                                next_state_tx_rx = RX_TX_STOP;
690 2 redbear
                        end
691
 
692
                end
693
 
694
        end
695 19 redbear
        RX_TX_NACK://NOT TESTED YET !!!!
696 2 redbear
        begin
697
                if(count_send_data != DATA_CONFIG_REG[13:2]*2'd2)
698
                begin
699 19 redbear
                        next_state_tx_rx = RX_TX_NACK;
700 2 redbear
                end
701
                else
702
                begin
703 6 redbear
                        if(count_tx == 2'd0)
704 2 redbear
                        begin
705 19 redbear
                                next_state_tx_rx = RX_TX_CONTROLIN_1;
706 2 redbear
                        end
707 6 redbear
                        else if(count_tx == 2'd1)
708 2 redbear
                        begin
709 19 redbear
                                next_state_tx_rx = RX_TX_ADRESS_1;
710 2 redbear
                        end
711 6 redbear
                        else if(count_tx == 2'd2)
712 2 redbear
                        begin
713 19 redbear
                                next_state_tx_rx = RX_TX_DATA0_1;
714 2 redbear
                        end
715 6 redbear
                        else if(count_tx == 2'd3)
716 2 redbear
                        begin
717 19 redbear
                                next_state_tx_rx = RX_TX_DATA1_1;
718 2 redbear
                        end
719
                end
720
        end
721 19 redbear
        RX_TX_STOP://THIS WORK
722 2 redbear
        begin
723
                if(count_send_data != DATA_CONFIG_REG[13:2])
724
                begin
725 19 redbear
                        next_state_tx_rx = RX_TX_STOP;
726 2 redbear
                end
727
                else
728
                begin
729 19 redbear
                        next_state_tx_rx = RX_TX_IDLE;
730 2 redbear
                end
731
        end
732
        default:
733
        begin
734 19 redbear
                next_state_tx_rx = RX_TX_IDLE;
735 2 redbear
        end
736
        endcase
737
 
738
 
739
end
740 19 redbear
 
741
 
742
 
743 6 redbear
//SEQUENTIAL TX
744 2 redbear
always@(posedge PCLK)
745
begin
746
 
747
        //RESET SYNC
748
        if(!PRESETn)
749
        begin
750
                //SIGNALS MUST BE RESETED
751
                count_send_data <= 12'd0;
752 19 redbear
                state_tx_rx <= RX_TX_IDLE;
753 2 redbear
                SDA_OUT<= 1'b1;
754
                fifo_tx_rd_en <= 1'b0;
755 6 redbear
                count_tx <= 2'd0;
756 2 redbear
                BR_CLK_O <= 1'b1;
757
                RESPONSE<= 1'b0;
758
        end
759
        else
760
        begin
761
 
762
                // SEQUENTIAL FUN START
763 19 redbear
                state_tx_rx <= next_state_tx_rx;
764 2 redbear
 
765 19 redbear
                case(state_tx_rx)
766
                RX_TX_IDLE:
767 2 redbear
                begin
768
 
769
                        fifo_tx_rd_en <= 1'b0;
770
 
771
 
772 18 redbear
                        if(DATA_CONFIG_REG[0] == 1'b0 && (fifo_tx_f_full == 1'b1 ||fifo_tx_f_empty == 1'b0) && DATA_CONFIG_REG[1] == 1'b0)
773 2 redbear
                        begin
774
                                count_send_data <= 12'd0;
775
                                SDA_OUT<= 1'b1;
776
                                BR_CLK_O <= 1'b1;
777
                        end
778 18 redbear
                        else if(DATA_CONFIG_REG[0] == 1'b1 && (fifo_tx_f_full == 1'b1 ||fifo_tx_f_empty == 1'b0) && DATA_CONFIG_REG[1] == 1'b0)
779 2 redbear
                        begin
780
                                count_send_data <= count_send_data + 12'd1;
781
                                SDA_OUT<=1'b0;
782 4 redbear
                        end
783 18 redbear
                        else if(DATA_CONFIG_REG[0] == 1'b1 && (fifo_tx_f_full == 1'b1 ||fifo_tx_f_empty == 1'b0) && DATA_CONFIG_REG[1] == 1'b1)
784 4 redbear
                        begin
785
                                count_send_data <= 12'd0;
786
                                SDA_OUT<= 1'b1;
787
                                BR_CLK_O <= 1'b1;
788 2 redbear
                        end
789
 
790
                end
791 19 redbear
                RX_TX_START:
792 2 redbear
                begin
793
 
794
                        if(count_send_data < DATA_CONFIG_REG[13:2])
795
                        begin
796
                                count_send_data <= count_send_data + 12'd1;
797
                                BR_CLK_O <= 1'b0;
798
                        end
799
                        else
800
                        begin
801 7 redbear
                                count_send_data <= 12'd0;
802 2 redbear
                        end
803
 
804
                        if(count_send_data == DATA_CONFIG_REG[13:2]- 12'd1)
805
                        begin
806 6 redbear
                                SDA_OUT<=fifo_tx_data_out[0:0];
807
                                count_tx <= 2'd0;
808 2 redbear
                        end
809
 
810
                end
811 19 redbear
                RX_TX_CONTROLIN_1:
812 2 redbear
                begin
813
 
814
 
815
 
816
                        if(count_send_data < DATA_CONFIG_REG[13:2])
817
                        begin
818
 
819
                                count_send_data <= count_send_data + 12'd1;
820
                                SDA_OUT<=fifo_tx_data_out[0:0];
821
 
822 7 redbear
 
823
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
824 2 redbear
                                begin
825 7 redbear
                                        BR_CLK_O <= 1'b0;
826
                                end
827
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
828
                                begin
829 2 redbear
                                        BR_CLK_O <= 1'b1;
830
                                end
831 7 redbear
                                else
832 2 redbear
                                begin
833
                                        BR_CLK_O <= 1'b0;
834
                                end
835
                        end
836
                        else
837
                        begin
838
                                count_send_data <= 12'd0;
839
                                SDA_OUT<=fifo_tx_data_out[1:1];
840
                        end
841
 
842
 
843
                end
844
 
845 19 redbear
                RX_TX_CONTROLIN_2:
846 2 redbear
                begin
847
 
848
 
849
 
850
                        if(count_send_data < DATA_CONFIG_REG[13:2])
851
                        begin
852
                                count_send_data <= count_send_data + 12'd1;
853
                                SDA_OUT<=fifo_tx_data_out[1:1];
854
 
855 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
856 2 redbear
                                begin
857 7 redbear
                                        BR_CLK_O <= 1'b0;
858
                                end
859
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
860
                                begin
861 2 redbear
                                        BR_CLK_O <= 1'b1;
862
                                end
863 7 redbear
                                else
864 2 redbear
                                begin
865
                                        BR_CLK_O <= 1'b0;
866 7 redbear
                                end
867 2 redbear
                        end
868
                        else
869
                        begin
870
                                count_send_data <= 12'd0;
871
                                SDA_OUT<=fifo_tx_data_out[2:2];
872
                        end
873
 
874
                end
875
 
876 19 redbear
                RX_TX_CONTROLIN_3:
877 2 redbear
                begin
878
 
879
 
880
 
881
                        if(count_send_data < DATA_CONFIG_REG[13:2])
882
                        begin
883
                                count_send_data <= count_send_data + 12'd1;
884
                                SDA_OUT<=fifo_tx_data_out[2:2];
885
 
886 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
887 2 redbear
                                begin
888 7 redbear
                                        BR_CLK_O <= 1'b0;
889
                                end
890
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
891
                                begin
892 2 redbear
                                        BR_CLK_O <= 1'b1;
893
                                end
894 7 redbear
                                else
895 2 redbear
                                begin
896
                                        BR_CLK_O <= 1'b0;
897 7 redbear
                                end
898 2 redbear
                        end
899
                        else
900
                        begin
901
                                count_send_data <= 12'd0;
902
                                SDA_OUT<=fifo_tx_data_out[3:3];
903
                        end
904
 
905
 
906
 
907
                end
908 19 redbear
                RX_TX_CONTROLIN_4:
909 2 redbear
                begin
910
 
911
 
912
 
913
                        if(count_send_data < DATA_CONFIG_REG[13:2])
914
                        begin
915
                                count_send_data <= count_send_data + 12'd1;
916
                                SDA_OUT<=fifo_tx_data_out[3:3];
917
 
918 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
919 2 redbear
                                begin
920 7 redbear
                                        BR_CLK_O <= 1'b0;
921
                                end
922
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
923
                                begin
924 2 redbear
                                        BR_CLK_O <= 1'b1;
925
                                end
926 7 redbear
                                else
927 2 redbear
                                begin
928
                                        BR_CLK_O <= 1'b0;
929 7 redbear
                                end
930 2 redbear
                        end
931
                        else
932
                        begin
933
                                count_send_data <= 12'd0;
934
                                SDA_OUT<=fifo_tx_data_out[4:4];
935
                        end
936
 
937
                end
938
 
939 19 redbear
                RX_TX_CONTROLIN_5:
940 2 redbear
                begin
941
 
942
 
943
 
944
                        if(count_send_data < DATA_CONFIG_REG[13:2])
945
                        begin
946
                                count_send_data <= count_send_data + 12'd1;
947
                                SDA_OUT<=fifo_tx_data_out[4:4];
948
 
949 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
950 2 redbear
                                begin
951 7 redbear
                                        BR_CLK_O <= 1'b0;
952
                                end
953
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
954
                                begin
955 2 redbear
                                        BR_CLK_O <= 1'b1;
956
                                end
957 7 redbear
                                else
958 2 redbear
                                begin
959
                                        BR_CLK_O <= 1'b0;
960 7 redbear
                                end
961 2 redbear
                        end
962
                        else
963
                        begin
964
                                count_send_data <= 12'd0;
965
                                SDA_OUT<=fifo_tx_data_out[5:5];
966
                        end
967
 
968
                end
969
 
970
 
971 19 redbear
                RX_TX_CONTROLIN_6:
972 2 redbear
                begin
973
 
974
                        if(count_send_data < DATA_CONFIG_REG[13:2])
975
                        begin
976
                                count_send_data <= count_send_data + 12'd1;
977
                                SDA_OUT<=fifo_tx_data_out[5:5];
978
 
979 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
980 2 redbear
                                begin
981 7 redbear
                                        BR_CLK_O <= 1'b0;
982
                                end
983
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
984
                                begin
985 2 redbear
                                        BR_CLK_O <= 1'b1;
986
                                end
987 7 redbear
                                else
988 2 redbear
                                begin
989
                                        BR_CLK_O <= 1'b0;
990
                                end
991
                        end
992
                        else
993
                        begin
994
                                count_send_data <= 12'd0;
995
                                SDA_OUT<=fifo_tx_data_out[6:6];
996
                        end
997
 
998
 
999
                end
1000
 
1001 19 redbear
                RX_TX_CONTROLIN_7:
1002 2 redbear
                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[6:6];
1008
 
1009 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1010 2 redbear
                                begin
1011 7 redbear
                                        BR_CLK_O <= 1'b0;
1012
                                end
1013
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1014
                                begin
1015 2 redbear
                                        BR_CLK_O <= 1'b1;
1016
                                end
1017 7 redbear
                                else
1018 2 redbear
                                begin
1019
                                        BR_CLK_O <= 1'b0;
1020
                                end
1021
                        end
1022
                        else
1023
                        begin
1024
                                count_send_data <= 12'd0;
1025
                                SDA_OUT<=fifo_tx_data_out[7:7];
1026
                        end
1027
 
1028
 
1029
                end
1030 19 redbear
                RX_TX_CONTROLIN_8:
1031 2 redbear
                begin
1032
 
1033
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1034
                        begin
1035
                                count_send_data <= count_send_data + 12'd1;
1036
                                SDA_OUT<=fifo_tx_data_out[7:7];
1037
 
1038 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1039 2 redbear
                                begin
1040 7 redbear
                                        BR_CLK_O <= 1'b0;
1041
                                end
1042
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1043
                                begin
1044 2 redbear
                                        BR_CLK_O <= 1'b1;
1045
                                end
1046 7 redbear
                                else
1047 2 redbear
                                begin
1048
                                        BR_CLK_O <= 1'b0;
1049 7 redbear
                                end
1050 2 redbear
                        end
1051
                        else
1052
                        begin
1053
                                count_send_data <= 12'd0;
1054
                                SDA_OUT<= 1'b0;
1055
                        end
1056
 
1057
 
1058
                end
1059 19 redbear
                RX_TX_RESPONSE_CIN:
1060 2 redbear
                begin
1061
 
1062
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1063
                        begin
1064
                                count_send_data <= count_send_data + 12'd1;
1065
 
1066
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1067
                                RESPONSE<= SDA;
1068
 
1069 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1070 2 redbear
                                begin
1071 7 redbear
                                        BR_CLK_O <= 1'b0;
1072
                                end
1073
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1074
                                begin
1075 2 redbear
                                        BR_CLK_O <= 1'b1;
1076
                                end
1077 7 redbear
                                else
1078 2 redbear
                                begin
1079
                                        BR_CLK_O <= 1'b0;
1080 7 redbear
                                end
1081 2 redbear
                        end
1082
                        else
1083
                        begin
1084
                                count_send_data <= 12'd0;
1085
                        end
1086
 
1087
 
1088
                end
1089 19 redbear
                RX_TX_ADRESS_1:
1090 2 redbear
                begin
1091
 
1092
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1093
                        begin
1094
                                count_send_data <= count_send_data + 12'd1;
1095
                                SDA_OUT<=fifo_tx_data_out[8:8];
1096
 
1097 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1098 2 redbear
                                begin
1099 7 redbear
                                        BR_CLK_O <= 1'b0;
1100
                                end
1101
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1102
                                begin
1103 2 redbear
                                        BR_CLK_O <= 1'b1;
1104
                                end
1105 7 redbear
                                else
1106 2 redbear
                                begin
1107
                                        BR_CLK_O <= 1'b0;
1108 7 redbear
                                end
1109 2 redbear
                        end
1110
                        else
1111
                        begin
1112
                                count_send_data <= 12'd0;
1113
                                SDA_OUT<=fifo_tx_data_out[9:9];
1114
                        end
1115
 
1116
                end
1117 19 redbear
                RX_TX_ADRESS_2:
1118 2 redbear
                begin
1119
 
1120
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1121
                        begin
1122
                                count_send_data <= count_send_data + 12'd1;
1123
                                SDA_OUT<=fifo_tx_data_out[9:9];
1124
 
1125 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1126 2 redbear
                                begin
1127 7 redbear
                                        BR_CLK_O <= 1'b0;
1128
                                end
1129
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1130
                                begin
1131 2 redbear
                                        BR_CLK_O <= 1'b1;
1132
                                end
1133 7 redbear
                                else
1134 2 redbear
                                begin
1135
                                        BR_CLK_O <= 1'b0;
1136 7 redbear
                                end
1137 2 redbear
                        end
1138
                        else
1139
                        begin
1140
                                count_send_data <= 12'd0;
1141
                                SDA_OUT<=fifo_tx_data_out[10:10];
1142
                        end
1143
 
1144
                end
1145 19 redbear
                RX_TX_ADRESS_3:
1146 2 redbear
                begin
1147
 
1148
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1149
                        begin
1150
                                count_send_data <= count_send_data + 12'd1;
1151
                                SDA_OUT<=fifo_tx_data_out[10:10];
1152
 
1153 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1154 2 redbear
                                begin
1155 7 redbear
                                        BR_CLK_O <= 1'b0;
1156
                                end
1157
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1158
                                begin
1159 2 redbear
                                        BR_CLK_O <= 1'b1;
1160
                                end
1161 7 redbear
                                else
1162 2 redbear
                                begin
1163
                                        BR_CLK_O <= 1'b0;
1164 7 redbear
                                end
1165 2 redbear
                        end
1166
                        else
1167
                        begin
1168
                                count_send_data <= 12'd0;
1169
                                SDA_OUT<=fifo_tx_data_out[11:11];
1170
                        end
1171
 
1172
                end
1173 19 redbear
                RX_TX_ADRESS_4:
1174 2 redbear
                begin
1175
 
1176
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1177
                        begin
1178
                                count_send_data <= count_send_data + 12'd1;
1179
                                SDA_OUT<=fifo_tx_data_out[11:11];
1180
 
1181 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1182 2 redbear
                                begin
1183 7 redbear
                                        BR_CLK_O <= 1'b0;
1184
                                end
1185
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1186
                                begin
1187 2 redbear
                                        BR_CLK_O <= 1'b1;
1188
                                end
1189 7 redbear
                                else
1190 2 redbear
                                begin
1191
                                        BR_CLK_O <= 1'b0;
1192 7 redbear
                                end
1193 2 redbear
                        end
1194
                        else
1195
                        begin
1196
                                count_send_data <= 12'd0;
1197
                                SDA_OUT<=fifo_tx_data_out[12:12];
1198
                        end
1199
                end
1200 19 redbear
                RX_TX_ADRESS_5:
1201 2 redbear
                begin
1202
 
1203
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1204
                        begin
1205
                                count_send_data <= count_send_data + 12'd1;
1206
                                SDA_OUT<=fifo_tx_data_out[12:12];
1207
 
1208 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1209 2 redbear
                                begin
1210 7 redbear
                                        BR_CLK_O <= 1'b0;
1211
                                end
1212
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1213
                                begin
1214 2 redbear
                                        BR_CLK_O <= 1'b1;
1215
                                end
1216 7 redbear
                                else
1217 2 redbear
                                begin
1218
                                        BR_CLK_O <= 1'b0;
1219 7 redbear
                                end
1220 2 redbear
                        end
1221
                        else
1222
                        begin
1223
                                count_send_data <= 12'd0;
1224
                                SDA_OUT<=fifo_tx_data_out[13:13];
1225
                        end
1226
 
1227
 
1228
                end
1229 19 redbear
                RX_TX_ADRESS_6:
1230 2 redbear
                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[13:13];
1236
 
1237 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1238 2 redbear
                                begin
1239 7 redbear
                                        BR_CLK_O <= 1'b0;
1240
                                end
1241
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1242
                                begin
1243 2 redbear
                                        BR_CLK_O <= 1'b1;
1244
                                end
1245 7 redbear
                                else
1246 2 redbear
                                begin
1247
                                        BR_CLK_O <= 1'b0;
1248
                                end
1249
                        end
1250
                        else
1251
                        begin
1252 7 redbear
                                count_send_data <= 12'd0;
1253 2 redbear
                                SDA_OUT<=fifo_tx_data_out[14:14];
1254
                        end
1255
 
1256
                end
1257 19 redbear
                RX_TX_ADRESS_7:
1258 2 redbear
                begin
1259
 
1260
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1261
                        begin
1262
                                count_send_data <= count_send_data + 12'd1;
1263
                                SDA_OUT<=fifo_tx_data_out[14:14];
1264
 
1265 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1266 2 redbear
                                begin
1267 7 redbear
                                        BR_CLK_O <= 1'b0;
1268
                                end
1269
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1270
                                begin
1271 2 redbear
                                        BR_CLK_O <= 1'b1;
1272
                                end
1273 7 redbear
                                else
1274 2 redbear
                                begin
1275
                                        BR_CLK_O <= 1'b0;
1276 7 redbear
                                end
1277 2 redbear
                        end
1278
                        else
1279
                        begin
1280
                                count_send_data <= 12'd0;
1281
                                SDA_OUT<=fifo_tx_data_out[15:15];
1282
                        end
1283
 
1284
 
1285
                end
1286 19 redbear
                RX_TX_ADRESS_8:
1287 2 redbear
                begin
1288
 
1289
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1290
                        begin
1291
                                count_send_data <= count_send_data + 12'd1;
1292
                                SDA_OUT<=fifo_tx_data_out[15:15];
1293
 
1294 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1295 2 redbear
                                begin
1296 7 redbear
                                        BR_CLK_O <= 1'b0;
1297
                                end
1298
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1299
                                begin
1300 2 redbear
                                        BR_CLK_O <= 1'b1;
1301
                                end
1302 7 redbear
                                else
1303 2 redbear
                                begin
1304
                                        BR_CLK_O <= 1'b0;
1305
                                end
1306
                        end
1307
                        else
1308
                        begin
1309
                                count_send_data <= 12'd0;
1310 18 redbear
                                SDA_OUT<=1'b0;
1311 2 redbear
                        end
1312
 
1313
                end
1314 19 redbear
                RX_TX_RESPONSE_ADRESS:
1315 2 redbear
                begin
1316
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1317
                        begin
1318
                                count_send_data <= count_send_data + 12'd1;
1319
 
1320
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1321
                                RESPONSE<= SDA;
1322
 
1323 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1324 2 redbear
                                begin
1325 7 redbear
                                        BR_CLK_O <= 1'b0;
1326
                                end
1327
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1328
                                begin
1329 2 redbear
                                        BR_CLK_O <= 1'b1;
1330
                                end
1331 7 redbear
                                else
1332 2 redbear
                                begin
1333
                                        BR_CLK_O <= 1'b0;
1334
                                end
1335
                        end
1336
                        else
1337
                        begin
1338
                                count_send_data <= 12'd0;
1339
                        end
1340
 
1341
                end
1342 19 redbear
                RX_TX_DATA0_1:
1343 2 redbear
                begin
1344
 
1345
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1346
                        begin
1347
                                count_send_data <= count_send_data + 12'd1;
1348
                                SDA_OUT<=fifo_tx_data_out[16:16];
1349
 
1350 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1351 2 redbear
                                begin
1352 7 redbear
                                        BR_CLK_O <= 1'b0;
1353
                                end
1354
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1355
                                begin
1356 2 redbear
                                        BR_CLK_O <= 1'b1;
1357
                                end
1358 7 redbear
                                else
1359 2 redbear
                                begin
1360
                                        BR_CLK_O <= 1'b0;
1361
                                end
1362
                        end
1363
                        else
1364
                        begin
1365
                                count_send_data <= 12'd0;
1366
                                SDA_OUT<=fifo_tx_data_out[17:17];
1367
                        end
1368
 
1369
 
1370
                end
1371 19 redbear
                RX_TX_DATA0_2:
1372 2 redbear
                begin
1373
 
1374
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1375
                        begin
1376
                                count_send_data <= count_send_data + 12'd1;
1377
                                SDA_OUT<=fifo_tx_data_out[17:17];
1378
 
1379 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1380 2 redbear
                                begin
1381 7 redbear
                                        BR_CLK_O <= 1'b0;
1382
                                end
1383
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1384
                                begin
1385 2 redbear
                                        BR_CLK_O <= 1'b1;
1386
                                end
1387 7 redbear
                                else
1388 2 redbear
                                begin
1389
                                        BR_CLK_O <= 1'b0;
1390 7 redbear
                                end
1391 2 redbear
                        end
1392
                        else
1393
                        begin
1394
                                count_send_data <= 12'd0;
1395
                                SDA_OUT<=fifo_tx_data_out[18:18];
1396
                        end
1397
 
1398
 
1399
                end
1400 19 redbear
                RX_TX_DATA0_3:
1401 2 redbear
                begin
1402
 
1403
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1404
                        begin
1405
                                count_send_data <= count_send_data + 12'd1;
1406
                                SDA_OUT<=fifo_tx_data_out[18:18];
1407
 
1408 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1409 2 redbear
                                begin
1410 7 redbear
                                        BR_CLK_O <= 1'b0;
1411
                                end
1412
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1413
                                begin
1414 2 redbear
                                        BR_CLK_O <= 1'b1;
1415
                                end
1416 7 redbear
                                else
1417 2 redbear
                                begin
1418
                                        BR_CLK_O <= 1'b0;
1419 7 redbear
                                end
1420 2 redbear
                        end
1421
                        else
1422
                        begin
1423
                                count_send_data <= 12'd0;
1424
                                SDA_OUT<=fifo_tx_data_out[19:19];
1425
                        end
1426
 
1427
                end
1428 19 redbear
                RX_TX_DATA0_4:
1429 2 redbear
                begin
1430
 
1431
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1432
                        begin
1433
                                count_send_data <= count_send_data + 12'd1;
1434
                                SDA_OUT<=fifo_tx_data_out[19:19];
1435
 
1436 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1437 2 redbear
                                begin
1438 7 redbear
                                        BR_CLK_O <= 1'b0;
1439
                                end
1440
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1441
                                begin
1442 2 redbear
                                        BR_CLK_O <= 1'b1;
1443
                                end
1444 7 redbear
                                else
1445 2 redbear
                                begin
1446
                                        BR_CLK_O <= 1'b0;
1447 7 redbear
                                end
1448 2 redbear
                        end
1449
                        else
1450
                        begin
1451
                                count_send_data <= 12'd0;
1452
                                SDA_OUT<=fifo_tx_data_out[20:20];
1453
                        end
1454
 
1455
                end
1456 19 redbear
                RX_TX_DATA0_5:
1457 2 redbear
                begin
1458
 
1459
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1460
                        begin
1461
                                count_send_data <= count_send_data + 12'd1;
1462
                                SDA_OUT<=fifo_tx_data_out[20:20];
1463
 
1464 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1465 2 redbear
                                begin
1466 7 redbear
                                        BR_CLK_O <= 1'b0;
1467
                                end
1468
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1469
                                begin
1470 2 redbear
                                        BR_CLK_O <= 1'b1;
1471
                                end
1472 7 redbear
                                else
1473 2 redbear
                                begin
1474
                                        BR_CLK_O <= 1'b0;
1475
                                end
1476
                        end
1477
                        else
1478
                        begin
1479
                                count_send_data <= 12'd0;
1480
                                SDA_OUT<=fifo_tx_data_out[21:21];
1481
                        end
1482
 
1483
                end
1484 19 redbear
                RX_TX_DATA0_6:
1485 2 redbear
                begin
1486
 
1487
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1488
                        begin
1489
                                count_send_data <= count_send_data + 12'd1;
1490
                                SDA_OUT<=fifo_tx_data_out[21:21];
1491
 
1492 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1493 2 redbear
                                begin
1494 7 redbear
                                        BR_CLK_O <= 1'b0;
1495
                                end
1496
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1497
                                begin
1498 2 redbear
                                        BR_CLK_O <= 1'b1;
1499
                                end
1500 7 redbear
                                else
1501 2 redbear
                                begin
1502
                                        BR_CLK_O <= 1'b0;
1503
                                end
1504
                        end
1505
                        else
1506
                        begin
1507
                                count_send_data <= 12'd0;
1508
                                SDA_OUT<=fifo_tx_data_out[22:22];
1509
                        end
1510
 
1511
                end
1512 19 redbear
                RX_TX_DATA0_7:
1513 2 redbear
                begin
1514
 
1515
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1516
                        begin
1517
                                count_send_data <= count_send_data + 12'd1;
1518
                                SDA_OUT<=fifo_tx_data_out[22:22];
1519
 
1520 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1521 2 redbear
                                begin
1522 7 redbear
                                        BR_CLK_O <= 1'b0;
1523
                                end
1524
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1525
                                begin
1526 2 redbear
                                        BR_CLK_O <= 1'b1;
1527
                                end
1528 7 redbear
                                else
1529 2 redbear
                                begin
1530
                                        BR_CLK_O <= 1'b0;
1531 7 redbear
                                end
1532 2 redbear
                        end
1533
                        else
1534
                        begin
1535
                                count_send_data <= 12'd0;
1536
                                SDA_OUT<=fifo_tx_data_out[23:23];
1537
                        end
1538
 
1539
                end
1540 19 redbear
                RX_TX_DATA0_8:
1541 2 redbear
                begin
1542
 
1543
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1544
                        begin
1545
                                count_send_data <= count_send_data + 12'd1;
1546
                                SDA_OUT<=fifo_tx_data_out[23:23];
1547
 
1548 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1549 2 redbear
                                begin
1550 7 redbear
                                        BR_CLK_O <= 1'b0;
1551
                                end
1552
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1553
                                begin
1554 2 redbear
                                        BR_CLK_O <= 1'b1;
1555
                                end
1556 7 redbear
                                else
1557 2 redbear
                                begin
1558
                                        BR_CLK_O <= 1'b0;
1559
                                end
1560
 
1561
                        end
1562
                        else
1563
                        begin
1564
                                count_send_data <= 12'd0;
1565 18 redbear
                                SDA_OUT<=1'b0;
1566 2 redbear
                        end
1567
 
1568
                end
1569 19 redbear
                RX_TX_RESPONSE_DATA0_1:
1570 2 redbear
                begin
1571
 
1572
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1573
                        begin
1574
                                count_send_data <= count_send_data + 12'd1;
1575
 
1576
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1577
                                RESPONSE<= SDA;
1578
 
1579 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1580 2 redbear
                                begin
1581 7 redbear
                                        BR_CLK_O <= 1'b0;
1582
                                end
1583
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1584
                                begin
1585 2 redbear
                                        BR_CLK_O <= 1'b1;
1586
                                end
1587 7 redbear
                                else
1588 2 redbear
                                begin
1589
                                        BR_CLK_O <= 1'b0;
1590 7 redbear
                                end
1591 2 redbear
                        end
1592
                        else
1593
                        begin
1594
                                count_send_data <= 12'd0;
1595
                        end
1596
 
1597
                end
1598 19 redbear
                RX_TX_DATA1_1:
1599 2 redbear
                begin
1600
 
1601
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1602
                        begin
1603
                                count_send_data <= count_send_data + 12'd1;
1604
                                SDA_OUT<=fifo_tx_data_out[24:24];
1605
 
1606 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1607 2 redbear
                                begin
1608 7 redbear
                                        BR_CLK_O <= 1'b0;
1609
                                end
1610
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1611
                                begin
1612 2 redbear
                                        BR_CLK_O <= 1'b1;
1613
                                end
1614 7 redbear
                                else
1615 2 redbear
                                begin
1616
                                        BR_CLK_O <= 1'b0;
1617 7 redbear
                                end
1618 2 redbear
                        end
1619
                        else
1620
                        begin
1621
                                count_send_data <= 12'd0;
1622
                                SDA_OUT<=fifo_tx_data_out[25:25];
1623
 
1624
                        end
1625
 
1626
 
1627
                end
1628 19 redbear
                RX_TX_DATA1_2:
1629 2 redbear
                begin
1630
 
1631
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1632
                        begin
1633
                                count_send_data <= count_send_data + 12'd1;
1634
                                SDA_OUT<=fifo_tx_data_out[25:25];
1635
 
1636 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1637 2 redbear
                                begin
1638 7 redbear
                                        BR_CLK_O <= 1'b0;
1639
                                end
1640
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1641
                                begin
1642 2 redbear
                                        BR_CLK_O <= 1'b1;
1643
                                end
1644 7 redbear
                                else
1645 2 redbear
                                begin
1646
                                        BR_CLK_O <= 1'b0;
1647 7 redbear
                                end
1648 2 redbear
                        end
1649
                        else
1650
                        begin
1651
                                count_send_data <= 12'd0;
1652
                                SDA_OUT<=fifo_tx_data_out[26:26];
1653
                        end
1654
 
1655
                end
1656 19 redbear
                RX_TX_DATA1_3:
1657 2 redbear
                begin
1658
 
1659
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1660
                        begin
1661
                                count_send_data <= count_send_data + 12'd1;
1662
                                SDA_OUT<=fifo_tx_data_out[26:26];
1663
 
1664 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1665 2 redbear
                                begin
1666 7 redbear
                                        BR_CLK_O <= 1'b0;
1667
                                end
1668
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1669
                                begin
1670 2 redbear
                                        BR_CLK_O <= 1'b1;
1671
                                end
1672 7 redbear
                                else
1673 2 redbear
                                begin
1674
                                        BR_CLK_O <= 1'b0;
1675
                                end
1676
 
1677
                        end
1678
                        else
1679
                        begin
1680
                                count_send_data <= 12'd0;
1681
                                SDA_OUT<=fifo_tx_data_out[27:27];
1682
                        end
1683
 
1684
                end
1685 19 redbear
                RX_TX_DATA1_4:
1686 2 redbear
                begin
1687
 
1688
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1689
                        begin
1690
                                count_send_data <= count_send_data + 12'd1;
1691
                                SDA_OUT<=fifo_tx_data_out[27:27];
1692
 
1693 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1694 2 redbear
                                begin
1695 7 redbear
                                        BR_CLK_O <= 1'b0;
1696
                                end
1697
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1698
                                begin
1699 2 redbear
                                        BR_CLK_O <= 1'b1;
1700
                                end
1701 7 redbear
                                else
1702 2 redbear
                                begin
1703
                                        BR_CLK_O <= 1'b0;
1704 7 redbear
                                end
1705 2 redbear
 
1706
                        end
1707
                        else
1708
                        begin
1709
                                count_send_data <= 12'd0;
1710
                                SDA_OUT<=fifo_tx_data_out[28:28];
1711
                        end
1712
 
1713
                end
1714 19 redbear
                RX_TX_DATA1_5:
1715 2 redbear
                begin
1716
 
1717
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1718
                        begin
1719
                                count_send_data <= count_send_data + 12'd1;
1720
                                SDA_OUT<=fifo_tx_data_out[28:28];
1721
 
1722 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1723 2 redbear
                                begin
1724 7 redbear
                                        BR_CLK_O <= 1'b0;
1725
                                end
1726
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1727
                                begin
1728 2 redbear
                                        BR_CLK_O <= 1'b1;
1729
                                end
1730 7 redbear
                                else
1731 2 redbear
                                begin
1732
                                        BR_CLK_O <= 1'b0;
1733
                                end
1734
 
1735
                        end
1736
                        else
1737
                        begin
1738
                                count_send_data <= 12'd0;
1739
                                SDA_OUT<=fifo_tx_data_out[29:29];
1740
                        end
1741
 
1742
                end
1743 19 redbear
                RX_TX_DATA1_6:
1744 2 redbear
                begin
1745
 
1746
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1747
                        begin
1748
                                count_send_data <= count_send_data + 12'd1;
1749
                                SDA_OUT<=fifo_tx_data_out[29:29];
1750
 
1751 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1752 2 redbear
                                begin
1753 7 redbear
                                        BR_CLK_O <= 1'b0;
1754
                                end
1755
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1756
                                begin
1757 2 redbear
                                        BR_CLK_O <= 1'b1;
1758
                                end
1759 7 redbear
                                else
1760 2 redbear
                                begin
1761
                                        BR_CLK_O <= 1'b0;
1762
                                end
1763
 
1764
                        end
1765
                        else
1766
                        begin
1767
                                count_send_data <= 12'd0;
1768
                                SDA_OUT<=fifo_tx_data_out[30:30];
1769
                        end
1770
 
1771
                end
1772 19 redbear
                RX_TX_DATA1_7:
1773 2 redbear
                begin
1774
 
1775
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1776
                        begin
1777
                                count_send_data <= count_send_data + 12'd1;
1778
                                SDA_OUT<=fifo_tx_data_out[30:30];
1779
 
1780 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1781 2 redbear
                                begin
1782 7 redbear
                                        BR_CLK_O <= 1'b0;
1783
                                end
1784
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1785
                                begin
1786 2 redbear
                                        BR_CLK_O <= 1'b1;
1787
                                end
1788 7 redbear
                                else
1789 2 redbear
                                begin
1790
                                        BR_CLK_O <= 1'b0;
1791
                                end
1792
 
1793
                        end
1794
                        else
1795
                        begin
1796
                                count_send_data <= 12'd0;
1797
                                SDA_OUT<=fifo_tx_data_out[31:31];
1798
                        end
1799
 
1800
 
1801
                end
1802 19 redbear
                RX_TX_DATA1_8:
1803 2 redbear
                begin
1804
 
1805
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1806
                        begin
1807
                                count_send_data <= count_send_data + 12'd1;
1808
                                SDA_OUT<=fifo_tx_data_out[31:31];
1809
 
1810 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1811 2 redbear
                                begin
1812 7 redbear
                                        BR_CLK_O <= 1'b0;
1813
                                end
1814
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1815
                                begin
1816 2 redbear
                                        BR_CLK_O <= 1'b1;
1817
                                end
1818 7 redbear
                                else
1819 2 redbear
                                begin
1820
                                        BR_CLK_O <= 1'b0;
1821
                                end
1822
 
1823
                        end
1824
                        else
1825
                        begin
1826
                                count_send_data <= 12'd0;
1827 18 redbear
                                SDA_OUT<=1'b0;
1828 2 redbear
                        end
1829
 
1830
                end
1831 19 redbear
                RX_TX_RESPONSE_DATA1_1:
1832 2 redbear
                begin
1833
                        //fifo_tx_rd_en <= 1'b1;
1834
 
1835
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1836
                        begin
1837
                                count_send_data <= count_send_data + 12'd1;
1838
 
1839
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
1840
                                RESPONSE<= SDA;
1841
 
1842 7 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
1843 2 redbear
                                begin
1844 7 redbear
                                        BR_CLK_O <= 1'b0;
1845
                                end
1846
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
1847
                                begin
1848 2 redbear
                                        BR_CLK_O <= 1'b1;
1849
                                end
1850 7 redbear
                                else
1851 2 redbear
                                begin
1852
                                        BR_CLK_O <= 1'b0;
1853 7 redbear
                                end
1854 2 redbear
                        end
1855
                        else
1856
                        begin
1857
                                count_send_data <= 12'd0;
1858
                                fifo_tx_rd_en <= 1'b1;
1859
                        end
1860
 
1861
                end
1862 19 redbear
                RX_TX_DELAY_BYTES:
1863 2 redbear
                begin
1864
 
1865
                        fifo_tx_rd_en <= 1'b0;
1866
 
1867
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1868
                        begin
1869
 
1870
                                count_send_data <= count_send_data + 12'd1;
1871
                                BR_CLK_O <= 1'b0;
1872
                                SDA_OUT<=1'b0;
1873
                        end
1874
                        else
1875
                        begin
1876
 
1877
 
1878 6 redbear
                                if(count_tx == 2'd0)
1879 2 redbear
                                begin
1880 6 redbear
                                        count_tx <= count_tx + 2'd1;
1881 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[8:8];
1882
                                end
1883 6 redbear
                                else if(count_tx == 2'd1)
1884 2 redbear
                                begin
1885 6 redbear
                                        count_tx <= count_tx + 2'd1;
1886 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[16:16];
1887
                                end
1888 6 redbear
                                else if(count_tx == 2'd2)
1889 2 redbear
                                begin
1890 6 redbear
                                        count_tx <= count_tx + 2'd1;
1891 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[24:24];
1892
                                end
1893 6 redbear
                                else if(count_tx == 2'd3)
1894 2 redbear
                                begin
1895 6 redbear
                                        count_tx <= 2'd0;
1896 2 redbear
                                end
1897
 
1898
                                count_send_data <= 12'd0;
1899
 
1900
                        end
1901
 
1902
                end
1903
                //THIS BLOCK MUST BE CHECKED WITH CARE
1904 19 redbear
                RX_TX_NACK:// MORE A RESTART 
1905 2 redbear
                begin
1906
                        fifo_tx_rd_en <= 1'b0;
1907
 
1908
                        if(count_send_data < DATA_CONFIG_REG[13:2]*2'd2)
1909
                        begin
1910
                                count_send_data <= count_send_data + 12'd1;
1911
 
1912 6 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1913 2 redbear
                                begin
1914
                                        SDA_OUT<=1'b0;
1915
                                end
1916
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1917
                                begin
1918
                                        SDA_OUT<=1'b1;
1919
                                end
1920
                                else if(count_send_data  == DATA_CONFIG_REG[13:2]*2'd2)
1921
                                begin
1922
                                        SDA_OUT<=1'b0;
1923
                                end
1924
 
1925 6 redbear
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2)
1926 2 redbear
                                begin
1927
                                        BR_CLK_O <= 1'b1;
1928
                                end
1929
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1930
                                begin
1931
                                        BR_CLK_O <= 1'b0;
1932
                                end
1933
                                else if(count_send_data < DATA_CONFIG_REG[13:2]*2'd2)
1934
                                begin
1935
                                        BR_CLK_O <= 1'b1;
1936
                                end
1937
 
1938
                        end
1939
                        else
1940
                        begin
1941
                                count_send_data <= 12'd0;
1942
 
1943 6 redbear
                                if(count_tx == 2'd0)
1944 2 redbear
                                begin
1945 6 redbear
                                        count_tx <= 2'd0;
1946 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[0:0];
1947
                                end
1948 6 redbear
                                else if(count_tx == 2'd1)
1949 2 redbear
                                begin
1950 6 redbear
                                        count_tx <= 2'd1;
1951 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[8:8];
1952
                                end
1953 6 redbear
                                else if(count_tx == 2'd2)
1954 2 redbear
                                begin
1955 6 redbear
                                        count_tx <= 2'd2;
1956 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[16:16];
1957
                                end
1958 6 redbear
                                else if(count_tx == 2'd3)
1959 2 redbear
                                begin
1960 6 redbear
                                        count_tx <= 2'd3;
1961 2 redbear
                                        SDA_OUT<=fifo_tx_data_out[24:24];
1962
                                end
1963
 
1964
 
1965
                        end
1966
                end
1967 19 redbear
                RX_TX_STOP:
1968 2 redbear
                begin
1969 7 redbear
 
1970
                        BR_CLK_O <= 1'b1;
1971
 
1972 2 redbear
                        if(count_send_data < DATA_CONFIG_REG[13:2])
1973
                        begin
1974
                                count_send_data <= count_send_data + 12'd1;
1975
 
1976
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
1977
                                begin
1978
                                        SDA_OUT<=1'b0;
1979
                                end
1980
                                else if(count_send_data > DATA_CONFIG_REG[13:2]/12'd2-12'd1 && count_send_data < DATA_CONFIG_REG[13:2])
1981
                                begin
1982
                                        SDA_OUT<=1'b1;
1983
                                end
1984
                        end
1985
                        else
1986
                        begin
1987
                                count_send_data <= 12'd0;
1988
                        end
1989
                end
1990
                default:
1991
                begin
1992
                        fifo_tx_rd_en <= 1'b0;
1993
                        count_send_data <= 12'd4095;
1994
                end
1995
                endcase
1996
 
1997
        end
1998
 
1999
 
2000
end
2001
 
2002 19 redbear
endmodule
2003 2 redbear
 

powered by: WebSVN 2.1.0

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