CC26xx Driver Library
ddi.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: ddi.h
3 * Revised: 2016-05-09 12:05:02 +0200 (Mon, 09 May 2016)
4 * Revision: 46315
5 *
6 * Description: Defines and prototypes for the DDI 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 __DDI_H__
49 #define __DDI_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_memmap.h>
66 #include <inc/hw_ddi.h>
67 #include <inc/hw_aux_smph.h>
68 #include <driverlib/debug.h>
69 #include <driverlib/cpu.h>
70 
71 //*****************************************************************************
72 //
73 // Support for DriverLib in ROM:
74 // This section renames all functions that are not "static inline", so that
75 // calling these functions will default to implementation in flash. At the end
76 // of this file a second renaming will change the defaults to implementation in
77 // ROM for available functions.
78 //
79 // To force use of the implementation in flash, e.g. for debugging:
80 // - Globally: Define DRIVERLIB_NOROM at project level
81 // - Per function: Use prefix "NOROM_" when calling the function
82 //
83 //*****************************************************************************
84 #if !defined(DOXYGEN)
85  #define DDI32RegWrite NOROM_DDI32RegWrite
86  #define DDI16BitWrite NOROM_DDI16BitWrite
87  #define DDI16BitfieldWrite NOROM_DDI16BitfieldWrite
88  #define DDI16BitRead NOROM_DDI16BitRead
89  #define DDI16BitfieldRead NOROM_DDI16BitfieldRead
90 #endif
91 
92 //*****************************************************************************
93 //
94 // Number of register in the DDI slave
95 //
96 //*****************************************************************************
97 #define DDI_SLAVE_REGS 64
98 
99 
100 //*****************************************************************************
101 //
102 // Defines that is used to control the ADI slave and master
103 //
104 //*****************************************************************************
105 #define DDI_PROTECT 0x00000080
106 #define DDI_ACK 0x00000001
107 #define DDI_SYNC 0x00000000
108 
109 //*****************************************************************************
110 //
111 // API Functions and prototypes
112 //
113 //*****************************************************************************
114 
115 
116 //*****************************************************************************
117 //
118 // Helper functions
119 //
120 //*****************************************************************************
121 
122 //*****************************************************************************
123 //
134 //
135 //*****************************************************************************
136 __STATIC_INLINE void
137 AuxAdiDdiSafeWrite(uint32_t nAddr, uint32_t nData, uint32_t nSize)
138 {
139  // Disable interrupts and remember whether to re-enable
140  bool bIrqEnabled = !CPUcpsid();
141  // Acquire semaphore for accessing ADI/DDI in AUX, perform access, release semaphore
142  while (!HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0));
143  switch (nSize) {
144  case 1: HWREGB(nAddr) = (uint8_t)nData; break;
145  case 2: HWREGH(nAddr) = (uint16_t)nData; break;
146  case 4: default: HWREG(nAddr) = nData; break;
147  }
148  HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0) = 1;
149  // Restore interrupt enable
150  if (bIrqEnabled) {
151  CPUcpsie();
152  }
153 }
154 
155 //*****************************************************************************
156 //
166 //
167 //*****************************************************************************
168 __STATIC_INLINE uint32_t
169 AuxAdiDdiSafeRead(uint32_t nAddr, uint32_t nSize)
170 {
171  uint32_t nRet;
172  // Disable interrupts and remember whether to re-enable
173  bool bIrqEnabled = !CPUcpsid();
174  // Acquire semaphore for accessing ADI/DDI in AUX, perform access, release semaphore
175  while (!HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0));
176  switch (nSize) {
177  case 1: nRet = HWREGB(nAddr); break;
178  case 2: nRet = HWREGH(nAddr); break;
179  case 4: default: nRet = HWREG(nAddr); break;
180  }
181  HWREG(AUX_SMPH_BASE + AUX_SMPH_O_SMPH0) = 1;
182  // Restore interrupt enable
183  if (bIrqEnabled) {
184  CPUcpsie();
185  }
186  return nRet;
187 }
188 
189 #ifdef DRIVERLIB_DEBUG
190 //*****************************************************************************
191 //
204 //
205 //*****************************************************************************
206 static bool
207 DDIBaseValid(uint32_t ui32Base)
208 {
209  return(ui32Base == AUX_DDI0_OSC_BASE);
210 }
211 #endif
212 
213 
214 //*****************************************************************************
215 //
228 //
229 //*****************************************************************************
230 __STATIC_INLINE uint32_t
231 DDI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
232 {
233  //
234  // Check the arguments.
235  //
236  ASSERT(DDIBaseValid(ui32Base));
237  ASSERT(ui32Reg < DDI_SLAVE_REGS);
238 
239  //
240  // Read the register and return the value.
241  //
242  return AuxAdiDdiSafeRead(ui32Base + ui32Reg, 4);
243 }
244 
245 //*****************************************************************************
246 //
265 //
266 //*****************************************************************************
267 __STATIC_INLINE void
268 DDI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
269 {
270  uint32_t ui32RegOffset;
271 
272  //
273  // Check the arguments.
274  //
275  ASSERT(DDIBaseValid(ui32Base));
276  ASSERT(ui32Reg < DDI_SLAVE_REGS);
277 
278  //
279  // Get the correct address of the first register used for setting bits
280  // in the DDI slave.
281  //
282  ui32RegOffset = DDI_O_SET;
283 
284  //
285  // Set the selected bits.
286  //
287  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + ui32Reg, ui32Val, 4);
288 }
289 
290 //*****************************************************************************
291 //
305 //
306 //*****************************************************************************
307 __STATIC_INLINE void
308 DDI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg,
309  uint32_t ui32Val)
310 {
311  uint32_t ui32RegOffset;
312 
313  //
314  // Check the arguments.
315  //
316  ASSERT(DDIBaseValid(ui32Base));
317  ASSERT(ui32Reg < DDI_SLAVE_REGS);
318 
319  //
320  // Get the correct address of the first register used for setting bits
321  // in the DDI slave.
322  //
323  ui32RegOffset = DDI_O_CLR;
324 
325  //
326  // Clear the selected bits.
327  //
328  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset + ui32Reg, ui32Val, 4);
329 }
330 
331 //*****************************************************************************
332 //
356 //
357 //*****************************************************************************
358 __STATIC_INLINE void
359 DDI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Byte,
360  uint16_t ui16Mask, uint16_t ui16Val)
361 {
362  uint32_t ui32RegOffset;
363 
364  //
365  // Check the arguments.
366  //
367  ASSERT(DDIBaseValid(ui32Base));
368  ASSERT(ui32Reg < DDI_SLAVE_REGS);
369  ASSERT(!(ui16Val & 0xFF00));
370  ASSERT(!(ui16Mask & 0xFF00));
371 
372  //
373  // Get the correct address of the first register used for setting bits
374  // in the DDI slave.
375  //
376  ui32RegOffset = DDI_O_MASK8B + (ui32Reg << 1) + (ui32Byte << 1);
377 
378  //
379  // Set the selected bits.
380  //
381  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui16Mask << 8) | ui16Val, 2);
382 }
383 
384 //*****************************************************************************
385 //
409 //
410 //*****************************************************************************
411 __STATIC_INLINE void
412 DDI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh,
413  uint32_t ui32Mask, uint32_t ui32Val)
414 {
415  uint32_t ui32RegOffset;
416 
417  //
418  // Check the arguments.
419  //
420  ASSERT(DDIBaseValid(ui32Base));
421  ASSERT(ui32Reg < DDI_SLAVE_REGS);
422  ASSERT(!(ui32Val & 0xFFFF0000));
423  ASSERT(!(ui32Mask & 0xFFFF0000));
424 
425  //
426  // Get the correct address of the first register used for setting bits
427  // in the DDI slave.
428  //
429  ui32RegOffset = DDI_O_MASK16B + (ui32Reg << 1) + (bWriteHigh ? 4 : 0);
430 
431  //
432  // Set the selected bits.
433  //
434  AuxAdiDdiSafeWrite(ui32Base + ui32RegOffset, (ui32Mask << 16) | ui32Val, 4);
435 }
436 
437 //*****************************************************************************
438 //
456 //
457 //*****************************************************************************
458 extern void DDI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val);
459 
460 //*****************************************************************************
461 //
477 //
478 //*****************************************************************************
479 extern void DDI16BitWrite(uint32_t ui32Base, uint32_t ui32Reg,
480  uint32_t ui32Mask, uint32_t ui32WrData);
481 
482 
483 //*****************************************************************************
484 //
500 //
501 //*****************************************************************************
502 extern void DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg,
503  uint32_t ui32Mask, uint32_t ui32Shift,
504  uint16_t ui32Data);
505 
506 //*****************************************************************************
507 //
518 //
519 //*****************************************************************************
520 extern uint16_t DDI16BitRead(uint32_t ui32Base, uint32_t ui32Reg,
521  uint32_t ui32Mask);
522 
523 //*****************************************************************************
524 //
539 //
540 //*****************************************************************************
541 extern uint16_t DDI16BitfieldRead(uint32_t ui32Base, uint32_t ui32Reg,
542  uint32_t ui32Mask, uint32_t ui32Shift);
543 
544 //*****************************************************************************
545 //
546 // Support for DriverLib in ROM:
547 // Redirect to implementation in ROM when available.
548 //
549 //*****************************************************************************
550 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
551  #include <driverlib/rom.h>
552  #ifdef ROM_DDI32RegWrite
553  #undef DDI32RegWrite
554  #define DDI32RegWrite ROM_DDI32RegWrite
555  #endif
556  #ifdef ROM_DDI16BitWrite
557  #undef DDI16BitWrite
558  #define DDI16BitWrite ROM_DDI16BitWrite
559  #endif
560  #ifdef ROM_DDI16BitfieldWrite
561  #undef DDI16BitfieldWrite
562  #define DDI16BitfieldWrite ROM_DDI16BitfieldWrite
563  #endif
564  #ifdef ROM_DDI16BitRead
565  #undef DDI16BitRead
566  #define DDI16BitRead ROM_DDI16BitRead
567  #endif
568  #ifdef ROM_DDI16BitfieldRead
569  #undef DDI16BitfieldRead
570  #define DDI16BitfieldRead ROM_DDI16BitfieldRead
571  #endif
572 #endif
573 
574 //*****************************************************************************
575 //
576 // Mark the end of the C bindings section for C++ compilers.
577 //
578 //*****************************************************************************
579 #ifdef __cplusplus
580 }
581 #endif
582 
583 #endif // __DDI_H__
584 
585 //*****************************************************************************
586 //
590 //
591 //*****************************************************************************
static void DDI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Byte, uint16_t ui16Mask, uint16_t ui16Val)
Set a value on any 8 bits inside a 32 bit register in the DDI slave.
Definition: ddi.h:359
void DDI16BitWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32WrData)
Write a single bit using a 16-bit maskable write.
Definition: ddi.c:87
static void DDI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Set specific bits in a DDI slave register.
Definition: ddi.h:268
static uint32_t AuxAdiDdiSafeRead(uint32_t nAddr, uint32_t nSize)
Safely read from AUX ADI/DDI interfaces using a semaphore.
Definition: ddi.h:169
uint16_t DDI16BitRead(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask)
Read a bit via the DDI using 16-bit read.
Definition: ddi.c:175
void DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift, uint16_t ui32Data)
Write a bit field via the DDI using 16-bit maskable write.
Definition: ddi.c:131
uint16_t DDI16BitfieldRead(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift)
Read a bitfield via the DDI using 16-bit read.
Definition: ddi.c:221
#define ASSERT(expr)
Definition: debug.h:74
uint32_t CPUcpsid(void)
Disable all external interrupts.
Definition: cpu.c:97
static void DDI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh, uint32_t ui32Mask, uint32_t ui32Val)
Set a value on any 16 bits inside a 32 bit register aligned on a half-word boundary in the DDI slave...
Definition: ddi.h:412
static uint32_t DDI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
Read the value in a 32 bit register.
Definition: ddi.h:231
uint32_t CPUcpsie(void)
Enable all external interrupts.
Definition: cpu.c:249
void DDI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Write a 32 bit value to a register in the DDI slave.
Definition: ddi.c:66
static void DDI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Clear specific bits in a 32 bit DDI register.
Definition: ddi.h:308
#define DDI_SLAVE_REGS
Definition: ddi.h:97
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