1 //*****************************************************************************
2 //
3 // i2c.c
4 //
5 // Driver for Inter-IC (I2C) bus block.
6 //
7 // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
8 //
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions
12 // are met:
13 //
14 // Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the
20 // distribution.
21 //
22 // Neither the name of Texas Instruments Incorporated nor the names of
23 // its contributors may be used to endorse or promote products derived
24 // from this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 //*****************************************************************************
39
40 //*****************************************************************************
41 //
42 //! \addtogroup I2C_api
43 //! @{
44 //
45 //*****************************************************************************
46
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "inc/hw_i2c.h"
50 #include "inc/hw_ints.h"
51 #include "inc/hw_memmap.h"
52 #include "inc/hw_types.h"
53 #include "debug.h"
54 #include "i2c.h"
55 #include "interrupt.h"
56
57 //*****************************************************************************
58 //
59 // A mapping of I2C base address to interrupt number.
60 //
61 //*****************************************************************************
62 static const uint32_t g_ppui32I2CIntMap[][2] =
63 {
64 { I2CA0_BASE, INT_I2CA0},
65 };
66
67 static const int_fast8_t g_i8I2CIntMapRows =
68 sizeof(g_ppui32I2CIntMap) / sizeof(g_ppui32I2CIntMap[0]);
69
70 //*****************************************************************************
71 //
72 //! \internal
73 //! Checks an I2C base address.
74 //!
75 //! \param ui32Base is the base address of the I2C module.
76 //!
77 //! This function determines if a I2C module base address is valid.
78 //!
79 //! \return Returns \b true if the base address is valid and \b false
80 //! otherwise.
81 //
82 //*****************************************************************************
83 #ifdef DEBUG
84 static bool
_I2CBaseValid(uint32_t ui32Base)85 _I2CBaseValid(uint32_t ui32Base)
86 {
87 return((ui32Base == I2CA0_BASE));
88 }
89 #else
90 #define _I2CBaseValid(ui32Base) (ui32Base)
91 #endif
92
93 //*****************************************************************************
94 //
95 //! \internal
96 //! Gets the I2C interrupt number.
97 //!
98 //! \param ui32Base is the base address of the I2C Master module.
99 //!
100 //! Given a I2C base address, this function returns the corresponding
101 //! interrupt number.
102 //!
103 //! \return Returns an I2C interrupt number, or 0 if \e ui32Base is invalid.
104 //
105 //*****************************************************************************
106 static uint32_t
_I2CIntNumberGet(uint32_t ui32Base)107 _I2CIntNumberGet(uint32_t ui32Base)
108 {
109 int_fast8_t i8Idx, i8Rows;
110 const uint32_t (*ppui32I2CIntMap)[2];
111
112 //
113 // Check the arguments.
114 //
115 ASSERT(_I2CBaseValid(ui32Base));
116
117 ppui32I2CIntMap = g_ppui32I2CIntMap;
118 i8Rows = g_i8I2CIntMapRows;
119
120 //
121 // Loop through the table that maps I2C base addresses to interrupt
122 // numbers.
123 //
124 for(i8Idx = 0; i8Idx < i8Rows; i8Idx++)
125 {
126 //
127 // See if this base address matches.
128 //
129 if(ppui32I2CIntMap[i8Idx][0] == ui32Base)
130 {
131 //
132 // Return the corresponding interrupt number.
133 //
134 return(ppui32I2CIntMap[i8Idx][1]);
135 }
136 }
137
138 //
139 // The base address could not be found, so return an error.
140 //
141 return(0);
142 }
143
144 //*****************************************************************************
145 //
146 //! Initializes the I2C Master block.
147 //!
148 //! \param ui32Base is the base address of the I2C Master module.
149 //! \param ui32I2CClk is the rate of the clock supplied to the I2C module.
150 //! \param bFast set up for fast data transfers.
151 //!
152 //! This function initializes operation of the I2C Master block by configuring
153 //! the bus speed for the master and enabling the I2C Master block.
154 //!
155 //! If the parameter \e bFast is \b true, then the master block is set up to
156 //! transfer data at 400 Kbps; otherwise, it is set up to transfer data at
157 //! 100 Kbps. If Fast Mode Plus (1 Mbps) is desired, software should manually
158 //! write the I2CMTPR after calling this function. For High Speed (3.4 Mbps)
159 //! mode, a specific command is used to switch to the faster clocks after the
160 //! initial communication with the slave is done at either 100 Kbps or
161 //! 400 Kbps.
162 //!
163 //! The peripheral clock is the same as the processor clock. This value is
164 //! returned by SysCtlClockGet(), or it can be explicitly hard coded if it is
165 //! constant and known (to save the code/execution overhead of a call to
166 //! SysCtlClockGet()).
167 //!
168 //! \return None.
169 //
170 //*****************************************************************************
171 void
I2CMasterInitExpClk(uint32_t ui32Base,uint32_t ui32SCLFreq)172 I2CMasterInitExpClk(uint32_t ui32Base, uint32_t ui32SCLFreq)
173 {
174 uint32_t ui32TPR;
175
176 //
177 // Check the arguments.
178 //
179 ASSERT(_I2CBaseValid(ui32Base));
180
181 //
182 // Must enable the device before doing anything else.
183 //
184 I2CMasterEnable(ui32Base);
185
186 //
187 // Compute the clock divider that achieves the fastest speed less than or
188 // equal to the desired speed. The numerator is biased to favor a larger
189 // clock divider so that the resulting clock is always less than or equal
190 // to the desired clock, never greater.
191 //
192 ui32TPR = ((80000000 + (2 * 10 * ui32SCLFreq) - 1) /
193 (2 * 10 * ui32SCLFreq)) - 1;
194 HWREG(ui32Base + I2C_O_MTPR) = ui32TPR;
195
196 //
197 // Check to see if this I2C peripheral is High-Speed enabled. If yes, also
198 // choose the fastest speed that is less than or equal to 3.4 Mbps.
199 //
200 if(HWREG(ui32Base + I2C_O_PP) & I2C_PP_HS)
201 {
202 ui32TPR = ((80000000 + (2 * 3 * 3400000) - 1) /
203 (2 * 3 * 3400000)) - 1;
204 HWREG(ui32Base + I2C_O_MTPR) = I2C_MTPR_HS | ui32TPR;
205 }
206 }
207
208 //*****************************************************************************
209 //
210 //! Initializes the I2C Slave block.
211 //!
212 //! \param ui32Base is the base address of the I2C Slave module.
213 //! \param ui8SlaveAddr 7-bit slave address
214 //!
215 //! This function initializes operation of the I2C Slave block by configuring
216 //! the slave address and enabling the I2C Slave block.
217 //!
218 //! The parameter \e ui8SlaveAddr is the value that is compared against the
219 //! slave address sent by an I2C master.
220 //!
221 //! \return None.
222 //
223 //*****************************************************************************
224 void
I2CSlaveInit(uint32_t ui32Base,uint8_t ui8SlaveAddr)225 I2CSlaveInit(uint32_t ui32Base, uint8_t ui8SlaveAddr)
226 {
227 //
228 // Check the arguments.
229 //
230 ASSERT(_I2CBaseValid(ui32Base));
231 ASSERT(!(ui8SlaveAddr & 0x80));
232
233 //
234 // Must enable the device before doing anything else.
235 //
236 I2CSlaveEnable(ui32Base);
237
238 //
239 // Set up the slave address.
240 //
241 HWREG(ui32Base + I2C_O_SOAR) = ui8SlaveAddr;
242 }
243
244 //*****************************************************************************
245 //
246 //! Sets the I2C slave address.
247 //!
248 //! \param ui32Base is the base address of the I2C Slave module.
249 //! \param ui8AddrNum determines which slave address is set.
250 //! \param ui8SlaveAddr is the 7-bit slave address
251 //!
252 //! This function writes the specified slave address. The \e ui32AddrNum field
253 //! dictates which slave address is configured. For example, a value of 0
254 //! configures the primary address and a value of 1 configures the secondary.
255 //!
256 //!
257 //! \return None.
258 //
259 //*****************************************************************************
260 void
I2CSlaveAddressSet(uint32_t ui32Base,uint8_t ui8AddrNum,uint8_t ui8SlaveAddr)261 I2CSlaveAddressSet(uint32_t ui32Base, uint8_t ui8AddrNum, uint8_t ui8SlaveAddr)
262 {
263 //
264 // Check the arguments.
265 //
266 ASSERT(_I2CBaseValid(ui32Base));
267 ASSERT(!(ui8AddrNum > 1));
268 ASSERT(!(ui8SlaveAddr & 0x80));
269
270 //
271 // Determine which slave address is being set.
272 //
273 switch(ui8AddrNum)
274 {
275 //
276 // Set up the primary slave address.
277 //
278 case 0:
279 {
280 HWREG(ui32Base + I2C_O_SOAR) = ui8SlaveAddr;
281 break;
282 }
283
284 //
285 // Set up and enable the secondary slave address.
286 //
287 case 1:
288 {
289 HWREG(ui32Base + I2C_O_SOAR2) = I2C_SOAR2_OAR2EN | ui8SlaveAddr;
290 break;
291 }
292 }
293 }
294
295 //*****************************************************************************
296 //
297 //! Enables the I2C Master block.
298 //!
299 //! \param ui32Base is the base address of the I2C Master module.
300 //!
301 //! This function enables operation of the I2C Master block.
302 //!
303 //! \return None.
304 //
305 //*****************************************************************************
306 void
I2CMasterEnable(uint32_t ui32Base)307 I2CMasterEnable(uint32_t ui32Base)
308 {
309 //
310 // Check the arguments.
311 //
312 ASSERT(_I2CBaseValid(ui32Base));
313
314 //
315 // Enable the master block.
316 //
317 HWREG(ui32Base + I2C_O_MCR) |= I2C_MCR_MFE;
318 }
319
320 //*****************************************************************************
321 //
322 //! Enables the I2C Slave block.
323 //!
324 //! \param ui32Base is the base address of the I2C Slave module.
325 //!
326 //! This fucntion enables operation of the I2C Slave block.
327 //!
328 //! \return None.
329 //
330 //*****************************************************************************
331 void
I2CSlaveEnable(uint32_t ui32Base)332 I2CSlaveEnable(uint32_t ui32Base)
333 {
334 //
335 // Check the arguments.
336 //
337 ASSERT(_I2CBaseValid(ui32Base));
338
339 //
340 // Enable the clock to the slave block.
341 //
342 HWREG(ui32Base + I2C_O_MCR) |= I2C_MCR_SFE;
343
344 //
345 // Enable the slave.
346 //
347 HWREG(ui32Base + I2C_O_SCSR) = I2C_SCSR_DA;
348 }
349
350 //*****************************************************************************
351 //
352 //! Disables the I2C master block.
353 //!
354 //! \param ui32Base is the base address of the I2C Master module.
355 //!
356 //! This function disables operation of the I2C master block.
357 //!
358 //! \return None.
359 //
360 //*****************************************************************************
361 void
I2CMasterDisable(uint32_t ui32Base)362 I2CMasterDisable(uint32_t ui32Base)
363 {
364 //
365 // Check the arguments.
366 //
367 ASSERT(_I2CBaseValid(ui32Base));
368
369 //
370 // Disable the master block.
371 //
372 HWREG(ui32Base + I2C_O_MCR) &= ~(I2C_MCR_MFE);
373 }
374
375 //*****************************************************************************
376 //
377 //! Disables the I2C slave block.
378 //!
379 //! \param ui32Base is the base address of the I2C Slave module.
380 //!
381 //! This function disables operation of the I2C slave block.
382 //!
383 //! \return None.
384 //
385 //*****************************************************************************
386 void
I2CSlaveDisable(uint32_t ui32Base)387 I2CSlaveDisable(uint32_t ui32Base)
388 {
389 //
390 // Check the arguments.
391 //
392 ASSERT(_I2CBaseValid(ui32Base));
393
394 //
395 // Disable the slave.
396 //
397 HWREG(ui32Base + I2C_O_SCSR) = 0;
398
399 //
400 // Disable the clock to the slave block.
401 //
402 HWREG(ui32Base + I2C_O_MCR) &= ~(I2C_MCR_SFE);
403 }
404
405 //*****************************************************************************
406 //
407 //! Registers an interrupt handler for the I2C module.
408 //!
409 //! \param ui32Base is the base address of the I2C Master module.
410 //! \param pfnHandler is a pointer to the function to be called when the
411 //! I2C interrupt occurs.
412 //!
413 //! This function sets the handler to be called when an I2C interrupt occurs.
414 //! This function enables the global interrupt in the interrupt controller;
415 //! specific I2C interrupts must be enabled via I2CMasterIntEnable() and
416 //! I2CSlaveIntEnable(). If necessary, it is the interrupt handler's
417 //! responsibility to clear the interrupt source via I2CMasterIntClear() and
418 //! I2CSlaveIntClear().
419 //!
420 //! \sa IntRegister() for important information about registering interrupt
421 //! handlers.
422 //!
423 //! \return None.
424 //
425 //*****************************************************************************
426 void
I2CIntRegister(uint32_t ui32Base,void (* pfnHandler)(void))427 I2CIntRegister(uint32_t ui32Base, void (*pfnHandler)(void))
428 {
429 uint32_t ui32Int;
430
431 //
432 // Check the arguments.
433 //
434 ASSERT(_I2CBaseValid(ui32Base));
435
436 //
437 // Determine the interrupt number based on the I2C port.
438 //
439 ui32Int = _I2CIntNumberGet(ui32Base);
440
441 ASSERT(ui32Int != 0);
442
443 //
444 // Register the interrupt handler, returning an error if an error occurs.
445 //
446 IntRegister(ui32Int, pfnHandler);
447
448 //
449 // Enable the I2C interrupt.
450 //
451 IntEnable(ui32Int);
452 }
453
454 //*****************************************************************************
455 //
456 //! Unregisters an interrupt handler for the I2C module.
457 //!
458 //! \param ui32Base is the base address of the I2C Master module.
459 //!
460 //! This function clears the handler to be called when an I2C interrupt
461 //! occurs. This function also masks off the interrupt in the interrupt r
462 //! controller so that the interrupt handler no longer is called.
463 //!
464 //! \sa IntRegister() for important information about registering interrupt
465 //! handlers.
466 //!
467 //! \return None.
468 //
469 //*****************************************************************************
470 void
I2CIntUnregister(uint32_t ui32Base)471 I2CIntUnregister(uint32_t ui32Base)
472 {
473 uint32_t ui32Int;
474
475 //
476 // Check the arguments.
477 //
478 ASSERT(_I2CBaseValid(ui32Base));
479
480 //
481 // Determine the interrupt number based on the I2C port.
482 //
483 ui32Int = _I2CIntNumberGet(ui32Base);
484
485 ASSERT(ui32Int != 0);
486
487 //
488 // Disable the interrupt.
489 //
490 IntDisable(ui32Int);
491
492 //
493 // Unregister the interrupt handler.
494 //
495 IntUnregister(ui32Int);
496 }
497
498 //*****************************************************************************
499 //
500 //! Enables the I2C Master interrupt.
501 //!
502 //! \param ui32Base is the base address of the I2C Master module.
503 //!
504 //! This function enables the I2C Master interrupt source.
505 //!
506 //! \return None.
507 //
508 //*****************************************************************************
509 void
I2CMasterIntEnable(uint32_t ui32Base)510 I2CMasterIntEnable(uint32_t ui32Base)
511 {
512 //
513 // Check the arguments.
514 //
515 ASSERT(_I2CBaseValid(ui32Base));
516
517 //
518 // Enable the master interrupt.
519 //
520 HWREG(ui32Base + I2C_O_MIMR) = 1;
521 }
522
523 //*****************************************************************************
524 //
525 //! Enables individual I2C Master interrupt sources.
526 //!
527 //! \param ui32Base is the base address of the I2C Master module.
528 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
529 //!
530 //! This function enables the indicated I2C Master interrupt sources. Only the
531 //! sources that are enabled can be reflected to the processor interrupt;
532 //! disabled sources have no effect on the processor.
533 //!
534 //! The \e ui32IntFlags parameter is the logical OR of any of the following:
535 //!
536 //! - \b I2C_MASTER_INT_RX_FIFO_FULL - RX FIFO Full interrupt
537 //! - \b I2C_MASTER_INT_TX_FIFO_EMPTY - TX FIFO Empty interrupt
538 //! - \b I2C_MASTER_INT_RX_FIFO_REQ - RX FIFO Request interrupt
539 //! - \b I2C_MASTER_INT_TX_FIFO_REQ - TX FIFO Request interrupt
540 //! - \b I2C_MASTER_INT_ARB_LOST - Arbitration Lost interrupt
541 //! - \b I2C_MASTER_INT_STOP - Stop Condition interrupt
542 //! - \b I2C_MASTER_INT_START - Start Condition interrupt
543 //! - \b I2C_MASTER_INT_NACK - Address/Data NACK interrupt
544 //! - \b I2C_MASTER_INT_TX_DMA_DONE - TX DMA Complete interrupt
545 //! - \b I2C_MASTER_INT_RX_DMA_DONE - RX DMA Complete interrupt
546 //! - \b I2C_MASTER_INT_TIMEOUT - Clock Timeout interrupt
547 //! - \b I2C_MASTER_INT_DATA - Data interrupt
548 //!
549 //!
550 //! \return None.
551 //
552 //*****************************************************************************
553 void
I2CMasterIntEnableEx(uint32_t ui32Base,uint32_t ui32IntFlags)554 I2CMasterIntEnableEx(uint32_t ui32Base, uint32_t ui32IntFlags)
555 {
556 //
557 // Check the arguments.
558 //
559 ASSERT(_I2CBaseValid(ui32Base));
560
561 //
562 // Enable the master interrupt.
563 //
564 HWREG(ui32Base + I2C_O_MIMR) |= ui32IntFlags;
565 }
566
567 //*****************************************************************************
568 //
569 //! Enables the I2C Slave interrupt.
570 //!
571 //! \param ui32Base is the base address of the I2C Slave module.
572 //!
573 //! This function enables the I2C Slave interrupt source.
574 //!
575 //! \return None.
576 //
577 //*****************************************************************************
578 void
I2CSlaveIntEnable(uint32_t ui32Base)579 I2CSlaveIntEnable(uint32_t ui32Base)
580 {
581 //
582 // Check the arguments.
583 //
584 ASSERT(_I2CBaseValid(ui32Base));
585
586 //
587 // Enable the slave interrupt.
588 //
589 HWREG(ui32Base + I2C_O_SIMR) |= I2C_SLAVE_INT_DATA;
590 }
591
592 //*****************************************************************************
593 //
594 //! Enables individual I2C Slave interrupt sources.
595 //!
596 //! \param ui32Base is the base address of the I2C Slave module.
597 //! \param ui32IntFlags is the bit mask of the interrupt sources to be enabled.
598 //!
599 //! This function enables the indicated I2C Slave interrupt sources. Only the
600 //! sources that are enabled can be reflected to the processor interrupt;
601 //! disabled sources have no effect on the processor.
602 //!
603 //! The \e ui32IntFlags parameter is the logical OR of any of the following:
604 //!
605 //! - \b I2C_SLAVE_INT_RX_FIFO_FULL - RX FIFO Full interrupt
606 //! - \b I2C_SLAVE_INT_TX_FIFO_EMPTY - TX FIFO Empty interrupt
607 //! - \b I2C_SLAVE_INT_RX_FIFO_REQ - RX FIFO Request interrupt
608 //! - \b I2C_SLAVE_INT_TX_FIFO_REQ - TX FIFO Request interrupt
609 //! - \b I2C_SLAVE_INT_TX_DMA_DONE - TX DMA Complete interrupt
610 //! - \b I2C_SLAVE_INT_RX_DMA_DONE - RX DMA Complete interrupt
611 //! - \b I2C_SLAVE_INT_STOP - Stop condition detected interrupt
612 //! - \b I2C_SLAVE_INT_START - Start condition detected interrupt
613 //! - \b I2C_SLAVE_INT_DATA - Data interrupt
614 //!
615 //!
616 //! \return None.
617 //
618 //*****************************************************************************
619 void
I2CSlaveIntEnableEx(uint32_t ui32Base,uint32_t ui32IntFlags)620 I2CSlaveIntEnableEx(uint32_t ui32Base, uint32_t ui32IntFlags)
621 {
622 //
623 // Check the arguments.
624 //
625 ASSERT(_I2CBaseValid(ui32Base));
626
627 //
628 // Enable the slave interrupt.
629 //
630 HWREG(ui32Base + I2C_O_SIMR) |= ui32IntFlags;
631 }
632
633 //*****************************************************************************
634 //
635 //! Disables the I2C Master interrupt.
636 //!
637 //! \param ui32Base is the base address of the I2C Master module.
638 //!
639 //! This function disables the I2C Master interrupt source.
640 //!
641 //! \return None.
642 //
643 //*****************************************************************************
644 void
I2CMasterIntDisable(uint32_t ui32Base)645 I2CMasterIntDisable(uint32_t ui32Base)
646 {
647 //
648 // Check the arguments.
649 //
650 ASSERT(_I2CBaseValid(ui32Base));
651
652 //
653 // Disable the master interrupt.
654 //
655 HWREG(ui32Base + I2C_O_MIMR) = 0;
656 }
657
658 //*****************************************************************************
659 //
660 //! Disables individual I2C Master interrupt sources.
661 //!
662 //! \param ui32Base is the base address of the I2C Master module.
663 //! \param ui32IntFlags is the bit mask of the interrupt sources to be
664 //! disabled.
665 //!
666 //! This function disables the indicated I2C Master interrupt sources. Only
667 //! the sources that are enabled can be reflected to the processor interrupt;
668 //! disabled sources have no effect on the processor.
669 //!
670 //! The \e ui32IntFlags parameter has the same definition as the
671 //! \e ui32IntFlags parameter to I2CMasterIntEnableEx().
672 //!
673 //! \return None.
674 //
675 //*****************************************************************************
676 void
I2CMasterIntDisableEx(uint32_t ui32Base,uint32_t ui32IntFlags)677 I2CMasterIntDisableEx(uint32_t ui32Base, uint32_t ui32IntFlags)
678 {
679 //
680 // Check the arguments.
681 //
682 ASSERT(_I2CBaseValid(ui32Base));
683
684 //
685 // Disable the master interrupt.
686 //
687 HWREG(ui32Base + I2C_O_MIMR) &= ~ui32IntFlags;
688 }
689
690 //*****************************************************************************
691 //
692 //! Disables the I2C Slave interrupt.
693 //!
694 //! \param ui32Base is the base address of the I2C Slave module.
695 //!
696 //! This function disables the I2C Slave interrupt source.
697 //!
698 //! \return None.
699 //
700 //*****************************************************************************
701 void
I2CSlaveIntDisable(uint32_t ui32Base)702 I2CSlaveIntDisable(uint32_t ui32Base)
703 {
704 //
705 // Check the arguments.
706 //
707 ASSERT(_I2CBaseValid(ui32Base));
708
709 //
710 // Disable the slave interrupt.
711 //
712 HWREG(ui32Base + I2C_O_SIMR) &= ~I2C_SLAVE_INT_DATA;
713 }
714
715 //*****************************************************************************
716 //
717 //! Disables individual I2C Slave interrupt sources.
718 //!
719 //! \param ui32Base is the base address of the I2C Slave module.
720 //! \param ui32IntFlags is the bit mask of the interrupt sources to be
721 //! disabled.
722 //!
723 //! This function disables the indicated I2C Slave interrupt sources. Only
724 //! the sources that are enabled can be reflected to the processor interrupt;
725 //! disabled sources have no effect on the processor.
726 //!
727 //! The \e ui32IntFlags parameter has the same definition as the
728 //! \e ui32IntFlags parameter to I2CSlaveIntEnableEx().
729 //!
730 //! \return None.
731 //
732 //*****************************************************************************
733 void
I2CSlaveIntDisableEx(uint32_t ui32Base,uint32_t ui32IntFlags)734 I2CSlaveIntDisableEx(uint32_t ui32Base, uint32_t ui32IntFlags)
735 {
736 //
737 // Check the arguments.
738 //
739 ASSERT(_I2CBaseValid(ui32Base));
740
741 //
742 // Disable the slave interrupt.
743 //
744 HWREG(ui32Base + I2C_O_SIMR) &= ~ui32IntFlags;
745 }
746
747 //*****************************************************************************
748 //
749 //! Gets the current I2C Master interrupt status.
750 //!
751 //! \param ui32Base is the base address of the I2C Master module.
752 //! \param bMasked is false if the raw interrupt status is requested and
753 //! true if the masked interrupt status is requested.
754 //!
755 //! This function returns the interrupt status for the I2C Master module.
756 //! Either the raw interrupt status or the status of interrupts that are
757 //! allowed to reflect to the processor can be returned.
758 //!
759 //! \return The current interrupt status, returned as \b true if active
760 //! or \b false if not active.
761 //
762 //*****************************************************************************
763 bool
I2CMasterIntStatus(uint32_t ui32Base,bool bMasked)764 I2CMasterIntStatus(uint32_t ui32Base, bool bMasked)
765 {
766 //
767 // Check the arguments.
768 //
769 ASSERT(_I2CBaseValid(ui32Base));
770
771 //
772 // Return either the interrupt status or the raw interrupt status as
773 // requested.
774 //
775 if(bMasked)
776 {
777 return((HWREG(ui32Base + I2C_O_MMIS)) ? true : false);
778 }
779 else
780 {
781 return((HWREG(ui32Base + I2C_O_MRIS)) ? true : false);
782 }
783 }
784
785 //*****************************************************************************
786 //
787 //! Gets the current I2C Master interrupt status.
788 //!
789 //! \param ui32Base is the base address of the I2C Master module.
790 //! \param bMasked is false if the raw interrupt status is requested and
791 //! true if the masked interrupt status is requested.
792 //!
793 //! This function returns the interrupt status for the I2C Master module.
794 //! Either the raw interrupt status or the status of interrupts that are
795 //! allowed to reflect to the processor can be returned.
796 //!
797 //! \return Returns the current interrupt status, enumerated as a bit field of
798 //! values described in I2CMasterIntEnableEx().
799 //
800 //*****************************************************************************
801 uint32_t
I2CMasterIntStatusEx(uint32_t ui32Base,bool bMasked)802 I2CMasterIntStatusEx(uint32_t ui32Base, bool bMasked)
803 {
804 //
805 // Check the arguments.
806 //
807 ASSERT(_I2CBaseValid(ui32Base));
808
809 //
810 // Return either the interrupt status or the raw interrupt status as
811 // requested.
812 //
813 if(bMasked)
814 {
815 return(HWREG(ui32Base + I2C_O_MMIS));
816 }
817 else
818 {
819 return(HWREG(ui32Base + I2C_O_MRIS));
820 }
821 }
822
823 //*****************************************************************************
824 //
825 //! Gets the current I2C Slave interrupt status.
826 //!
827 //! \param ui32Base is the base address of the I2C Slave module.
828 //! \param bMasked is false if the raw interrupt status is requested and
829 //! true if the masked interrupt status is requested.
830 //!
831 //! This function returns the interrupt status for the I2C Slave module.
832 //! Either the raw interrupt status or the status of interrupts that are
833 //! allowed to reflect to the processor can be returned.
834 //!
835 //! \return The current interrupt status, returned as \b true if active
836 //! or \b false if not active.
837 //
838 //*****************************************************************************
839 bool
I2CSlaveIntStatus(uint32_t ui32Base,bool bMasked)840 I2CSlaveIntStatus(uint32_t ui32Base, bool bMasked)
841 {
842 //
843 // Check the arguments.
844 //
845 ASSERT(_I2CBaseValid(ui32Base));
846
847 //
848 // Return either the interrupt status or the raw interrupt status as
849 // requested.
850 //
851 if(bMasked)
852 {
853 return((HWREG(ui32Base + I2C_O_SMIS)) ? true : false);
854 }
855 else
856 {
857 return((HWREG(ui32Base + I2C_O_SRIS)) ? true : false);
858 }
859 }
860
861 //*****************************************************************************
862 //
863 //! Gets the current I2C Slave interrupt status.
864 //!
865 //! \param ui32Base is the base address of the I2C Slave module.
866 //! \param bMasked is false if the raw interrupt status is requested and
867 //! true if the masked interrupt status is requested.
868 //!
869 //! This function returns the interrupt status for the I2C Slave module.
870 //! Either the raw interrupt status or the status of interrupts that are
871 //! allowed to reflect to the processor can be returned.
872 //!
873 //! \return Returns the current interrupt status, enumerated as a bit field of
874 //! values described in I2CSlaveIntEnableEx().
875 //
876 //*****************************************************************************
877 uint32_t
I2CSlaveIntStatusEx(uint32_t ui32Base,bool bMasked)878 I2CSlaveIntStatusEx(uint32_t ui32Base, bool bMasked)
879 {
880 //
881 // Check the arguments.
882 //
883 ASSERT(_I2CBaseValid(ui32Base));
884
885 //
886 // Return either the interrupt status or the raw interrupt status as
887 // requested.
888 //
889 if(bMasked)
890 {
891 return(HWREG(ui32Base + I2C_O_SMIS));
892 }
893 else
894 {
895 return(HWREG(ui32Base + I2C_O_SRIS));
896 }
897 }
898
899 //*****************************************************************************
900 //
901 //! Clears I2C Master interrupt sources.
902 //!
903 //! \param ui32Base is the base address of the I2C Master module.
904 //!
905 //! The I2C Master interrupt source is cleared, so that it no longer
906 //! asserts. This function must be called in the interrupt handler to keep the
907 //! interrupt from being triggered again immediately upon exit.
908 //!
909 //! \note Because there is a write buffer in the Cortex-M processor, it may
910 //! take several clock cycles before the interrupt source is actually cleared.
911 //! Therefore, it is recommended that the interrupt source be cleared early in
912 //! the interrupt handler (as opposed to the very last action) to avoid
913 //! returning from the interrupt handler before the interrupt source is
914 //! actually cleared. Failure to do so may result in the interrupt handler
915 //! being immediately reentered (because the interrupt controller still sees
916 //! the interrupt source asserted).
917 //!
918 //! \return None.
919 //
920 //*****************************************************************************
921 void
I2CMasterIntClear(uint32_t ui32Base)922 I2CMasterIntClear(uint32_t ui32Base)
923 {
924 //
925 // Check the arguments.
926 //
927 ASSERT(_I2CBaseValid(ui32Base));
928
929 //
930 // Clear the I2C master interrupt source.
931 //
932 HWREG(ui32Base + I2C_O_MICR) = I2C_MICR_IC;
933
934 //
935 // Workaround for I2C master interrupt clear errata for some
936 // devices. For later devices, this write is ignored and therefore
937 // harmless (other than the slight performance hit).
938 //
939 HWREG(ui32Base + I2C_O_MMIS) = I2C_MICR_IC;
940 }
941
942 //*****************************************************************************
943 //
944 //! Clears I2C Master interrupt sources.
945 //!
946 //! \param ui32Base is the base address of the I2C Master module.
947 //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
948 //!
949 //! The specified I2C Master interrupt sources are cleared, so that they no
950 //! longer assert. This function must be called in the interrupt handler to
951 //! keep the interrupt from being triggered again immediately upon exit.
952 //!
953 //! The \e ui32IntFlags parameter has the same definition as the
954 //! \e ui32IntFlags parameter to I2CMasterIntEnableEx().
955 //!
956 //! \note Because there is a write buffer in the Cortex-M processor, it may
957 //! take several clock cycles before the interrupt source is actually cleared.
958 //! Therefore, it is recommended that the interrupt source be cleared early in
959 //! the interrupt handler (as opposed to the very last action) to avoid
960 //! returning from the interrupt handler before the interrupt source is
961 //! actually cleared. Failure to do so may result in the interrupt handler
962 //! being immediately reentered (because the interrupt controller still sees
963 //! the interrupt source asserted).
964 //!
965 //! \return None.
966 //
967 //*****************************************************************************
968 void
I2CMasterIntClearEx(uint32_t ui32Base,uint32_t ui32IntFlags)969 I2CMasterIntClearEx(uint32_t ui32Base, uint32_t ui32IntFlags)
970 {
971 //
972 // Check the arguments.
973 //
974 ASSERT(_I2CBaseValid(ui32Base));
975
976 //
977 // Clear the I2C master interrupt source.
978 //
979 HWREG(ui32Base + I2C_O_MICR) = ui32IntFlags;
980 }
981
982 //*****************************************************************************
983 //
984 //! Clears I2C Slave interrupt sources.
985 //!
986 //! \param ui32Base is the base address of the I2C Slave module.
987 //!
988 //! The I2C Slave interrupt source is cleared, so that it no longer asserts.
989 //! This function must be called in the interrupt handler to keep the interrupt
990 //! from being triggered again immediately upon exit.
991 //!
992 //! \note Because there is a write buffer in the Cortex-M processor, it may
993 //! take several clock cycles before the interrupt source is actually cleared.
994 //! Therefore, it is recommended that the interrupt source be cleared early in
995 //! the interrupt handler (as opposed to the very last action) to avoid
996 //! returning from the interrupt handler before the interrupt source is
997 //! actually cleared. Failure to do so may result in the interrupt handler
998 //! being immediately reentered (because the interrupt controller still sees
999 //! the interrupt source asserted).
1000 //!
1001 //! \return None.
1002 //
1003 //*****************************************************************************
1004 void
I2CSlaveIntClear(uint32_t ui32Base)1005 I2CSlaveIntClear(uint32_t ui32Base)
1006 {
1007 //
1008 // Check the arguments.
1009 //
1010 ASSERT(_I2CBaseValid(ui32Base));
1011
1012 //
1013 // Clear the I2C slave interrupt source.
1014 //
1015 HWREG(ui32Base + I2C_O_SICR) = I2C_SICR_DATAIC;
1016 }
1017
1018 //*****************************************************************************
1019 //
1020 //! Clears I2C Slave interrupt sources.
1021 //!
1022 //! \param ui32Base is the base address of the I2C Slave module.
1023 //! \param ui32IntFlags is a bit mask of the interrupt sources to be cleared.
1024 //!
1025 //! The specified I2C Slave interrupt sources are cleared, so that they no
1026 //! longer assert. This function must be called in the interrupt handler to
1027 //! keep the interrupt from being triggered again immediately upon exit.
1028 //!
1029 //! The \e ui32IntFlags parameter has the same definition as the
1030 //! \e ui32IntFlags parameter to I2CSlaveIntEnableEx().
1031 //!
1032 //! \note Because there is a write buffer in the Cortex-M processor, it may
1033 //! take several clock cycles before the interrupt source is actually cleared.
1034 //! Therefore, it is recommended that the interrupt source be cleared early in
1035 //! the interrupt handler (as opposed to the very last action) to avoid
1036 //! returning from the interrupt handler before the interrupt source is
1037 //! actually cleared. Failure to do so may result in the interrupt handler
1038 //! being immediately reentered (because the interrupt controller still sees
1039 //! the interrupt source asserted).
1040 //!
1041 //! \return None.
1042 //
1043 //*****************************************************************************
1044 void
I2CSlaveIntClearEx(uint32_t ui32Base,uint32_t ui32IntFlags)1045 I2CSlaveIntClearEx(uint32_t ui32Base, uint32_t ui32IntFlags)
1046 {
1047 //
1048 // Check the arguments.
1049 //
1050 ASSERT(_I2CBaseValid(ui32Base));
1051
1052 //
1053 // Clear the I2C slave interrupt source.
1054 //
1055 HWREG(ui32Base + I2C_O_SICR) = ui32IntFlags;
1056 }
1057
1058 //*****************************************************************************
1059 //
1060 //! Sets the address that the I2C Master places on the bus.
1061 //!
1062 //! \param ui32Base is the base address of the I2C Master module.
1063 //! \param ui8SlaveAddr 7-bit slave address
1064 //! \param bReceive flag indicating the type of communication with the slave
1065 //!
1066 //! This function configures the address that the I2C Master places on the
1067 //! bus when initiating a transaction. When the \e bReceive parameter is set
1068 //! to \b true, the address indicates that the I2C Master is initiating a
1069 //! read from the slave; otherwise the address indicates that the I2C
1070 //! Master is initiating a write to the slave.
1071 //!
1072 //! \return None.
1073 //
1074 //*****************************************************************************
1075 void
I2CMasterSlaveAddrSet(uint32_t ui32Base,uint8_t ui8SlaveAddr,bool bReceive)1076 I2CMasterSlaveAddrSet(uint32_t ui32Base, uint8_t ui8SlaveAddr,
1077 bool bReceive)
1078 {
1079 //
1080 // Check the arguments.
1081 //
1082 ASSERT(_I2CBaseValid(ui32Base));
1083 ASSERT(!(ui8SlaveAddr & 0x80));
1084
1085 //
1086 // Set the address of the slave with which the master will communicate.
1087 //
1088 HWREG(ui32Base + I2C_O_MSA) = (ui8SlaveAddr << 1) | bReceive;
1089 }
1090
1091 //*****************************************************************************
1092 //
1093 //! Reads the state of the SDA and SCL pins.
1094 //!
1095 //! \param ui32Base is the base address of the I2C Master module.
1096 //!
1097 //! This function returns the state of the I2C bus by providing the real time
1098 //! values of the SDA and SCL pins.
1099 //!
1100 //!
1101 //! \return Returns the state of the bus with SDA in bit position 1 and SCL in
1102 //! bit position 0.
1103 //
1104 //*****************************************************************************
1105 uint32_t
I2CMasterLineStateGet(uint32_t ui32Base)1106 I2CMasterLineStateGet(uint32_t ui32Base)
1107 {
1108 //
1109 // Check the arguments.
1110 //
1111 ASSERT(_I2CBaseValid(ui32Base));
1112
1113 //
1114 // Return the line state.
1115 //
1116 return(HWREG(ui32Base + I2C_O_MBMON));
1117 }
1118
1119 //*****************************************************************************
1120 //
1121 //! Indicates whether or not the I2C Master is busy.
1122 //!
1123 //! \param ui32Base is the base address of the I2C Master module.
1124 //!
1125 //! This function returns an indication of whether or not the I2C Master is
1126 //! busy transmitting or receiving data.
1127 //!
1128 //! \return Returns \b true if the I2C Master is busy; otherwise, returns
1129 //! \b false.
1130 //
1131 //*****************************************************************************
1132 bool
I2CMasterBusy(uint32_t ui32Base)1133 I2CMasterBusy(uint32_t ui32Base)
1134 {
1135 //
1136 // Check the arguments.
1137 //
1138 ASSERT(_I2CBaseValid(ui32Base));
1139
1140 //
1141 // Return the busy status.
1142 //
1143 if(HWREG(ui32Base + I2C_O_MCS) & I2C_MCS_BUSY)
1144 {
1145 return(true);
1146 }
1147 else
1148 {
1149 return(false);
1150 }
1151 }
1152
1153 //*****************************************************************************
1154 //
1155 //! Indicates whether or not the I2C bus is busy.
1156 //!
1157 //! \param ui32Base is the base address of the I2C Master module.
1158 //!
1159 //! This function returns an indication of whether or not the I2C bus is busy.
1160 //! This function can be used in a multi-master environment to determine if
1161 //! another master is currently using the bus.
1162 //!
1163 //! \return Returns \b true if the I2C bus is busy; otherwise, returns
1164 //! \b false.
1165 //
1166 //*****************************************************************************
1167 bool
I2CMasterBusBusy(uint32_t ui32Base)1168 I2CMasterBusBusy(uint32_t ui32Base)
1169 {
1170 //
1171 // Check the arguments.
1172 //
1173 ASSERT(_I2CBaseValid(ui32Base));
1174
1175 //
1176 // Return the bus busy status.
1177 //
1178 if(HWREG(ui32Base + I2C_O_MCS) & I2C_MCS_BUSBSY)
1179 {
1180 return(true);
1181 }
1182 else
1183 {
1184 return(false);
1185 }
1186 }
1187
1188 //*****************************************************************************
1189 //
1190 //! Controls the state of the I2C Master module.
1191 //!
1192 //! \param ui32Base is the base address of the I2C Master module.
1193 //! \param ui32Cmd command to be issued to the I2C Master module.
1194 //!
1195 //! This function is used to control the state of the Master module send and
1196 //! receive operations. The \e ui8Cmd parameter can be one of the following
1197 //! values:
1198 //!
1199 //! - \b I2C_MASTER_CMD_SINGLE_SEND
1200 //! - \b I2C_MASTER_CMD_SINGLE_RECEIVE
1201 //! - \b I2C_MASTER_CMD_BURST_SEND_START
1202 //! - \b I2C_MASTER_CMD_BURST_SEND_CONT
1203 //! - \b I2C_MASTER_CMD_BURST_SEND_FINISH
1204 //! - \b I2C_MASTER_CMD_BURST_SEND_ERROR_STOP
1205 //! - \b I2C_MASTER_CMD_BURST_RECEIVE_START
1206 //! - \b I2C_MASTER_CMD_BURST_RECEIVE_CONT
1207 //! - \b I2C_MASTER_CMD_BURST_RECEIVE_FINISH
1208 //! - \b I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP
1209 //! - \b I2C_MASTER_CMD_QUICK_COMMAND
1210 //! - \b I2C_MASTER_CMD_HS_MASTER_CODE_SEND
1211 //! - \b I2C_MASTER_CMD_FIFO_SINGLE_SEND
1212 //! - \b I2C_MASTER_CMD_FIFO_SINGLE_RECEIVE
1213 //! - \b I2C_MASTER_CMD_FIFO_BURST_SEND_START
1214 //! - \b I2C_MASTER_CMD_FIFO_BURST_SEND_CONT
1215 //! - \b I2C_MASTER_CMD_FIFO_BURST_SEND_FINISH
1216 //! - \b I2C_MASTER_CMD_FIFO_BURST_SEND_ERROR_STOP
1217 //! - \b I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START
1218 //! - \b I2C_MASTER_CMD_FIFO_BURST_RECEIVE_CONT
1219 //! - \b I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH
1220 //! - \b I2C_MASTER_CMD_FIFO_BURST_RECEIVE_ERROR_STOP
1221 //!
1222 //!
1223 //! \return None.
1224 //
1225 //*****************************************************************************
1226 void
I2CMasterControl(uint32_t ui32Base,uint32_t ui32Cmd)1227 I2CMasterControl(uint32_t ui32Base, uint32_t ui32Cmd)
1228 {
1229 //
1230 // Check the arguments.
1231 //
1232 ASSERT(_I2CBaseValid(ui32Base));
1233 ASSERT((ui32Cmd == I2C_MASTER_CMD_SINGLE_SEND) ||
1234 (ui32Cmd == I2C_MASTER_CMD_SINGLE_RECEIVE) ||
1235 (ui32Cmd == I2C_MASTER_CMD_BURST_SEND_START) ||
1236 (ui32Cmd == I2C_MASTER_CMD_BURST_SEND_CONT) ||
1237 (ui32Cmd == I2C_MASTER_CMD_BURST_SEND_FINISH) ||
1238 (ui32Cmd == I2C_MASTER_CMD_BURST_SEND_ERROR_STOP) ||
1239 (ui32Cmd == I2C_MASTER_CMD_BURST_RECEIVE_START) ||
1240 (ui32Cmd == I2C_MASTER_CMD_BURST_RECEIVE_CONT) ||
1241 (ui32Cmd == I2C_MASTER_CMD_BURST_RECEIVE_FINISH) ||
1242 (ui32Cmd == I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP) ||
1243 (ui32Cmd == I2C_MASTER_CMD_QUICK_COMMAND) ||
1244 (ui32Cmd == I2C_MASTER_CMD_FIFO_SINGLE_SEND) ||
1245 (ui32Cmd == I2C_MASTER_CMD_FIFO_SINGLE_RECEIVE) ||
1246 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_SEND_START) ||
1247 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_SEND_CONT) ||
1248 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_SEND_FINISH) ||
1249 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_SEND_ERROR_STOP) ||
1250 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_RECEIVE_START) ||
1251 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_RECEIVE_CONT) ||
1252 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH) ||
1253 (ui32Cmd == I2C_MASTER_CMD_FIFO_BURST_RECEIVE_ERROR_STOP) ||
1254 (ui32Cmd == I2C_MASTER_CMD_HS_MASTER_CODE_SEND));
1255
1256 //
1257 // Send the command.
1258 //
1259 HWREG(ui32Base + I2C_O_MCS) = ui32Cmd;
1260 }
1261
1262 //*****************************************************************************
1263 //
1264 //! Gets the error status of the I2C Master module.
1265 //!
1266 //! \param ui32Base is the base address of the I2C Master module.
1267 //!
1268 //! This function is used to obtain the error status of the Master module send
1269 //! and receive operations.
1270 //!
1271 //! \return Returns the error status, as one of \b I2C_MASTER_ERR_NONE,
1272 //! \b I2C_MASTER_ERR_ADDR_ACK, \b I2C_MASTER_ERR_DATA_ACK, or
1273 //! \b I2C_MASTER_ERR_ARB_LOST.
1274 //
1275 //*****************************************************************************
1276 uint32_t
I2CMasterErr(uint32_t ui32Base)1277 I2CMasterErr(uint32_t ui32Base)
1278 {
1279 uint32_t ui32Err;
1280
1281 //
1282 // Check the arguments.
1283 //
1284 ASSERT(_I2CBaseValid(ui32Base));
1285
1286 //
1287 // Get the raw error state
1288 //
1289 ui32Err = HWREG(ui32Base + I2C_O_MCS);
1290
1291 //
1292 // If the I2C master is busy, then all the other bit are invalid, and
1293 // don't have an error to report.
1294 //
1295 if(ui32Err & I2C_MCS_BUSY)
1296 {
1297 return(I2C_MASTER_ERR_NONE);
1298 }
1299
1300 //
1301 // Check for errors.
1302 //
1303 if(ui32Err & (I2C_MCS_ERROR | I2C_MCS_ARBLST))
1304 {
1305 return(ui32Err & (I2C_MCS_ARBLST | I2C_MCS_ACK | I2C_MCS_ADRACK));
1306 }
1307 else
1308 {
1309 return(I2C_MASTER_ERR_NONE);
1310 }
1311 }
1312
1313 //*****************************************************************************
1314 //
1315 //! Transmits a byte from the I2C Master.
1316 //!
1317 //! \param ui32Base is the base address of the I2C Master module.
1318 //! \param ui8Data data to be transmitted from the I2C Master.
1319 //!
1320 //! This function places the supplied data into I2C Master Data Register.
1321 //!
1322 //! \return None.
1323 //
1324 //*****************************************************************************
1325 void
I2CMasterDataPut(uint32_t ui32Base,uint8_t ui8Data)1326 I2CMasterDataPut(uint32_t ui32Base, uint8_t ui8Data)
1327 {
1328 //
1329 // Check the arguments.
1330 //
1331 ASSERT(_I2CBaseValid(ui32Base));
1332
1333 //
1334 // Write the byte.
1335 //
1336 HWREG(ui32Base + I2C_O_MDR) = ui8Data;
1337 }
1338
1339 //*****************************************************************************
1340 //
1341 //! Receives a byte that has been sent to the I2C Master.
1342 //!
1343 //! \param ui32Base is the base address of the I2C Master module.
1344 //!
1345 //! This function reads a byte of data from the I2C Master Data Register.
1346 //!
1347 //! \return Returns the byte received from by the I2C Master, cast as an
1348 //! uint32_t.
1349 //
1350 //*****************************************************************************
1351 uint32_t
I2CMasterDataGet(uint32_t ui32Base)1352 I2CMasterDataGet(uint32_t ui32Base)
1353 {
1354 //
1355 // Check the arguments.
1356 //
1357 ASSERT(_I2CBaseValid(ui32Base));
1358
1359 //
1360 // Read a byte.
1361 //
1362 return(HWREG(ui32Base + I2C_O_MDR));
1363 }
1364
1365 //*****************************************************************************
1366 //
1367 //! Sets the Master clock timeout value.
1368 //!
1369 //! \param ui32Base is the base address of the I2C Master module.
1370 //! \param ui32Value is the number of I2C clocks before the timeout is
1371 //! asserted.
1372 //!
1373 //! This function enables and configures the clock low timeout feature in the
1374 //! I2C peripheral. This feature is implemented as a 12-bit counter, with the
1375 //! upper 8-bits being programmable. For example, to program a timeout of 20ms
1376 //! with a 100kHz SCL frequency, \e ui32Value would be 0x7d.
1377 //!
1378 //!
1379 //! \return None.
1380 //
1381 //*****************************************************************************
1382 void
I2CMasterTimeoutSet(uint32_t ui32Base,uint32_t ui32Value)1383 I2CMasterTimeoutSet(uint32_t ui32Base, uint32_t ui32Value)
1384 {
1385 //
1386 // Check the arguments.
1387 //
1388 ASSERT(_I2CBaseValid(ui32Base));
1389
1390 //
1391 // Write the timeout value.
1392 //
1393 HWREG(ui32Base + I2C_O_MCLKOCNT) = ui32Value;
1394 }
1395
1396 //*****************************************************************************
1397 //
1398 //! Configures ACK override behavior of the I2C Slave.
1399 //!
1400 //! \param ui32Base is the base address of the I2C Slave module.
1401 //! \param bEnable enables or disables ACK override.
1402 //!
1403 //! This function enables or disables ACK override, allowing the user
1404 //! application to drive the value on SDA during the ACK cycle.
1405 //!
1406 //!
1407 //! \return None.
1408 //
1409 //*****************************************************************************
1410 void
I2CSlaveACKOverride(uint32_t ui32Base,bool bEnable)1411 I2CSlaveACKOverride(uint32_t ui32Base, bool bEnable)
1412 {
1413 //
1414 // Check the arguments.
1415 //
1416 ASSERT(_I2CBaseValid(ui32Base));
1417
1418 //
1419 // Enable or disable based on bEnable.
1420 //
1421 if(bEnable)
1422 {
1423 HWREG(ui32Base + I2C_O_SACKCTL) |= I2C_SACKCTL_ACKOEN;
1424 }
1425 else
1426 {
1427 HWREG(ui32Base + I2C_O_SACKCTL) &= ~I2C_SACKCTL_ACKOEN;
1428 }
1429 }
1430
1431 //*****************************************************************************
1432 //
1433 //! Writes the ACK value.
1434 //!
1435 //! \param ui32Base is the base address of the I2C Slave module.
1436 //! \param bACK chooses whether to ACK (true) or NACK (false) the transfer.
1437 //!
1438 //! This function puts the desired ACK value on SDA during the ACK cycle. The
1439 //! value written is only valid when ACK override is enabled using
1440 //! I2CSlaveACKOverride().
1441 //!
1442 //! \return None.
1443 //
1444 //*****************************************************************************
1445 void
I2CSlaveACKValueSet(uint32_t ui32Base,bool bACK)1446 I2CSlaveACKValueSet(uint32_t ui32Base, bool bACK)
1447 {
1448 //
1449 // Check the arguments.
1450 //
1451 ASSERT(_I2CBaseValid(ui32Base));
1452
1453 //
1454 // ACK or NACK based on the value of bACK.
1455 //
1456 if(bACK)
1457 {
1458 HWREG(ui32Base + I2C_O_SACKCTL) &= ~I2C_SACKCTL_ACKOVAL;
1459 }
1460 else
1461 {
1462 HWREG(ui32Base + I2C_O_SACKCTL) |= I2C_SACKCTL_ACKOVAL;
1463 }
1464 }
1465
1466 //*****************************************************************************
1467 //
1468 //! Gets the I2C Slave module status
1469 //!
1470 //! \param ui32Base is the base address of the I2C Slave module.
1471 //!
1472 //! This function returns the action requested from a master, if any.
1473 //! Possible values are:
1474 //!
1475 //! - \b I2C_SLAVE_ACT_NONE
1476 //! - \b I2C_SLAVE_ACT_RREQ
1477 //! - \b I2C_SLAVE_ACT_TREQ
1478 //! - \b I2C_SLAVE_ACT_RREQ_FBR
1479 //! - \b I2C_SLAVE_ACT_OWN2SEL
1480 //! - \b I2C_SLAVE_ACT_QCMD
1481 //! - \b I2C_SLAVE_ACT_QCMD_DATA
1482 //!
1483 //! \note Not all devices support the second I2C slave's own address
1484 //! or the quick command function. Please consult the device data sheet to
1485 //! determine if these features are supported.
1486 //!
1487 //! \return Returns \b I2C_SLAVE_ACT_NONE to indicate that no action has been
1488 //! requested of the I2C Slave module, \b I2C_SLAVE_ACT_RREQ to indicate that
1489 //! an I2C master has sent data to the I2C Slave module, \b I2C_SLAVE_ACT_TREQ
1490 //! to indicate that an I2C master has requested that the I2C Slave module send
1491 //! data, \b I2C_SLAVE_ACT_RREQ_FBR to indicate that an I2C master has sent
1492 //! data to the I2C slave and the first byte following the slave's own address
1493 //! has been received, \b I2C_SLAVE_ACT_OWN2SEL to indicate that the second I2C
1494 //! slave address was matched, \b I2C_SLAVE_ACT_QCMD to indicate that a quick
1495 //! command was received, and \b I2C_SLAVE_ACT_QCMD_DATA to indicate that the
1496 //! data bit was set when the quick command was received.
1497 //
1498 //*****************************************************************************
1499 uint32_t
I2CSlaveStatus(uint32_t ui32Base)1500 I2CSlaveStatus(uint32_t ui32Base)
1501 {
1502 //
1503 // Check the arguments.
1504 //
1505 ASSERT(_I2CBaseValid(ui32Base));
1506
1507 //
1508 // Return the slave status.
1509 //
1510 return(HWREG(ui32Base + I2C_O_SCSR));
1511 }
1512
1513 //*****************************************************************************
1514 //
1515 //! Transmits a byte from the I2C Slave.
1516 //!
1517 //! \param ui32Base is the base address of the I2C Slave module.
1518 //! \param ui8Data is the data to be transmitted from the I2C Slave
1519 //!
1520 //! This function places the supplied data into I2C Slave Data Register.
1521 //!
1522 //! \return None.
1523 //
1524 //*****************************************************************************
1525 void
I2CSlaveDataPut(uint32_t ui32Base,uint8_t ui8Data)1526 I2CSlaveDataPut(uint32_t ui32Base, uint8_t ui8Data)
1527 {
1528 //
1529 // Check the arguments.
1530 //
1531 ASSERT(_I2CBaseValid(ui32Base));
1532
1533 //
1534 // Write the byte.
1535 //
1536 HWREG(ui32Base + I2C_O_SDR) = ui8Data;
1537 }
1538
1539 //*****************************************************************************
1540 //
1541 //! Receives a byte that has been sent to the I2C Slave.
1542 //!
1543 //! \param ui32Base is the base address of the I2C Slave module.
1544 //!
1545 //! This function reads a byte of data from the I2C Slave Data Register.
1546 //!
1547 //! \return Returns the byte received from by the I2C Slave, cast as an
1548 //! uint32_t.
1549 //
1550 //*****************************************************************************
1551 uint32_t
I2CSlaveDataGet(uint32_t ui32Base)1552 I2CSlaveDataGet(uint32_t ui32Base)
1553 {
1554 //
1555 // Check the arguments.
1556 //
1557 ASSERT(_I2CBaseValid(ui32Base));
1558
1559 //
1560 // Read a byte.
1561 //
1562 return(HWREG(ui32Base + I2C_O_SDR));
1563 }
1564
1565 //*****************************************************************************
1566 //
1567 //! Configures the I2C transmit (TX) FIFO.
1568 //!
1569 //! \param ui32Base is the base address of the I2C Master or Slave module.
1570 //! \param ui32Config is the configuration of the FIFO using specified macros.
1571 //!
1572 //! This configures the I2C peripheral's transmit FIFO. The transmit FIFO can
1573 //! be used by the master or slave, but not both. The following macros are
1574 //! used to configure the TX FIFO behavior for master or slave, with or without
1575 //! DMA:
1576 //!
1577 //! \b I2C_FIFO_CFG_TX_MASTER, \b I2C_FIFO_CFG_TX_SLAVE,
1578 //! \b I2C_FIFO_CFG_TX_MASTER_DMA, \b I2C_FIFO_CFG_TX_SLAVE_DMA
1579 //!
1580 //! To select the trigger level, one of the following macros should be used:
1581 //!
1582 //! \b I2C_FIFO_CFG_TX_TRIG_1, \b I2C_FIFO_CFG_TX_TRIG_2,
1583 //! \b I2C_FIFO_CFG_TX_TRIG_3, \b I2C_FIFO_CFG_TX_TRIG_4,
1584 //! \b I2C_FIFO_CFG_TX_TRIG_5, \b I2C_FIFO_CFG_TX_TRIG_6,
1585 //! \b I2C_FIFO_CFG_TX_TRIG_7, \b I2C_FIFO_CFG_TX_TRIG_8
1586 //!
1587 //!
1588 //! \return None.
1589 //
1590 //*****************************************************************************
1591 void
I2CTxFIFOConfigSet(uint32_t ui32Base,uint32_t ui32Config)1592 I2CTxFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Config)
1593 {
1594 //
1595 // Check the arguments.
1596 //
1597 ASSERT(_I2CBaseValid(ui32Base));
1598
1599 //
1600 // Clear transmit configuration data.
1601 //
1602 HWREG(ui32Base + I2C_O_FIFOCTL) &= 0xffff0000;
1603
1604 //
1605 // Store new transmit configuration data.
1606 //
1607 HWREG(ui32Base + I2C_O_FIFOCTL) |= ui32Config;
1608 }
1609
1610 //*****************************************************************************
1611 //
1612 //! Flushes the transmit (TX) FIFO.
1613 //!
1614 //! \param ui32Base is the base address of the I2C Master or Slave module.
1615 //!
1616 //! This function flushes the I2C transmit FIFO.
1617 //!
1618 //!
1619 //! \return None.
1620 //
1621 //*****************************************************************************
1622 void
I2CTxFIFOFlush(uint32_t ui32Base)1623 I2CTxFIFOFlush(uint32_t ui32Base)
1624 {
1625 //
1626 // Check the arguments.
1627 //
1628 ASSERT(_I2CBaseValid(ui32Base));
1629
1630 //
1631 // Flush the TX FIFO.
1632 //
1633 HWREG(ui32Base + I2C_O_FIFOCTL) |= I2C_FIFOCTL_TXFLUSH;
1634 }
1635
1636 //*****************************************************************************
1637 //
1638 //! Configures the I2C receive (RX) FIFO.
1639 //!
1640 //! \param ui32Base is the base address of the I2C Master or Slave module.
1641 //! \param ui32Config is the configuration of the FIFO using specified macros.
1642 //!
1643 //! This configures the I2C peripheral's receive FIFO. The receive FIFO can be
1644 //! used by the master or slave, but not both. The following macros are used
1645 //! to configure the RX FIFO behavior for master or slave, with or without DMA:
1646 //!
1647 //! \b I2C_FIFO_CFG_RX_MASTER, \b I2C_FIFO_CFG_RX_SLAVE,
1648 //! \b I2C_FIFO_CFG_RX_MASTER_DMA, \b I2C_FIFO_CFG_RX_SLAVE_DMA
1649 //!
1650 //! To select the trigger level, one of the following macros should be used:
1651 //!
1652 //! \b I2C_FIFO_CFG_RX_TRIG_1, \b I2C_FIFO_CFG_RX_TRIG_2,
1653 //! \b I2C_FIFO_CFG_RX_TRIG_3, \b I2C_FIFO_CFG_RX_TRIG_4,
1654 //! \b I2C_FIFO_CFG_RX_TRIG_5, \b I2C_FIFO_CFG_RX_TRIG_6,
1655 //! \b I2C_FIFO_CFG_RX_TRIG_7, \b I2C_FIFO_CFG_RX_TRIG_8
1656 //!
1657 //!
1658 //! \return None.
1659 //
1660 //*****************************************************************************
1661 void
I2CRxFIFOConfigSet(uint32_t ui32Base,uint32_t ui32Config)1662 I2CRxFIFOConfigSet(uint32_t ui32Base, uint32_t ui32Config)
1663 {
1664 //
1665 // Check the arguments.
1666 //
1667 ASSERT(_I2CBaseValid(ui32Base));
1668
1669 //
1670 // Clear receive configuration data.
1671 //
1672 HWREG(ui32Base + I2C_O_FIFOCTL) &= 0x0000ffff;
1673
1674 //
1675 // Store new receive configuration data.
1676 //
1677 HWREG(ui32Base + I2C_O_FIFOCTL) |= ui32Config;
1678 }
1679
1680 //*****************************************************************************
1681 //
1682 //! Flushes the receive (RX) FIFO.
1683 //!
1684 //! \param ui32Base is the base address of the I2C Master or Slave module.
1685 //!
1686 //! This function flushes the I2C receive FIFO.
1687 //!
1688 //! \return None.
1689 //
1690 //*****************************************************************************
1691 void
I2CRxFIFOFlush(uint32_t ui32Base)1692 I2CRxFIFOFlush(uint32_t ui32Base)
1693 {
1694 //
1695 // Check the arguments.
1696 //
1697 ASSERT(_I2CBaseValid(ui32Base));
1698
1699 //
1700 // Flush the TX FIFO.
1701 //
1702 HWREG(ui32Base + I2C_O_FIFOCTL) |= I2C_FIFOCTL_RXFLUSH;
1703 }
1704
1705 //*****************************************************************************
1706 //
1707 //! Gets the current FIFO status.
1708 //!
1709 //! \param ui32Base is the base address of the I2C Master or Slave module.
1710 //!
1711 //! This function retrieves the status for both the transmit (TX) and receive
1712 //! (RX) FIFOs. The trigger level for the transmit FIFO is set using
1713 //! I2CTxFIFOConfigSet() and for the receive FIFO using I2CTxFIFOConfigSet().
1714 //!
1715 //! \return Returns the FIFO status, enumerated as a bit field containing
1716 //! \b I2C_FIFO_RX_BELOW_TRIG_LEVEL, \b I2C_FIFO_RX_FULL, \b I2C_FIFO_RX_EMPTY,
1717 //! \b I2C_FIFO_TX_BELOW_TRIG_LEVEL, \b I2C_FIFO_TX_FULL, and
1718 //! \b I2C_FIFO_TX_EMPTY.
1719 //
1720 //*****************************************************************************
1721 uint32_t
I2CFIFOStatus(uint32_t ui32Base)1722 I2CFIFOStatus(uint32_t ui32Base)
1723 {
1724 //
1725 // Check the arguments.
1726 //
1727 ASSERT(_I2CBaseValid(ui32Base));
1728
1729 //
1730 // Return the contents of the FIFO status register.
1731 //
1732 return(HWREG(ui32Base + I2C_O_FIFOSTATUS));
1733 }
1734
1735 //*****************************************************************************
1736 //
1737 //! Writes a data byte to the I2C transmit FIFO.
1738 //!
1739 //! \param ui32Base is the base address of the I2C Master or Slave module.
1740 //! \param ui8Data is the data to be placed into the transmit FIFO.
1741 //!
1742 //! This function adds a byte of data to the I2C transmit FIFO. If there is
1743 //! no space available in the FIFO, this function waits for space to become
1744 //! available before returning.
1745 //!
1746 //! \return None.
1747 //
1748 //*****************************************************************************
1749 void
I2CFIFODataPut(uint32_t ui32Base,uint8_t ui8Data)1750 I2CFIFODataPut(uint32_t ui32Base, uint8_t ui8Data)
1751 {
1752 //
1753 // Check the arguments.
1754 //
1755 ASSERT(_I2CBaseValid(ui32Base));
1756
1757 //
1758 // Wait until there is space.
1759 //
1760 while(HWREG(ui32Base + I2C_O_FIFOSTATUS) & I2C_FIFOSTATUS_TXFF)
1761 {
1762 }
1763
1764 //
1765 // Place data into the FIFO.
1766 //
1767 HWREG(ui32Base + I2C_O_FIFODATA) = ui8Data;
1768 }
1769
1770 //*****************************************************************************
1771 //
1772 //! Writes a data byte to the I2C transmit FIFO.
1773 //!
1774 //! \param ui32Base is the base address of the I2C Master or Slave module.
1775 //! \param ui8Data is the data to be placed into the transmit FIFO.
1776 //!
1777 //! This function adds a byte of data to the I2C transmit FIFO. If there is
1778 //! no space available in the FIFO, this function returns a zero.
1779 //!
1780 //! \return The number of elements added to the I2C transmit FIFO.
1781 //
1782 //*****************************************************************************
1783 uint32_t
I2CFIFODataPutNonBlocking(uint32_t ui32Base,uint8_t ui8Data)1784 I2CFIFODataPutNonBlocking(uint32_t ui32Base, uint8_t ui8Data)
1785 {
1786 //
1787 // Check the arguments.
1788 //
1789 ASSERT(_I2CBaseValid(ui32Base));
1790
1791 //
1792 // If FIFO is full, return zero.
1793 //
1794 if(HWREG(ui32Base + I2C_O_FIFOSTATUS) & I2C_FIFOSTATUS_TXFF)
1795 {
1796 return(0);
1797 }
1798 else
1799 {
1800 HWREG(ui32Base + I2C_O_FIFODATA) = ui8Data;
1801 return(1);
1802 }
1803 }
1804
1805 //*****************************************************************************
1806 //
1807 //! Reads a byte from the I2C receive FIFO.
1808 //!
1809 //! \param ui32Base is the base address of the I2C Master or Slave module.
1810 //!
1811 //! This function reads a byte of data from I2C receive FIFO and places it in
1812 //! the location specified by the \e pui8Data parameter. If there is no data
1813 //! available, this function waits until data is received before returning.
1814 //!
1815 //! \return The data byte.
1816 //
1817 //*****************************************************************************
1818 uint32_t
I2CFIFODataGet(uint32_t ui32Base)1819 I2CFIFODataGet(uint32_t ui32Base)
1820 {
1821 //
1822 // Check the arguments.
1823 //
1824 ASSERT(_I2CBaseValid(ui32Base));
1825
1826 //
1827 // Wait until there is data to read.
1828 //
1829 while(HWREG(ui32Base + I2C_O_FIFOSTATUS) & I2C_FIFOSTATUS_RXFE)
1830 {
1831 }
1832
1833 //
1834 // Read a byte.
1835 //
1836 return(HWREG(ui32Base + I2C_O_FIFODATA));
1837 }
1838
1839 //*****************************************************************************
1840 //
1841 //! Reads a byte from the I2C receive FIFO.
1842 //!
1843 //! \param ui32Base is the base address of the I2C Master or Slave module.
1844 //! \param pui8Data is a pointer where the read data is stored.
1845 //!
1846 //! This function reads a byte of data from I2C receive FIFO and places it in
1847 //! the location specified by the \e pui8Data parameter. If there is no data
1848 //! available, this functions returns 0.
1849 //!
1850 //! \return The number of elements read from the I2C receive FIFO.
1851 //
1852 //*****************************************************************************
1853 uint32_t
I2CFIFODataGetNonBlocking(uint32_t ui32Base,uint8_t * pui8Data)1854 I2CFIFODataGetNonBlocking(uint32_t ui32Base, uint8_t *pui8Data)
1855 {
1856 //
1857 // Check the arguments.
1858 //
1859 ASSERT(_I2CBaseValid(ui32Base));
1860
1861 //
1862 // If nothing in the FIFO, return zero.
1863 //
1864 if(HWREG(ui32Base + I2C_O_FIFOSTATUS) & I2C_FIFOSTATUS_RXFE)
1865 {
1866 return(0);
1867 }
1868 else
1869 {
1870 *pui8Data = HWREG(ui32Base + I2C_O_FIFODATA);
1871 return(1);
1872 }
1873 }
1874
1875 //*****************************************************************************
1876 //
1877 //! Set the burst length for a I2C master FIFO operation.
1878 //!
1879 //! \param ui32Base is the base address of the I2C Master module.
1880 //! \param ui8Length is the length of the burst transfer.
1881 //!
1882 //! This function configures the burst length for a I2C Master FIFO operation.
1883 //! The burst field is limited to 8 bits or 256 bytes. The burst length
1884 //! applies to a single I2CMCS BURST operation meaning that it specifies the
1885 //! burst length for only the current operation (can be TX or RX). Each burst
1886 //! operation must configure the burst length prior to writing the BURST bit
1887 //! in the I2CMCS using I2CMasterControl().
1888 //!
1889 //! \return None.
1890 //
1891 //*****************************************************************************
1892 void
I2CMasterBurstLengthSet(uint32_t ui32Base,uint8_t ui8Length)1893 I2CMasterBurstLengthSet(uint32_t ui32Base, uint8_t ui8Length)
1894 {
1895 //
1896 // Check the arguments.
1897 //
1898 ASSERT(_I2CBaseValid(ui32Base) && (ui8Length < 255));
1899
1900 //
1901 // Set the burst length.
1902 //
1903 HWREG(ui32Base + I2C_O_MBLEN) = ui8Length;
1904 }
1905
1906 //*****************************************************************************
1907 //
1908 //! Returns the current value of the burst transfer counter.
1909 //!
1910 //! \param ui32Base is the base address of the I2C Master module.
1911 //!
1912 //! This function returns the current value of the burst transfer counter that
1913 //! is used by the FIFO mechanism. Software can use this value to determine
1914 //! how many bytes remain in a transfer, or where in the transfer the burst
1915 //! operation was if an error has occurred.
1916 //!
1917 //! \return None.
1918 //
1919 //*****************************************************************************
1920 uint32_t
I2CMasterBurstCountGet(uint32_t ui32Base)1921 I2CMasterBurstCountGet(uint32_t ui32Base)
1922 {
1923 //
1924 // Check the arguments.
1925 //
1926 ASSERT(_I2CBaseValid(ui32Base));
1927
1928 //
1929 // Get burst count.
1930 //
1931 return(HWREG(ui32Base + I2C_O_MBCNT));
1932 }
1933
1934 //*****************************************************************************
1935 //
1936 //! Configures the I2C Master glitch filter.
1937 //!
1938 //! \param ui32Base is the base address of the I2C Master module.
1939 //! \param ui32Config is the glitch filter configuration.
1940 //!
1941 //! This function configures the I2C Master glitch filter. The value passed in
1942 //! to \e ui32Config determines the sampling range of the glitch filter, which
1943 //! is configurable between 1 and 32 system clock cycles. The default
1944 //! configuration of the glitch filter is 0 system clock cycles, which means
1945 //! that it's disabled.
1946 //!
1947 //! The \e ui32Config field should be any of the following values:
1948 //!
1949 //! - \b I2C_MASTER_GLITCH_FILTER_DISABLED
1950 //! - \b I2C_MASTER_GLITCH_FILTER_1
1951 //! - \b I2C_MASTER_GLITCH_FILTER_2
1952 //! - \b I2C_MASTER_GLITCH_FILTER_3
1953 //! - \b I2C_MASTER_GLITCH_FILTER_4
1954 //! - \b I2C_MASTER_GLITCH_FILTER_8
1955 //! - \b I2C_MASTER_GLITCH_FILTER_16
1956 //! - \b I2C_MASTER_GLITCH_FILTER_32
1957 //!
1958 //! \return None.
1959 //
1960 //*****************************************************************************
1961 void
I2CMasterGlitchFilterConfigSet(uint32_t ui32Base,uint32_t ui32Config)1962 I2CMasterGlitchFilterConfigSet(uint32_t ui32Base, uint32_t ui32Config)
1963 {
1964 //
1965 // Check the arguments.
1966 //
1967 ASSERT(_I2CBaseValid(ui32Base));
1968
1969 //
1970 // Configure the glitch filter field of MTPR.
1971 //
1972 HWREG(ui32Base + I2C_O_MTPR) |= ui32Config;
1973 }
1974
1975 //*****************************************************************************
1976 //
1977 //! Enables FIFO usage for the I2C Slave module.
1978 //!
1979 //! \param ui32Base is the base address of the I2C Slave module.
1980 //! \param ui32Config is the desired FIFO configuration of the I2C Slave.
1981 //!
1982 //! This function configures the I2C Slave module to use the FIFO(s). This
1983 //! function should be used in combination with I2CTxFIFOConfigSet() and/or
1984 //! I2CRxFIFOConfigSet(), which configure the FIFO trigger level and tell
1985 //! the FIFO hardware whether to interact with the I2C Master or Slave. The
1986 //! application appropriate combination of \b I2C_SLAVE_TX_FIFO_ENABLE and
1987 //! \b I2C_SLAVE_RX_FIFO_ENABLE should be passed in to the \e ui32Config
1988 //! field.
1989 //!
1990 //! The Slave I2CSCSR register is write-only, so any call to I2CSlaveEnable(),
1991 //! I2CSlaveDisable or I2CSlaveFIFOEnable() overwrites the slave configuration.
1992 //! Therefore, application software should call I2CSlaveEnable() followed by
1993 //! I2CSlaveFIFOEnable() with the desired FIFO configuration.
1994 //!
1995 //! \return None.
1996 //
1997 //*****************************************************************************
1998 void
I2CSlaveFIFOEnable(uint32_t ui32Base,uint32_t ui32Config)1999 I2CSlaveFIFOEnable(uint32_t ui32Base, uint32_t ui32Config)
2000 {
2001 //
2002 // Check the arguments.
2003 //
2004 ASSERT(_I2CBaseValid(ui32Base));
2005
2006 //
2007 // Enable the FIFOs for the slave.
2008 //
2009 HWREG(ui32Base + I2C_O_SCSR) = ui32Config | I2C_SCSR_DA;
2010 }
2011
2012 //*****************************************************************************
2013 //
2014 //! Disable FIFO usage for the I2C Slave module.
2015 //!
2016 //! \param ui32Base is the base address of the I2C Slave module.
2017 //!
2018 //! This function disables the FIFOs for the I2C Slave. After calling this
2019 //! this function, the FIFOs are disabled, but the Slave remains active.
2020 //!
2021 //! \return None.
2022 //
2023 //*****************************************************************************
2024 void
I2CSlaveFIFODisable(uint32_t ui32Base)2025 I2CSlaveFIFODisable(uint32_t ui32Base)
2026 {
2027 //
2028 // Check the arguments.
2029 //
2030 ASSERT(_I2CBaseValid(ui32Base));
2031
2032 //
2033 // Disable slave FIFOs.
2034 //
2035 HWREG(ui32Base + I2C_O_SCSR) = I2C_SCSR_DA;
2036 }
2037
2038 //*****************************************************************************
2039 //
2040 // Close the Doxygen group.
2041 //! @}
2042 //
2043 //*****************************************************************************
2044