CC13xx Driver Library
ddi.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: ddi.c
3 * Revised: 2015-01-13 16:59:55 +0100 (Tue, 13 Jan 2015)
4 * Revision: 42365
5 *
6 * Description: Driver for the DDI master interface
7 *
8 * Copyright (c) 2015, 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 DDI16BitWrite
49  #define DDI16BitWrite NOROM_DDI16BitWrite
50  #undef DDI16BitfieldWrite
51  #define DDI16BitfieldWrite NOROM_DDI16BitfieldWrite
52  #undef DDI16BitRead
53  #define DDI16BitRead NOROM_DDI16BitRead
54  #undef DDI16BitfieldRead
55  #define DDI16BitfieldRead NOROM_DDI16BitfieldRead
56 #endif
57 
58 //*****************************************************************************
59 //
61 //
62 //*****************************************************************************
63 void
64 DDI16BitWrite(uint32_t ui32Base, uint32_t ui32Reg,
65  uint32_t ui32Mask, uint32_t ui32WrData)
66 {
67  uint32_t ui32RegAddr;
68  uint32_t ui32Data;
69 
70  //
71  // Check the arguments.
72  //
73  ASSERT(DDIBaseValid(ui32Base));
74  ASSERT(!((ui32Mask & 0xFFFF0000) ^ (ui32Mask & 0x0000FFFF)));
75  ASSERT(!(ui32WrData & 0xFFFF0000));
76 
77  //
78  // DDI 16-bit target is on 32-bit boundary so double offset
79  //
80  ui32RegAddr = ui32Base + (ui32Reg << 1) + DDI_O_MASK16B;
81 
82  //
83  // Adjust for target bit in high half of the word.
84  //
85  if(ui32Mask & 0xFFFF0000)
86  {
87  ui32RegAddr += 4;
88  ui32Mask >>= 16;
89  }
90 
91  //
92  // Write mask if data is not zero (to set mask bit), else write '0'.
93  //
94  ui32Data = ui32WrData ? ui32Mask : 0x0;
95 
96  //
97  // Update the register.
98  //
99  AuxAdiDdiSafeWrite(ui32RegAddr, (ui32Mask << 16) | ui32Data, 4);
100 }
101 
102 //*****************************************************************************
103 //
105 //
106 //*****************************************************************************
107 void
108 DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg,
109  uint32_t ui32Mask, uint32_t ui32Shift,
110  uint16_t ui32Data)
111 {
112  uint32_t ui32RegAddr;
113  uint32_t ui32WrData;
114 
115  //
116  // Check the arguments.
117  //
118  ASSERT(DDIBaseValid(ui32Base));
119 
120  //
121  // 16-bit target is on 32-bit boundary so double offset.
122  //
123  ui32RegAddr = ui32Base + (ui32Reg << 1) + DDI_O_MASK16B;
124 
125  //
126  // Adjust for target bit in high half of the word.
127  //
128  if(ui32Shift >= 16)
129  {
130  ui32Shift = ui32Shift - 16;
131  ui32RegAddr += 4;
132  ui32Mask = ui32Mask >> 16;
133  }
134 
135  //
136  // Shift data in to position.
137  //
138  ui32WrData = ui32Data << ui32Shift;
139 
140  //
141  // Write data.
142  //
143  AuxAdiDdiSafeWrite(ui32RegAddr, (ui32Mask << 16) | ui32WrData, 4);
144 }
145 
146 //*****************************************************************************
147 //
149 //
150 //*****************************************************************************
151 uint16_t
152 DDI16BitRead(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask)
153 {
154  uint32_t ui32RegAddr;
155  uint16_t ui16Data;
156 
157  //
158  // Check the arguments.
159  //
160  ASSERT(DDIBaseValid(ui32Base));
161 
162  //
163  // Calculate the address of the register.
164  //
165  ui32RegAddr = ui32Base + ui32Reg + DDI_O_DIR;
166 
167  //
168  // Adjust for target bit in high half of the word.
169  //
170  if(ui32Mask & 0xFFFF0000)
171  {
172  ui32RegAddr += 2;
173  ui32Mask = ui32Mask >> 16;
174  }
175 
176  //
177  // Read a halfword on the DDI interface.
178  //
179  ui16Data = AuxAdiDdiSafeRead(ui32RegAddr, 2);
180 
181  //
182  // Mask data.
183  //
184  ui16Data = ui16Data & ui32Mask;
185 
186  //
187  // Return masked data.
188  //
189  return(ui16Data);
190 }
191 
192 //*****************************************************************************
193 //
195 //
196 //*****************************************************************************
197 uint16_t
198 DDI16BitfieldRead(uint32_t ui32Base, uint32_t ui32Reg,
199  uint32_t ui32Mask, uint32_t ui32Shift)
200 {
201  uint32_t ui32RegAddr;
202  uint16_t ui16Data;
203 
204  //
205  // Check the arguments.
206  //
207  ASSERT(DDIBaseValid(ui32Base));
208 
209  //
210  // Calculate the register address.
211  //
212  ui32RegAddr = ui32Base + ui32Reg + DDI_O_DIR;
213 
214  //
215  // Adjust for target bit in high half of the word.
216  //
217  if(ui32Shift >= 16)
218  {
219  ui32Shift = ui32Shift - 16;
220  ui32RegAddr += 2;
221  ui32Mask = ui32Mask >> 16;
222  }
223 
224  //
225  // Read the register.
226  //
227  ui16Data = AuxAdiDdiSafeRead(ui32RegAddr, 2);
228 
229  //
230  // Mask data and shift into place.
231  //
232  ui16Data &= ui32Mask;
233  ui16Data >>= ui32Shift;
234 
235  //
236  // Return data.
237  //
238  return(ui16Data);
239 }
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:64
static uint32_t AuxAdiDdiSafeRead(uint32_t nAddr, uint32_t nSize)
Safely read from AUX ADI/DDI interfaces using a semaphore.
Definition: ddi.h:168
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:152
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:108
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:198
#define ASSERT(expr)
Definition: debug.h:74
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:136