CC13xx Driver Library
adi.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: adi.h
3 * Revised: 2016-08-10 11:10:10 +0200 (Wed, 10 Aug 2016)
4 * Revision: 46997
5 *
6 * Description: Defines and prototypes for the ADI master interface.
7 *
8 * Copyright (c) 2015 - 2016, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #ifndef __ADI_H__
49 #define __ADI_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_uart.h>
66 #include <inc/hw_memmap.h>
67 #include <inc/hw_ints.h>
68 #include <inc/hw_adi.h>
69 #include <driverlib/debug.h>
70 #include <driverlib/ddi.h>
71 
72 //*****************************************************************************
73 //
74 // Number of registers in the ADI slave
75 //
76 //*****************************************************************************
77 #define ADI_SLAVE_REGS 16
78 
79 
80 //*****************************************************************************
81 //
82 // Defines that is used to control the ADI slave and master
83 //
84 //*****************************************************************************
85 #define ADI_PROTECT 0x00000080
86 #define ADI_ACK 0x00000001
87 #define ADI_SYNC 0x00000000
88 
89 //*****************************************************************************
90 //
91 // API Functions and prototypes
92 //
93 //*****************************************************************************
94 
95 #ifdef DRIVERLIB_DEBUG
96 //*****************************************************************************
97 //
107 //
108 //*****************************************************************************
109 static bool
110 ADIBaseValid(uint32_t ui32Base)
111 {
112  return(ui32Base == ADI2_BASE || ui32Base == ADI3_BASE ||
113  ui32Base == AUX_ADI4_BASE);
114 }
115 #endif
116 
117 
118 
119 
120 
121 //*****************************************************************************
122 //
146 //
147 //*****************************************************************************
148 __STATIC_INLINE void
149 ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
150 {
151  //
152  // Check the arguments.
153  //
154  ASSERT(ADIBaseValid(ui32Base));
155  ASSERT(ui32Reg < ADI_SLAVE_REGS);
156 
157  //
158  // Write the value to the register.
159  //
160  if (ui32Base==AUX_ADI4_BASE) {
161  AuxAdiDdiSafeWrite(ui32Base + ui32Reg, ui8Val, 1);
162  } else {
163  HWREGB(ui32Base + ui32Reg) = ui8Val;
164  }
165 }
166 
167 //*****************************************************************************
168 //
195 //
196 //*****************************************************************************
197 __STATIC_INLINE void
198 ADI16RegWrite(uint32_t ui32Base, uint32_t ui32Reg,
199  uint16_t ui16Val)
200 {
201  //
202  // Check the arguments.
203  //
204  ASSERT(ADIBaseValid(ui32Base));
205  ASSERT(ui32Reg < ADI_SLAVE_REGS);
206 
207  //
208  // Write the value to the register.
209  //
210  if (ui32Base==AUX_ADI4_BASE) {
211  AuxAdiDdiSafeWrite(ui32Base + (ui32Reg & 0xFE), ui16Val, 2);
212  } else {
213  HWREGH(ui32Base + (ui32Reg & 0xFE)) = ui16Val;
214  }
215 }
216 
217 //*****************************************************************************
218 //
245 //
246 //*****************************************************************************
247 __STATIC_INLINE void
248 ADI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
249 {
250  //
251  // Check the arguments.
252  //
253  ASSERT(ADIBaseValid(ui32Base));
254  ASSERT(ui32Reg < ADI_SLAVE_REGS);
255 
256  //
257  // Write the value to the register.
258  //
259  if (ui32Base==AUX_ADI4_BASE) {
260  AuxAdiDdiSafeWrite(ui32Base + (ui32Reg & 0xFC), ui32Val, 4);
261  } else {
262  HWREG(ui32Base + (ui32Reg & 0xFC)) = ui32Val;
263  }
264 }
265 
266 //*****************************************************************************
267 //
285 //
286 //*****************************************************************************
287 __STATIC_INLINE uint32_t
288 ADI8RegRead(uint32_t ui32Base, uint32_t ui32Reg)
289 {
290  //
291  // Check the arguments.
292  //
293  ASSERT(ADIBaseValid(ui32Base));
294  ASSERT(ui32Reg < ADI_SLAVE_REGS);
295 
296  //
297  // Read the register and return the value.
298  //
299  if (ui32Base==AUX_ADI4_BASE) {
300  return AuxAdiDdiSafeRead(ui32Base + ui32Reg, 1);
301  } else {
302  return(HWREGB(ui32Base + ui32Reg));
303  }
304 }
305 
306 //*****************************************************************************
307 //
328 //
329 //*****************************************************************************
330 __STATIC_INLINE uint32_t
331 ADI16RegRead(uint32_t ui32Base, uint32_t ui32Reg)
332 {
333  //
334  // Check the arguments.
335  //
336  ASSERT(ADIBaseValid(ui32Base));
337  ASSERT(ui32Reg < ADI_SLAVE_REGS);
338 
339  //
340  // Read the registers and return the value.
341  //
342  if (ui32Base==AUX_ADI4_BASE) {
343  return AuxAdiDdiSafeRead(ui32Base + (ui32Reg & 0xFE), 2);
344  } else {
345  return(HWREGH(ui32Base + (ui32Reg & 0xFE)));
346  }
347 }
348 
349 //*****************************************************************************
350 //
369 //
370 //*****************************************************************************
371 __STATIC_INLINE uint32_t
372 ADI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
373 {
374  //
375  // Check the arguments.
376  //
377  ASSERT(ADIBaseValid(ui32Base));
378  ASSERT(ui32Reg < ADI_SLAVE_REGS);
379 
380  //
381  // Read the registers and return the value.
382  //
383  if (ui32Base==AUX_ADI4_BASE) {
384  return AuxAdiDdiSafeRead(ui32Base + (ui32Reg & 0xFC), 4);
385  } else {
386  return(HWREG(ui32Base + (ui32Reg & 0xFC)));
387  }
388 }
389 
390 //*****************************************************************************
391 //
418 //
419 //*****************************************************************************
420 __STATIC_INLINE void
421 ADI8BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
422 {
423  uint32_t ui32RegOffset;
424 
425  //
426  // Check the arguments.
427  //
428  ASSERT(ADIBaseValid(ui32Base));
429  ASSERT(ui32Reg < ADI_SLAVE_REGS);
430 
431  //
432  // Get the correct address of the first register used for setting bits
433  // in the ADI slave.
434  //
435  ui32RegOffset = ADI_O_SET;
436 
437  //
438  // Set the selected bits.
439  //
440  if (ui32Base==AUX_ADI4_BASE) {
441  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + ui32Reg, ui8Val, 1);
442  } else {
443  HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
444  }
445 }
446 
447 //*****************************************************************************
448 //
475 //
476 //*****************************************************************************
477 __STATIC_INLINE void
478 ADI16BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
479 {
480  uint32_t ui32RegOffset;
481 
482  //
483  // Check the arguments.
484  //
485  ASSERT(ADIBaseValid(ui32Base));
486  ASSERT(ui32Reg < ADI_SLAVE_REGS);
487 
488  //
489  // Get the correct address of the first register used for setting bits
490  // in the ADI slave.
491  //
492  ui32RegOffset = ADI_O_SET;
493 
494  //
495  // Set the selected bits.
496  //
497  if (ui32Base==AUX_ADI4_BASE) {
498  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFE), ui16Val, 2);
499  } else {
500  HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
501  }
502 }
503 
504 //*****************************************************************************
505 //
532 //
533 //*****************************************************************************
534 __STATIC_INLINE void
535 ADI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
536 {
537  uint32_t ui32RegOffset;
538 
539  //
540  // Check the arguments.
541  //
542  ASSERT(ADIBaseValid(ui32Base));
543  ASSERT(ui32Reg < ADI_SLAVE_REGS);
544 
545  //
546  // Get the correct address of the first register used for setting bits
547  // in the ADI slave.
548  //
549  ui32RegOffset = ADI_O_SET;
550 
551  //
552  // Set the selected bits.
553  //
554  if (ui32Base==AUX_ADI4_BASE) {
555  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFC), ui32Val, 4);
556  } else {
557  HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
558  }
559 }
560 
561 //*****************************************************************************
562 //
589 //
590 //*****************************************************************************
591 __STATIC_INLINE void
592 ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
593 {
594  uint32_t ui32RegOffset;
595 
596  //
597  // Check the arguments.
598  //
599  ASSERT(ADIBaseValid(ui32Base));
600  ASSERT(ui32Reg < ADI_SLAVE_REGS);
601 
602  //
603  // Get the correct address of the first register used for setting bits
604  // in the ADI slave.
605  //
606  ui32RegOffset = ADI_O_CLR;
607 
608  //
609  // Set the selected bits.
610  //
611  if (ui32Base==AUX_ADI4_BASE) {
612  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + ui32Reg, ui8Val, 1);
613  } else {
614  HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
615  }
616 }
617 
618 //*****************************************************************************
619 //
646 //
647 //*****************************************************************************
648 __STATIC_INLINE void
649 ADI16BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
650 {
651  uint32_t ui32RegOffset;
652 
653  //
654  // Check the arguments.
655  //
656  ASSERT(ADIBaseValid(ui32Base));
657  ASSERT(ui32Reg < ADI_SLAVE_REGS);
658 
659  //
660  // Get the correct address of the first register used for setting bits
661  // in the ADI slave.
662  //
663  ui32RegOffset = ADI_O_CLR;
664 
665  //
666  // Set the selected bits.
667  //
668  if (ui32Base==AUX_ADI4_BASE) {
669  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFE), ui16Val, 2);
670  } else {
671  HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
672  }
673 }
674 
675 //*****************************************************************************
676 //
703 //
704 //*****************************************************************************
705 __STATIC_INLINE void
706 ADI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
707 {
708  uint32_t ui32RegOffset;
709 
710  //
711  // Check the arguments.
712  //
713  ASSERT(ADIBaseValid(ui32Base));
714  ASSERT(ui32Reg < ADI_SLAVE_REGS);
715 
716  //
717  // Get the correct address of the first register used for setting bits
718  // in the ADI slave.
719  //
720  ui32RegOffset = ADI_O_CLR;
721 
722  //
723  // Set the selected bits.
724  //
725  if (ui32Base==AUX_ADI4_BASE) {
726  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFC), ui32Val, 4);
727  } else {
728  HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
729  }
730 }
731 
732 //*****************************************************************************
733 //
763 //
764 //*****************************************************************************
765 __STATIC_INLINE void
766 ADI4SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh,
767  uint8_t ui8Mask, uint8_t ui8Val)
768 {
769  uint32_t ui32RegOffset;
770 
771  //
772  // Check the arguments.
773  //
774  ASSERT(ADIBaseValid(ui32Base));
775  ASSERT(ui32Reg < ADI_SLAVE_REGS);
776  ASSERT(!(ui8Val & 0xF0));
777  ASSERT(!(ui8Mask & 0xF0));
778 
779  //
780  // Get the correct address of the first register used for setting bits
781  // in the ADI slave.
782  //
783  ui32RegOffset = ADI_O_MASK4B + (ui32Reg << 1) + (bWriteHigh ? 1 : 0);
784 
785  //
786  // Set the selected bits.
787  //
788  if (ui32Base==AUX_ADI4_BASE) {
789  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui8Mask << 4) | ui8Val, 1);
790  } else {
791  HWREGB(ui32Base + ui32RegOffset) = (ui8Mask << 4) | ui8Val;
792  }
793 }
794 
795 //*****************************************************************************
796 //
821 //
822 //*****************************************************************************
823 __STATIC_INLINE void
824 ADI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Mask,
825  uint16_t ui16Val)
826 {
827  uint32_t ui32RegOffset;
828 
829  //
830  // Check the arguments.
831  //
832  ASSERT(ADIBaseValid(ui32Base));
833  ASSERT(ui32Reg < ADI_SLAVE_REGS);
834  ASSERT(!(ui16Val & 0xFF00));
835  ASSERT(!(ui16Mask & 0xFF00));
836 
837  //
838  // Get the correct address of the first register used for setting bits
839  // in the ADI slave.
840  //
841  ui32RegOffset = ADI_O_MASK8B + (ui32Reg << 1);
842 
843  //
844  // Set the selected bits.
845  //
846  if (ui32Base==AUX_ADI4_BASE) {
847  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui16Mask << 8) | ui16Val, 2);
848  } else {
849  HWREGH(ui32Base + ui32RegOffset) = (ui16Mask << 8) | ui16Val;
850  }
851 }
852 
853 //*****************************************************************************
854 //
880 //
881 //*****************************************************************************
882 __STATIC_INLINE void
883 ADI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask,
884  uint32_t ui32Val)
885 {
886  uint32_t ui32RegOffset;
887 
888  //
889  // Check the arguments.
890  //
891  ASSERT(ADIBaseValid(ui32Base));
892  ASSERT(ui32Reg < ADI_SLAVE_REGS);
893  ASSERT(!(ui32Val & 0xFFFF0000));
894  ASSERT(!(ui32Mask & 0xFFFF0000));
895 
896  //
897  // Get the correct address of the first register used for setting bits
898  // in the ADI slave.
899  //
900  ui32RegOffset = ADI_O_MASK16B + ((ui32Reg << 1) & 0xFC);
901 
902  //
903  // Set the selected bits.
904  //
905  if (ui32Base==AUX_ADI4_BASE) {
906  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui32Mask << 16) | ui32Val, 4);
907  } else {
908  HWREG(ui32Base + ui32RegOffset) = (ui32Mask << 16) | ui32Val;
909  }
910 }
911 
912 //*****************************************************************************
913 //
914 // Mark the end of the C bindings section for C++ compilers.
915 //
916 //*****************************************************************************
917 #ifdef __cplusplus
918 }
919 #endif
920 
921 #endif // __ADI_H__
922 
923 //*****************************************************************************
924 //
928 //
929 //*****************************************************************************
static void ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Clear specific bits in an 8 bit ADI register.
Definition: adi.h:592
static void ADI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Val)
Set a value on any bits inside an 2 x 8 bit register aligned on a half-word (byte) boundary in the AD...
Definition: adi.h:883
static uint32_t ADI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
Read the value in a 32 bit register.
Definition: adi.h:372
static void ADI16BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
Clear specific bits in two 8 bit ADI register.
Definition: adi.h:649
static void ADI16BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
Set specific bits in 2 x 8 bit ADI slave registers.
Definition: adi.h:478
static uint32_t AuxAdiDdiSafeRead(uint32_t nAddr, uint32_t nSize)
Safely read from AUX ADI/DDI interfaces using a semaphore.
Definition: ddi.h:169
static void ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Write an 8 bit value to a register in an ADI slave.
Definition: adi.h:149
static uint32_t ADI8RegRead(uint32_t ui32Base, uint32_t ui32Reg)
Read the value of an 8 bit register in the ADI slave.
Definition: adi.h:288
static void ADI4SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh, uint8_t ui8Mask, uint8_t ui8Val)
Set a value on any 4 bits inside an 8 bit register in the ADI slave.
Definition: adi.h:766
static void ADI16RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
Write a 16 bit value to 2 registers in the ADI slave.
Definition: adi.h:198
#define ASSERT(expr)
Definition: debug.h:74
static void ADI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Mask, uint16_t ui16Val)
Set a value on any bits inside an 8 bit register in the ADI slave.
Definition: adi.h:824
static void ADI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Set specific bits in 4 x 8 bit ADI slave registers.
Definition: adi.h:535
static void ADI8BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Set specific bits in a single 8 bit ADI register.
Definition: adi.h:421
static uint32_t ADI16RegRead(uint32_t ui32Base, uint32_t ui32Reg)
Read the value in a 16 bit register.
Definition: adi.h:331
#define ADI_SLAVE_REGS
Definition: adi.h:77
static void ADI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Clear specific bits in four 8 bit ADI register.
Definition: adi.h:706
static void AuxAdiDdiSafeWrite(uint32_t nAddr, uint32_t nData, uint32_t nSize)
Safely write to AUX ADI/DDI interfaces using a semaphore.
Definition: ddi.h:137
static void ADI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Write a 32 bit value to 4 registers in the ADI slave.
Definition: adi.h:248