CC26xx Driver Library
ddi.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: ddi.c
3 * Revised: 2016-05-09 12:05:02 +0200 (Mon, 09 May 2016)
4 * Revision: 46315
5 *
6 * Description: Driver 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 #include <driverlib/ddi.h>
40 
41 //*****************************************************************************
42 //
43 // Handle support for DriverLib in ROM:
44 // This section will undo prototype renaming made in the header file
45 //
46 //*****************************************************************************
47 #if !defined(DOXYGEN)
48  #undef DDI32RegWrite
49  #define DDI32RegWrite NOROM_DDI32RegWrite
50  #undef DDI16BitWrite
51  #define DDI16BitWrite NOROM_DDI16BitWrite
52  #undef DDI16BitfieldWrite
53  #define DDI16BitfieldWrite NOROM_DDI16BitfieldWrite
54  #undef DDI16BitRead
55  #define DDI16BitRead NOROM_DDI16BitRead
56  #undef DDI16BitfieldRead
57  #define DDI16BitfieldRead NOROM_DDI16BitfieldRead
58 #endif
59 
60 //*****************************************************************************
61 //
63 //
64 //*****************************************************************************
65 void
66 DDI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg,
67  uint32_t ui32Val)
68 {
69  //
70  // Check the arguments.
71  //
72  ASSERT(DDIBaseValid(ui32Base));
73  ASSERT(ui32Reg < DDI_SLAVE_REGS);
74 
75  //
76  // Write the value to the register.
77  //
78  AuxAdiDdiSafeWrite(ui32Base + ui32Reg, ui32Val, 4);
79 }
80 
81 //*****************************************************************************
82 //
84 //
85 //*****************************************************************************
86 void
87 DDI16BitWrite(uint32_t ui32Base, uint32_t ui32Reg,
88  uint32_t ui32Mask, uint32_t ui32WrData)
89 {
90  uint32_t ui32RegAddr;
91  uint32_t ui32Data;
92 
93  //
94  // Check the arguments.
95  //
96  ASSERT(DDIBaseValid(ui32Base));
97  ASSERT(!((ui32Mask & 0xFFFF0000) ^ (ui32Mask & 0x0000FFFF)));
98  ASSERT(!(ui32WrData & 0xFFFF0000));
99 
100  //
101  // DDI 16-bit target is on 32-bit boundary so double offset
102  //
103  ui32RegAddr = ui32Base + (ui32Reg << 1) + DDI_O_MASK16B;
104 
105  //
106  // Adjust for target bit in high half of the word.
107  //
108  if(ui32Mask & 0xFFFF0000)
109  {
110  ui32RegAddr += 4;
111  ui32Mask >>= 16;
112  }
113 
114  //
115  // Write mask if data is not zero (to set mask bit), else write '0'.
116  //
117  ui32Data = ui32WrData ? ui32Mask : 0x0;
118 
119  //
120  // Update the register.
121  //
122  AuxAdiDdiSafeWrite(ui32RegAddr, (ui32Mask << 16) | ui32Data, 4);
123 }
124 
125 //*****************************************************************************
126 //
128 //
129 //*****************************************************************************
130 void
131 DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg,
132  uint32_t ui32Mask, uint32_t ui32Shift,
133  uint16_t ui32Data)
134 {
135  uint32_t ui32RegAddr;
136  uint32_t ui32WrData;
137 
138  //
139  // Check the arguments.
140  //
141  ASSERT(DDIBaseValid(ui32Base));
142 
143  //
144  // 16-bit target is on 32-bit boundary so double offset.
145  //
146  ui32RegAddr = ui32Base + (ui32Reg << 1) + DDI_O_MASK16B;
147 
148  //
149  // Adjust for target bit in high half of the word.
150  //
151  if(ui32Shift >= 16)
152  {
153  ui32Shift = ui32Shift - 16;
154  ui32RegAddr += 4;
155  ui32Mask = ui32Mask >> 16;
156  }
157 
158  //
159  // Shift data in to position.
160  //
161  ui32WrData = ui32Data << ui32Shift;
162 
163  //
164  // Write data.
165  //
166  AuxAdiDdiSafeWrite(ui32RegAddr, (ui32Mask << 16) | ui32WrData, 4);
167 }
168 
169 //*****************************************************************************
170 //
172 //
173 //*****************************************************************************
174 uint16_t
175 DDI16BitRead(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask)
176 {
177  uint32_t ui32RegAddr;
178  uint16_t ui16Data;
179 
180  //
181  // Check the arguments.
182  //
183  ASSERT(DDIBaseValid(ui32Base));
184 
185  //
186  // Calculate the address of the register.
187  //
188  ui32RegAddr = ui32Base + ui32Reg + DDI_O_DIR;
189 
190  //
191  // Adjust for target bit in high half of the word.
192  //
193  if(ui32Mask & 0xFFFF0000)
194  {
195  ui32RegAddr += 2;
196  ui32Mask = ui32Mask >> 16;
197  }
198 
199  //
200  // Read a halfword on the DDI interface.
201  //
202  ui16Data = AuxAdiDdiSafeRead(ui32RegAddr, 2);
203 
204  //
205  // Mask data.
206  //
207  ui16Data = ui16Data & ui32Mask;
208 
209  //
210  // Return masked data.
211  //
212  return(ui16Data);
213 }
214 
215 //*****************************************************************************
216 //
218 //
219 //*****************************************************************************
220 uint16_t
221 DDI16BitfieldRead(uint32_t ui32Base, uint32_t ui32Reg,
222  uint32_t ui32Mask, uint32_t ui32Shift)
223 {
224  uint32_t ui32RegAddr;
225  uint16_t ui16Data;
226 
227  //
228  // Check the arguments.
229  //
230  ASSERT(DDIBaseValid(ui32Base));
231 
232  //
233  // Calculate the register address.
234  //
235  ui32RegAddr = ui32Base + ui32Reg + DDI_O_DIR;
236 
237  //
238  // Adjust for target bit in high half of the word.
239  //
240  if(ui32Shift >= 16)
241  {
242  ui32Shift = ui32Shift - 16;
243  ui32RegAddr += 2;
244  ui32Mask = ui32Mask >> 16;
245  }
246 
247  //
248  // Read the register.
249  //
250  ui16Data = AuxAdiDdiSafeRead(ui32RegAddr, 2);
251 
252  //
253  // Mask data and shift into place.
254  //
255  ui16Data &= ui32Mask;
256  ui16Data >>= ui32Shift;
257 
258  //
259  // Return data.
260  //
261  return(ui16Data);
262 }
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 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 bitfield 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
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
#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