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