1 /******************************************************************************
2 * Filename: adi.h
3 * Revised: 2016-11-17 16:39:28 +0100 (Thu, 17 Nov 2016)
4 * Revision: 47706
5 *
6 * Description: Defines and prototypes for the ADI master interface.
7 *
8 * Copyright (c) 2015 - 2017, 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 //
41 //! \addtogroup analog_group
42 //! @{
43 //! \addtogroup adi_api
44 //! @{
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 "debug.h"
70 #include "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 //
98 //! \internal
99 //! \brief Checks an ADI base address.
100 //!
101 //! This function determines if an ADI port base address is valid.
102 //!
103 //! \param ui32Base is the base address of the ADI port.
104 //!
105 //! \return Returns \c true if the base address is valid and \c false
106 //! otherwise
107 //
108 //*****************************************************************************
109 static bool
ADIBaseValid(uint32_t ui32Base)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 //
123 //! \brief Write an 8 bit value to a register in an ADI slave.
124 //!
125 //! This function will write a value to a single register in the analog domain.
126 //! The access to the registers in the analog domain is either 8, 16, or 32 bit
127 //! aligned. You can only do 16 bit access on registers 0-1 / 2-3, etc. Similarly
128 //! 32 bit accesses are always performed on register 0-3 / 4-7, etc. Addresses
129 //! for the registers and values being written to the registers will be
130 //! truncated according to this access scheme.
131 //!
132 //! \note This operation is write only for the specified register. No
133 //! previous value of the register will be kept (i.e. this is NOT
134 //! read-modify-write on the register).
135 //!
136 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
137 //! enabled before calling this function.
138 //!
139 //! \param ui32Base is ADI base address.
140 //! \param ui32Reg is the register to write.
141 //! \param ui8Val is the 8 bit value to write to the register.
142 //!
143 //! \return None
144 //!
145 //! \sa ADI16RegWrite(), ADI32RegWrite()
146 //
147 //*****************************************************************************
148 __STATIC_INLINE void
ADI8RegWrite(uint32_t ui32Base,uint32_t ui32Reg,uint8_t ui8Val)149 ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
150 {
151 // Check the arguments.
152 ASSERT(ADIBaseValid(ui32Base));
153 ASSERT(ui32Reg < ADI_SLAVE_REGS);
154
155 // Write the value to the register.
156 HWREGB(ui32Base + ui32Reg) = ui8Val;
157 }
158
159 //*****************************************************************************
160 //
161 //! \brief Write a 16 bit value to 2 registers in the ADI slave.
162 //!
163 //! This function will write a value to 2 consecutive registers in the analog
164 //! domain. The access to the registers in the analog domain is either 8, 16
165 //! or 32 bit aligned. You can only do 16 bit access on registers 0-1 / 2-3,
166 //! etc. Similarly 32 bit accesses are always performed on register 0-3 / 4-7,
167 //! etc. Addresses for the registers and values being written
168 //! to the registers will be truncated according to this access scheme.
169 //!
170 //! \note The byte addressing bit will be ignored, to ensure 16 bit access
171 //! to the ADI slave.
172 //!
173 //! \note This operation is write only for the specified register. No
174 //! previous value of the register will be kept (i.e. this is NOT
175 //! read-modify-write on the register).
176 //!
177 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
178 //! enabled before calling this function.
179 //!
180 //! \param ui32Base is ADI base address.
181 //! \param ui32Reg is the register to write.
182 //! \param ui16Val is the 16 bit value to write to the register.
183 //!
184 //! \return None
185 //!
186 //! \sa ADI8RegWrite(), ADI32RegWrite()
187 //
188 //*****************************************************************************
189 __STATIC_INLINE void
ADI16RegWrite(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Val)190 ADI16RegWrite(uint32_t ui32Base, uint32_t ui32Reg,
191 uint16_t ui16Val)
192 {
193 // Check the arguments.
194 ASSERT(ADIBaseValid(ui32Base));
195 ASSERT(ui32Reg < ADI_SLAVE_REGS);
196
197 // Write the value to the register.
198 HWREGH(ui32Base + (ui32Reg & 0xFE)) = ui16Val;
199 }
200
201 //*****************************************************************************
202 //
203 //! \brief Write a 32 bit value to 4 registers in the ADI slave.
204 //!
205 //! This function will write a value to 4 consecutive registers in the analog
206 //! domain. The access to the registers in the analog domain is either 8, 16
207 //! or 32 bit aligned. You can only do 16 bit access on registers 0-1 / 2-3,
208 //! etc. Similarly 32 bit accesses are always performed on register 0-3 / 4-7,
209 //! etc. Addresses for the registers and values being written
210 //! to the registers will be truncated according to this access scheme.
211 //!
212 //! \note The byte and half word addressing bits will be ignored, to ensure
213 //! 32 bit access to the ADI slave.
214 //!
215 //! \note This operation is write only for the specified register. No
216 //! previous value of the register will be kept (i.e. this is NOT
217 //! read-modify-write on the register).
218 //!
219 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
220 //! enabled before calling this function.
221 //!
222 //! \param ui32Base is ADI base address.
223 //! \param ui32Reg is the register to write.
224 //! \param ui32Val is the 32 bit value to write to the register.
225 //!
226 //! \return None
227 //!
228 //! \sa ADI8RegWrite(), ADI16RegWrite()
229 //
230 //*****************************************************************************
231 __STATIC_INLINE void
ADI32RegWrite(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Val)232 ADI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
233 {
234 // Check the arguments.
235 ASSERT(ADIBaseValid(ui32Base));
236 ASSERT(ui32Reg < ADI_SLAVE_REGS);
237
238 // Write the value to the register.
239 HWREG(ui32Base + (ui32Reg & 0xFC)) = ui32Val;
240 }
241
242 //*****************************************************************************
243 //
244 //! \brief Read the value of an 8 bit register in the ADI slave.
245 //!
246 //! This function will read an 8 bit register in the analog domain and return
247 //! the value as the lower 8 bits of an \c uint32_t. The access to the
248 //! registers in the analog domain is either 8, 16 or 32 bit aligned. You can
249 //! only do 16 bit access on registers 0-1 / 2-3, etc. Similarly 32 bit accesses
250 //! are always performed on register 0-3 / 4-7, etc. Addresses for the
251 //! registers and values being written to the registers will be truncated
252 //! according to this access scheme.
253 //!
254 //! \param ui32Base is ADI base address.
255 //! \param ui32Reg is the 8 bit register to read.
256 //!
257 //! \return Returns the 8 bit value of the analog register in the least
258 //! significant byte of the \c uint32_t.
259 //!
260 //! \sa ADI16RegRead(), ADI32RegRead()
261 //
262 //*****************************************************************************
263 __STATIC_INLINE uint32_t
ADI8RegRead(uint32_t ui32Base,uint32_t ui32Reg)264 ADI8RegRead(uint32_t ui32Base, uint32_t ui32Reg)
265 {
266 // Check the arguments.
267 ASSERT(ADIBaseValid(ui32Base));
268 ASSERT(ui32Reg < ADI_SLAVE_REGS);
269
270 // Read the register and return the value.
271 return(HWREGB(ui32Base + ui32Reg));
272 }
273
274 //*****************************************************************************
275 //
276 //! \brief Read the value in a 16 bit register.
277 //!
278 //! This function will read 2 x 8 bit registers in the analog domain and return
279 //! the value as the lower 16 bits of an \c uint32_t. The access to the
280 //! registers in the analog domain is either 8, 16 or 32 bit aligned. You can
281 //! only do 16 bit access on registers 0-1 / 2-3, etc. Similarly 32 bit accesses
282 //! are always performed on register 0-3 / 4-7, etc. Addresses for the
283 //! registers and values being written to the registers will be truncated
284 //! according to this access scheme.
285 //!
286 //! \note The byte addressing bit will be ignored, to ensure 16 bit access
287 //! to the ADI slave.
288 //!
289 //! \param ui32Base is ADI base address.
290 //! \param ui32Reg is the 16 bit register to read.
291 //!
292 //! \return Returns the 16 bit value of the 2 analog register in the 2 least
293 //! significant bytes of the \c uint32_t.
294 //!
295 //! \sa ADI8RegRead(), ADI32RegRead()
296 //
297 //*****************************************************************************
298 __STATIC_INLINE uint32_t
ADI16RegRead(uint32_t ui32Base,uint32_t ui32Reg)299 ADI16RegRead(uint32_t ui32Base, uint32_t ui32Reg)
300 {
301 // Check the arguments.
302 ASSERT(ADIBaseValid(ui32Base));
303 ASSERT(ui32Reg < ADI_SLAVE_REGS);
304
305 // Read the registers and return the value.
306 return(HWREGH(ui32Base + (ui32Reg & 0xFE)));
307 }
308
309 //*****************************************************************************
310 //
311 //! \brief Read the value in a 32 bit register.
312 //!
313 //! This function will read 4 x 8 bit registers in the analog domain and return
314 //! the value as an \c uint32_t. The access to the registers in the analog
315 //! domain is either 8, 16 or 32 bit aligned. You can only do 16 bit access on
316 //! registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always performed on
317 //! register 0-3 / 4-7, etc. Addresses for the registers and values being
318 //! written to the registers will be truncated according to this access scheme.
319 //!
320 //! \note The byte and half word addressing bits will be ignored, to ensure
321 //! 32 bit access to the ADI slave.
322 //!
323 //! \param ui32Base is ADI base address.
324 //! \param ui32Reg is the 32 bit register to read.
325 //!
326 //! \return Returns the 32 bit value of the 4 analog registers.
327 //!
328 //! \sa ADI8RegRead(), ADI16RegRead()
329 //
330 //*****************************************************************************
331 __STATIC_INLINE uint32_t
ADI32RegRead(uint32_t ui32Base,uint32_t ui32Reg)332 ADI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
333 {
334 // Check the arguments.
335 ASSERT(ADIBaseValid(ui32Base));
336 ASSERT(ui32Reg < ADI_SLAVE_REGS);
337
338 // Read the registers and return the value.
339 return(HWREG(ui32Base + (ui32Reg & 0xFC)));
340 }
341
342 //*****************************************************************************
343 //
344 //! \brief Set specific bits in a single 8 bit ADI register.
345 //!
346 //! This function will set bits in a single register in the analog domain.
347 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
348 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
349 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
350 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
351 //! being written to the registers will be truncated according to this access
352 //! scheme.
353 //!
354 //! \note This operation is write only for the specified register.
355 //! This function is used to set bits in a specific 8 bit register in the
356 //! ADI slave. Only bits in the selected register are affected by the
357 //! operation.
358 //!
359 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
360 //! enabled before calling this function.
361 //!
362 //! \param ui32Base is ADI base address.
363 //! \param ui32Reg is the base register to assert the bits in.
364 //! \param ui8Val is the 8 bit one-hot encoded value specifying which
365 //! bits to set in the register.
366 //!
367 //! \return None
368 //!
369 //! \sa ADI16BitsSet(), ADI32BitsSet()
370 //
371 //*****************************************************************************
372 __STATIC_INLINE void
ADI8BitsSet(uint32_t ui32Base,uint32_t ui32Reg,uint8_t ui8Val)373 ADI8BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
374 {
375 uint32_t ui32RegOffset;
376
377 // Check the arguments.
378 ASSERT(ADIBaseValid(ui32Base));
379 ASSERT(ui32Reg < ADI_SLAVE_REGS);
380
381 // Get the correct address of the first register used for setting bits
382 // in the ADI slave.
383 ui32RegOffset = ADI_O_SET;
384
385 // Set the selected bits.
386 HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
387 }
388
389 //*****************************************************************************
390 //
391 //! \brief Set specific bits in 2 x 8 bit ADI slave registers.
392 //!
393 //! This function will set bits in 2 registers in the analog domain.
394 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
395 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
396 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
397 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
398 //! being written to the registers will be truncated according to this access
399 //! scheme.
400 //!
401 //! \note This operation is write only for the specified register.
402 //! This function is used to set bits in 2 consecutive 8 bit registers in the
403 //! ADI slave. Only bits in the selected registers are affected by the
404 //! operation.
405 //!
406 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
407 //! enabled before calling this function.
408 //!
409 //! \param ui32Base is ADI base address.
410 //! \param ui32Reg is the base register to assert the bits in.
411 //! \param ui16Val is the 16 bit one-hot encoded value specifying which
412 //! bits to set in the registers.
413 //!
414 //! \return None
415 //!
416 //! \sa ADI8BitsSet(), ADI32BitsSet()
417 //
418 //*****************************************************************************
419 __STATIC_INLINE void
ADI16BitsSet(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Val)420 ADI16BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
421 {
422 uint32_t ui32RegOffset;
423
424 // Check the arguments.
425 ASSERT(ADIBaseValid(ui32Base));
426 ASSERT(ui32Reg < ADI_SLAVE_REGS);
427
428 // Get the correct address of the first register used for setting bits
429 // in the ADI slave.
430 ui32RegOffset = ADI_O_SET;
431
432 // Set the selected bits.
433 HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
434 }
435
436 //*****************************************************************************
437 //
438 //! \brief Set specific bits in 4 x 8 bit ADI slave registers.
439 //!
440 //! This function will set bits in 4 registers in the analog domain.
441 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
442 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
443 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
444 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
445 //! being written to the registers will be truncated according to this access
446 //! scheme.
447 //!
448 //! \note This operation is write only for the specified register.
449 //! This function is used to set bits in 4 consecutive 8 bit registers in the
450 //! ADI slave. Only bits in the selected registers are affected by the
451 //! operation.
452 //!
453 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
454 //! enabled before calling this function.
455 //!
456 //! \param ui32Base is ADI base address.
457 //! \param ui32Reg is the base register to assert the bits in.
458 //! \param ui32Val is the 32 bit one-hot encoded value specifying which
459 //! bits to set in the registers.
460 //!
461 //! \return None
462 //!
463 //! \sa ADI8BitsSet(), ADI16BitsSet()
464 //
465 //*****************************************************************************
466 __STATIC_INLINE void
ADI32BitsSet(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Val)467 ADI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
468 {
469 uint32_t ui32RegOffset;
470
471 // Check the arguments.
472 ASSERT(ADIBaseValid(ui32Base));
473 ASSERT(ui32Reg < ADI_SLAVE_REGS);
474
475 // Get the correct address of the first register used for setting bits
476 // in the ADI slave.
477 ui32RegOffset = ADI_O_SET;
478
479 // Set the selected bits.
480 HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
481 }
482
483 //*****************************************************************************
484 //
485 //! \brief Clear specific bits in an 8 bit ADI register.
486 //!
487 //! This function will clear bits in a register in the analog domain.
488 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
489 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
490 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
491 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
492 //! being written to the registers will be truncated according to this access
493 //! scheme.
494 //!
495 //! \note This operation is write only for the specified register.
496 //! This function is used to clear bits in a specific 8 bit register in
497 //! the ADI slave. Only bits in the selected register are affected by the
498 //! operation.
499 //!
500 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
501 //! enabled before calling this function.
502 //!
503 //! \param ui32Base is ADI base address.
504 //! \param ui32Reg is the base registers to clear the bits in.
505 //! \param ui8Val is the 8 bit one-hot encoded value specifying which
506 //! bits to clear in the register.
507 //!
508 //! \return None
509 //!
510 //! \sa ADI16BitsClear(), ADI32BitsClear()
511 //
512 //*****************************************************************************
513 __STATIC_INLINE void
ADI8BitsClear(uint32_t ui32Base,uint32_t ui32Reg,uint8_t ui8Val)514 ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
515 {
516 uint32_t ui32RegOffset;
517
518 // Check the arguments.
519 ASSERT(ADIBaseValid(ui32Base));
520 ASSERT(ui32Reg < ADI_SLAVE_REGS);
521
522 // Get the correct address of the first register used for setting bits
523 // in the ADI slave.
524 ui32RegOffset = ADI_O_CLR;
525
526 // Set the selected bits.
527 HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
528 }
529
530 //*****************************************************************************
531 //
532 //! \brief Clear specific bits in two 8 bit ADI register.
533 //!
534 //! This function will clear bits in 2 registers in the analog domain.
535 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
536 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
537 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
538 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
539 //! being written to the registers will be truncated according to this access
540 //! scheme.
541 //!
542 //! \note This operation is write only for the specified register.
543 //! This function is used to clear bits in 2 consecutive 8 bit registers in
544 //! the ADI slave. Only bits in the selected registers are affected by the
545 //! operation.
546 //!
547 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
548 //! enabled before calling this function.
549 //!
550 //! \param ui32Base is ADI base address.
551 //! \param ui32Reg is the base registers to clear the bits in.
552 //! \param ui16Val is the 16 bit one-hot encoded value specifying which
553 //! bits to clear in the registers.
554 //!
555 //! \return None
556 //!
557 //! \sa ADI8BitsClear(), ADI32BitsClear()
558 //
559 //*****************************************************************************
560 __STATIC_INLINE void
ADI16BitsClear(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Val)561 ADI16BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
562 {
563 uint32_t ui32RegOffset;
564
565 // Check the arguments.
566 ASSERT(ADIBaseValid(ui32Base));
567 ASSERT(ui32Reg < ADI_SLAVE_REGS);
568
569 // Get the correct address of the first register used for setting bits
570 // in the ADI slave.
571 ui32RegOffset = ADI_O_CLR;
572
573 // Set the selected bits.
574 HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
575 }
576
577 //*****************************************************************************
578 //
579 //! \brief Clear specific bits in four 8 bit ADI register.
580 //!
581 //! This function will clear bits in 4 registers in the analog domain.
582 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
583 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
584 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
585 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
586 //! being written to the registers will be truncated according to this access
587 //! scheme.
588 //!
589 //! \note This operation is write only for the specified register.
590 //! This function is used to clear bits in 4 consecutive 8 bit registers in
591 //! the ADI slave. Only bits in the selected registers are affected by the
592 //! operation.
593 //!
594 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
595 //! enabled before calling this function.
596 //!
597 //! \param ui32Base is ADI base address.
598 //! \param ui32Reg is the base registers to clear the bits in.
599 //! \param ui32Val is the 32 bit one-hot encoded value specifying which
600 //! bits to clear in the registers.
601 //!
602 //! \return None
603 //!
604 //! \sa ADI8BitsClear(), ADI16BitsClear()
605 //
606 //*****************************************************************************
607 __STATIC_INLINE void
ADI32BitsClear(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Val)608 ADI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
609 {
610 uint32_t ui32RegOffset;
611
612 // Check the arguments.
613 ASSERT(ADIBaseValid(ui32Base));
614 ASSERT(ui32Reg < ADI_SLAVE_REGS);
615
616 // Get the correct address of the first register used for setting bits
617 // in the ADI slave.
618 ui32RegOffset = ADI_O_CLR;
619
620 // Set the selected bits.
621 HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
622 }
623
624 //*****************************************************************************
625 //
626 //! \brief Set a value on any 4 bits inside an 8 bit register in the ADI slave.
627 //!
628 //! This function allows halfbyte (4 bit) access to the ADI slave registers.
629 //! The parameter \c bWriteHigh determines whether to write to the lower
630 //! or higher part of the 8 bit register.
631 //!
632 //! Use this function to write any value in the range 0-3 bits aligned on a
633 //! half byte boundary. Fx. for writing the value 0b101 to bits 1 to 3 the
634 //! \c ui8Val = 0xA and the \c ui8Mask = 0xE. Bit 0 will not be affected by
635 //! the operation, as the corresponding bit is not set in the \c ui8Mask.
636 //!
637 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
638 //! enabled before calling this function.
639 //!
640 //! \param ui32Base is the base address of the ADI port.
641 //! \param ui32Reg is the Least Significant Register in the ADI slave that
642 //! will be affected by the write operation.
643 //! \param bWriteHigh defines which part of the register to write in.
644 //! - \c true: Write upper half byte of register.
645 //! - \c false: Write lower half byte of register.
646 //! \param ui8Mask is the mask defining which of the 4 bits that should be
647 //! overwritten. The mask must be defined in the lower half of the 8 bits of
648 //! the parameter.
649 //! \param ui8Val is the value to write. The value must be defined in the lower
650 //! half of the 8 bits of the parameter.
651 //!
652 //! \return None
653 //!
654 //! \sa ADI8SetValBit(), ADI16SetValBit
655 //
656 //*****************************************************************************
657 __STATIC_INLINE void
ADI4SetValBit(uint32_t ui32Base,uint32_t ui32Reg,bool bWriteHigh,uint8_t ui8Mask,uint8_t ui8Val)658 ADI4SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh,
659 uint8_t ui8Mask, uint8_t ui8Val)
660 {
661 uint32_t ui32RegOffset;
662
663 // Check the arguments.
664 ASSERT(ADIBaseValid(ui32Base));
665 ASSERT(ui32Reg < ADI_SLAVE_REGS);
666 ASSERT(!(ui8Val & 0xF0));
667 ASSERT(!(ui8Mask & 0xF0));
668
669 // Get the correct address of the first register used for setting bits
670 // in the ADI slave.
671 ui32RegOffset = ADI_O_MASK4B + (ui32Reg << 1) + (bWriteHigh ? 1 : 0);
672
673 // Set the selected bits.
674 HWREGB(ui32Base + ui32RegOffset) = (ui8Mask << 4) | ui8Val;
675 }
676
677 //*****************************************************************************
678 //
679 //! \brief Set a value on any bits inside an 8 bit register in the ADI slave.
680 //!
681 //! This function allows byte (8 bit) access to the ADI slave registers.
682 //!
683 //! Use this function to write any value in the range 0-7 bits aligned on a
684 //! byte boundary. Fx. for writing the value 0b101 to bits 1 and 3 the
685 //! \c ui16Val = 0x0A and the \c ui16Mask = 0x0E. Bits 0 and 5-7 will not be affected
686 //! by the operation, as the corresponding bits are not set in the
687 //! \c ui16Mask.
688 //!
689 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
690 //! enabled before calling this function.
691 //!
692 //! \param ui32Base is the base address of the ADI port.
693 //! \param ui32Reg is the Least Significant Register in the ADI slave that
694 //! will be affected by the write operation.
695 //! \param ui16Mask is the mask defining which of the 8 bit that should be
696 //! overwritten. The mask must be defined in the lower half of the 16 bits.
697 //! \param ui16Val is the value to write. The value must be defined in the lower
698 //! half of the 16 bits.
699 //!
700 //! \return None
701 //!
702 //! \sa ADI4SetValBit(), ADI16SetValBit()
703 //
704 //*****************************************************************************
705 __STATIC_INLINE void
ADI8SetValBit(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Mask,uint16_t ui16Val)706 ADI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Mask,
707 uint16_t ui16Val)
708 {
709 uint32_t ui32RegOffset;
710
711 // Check the arguments.
712 ASSERT(ADIBaseValid(ui32Base));
713 ASSERT(ui32Reg < ADI_SLAVE_REGS);
714 ASSERT(!(ui16Val & 0xFF00));
715 ASSERT(!(ui16Mask & 0xFF00));
716
717 // Get the correct address of the first register used for setting bits
718 // in the ADI slave.
719 ui32RegOffset = ADI_O_MASK8B + (ui32Reg << 1);
720
721 // Set the selected bits.
722 HWREGH(ui32Base + ui32RegOffset) = (ui16Mask << 8) | ui16Val;
723 }
724
725 //*****************************************************************************
726 //
727 //! \brief Set a value on any bits inside an 2 x 8 bit register aligned on a
728 //! half-word (byte) boundary in the ADI slave.
729 //!
730 //! This function allows 2 byte (16 bit) access to the ADI slave registers.
731 //!
732 //! Use this function to write any value in the range 0-15 bits aligned on a
733 //! half-word (byte) boundary. Fx. for writing the value 0b101 to bits 1 and 3 the
734 //! \c ui32Val = 0x000A and the \c ui32Mask = 0x000E. Bits 0 and 5-15 will not
735 //! be affected by the operation, as the corresponding bits are not set
736 //! in the \c ui32Mask.
737 //!
738 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
739 //! enabled before calling this function.
740 //!
741 //! \param ui32Base is the base address of the ADI port.
742 //! \param ui32Reg is the Least Significant Register in the ADI slave that
743 //! will be affected by the write operation.
744 //! \param ui32Mask is the mask defining which of the 16 bit that should be
745 //! overwritten. The mask must be defined in the lower half of the 32 bits.
746 //! \param ui32Val is the value to write. The value must be defined in the lower
747 //! half of the 32 bits.
748 //!
749 //! \return None
750 //!
751 //! \sa ADI4SetValBit(), ADI8SetValBit()
752 //
753 //*****************************************************************************
754 __STATIC_INLINE void
ADI16SetValBit(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Mask,uint32_t ui32Val)755 ADI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask,
756 uint32_t ui32Val)
757 {
758 uint32_t ui32RegOffset;
759
760 // Check the arguments.
761 ASSERT(ADIBaseValid(ui32Base));
762 ASSERT(ui32Reg < ADI_SLAVE_REGS);
763 ASSERT(!(ui32Val & 0xFFFF0000));
764 ASSERT(!(ui32Mask & 0xFFFF0000));
765
766 // Get the correct address of the first register used for setting bits
767 // in the ADI slave.
768 ui32RegOffset = ADI_O_MASK16B + ((ui32Reg << 1) & 0xFC);
769
770 // Set the selected bits.
771 HWREG(ui32Base + ui32RegOffset) = (ui32Mask << 16) | ui32Val;
772 }
773
774 //*****************************************************************************
775 //
776 // Mark the end of the C bindings section for C++ compilers.
777 //
778 //*****************************************************************************
779 #ifdef __cplusplus
780 }
781 #endif
782
783 #endif // __ADI_H__
784
785 //*****************************************************************************
786 //
787 //! Close the Doxygen group.
788 //! @}
789 //! @}
790 //
791 //*****************************************************************************
792