CC26xx Driver Library
adi.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: adi.h
3 * Revised: 2015-11-16 17:05:11 +0100 (Mon, 16 Nov 2015)
4 * Revision: 45087
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 // Defines that can be passed to the ADIConfigSet()
82 //
83 //*****************************************************************************
84 #define ADI_NO_WAIT 0x00000000
85 #define ADI_WAIT_FOR_ACK 0x00000004
86 #define ADI_SPEED_2 0x00000000
87 #define ADI_SPEED_4 0x00000001
88 #define ADI_SPEED_8 0x00000002
89 #define ADI_SPEED_16 0x00000003
90 #define ADI_CONFIG_MASK 0x00000007
91 
92 //*****************************************************************************
93 //
94 // Defines that is used to control the ADI slave and master
95 //
96 //*****************************************************************************
97 #define ADI_PROTECT 0x00000080
98 #define ADI_ACK 0x00000001
99 #define ADI_SYNC 0x00000000
100 
101 //*****************************************************************************
102 //
103 // API Functions and prototypes
104 //
105 //*****************************************************************************
106 
107 #ifdef DRIVERLIB_DEBUG
108 //*****************************************************************************
109 //
119 //
120 //*****************************************************************************
121 static bool
122 ADIBaseValid(uint32_t ui32Base)
123 {
124  return(ui32Base == ADI2_BASE || ui32Base == ADI3_BASE ||
125  ui32Base == AUX_ADI4_BASE);
126 }
127 #endif
128 
129 
130 
131 
132 
133 //*****************************************************************************
134 //
158 //
159 //*****************************************************************************
160 __STATIC_INLINE void
161 ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
162 {
163  //
164  // Check the arguments.
165  //
166  ASSERT(ADIBaseValid(ui32Base));
167  ASSERT(ui32Reg < ADI_SLAVE_REGS);
168 
169  //
170  // Write the value to the register.
171  //
172  if (ui32Base==AUX_ADI4_BASE) {
173  AuxAdiDdiSafeWrite(ui32Base + ui32Reg, ui8Val, 1);
174  } else {
175  HWREGB(ui32Base + ui32Reg) = ui8Val;
176  }
177 }
178 
179 //*****************************************************************************
180 //
207 //
208 //*****************************************************************************
209 __STATIC_INLINE void
210 ADI16RegWrite(uint32_t ui32Base, uint32_t ui32Reg,
211  uint16_t ui16Val)
212 {
213  //
214  // Check the arguments.
215  //
216  ASSERT(ADIBaseValid(ui32Base));
217  ASSERT(ui32Reg < ADI_SLAVE_REGS);
218 
219  //
220  // Write the value to the register.
221  //
222  if (ui32Base==AUX_ADI4_BASE) {
223  AuxAdiDdiSafeWrite(ui32Base + (ui32Reg & 0xFE), ui16Val, 2);
224  } else {
225  HWREGH(ui32Base + (ui32Reg & 0xFE)) = ui16Val;
226  }
227 }
228 
229 //*****************************************************************************
230 //
257 //
258 //*****************************************************************************
259 __STATIC_INLINE void
260 ADI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
261 {
262  //
263  // Check the arguments.
264  //
265  ASSERT(ADIBaseValid(ui32Base));
266  ASSERT(ui32Reg < ADI_SLAVE_REGS);
267 
268  //
269  // Write the value to the register.
270  //
271  if (ui32Base==AUX_ADI4_BASE) {
272  AuxAdiDdiSafeWrite(ui32Base + (ui32Reg & 0xFC), ui32Val, 4);
273  } else {
274  HWREG(ui32Base + (ui32Reg & 0xFC)) = ui32Val;
275  }
276 }
277 
278 //*****************************************************************************
279 //
297 //
298 //*****************************************************************************
299 __STATIC_INLINE uint32_t
300 ADI8RegRead(uint32_t ui32Base, uint32_t ui32Reg)
301 {
302  //
303  // Check the arguments.
304  //
305  ASSERT(ADIBaseValid(ui32Base));
306  ASSERT(ui32Reg < ADI_SLAVE_REGS);
307 
308  //
309  // Read the register and return the value.
310  //
311  if (ui32Base==AUX_ADI4_BASE) {
312  return AuxAdiDdiSafeRead(ui32Base + ui32Reg, 1);
313  } else {
314  return(HWREGB(ui32Base + ui32Reg));
315  }
316 }
317 
318 //*****************************************************************************
319 //
340 //
341 //*****************************************************************************
342 __STATIC_INLINE uint32_t
343 ADI16RegRead(uint32_t ui32Base, uint32_t ui32Reg)
344 {
345  //
346  // Check the arguments.
347  //
348  ASSERT(ADIBaseValid(ui32Base));
349  ASSERT(ui32Reg < ADI_SLAVE_REGS);
350 
351  //
352  // Read the registers and return the value.
353  //
354  if (ui32Base==AUX_ADI4_BASE) {
355  return AuxAdiDdiSafeRead(ui32Base + (ui32Reg & 0xFE), 2);
356  } else {
357  return(HWREGH(ui32Base + (ui32Reg & 0xFE)));
358  }
359 }
360 
361 //*****************************************************************************
362 //
381 //
382 //*****************************************************************************
383 __STATIC_INLINE uint32_t
384 ADI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
385 {
386  //
387  // Check the arguments.
388  //
389  ASSERT(ADIBaseValid(ui32Base));
390  ASSERT(ui32Reg < ADI_SLAVE_REGS);
391 
392  //
393  // Read the registers and return the value.
394  //
395  if (ui32Base==AUX_ADI4_BASE) {
396  return AuxAdiDdiSafeRead(ui32Base + (ui32Reg & 0xFC), 4);
397  } else {
398  return(HWREG(ui32Base + (ui32Reg & 0xFC)));
399  }
400 }
401 
402 //*****************************************************************************
403 //
430 //
431 //*****************************************************************************
432 __STATIC_INLINE void
433 ADI8BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
434 {
435  uint32_t ui32RegOffset;
436 
437  //
438  // Check the arguments.
439  //
440  ASSERT(ADIBaseValid(ui32Base));
441  ASSERT(ui32Reg < ADI_SLAVE_REGS);
442 
443  //
444  // Get the correct address of the first register used for setting bits
445  // in the ADI slave.
446  //
447  ui32RegOffset = ADI_O_SET;
448 
449  //
450  // Set the selected bits.
451  //
452  if (ui32Base==AUX_ADI4_BASE) {
453  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + ui32Reg, ui8Val, 1);
454  } else {
455  HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
456  }
457 }
458 
459 //*****************************************************************************
460 //
487 //
488 //*****************************************************************************
489 __STATIC_INLINE void
490 ADI16BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
491 {
492  uint32_t ui32RegOffset;
493 
494  //
495  // Check the arguments.
496  //
497  ASSERT(ADIBaseValid(ui32Base));
498  ASSERT(ui32Reg < ADI_SLAVE_REGS);
499 
500  //
501  // Get the correct address of the first register used for setting bits
502  // in the ADI slave.
503  //
504  ui32RegOffset = ADI_O_SET;
505 
506  //
507  // Set the selected bits.
508  //
509  if (ui32Base==AUX_ADI4_BASE) {
510  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFE), ui16Val, 2);
511  } else {
512  HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
513  }
514 }
515 
516 //*****************************************************************************
517 //
544 //
545 //*****************************************************************************
546 __STATIC_INLINE void
547 ADI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
548 {
549  uint32_t ui32RegOffset;
550 
551  //
552  // Check the arguments.
553  //
554  ASSERT(ADIBaseValid(ui32Base));
555  ASSERT(ui32Reg < ADI_SLAVE_REGS);
556 
557  //
558  // Get the correct address of the first register used for setting bits
559  // in the ADI slave.
560  //
561  ui32RegOffset = ADI_O_SET;
562 
563  //
564  // Set the selected bits.
565  //
566  if (ui32Base==AUX_ADI4_BASE) {
567  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFC), ui32Val, 4);
568  } else {
569  HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
570  }
571 }
572 
573 //*****************************************************************************
574 //
601 //
602 //*****************************************************************************
603 __STATIC_INLINE void
604 ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
605 {
606  uint32_t ui32RegOffset;
607 
608  //
609  // Check the arguments.
610  //
611  ASSERT(ADIBaseValid(ui32Base));
612  ASSERT(ui32Reg < ADI_SLAVE_REGS);
613 
614  //
615  // Get the correct address of the first register used for setting bits
616  // in the ADI slave.
617  //
618  ui32RegOffset = ADI_O_CLR;
619 
620  //
621  // Set the selected bits.
622  //
623  if (ui32Base==AUX_ADI4_BASE) {
624  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + ui32Reg, ui8Val, 1);
625  } else {
626  HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
627  }
628 }
629 
630 //*****************************************************************************
631 //
658 //
659 //*****************************************************************************
660 __STATIC_INLINE void
661 ADI16BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
662 {
663  uint32_t ui32RegOffset;
664 
665  //
666  // Check the arguments.
667  //
668  ASSERT(ADIBaseValid(ui32Base));
669  ASSERT(ui32Reg < ADI_SLAVE_REGS);
670 
671  //
672  // Get the correct address of the first register used for setting bits
673  // in the ADI slave.
674  //
675  ui32RegOffset = ADI_O_CLR;
676 
677  //
678  // Set the selected bits.
679  //
680  if (ui32Base==AUX_ADI4_BASE) {
681  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFE), ui16Val, 2);
682  } else {
683  HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
684  }
685 }
686 
687 //*****************************************************************************
688 //
715 //
716 //*****************************************************************************
717 __STATIC_INLINE void
718 ADI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
719 {
720  uint32_t ui32RegOffset;
721 
722  //
723  // Check the arguments.
724  //
725  ASSERT(ADIBaseValid(ui32Base));
726  ASSERT(ui32Reg < ADI_SLAVE_REGS);
727 
728  //
729  // Get the correct address of the first register used for setting bits
730  // in the ADI slave.
731  //
732  ui32RegOffset = ADI_O_CLR;
733 
734  //
735  // Set the selected bits.
736  //
737  if (ui32Base==AUX_ADI4_BASE) {
738  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + (ui32Reg & 0xFC), ui32Val, 4);
739  } else {
740  HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
741  }
742 }
743 
744 //*****************************************************************************
745 //
775 //
776 //*****************************************************************************
777 __STATIC_INLINE void
778 ADI4SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh,
779  uint8_t ui8Mask, uint8_t ui8Val)
780 {
781  uint32_t ui32RegOffset;
782 
783  //
784  // Check the arguments.
785  //
786  ASSERT(ADIBaseValid(ui32Base));
787  ASSERT(ui32Reg < ADI_SLAVE_REGS);
788  ASSERT(!(ui8Val & 0xF0));
789  ASSERT(!(ui8Mask & 0xF0));
790 
791  //
792  // Get the correct address of the first register used for setting bits
793  // in the ADI slave.
794  //
795  ui32RegOffset = ADI_O_MASK4B + (ui32Reg << 1) + (bWriteHigh ? 1 : 0);
796 
797  //
798  // Set the selected bits.
799  //
800  if (ui32Base==AUX_ADI4_BASE) {
801  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui8Mask << 4) | ui8Val, 1);
802  } else {
803  HWREGB(ui32Base + ui32RegOffset) = (ui8Mask << 4) | ui8Val;
804  }
805 }
806 
807 //*****************************************************************************
808 //
833 //
834 //*****************************************************************************
835 __STATIC_INLINE void
836 ADI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Mask,
837  uint16_t ui16Val)
838 {
839  uint32_t ui32RegOffset;
840 
841  //
842  // Check the arguments.
843  //
844  ASSERT(ADIBaseValid(ui32Base));
845  ASSERT(ui32Reg < ADI_SLAVE_REGS);
846  ASSERT(!(ui16Val & 0xFF00));
847  ASSERT(!(ui16Mask & 0xFF00));
848 
849  //
850  // Get the correct address of the first register used for setting bits
851  // in the ADI slave.
852  //
853  ui32RegOffset = ADI_O_MASK8B + (ui32Reg << 1);
854 
855  //
856  // Set the selected bits.
857  //
858  if (ui32Base==AUX_ADI4_BASE) {
859  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui16Mask << 8) | ui16Val, 2);
860  } else {
861  HWREGH(ui32Base + ui32RegOffset) = (ui16Mask << 8) | ui16Val;
862  }
863 }
864 
865 //*****************************************************************************
866 //
892 //
893 //*****************************************************************************
894 __STATIC_INLINE void
895 ADI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask,
896  uint32_t ui32Val)
897 {
898  uint32_t ui32RegOffset;
899 
900  //
901  // Check the arguments.
902  //
903  ASSERT(ADIBaseValid(ui32Base));
904  ASSERT(ui32Reg < ADI_SLAVE_REGS);
905  ASSERT(!(ui32Val & 0xFFFF0000));
906  ASSERT(!(ui32Mask & 0xFFFF0000));
907 
908  //
909  // Get the correct address of the first register used for setting bits
910  // in the ADI slave.
911  //
912  ui32RegOffset = ADI_O_MASK16B + ((ui32Reg << 1) & 0xFC);
913 
914  //
915  // Set the selected bits.
916  //
917  if (ui32Base==AUX_ADI4_BASE) {
918  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui32Mask << 16) | ui32Val, 4);
919  } else {
920  HWREG(ui32Base + ui32RegOffset) = (ui32Mask << 16) | ui32Val;
921  }
922 }
923 
924 //*****************************************************************************
925 //
926 // Mark the end of the C bindings section for C++ compilers.
927 //
928 //*****************************************************************************
929 #ifdef __cplusplus
930 }
931 #endif
932 
933 #endif // __ADI_H__
934 
935 //*****************************************************************************
936 //
940 //
941 //*****************************************************************************
static void ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
Clear specific bits in an 8 bit ADI register.
Definition: adi.h:604
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:895
static uint32_t ADI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
Read the value in a 32 bit register.
Definition: adi.h:384
static void ADI16BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
Clear specific bits in two 8 bit ADI register.
Definition: adi.h:661
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:490
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:161
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:300
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:778
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:210
#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:836
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:547
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:433
static uint32_t ADI16RegRead(uint32_t ui32Base, uint32_t ui32Reg)
Read the value in a 16 bit register.
Definition: adi.h:343
#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:718
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:260