1 /******************************************************************************
2 *  Filename:       adi.h
3 *
4 *  Description:    Defines and prototypes for the ADI master interface.
5 *
6 *  Copyright (c) 2015 - 2022, Texas Instruments Incorporated
7 *  All rights reserved.
8 *
9 *  Redistribution and use in source and binary forms, with or without
10 *  modification, are permitted provided that the following conditions are met:
11 *
12 *  1) Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *
15 *  2) Redistributions in binary form must reproduce the above copyright notice,
16 *     this list of conditions and the following disclaimer in the documentation
17 *     and/or other materials provided with the distribution.
18 *
19 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 *     be used to endorse or promote products derived from this software without
21 *     specific prior written permission.
22 *
23 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 *  POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36 
37 //*****************************************************************************
38 //
39 //! \addtogroup analog_group
40 //! @{
41 //! \addtogroup adi_api
42 //! @{
43 //
44 //*****************************************************************************
45 
46 #ifndef __ADI_H__
47 #define __ADI_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include "../inc/hw_types.h"
63 #include "../inc/hw_uart.h"
64 #include "../inc/hw_memmap.h"
65 #include "../inc/hw_ints.h"
66 #include "../inc/hw_adi.h"
67 #include "debug.h"
68 #include "ddi.h"
69 
70 //*****************************************************************************
71 //
72 // Number of registers in the ADI slave
73 //
74 //*****************************************************************************
75 #define ADI_SLAVE_REGS      16
76 
77 
78 //*****************************************************************************
79 //
80 // Defines that is used to control the ADI slave and master
81 //
82 //*****************************************************************************
83 #define ADI_PROTECT         0x00000080
84 #define ADI_ACK             0x00000001
85 #define ADI_SYNC            0x00000000
86 
87 //*****************************************************************************
88 //
89 // API Functions and prototypes
90 //
91 //*****************************************************************************
92 
93 #ifdef DRIVERLIB_DEBUG
94 //*****************************************************************************
95 //
96 //! \internal
97 //! \brief Checks an ADI base address.
98 //!
99 //! This function determines if an ADI port base address is valid.
100 //!
101 //! \param ui32Base is the base address of the ADI port.
102 //!
103 //! \return Returns \c true if the base address is valid and \c false
104 //! otherwise
105 //
106 //*****************************************************************************
107 static bool
ADIBaseValid(uint32_t ui32Base)108 ADIBaseValid(uint32_t ui32Base)
109 {
110     return(ui32Base == ADI2_BASE || ui32Base == ADI3_BASE ||
111            ui32Base == AUX_ADI4_BASE);
112 }
113 #endif
114 
115 
116 
117 
118 
119 //*****************************************************************************
120 //
121 //! \brief Write an 8 bit value to a register in an ADI slave.
122 //!
123 //! This function will write a value to a single register in the analog domain.
124 //! The access to the registers in the analog domain is either 8, 16, or 32 bit
125 //! aligned. You can only do 16 bit access on registers 0-1 / 2-3, etc. Similarly
126 //! 32 bit accesses are always performed on register 0-3 / 4-7, etc. Addresses
127 //! for the registers and values being written to the registers will be
128 //! truncated according to this access scheme.
129 //!
130 //! \note This operation is write only for the specified register. No
131 //! previous value of the register will be kept (i.e. this is NOT
132 //! read-modify-write on the register).
133 //!
134 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
135 //! enabled before calling this function.
136 //!
137 //! \param ui32Base is ADI base address.
138 //! \param ui32Reg is the register to write.
139 //! \param ui8Val is the 8 bit value to write to the register.
140 //!
141 //! \return None
142 //!
143 //! \sa ADI16RegWrite(), ADI32RegWrite()
144 //
145 //*****************************************************************************
146 __STATIC_INLINE void
ADI8RegWrite(uint32_t ui32Base,uint32_t ui32Reg,uint8_t ui8Val)147 ADI8RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
148 {
149     // Check the arguments.
150     ASSERT(ADIBaseValid(ui32Base));
151     ASSERT(ui32Reg < ADI_SLAVE_REGS);
152 
153     // Write the value to the register.
154     HWREGB(ui32Base + ui32Reg) = ui8Val;
155 }
156 
157 //*****************************************************************************
158 //
159 //! \brief Write a 16 bit value to 2 registers in the ADI slave.
160 //!
161 //! This function will write a value to 2 consecutive registers in the analog
162 //! domain. The access to the registers in the analog domain is either 8, 16
163 //! or 32 bit aligned. You can only do 16 bit access on registers 0-1 / 2-3,
164 //! etc. Similarly 32 bit accesses are always performed on register 0-3 / 4-7,
165 //! etc. Addresses for the registers and values being written
166 //! to the registers will be truncated according to this access scheme.
167 //!
168 //! \note The byte addressing bit will be ignored, to ensure 16 bit access
169 //! to the ADI slave.
170 //!
171 //! \note This operation is write only for the specified register. No
172 //! previous value of the register will be kept (i.e. this is NOT
173 //! read-modify-write on the register).
174 //!
175 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
176 //! enabled before calling this function.
177 //!
178 //! \param ui32Base is ADI base address.
179 //! \param ui32Reg is the register to write.
180 //! \param ui16Val is the 16 bit value to write to the register.
181 //!
182 //! \return None
183 //!
184 //! \sa ADI8RegWrite(), ADI32RegWrite()
185 //
186 //*****************************************************************************
187 __STATIC_INLINE void
ADI16RegWrite(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Val)188 ADI16RegWrite(uint32_t ui32Base, uint32_t ui32Reg,
189               uint16_t ui16Val)
190 {
191     // Check the arguments.
192     ASSERT(ADIBaseValid(ui32Base));
193     ASSERT(ui32Reg < ADI_SLAVE_REGS);
194 
195     // Write the value to the register.
196     HWREGH(ui32Base + (ui32Reg & 0xFE)) = ui16Val;
197 }
198 
199 //*****************************************************************************
200 //
201 //! \brief Write a 32 bit value to 4 registers in the ADI slave.
202 //!
203 //! This function will write a value to 4 consecutive registers in the analog
204 //! domain. The access to the registers in the analog domain is either 8, 16
205 //! or 32 bit aligned. You can only do 16 bit access on registers 0-1 / 2-3,
206 //! etc. Similarly 32 bit accesses are always performed on register 0-3 / 4-7,
207 //! etc. Addresses for the registers and values being written
208 //! to the registers will be truncated according to this access scheme.
209 //!
210 //! \note The byte and half word addressing bits will be ignored, to ensure
211 //! 32 bit access to the ADI slave.
212 //!
213 //! \note This operation is write only for the specified register. No
214 //! previous value of the register will be kept (i.e. this is NOT
215 //! read-modify-write on the register).
216 //!
217 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
218 //! enabled before calling this function.
219 //!
220 //! \param ui32Base is ADI base address.
221 //! \param ui32Reg is the register to write.
222 //! \param ui32Val is the 32 bit value to write to the register.
223 //!
224 //! \return None
225 //!
226 //! \sa ADI8RegWrite(), ADI16RegWrite()
227 //
228 //*****************************************************************************
229 __STATIC_INLINE void
ADI32RegWrite(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Val)230 ADI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
231 {
232     // Check the arguments.
233     ASSERT(ADIBaseValid(ui32Base));
234     ASSERT(ui32Reg < ADI_SLAVE_REGS);
235 
236     // Write the value to the register.
237     HWREG(ui32Base + (ui32Reg & 0xFC)) = ui32Val;
238 }
239 
240 //*****************************************************************************
241 //
242 //! \brief Read the value of an 8 bit register in the ADI slave.
243 //!
244 //! This function will read an 8 bit register in the analog domain and return
245 //! the value as the lower 8 bits of an \c uint32_t. The access to the
246 //! registers in the analog domain is either 8, 16 or 32 bit aligned. You can
247 //! only do 16 bit access on registers 0-1 / 2-3, etc. Similarly 32 bit accesses
248 //! are always performed on register 0-3 / 4-7, etc. Addresses for the
249 //! registers and values being written to the registers will be truncated
250 //! according to this access scheme.
251 //!
252 //! \param ui32Base is ADI base address.
253 //! \param ui32Reg is the 8 bit register to read.
254 //!
255 //! \return Returns the 8 bit value of the analog register in the least
256 //! significant byte of the \c uint32_t.
257 //!
258 //! \sa ADI16RegRead(), ADI32RegRead()
259 //
260 //*****************************************************************************
261 __STATIC_INLINE uint32_t
ADI8RegRead(uint32_t ui32Base,uint32_t ui32Reg)262 ADI8RegRead(uint32_t ui32Base, uint32_t ui32Reg)
263 {
264     // Check the arguments.
265     ASSERT(ADIBaseValid(ui32Base));
266     ASSERT(ui32Reg < ADI_SLAVE_REGS);
267 
268     // Read the register and return the value.
269     return(HWREGB(ui32Base + ui32Reg));
270 }
271 
272 //*****************************************************************************
273 //
274 //! \brief Read the value in a 16 bit register.
275 //!
276 //! This function will read 2 x 8 bit registers in the analog domain and return
277 //! the value as the lower 16 bits of an \c uint32_t. The access to the
278 //! registers in the analog domain is either 8, 16 or 32 bit aligned. You can
279 //! only do 16 bit access on registers 0-1 / 2-3, etc. Similarly 32 bit accesses
280 //! are always performed on register 0-3 / 4-7, etc. Addresses for the
281 //! registers and values being written to the registers will be truncated
282 //! according to this access scheme.
283 //!
284 //! \note The byte addressing bit will be ignored, to ensure 16 bit access
285 //! to the ADI slave.
286 //!
287 //! \param ui32Base is ADI base address.
288 //! \param ui32Reg is the 16 bit register to read.
289 //!
290 //! \return Returns the 16 bit value of the 2 analog register in the 2 least
291 //! significant bytes of the \c uint32_t.
292 //!
293 //! \sa ADI8RegRead(), ADI32RegRead()
294 //
295 //*****************************************************************************
296 __STATIC_INLINE uint32_t
ADI16RegRead(uint32_t ui32Base,uint32_t ui32Reg)297 ADI16RegRead(uint32_t ui32Base, uint32_t ui32Reg)
298 {
299     // Check the arguments.
300     ASSERT(ADIBaseValid(ui32Base));
301     ASSERT(ui32Reg < ADI_SLAVE_REGS);
302 
303     // Read the registers and return the value.
304     return(HWREGH(ui32Base + (ui32Reg & 0xFE)));
305 }
306 
307 //*****************************************************************************
308 //
309 //! \brief Read the value in a 32 bit register.
310 //!
311 //! This function will read 4 x 8 bit registers in the analog domain and return
312 //! the value as an \c uint32_t. The access to the registers in the analog
313 //! domain is either 8, 16 or 32 bit aligned. You can only do 16 bit access on
314 //! registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always performed on
315 //! register 0-3 / 4-7, etc. Addresses for the registers and values being
316 //! written to the registers will be truncated according to this access scheme.
317 //!
318 //! \note The byte and half word addressing bits will be ignored, to ensure
319 //! 32 bit access to the ADI slave.
320 //!
321 //! \param ui32Base is ADI base address.
322 //! \param ui32Reg is the 32 bit register to read.
323 //!
324 //! \return Returns the 32 bit value of the 4 analog registers.
325 //!
326 //! \sa ADI8RegRead(), ADI16RegRead()
327 //
328 //*****************************************************************************
329 __STATIC_INLINE uint32_t
ADI32RegRead(uint32_t ui32Base,uint32_t ui32Reg)330 ADI32RegRead(uint32_t ui32Base, uint32_t ui32Reg)
331 {
332     // Check the arguments.
333     ASSERT(ADIBaseValid(ui32Base));
334     ASSERT(ui32Reg < ADI_SLAVE_REGS);
335 
336     // Read the registers and return the value.
337     return(HWREG(ui32Base + (ui32Reg & 0xFC)));
338 }
339 
340 //*****************************************************************************
341 //
342 //! \brief Set specific bits in a single 8 bit ADI register.
343 //!
344 //! This function will set bits in a single register in the analog domain.
345 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
346 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
347 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
348 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
349 //! being written to the registers will be truncated according to this access
350 //! scheme.
351 //!
352 //! \note This operation is write only for the specified register.
353 //! This function is used to set bits in a specific 8 bit register in the
354 //! ADI slave. Only bits in the selected register are affected by the
355 //! operation.
356 //!
357 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
358 //! enabled before calling this function.
359 //!
360 //! \param ui32Base is ADI base address.
361 //! \param ui32Reg is the base register to assert the bits in.
362 //! \param ui8Val is the 8 bit one-hot encoded value specifying which
363 //! bits to set in the register.
364 //!
365 //! \return None
366 //!
367 //! \sa ADI16BitsSet(), ADI32BitsSet()
368 //
369 //*****************************************************************************
370 __STATIC_INLINE void
ADI8BitsSet(uint32_t ui32Base,uint32_t ui32Reg,uint8_t ui8Val)371 ADI8BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
372 {
373     uint32_t ui32RegOffset;
374 
375     // Check the arguments.
376     ASSERT(ADIBaseValid(ui32Base));
377     ASSERT(ui32Reg < ADI_SLAVE_REGS);
378 
379     // Get the correct address of the first register used for setting bits
380     // in the ADI slave.
381     ui32RegOffset = ADI_O_SET;
382 
383     // Set the selected bits.
384     HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
385 }
386 
387 //*****************************************************************************
388 //
389 //! \brief Set specific bits in 2 x 8 bit ADI slave registers.
390 //!
391 //! This function will set bits in 2 registers in the analog domain.
392 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
393 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
394 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
395 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
396 //! being written to the registers will be truncated according to this access
397 //! scheme.
398 //!
399 //! \note This operation is write only for the specified register.
400 //! This function is used to set bits in 2 consecutive 8 bit registers in the
401 //! ADI slave. Only bits in the selected registers are affected by the
402 //! operation.
403 //!
404 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
405 //! enabled before calling this function.
406 //!
407 //! \param ui32Base is ADI base address.
408 //! \param ui32Reg is the base register to assert the bits in.
409 //! \param ui16Val is the 16 bit one-hot encoded value specifying which
410 //! bits to set in the registers.
411 //!
412 //! \return None
413 //!
414 //! \sa ADI8BitsSet(), ADI32BitsSet()
415 //
416 //*****************************************************************************
417 __STATIC_INLINE void
ADI16BitsSet(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Val)418 ADI16BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
419 {
420     uint32_t ui32RegOffset;
421 
422     // Check the arguments.
423     ASSERT(ADIBaseValid(ui32Base));
424     ASSERT(ui32Reg < ADI_SLAVE_REGS);
425 
426     // Get the correct address of the first register used for setting bits
427     // in the ADI slave.
428     ui32RegOffset = ADI_O_SET;
429 
430     // Set the selected bits.
431     HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
432 }
433 
434 //*****************************************************************************
435 //
436 //! \brief Set specific bits in 4 x 8 bit ADI slave registers.
437 //!
438 //! This function will set bits in 4 registers in the analog domain.
439 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
440 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
441 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
442 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
443 //! being written to the registers will be truncated according to this access
444 //! scheme.
445 //!
446 //! \note This operation is write only for the specified register.
447 //! This function is used to set bits in 4 consecutive 8 bit registers in the
448 //! ADI slave. Only bits in the selected registers are affected by the
449 //! operation.
450 //!
451 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
452 //! enabled before calling this function.
453 //!
454 //! \param ui32Base is ADI base address.
455 //! \param ui32Reg is the base register to assert the bits in.
456 //! \param ui32Val is the 32 bit one-hot encoded value specifying which
457 //! bits to set in the registers.
458 //!
459 //! \return None
460 //!
461 //! \sa ADI8BitsSet(), ADI16BitsSet()
462 //
463 //*****************************************************************************
464 __STATIC_INLINE void
ADI32BitsSet(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Val)465 ADI32BitsSet(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
466 {
467     uint32_t ui32RegOffset;
468 
469     // Check the arguments.
470     ASSERT(ADIBaseValid(ui32Base));
471     ASSERT(ui32Reg < ADI_SLAVE_REGS);
472 
473     // Get the correct address of the first register used for setting bits
474     // in the ADI slave.
475     ui32RegOffset = ADI_O_SET;
476 
477     // Set the selected bits.
478     HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
479 }
480 
481 //*****************************************************************************
482 //
483 //! \brief Clear specific bits in an 8 bit ADI register.
484 //!
485 //! This function will clear bits in a register in the analog domain.
486 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
487 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
488 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
489 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
490 //! being written to the registers will be truncated according to this access
491 //! scheme.
492 //!
493 //! \note This operation is write only for the specified register.
494 //! This function is used to clear bits in a specific 8 bit register in
495 //! the ADI slave. Only bits in the selected register are affected by the
496 //! operation.
497 //!
498 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
499 //! enabled before calling this function.
500 //!
501 //! \param ui32Base is ADI base address.
502 //! \param ui32Reg is the base registers to clear the bits in.
503 //! \param ui8Val is the 8 bit one-hot encoded value specifying which
504 //! bits to clear in the register.
505 //!
506 //! \return None
507 //!
508 //! \sa ADI16BitsClear(), ADI32BitsClear()
509 //
510 //*****************************************************************************
511 __STATIC_INLINE void
ADI8BitsClear(uint32_t ui32Base,uint32_t ui32Reg,uint8_t ui8Val)512 ADI8BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint8_t ui8Val)
513 {
514     uint32_t ui32RegOffset;
515 
516     // Check the arguments.
517     ASSERT(ADIBaseValid(ui32Base));
518     ASSERT(ui32Reg < ADI_SLAVE_REGS);
519 
520     // Get the correct address of the first register used for setting bits
521     // in the ADI slave.
522     ui32RegOffset = ADI_O_CLR;
523 
524     // Set the selected bits.
525     HWREGB(ui32Base + ui32RegOffset + ui32Reg) = ui8Val;
526 }
527 
528 //*****************************************************************************
529 //
530 //! \brief Clear specific bits in two 8 bit ADI register.
531 //!
532 //! This function will clear bits in 2 registers in the analog domain.
533 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
534 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
535 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
536 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
537 //! being written to the registers will be truncated according to this access
538 //! scheme.
539 //!
540 //! \note This operation is write only for the specified register.
541 //! This function is used to clear bits in 2 consecutive 8 bit registers in
542 //! the ADI slave. Only bits in the selected registers are affected by the
543 //! operation.
544 //!
545 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
546 //! enabled before calling this function.
547 //!
548 //! \param ui32Base is ADI base address.
549 //! \param ui32Reg is the base registers to clear the bits in.
550 //! \param ui16Val is the 16 bit one-hot encoded value specifying which
551 //! bits to clear in the registers.
552 //!
553 //! \return None
554 //!
555 //! \sa ADI8BitsClear(), ADI32BitsClear()
556 //
557 //*****************************************************************************
558 __STATIC_INLINE void
ADI16BitsClear(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Val)559 ADI16BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Val)
560 {
561     uint32_t ui32RegOffset;
562 
563     // Check the arguments.
564     ASSERT(ADIBaseValid(ui32Base));
565     ASSERT(ui32Reg < ADI_SLAVE_REGS);
566 
567     // Get the correct address of the first register used for setting bits
568     // in the ADI slave.
569     ui32RegOffset = ADI_O_CLR;
570 
571     // Set the selected bits.
572     HWREGH(ui32Base + ui32RegOffset + (ui32Reg & 0xFE)) = ui16Val;
573 }
574 
575 //*****************************************************************************
576 //
577 //! \brief Clear specific bits in four 8 bit ADI register.
578 //!
579 //! This function will clear bits in 4 registers in the analog domain.
580 //! The access to the registers in the analog domain is either 8, 16 or 32 bit
581 //! aligned, but arranged in chunks of 32 bits. You can only do 16 bit access
582 //! on registers 0-1 / 2-3, etc. Similarly 32 bit accesses are always
583 //! performed on register 0-3 / 4-7 etc. Addresses for the registers and values
584 //! being written to the registers will be truncated according to this access
585 //! scheme.
586 //!
587 //! \note This operation is write only for the specified register.
588 //! This function is used to clear bits in 4 consecutive 8 bit registers in
589 //! the ADI slave. Only bits in the selected registers are affected by the
590 //! operation.
591 //!
592 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
593 //! enabled before calling this function.
594 //!
595 //! \param ui32Base is ADI base address.
596 //! \param ui32Reg is the base registers to clear the bits in.
597 //! \param ui32Val is the 32 bit one-hot encoded value specifying which
598 //! bits to clear in the registers.
599 //!
600 //! \return None
601 //!
602 //! \sa ADI8BitsClear(), ADI16BitsClear()
603 //
604 //*****************************************************************************
605 __STATIC_INLINE void
ADI32BitsClear(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Val)606 ADI32BitsClear(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
607 {
608     uint32_t ui32RegOffset;
609 
610     // Check the arguments.
611     ASSERT(ADIBaseValid(ui32Base));
612     ASSERT(ui32Reg < ADI_SLAVE_REGS);
613 
614     // Get the correct address of the first register used for setting bits
615     // in the ADI slave.
616     ui32RegOffset = ADI_O_CLR;
617 
618     // Set the selected bits.
619     HWREG(ui32Base + ui32RegOffset + (ui32Reg & 0xFC)) = ui32Val;
620 }
621 
622 //*****************************************************************************
623 //
624 //! \brief Set a value on any 4 bits inside an 8 bit register in the ADI slave.
625 //!
626 //! This function allows halfbyte (4 bit) access to the ADI slave registers.
627 //! The parameter \c bWriteHigh determines whether to write to the lower
628 //! or higher part of the 8 bit register.
629 //!
630 //! Use this function to write any value in the range 0-3 bits aligned on a
631 //! half byte boundary. Fx. for writing the value 0b101 to bits 1 to 3 the
632 //! \c ui8Val = 0xA and the \c ui8Mask = 0xE. Bit 0 will not be affected by
633 //! the operation, as the corresponding bit is not set in the \c ui8Mask.
634 //!
635 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
636 //! enabled before calling this function.
637 //!
638 //! \param ui32Base is the base address of the ADI port.
639 //! \param ui32Reg is the Least Significant Register in the ADI slave that
640 //! will be affected by the write operation.
641 //! \param bWriteHigh defines which part of the register to write in.
642 //! - \c true: Write upper half byte of register.
643 //! - \c false: Write lower half byte of register.
644 //! \param ui8Mask is the mask defining which of the 4 bits that should be
645 //! overwritten. The mask must be defined in the lower half of the 8 bits of
646 //! the parameter.
647 //! \param ui8Val is the value to write. The value must be defined in the lower
648 //! half of the 8 bits of the parameter.
649 //!
650 //! \return None
651 //!
652 //! \sa ADI8SetValBit(), ADI16SetValBit
653 //
654 //*****************************************************************************
655 __STATIC_INLINE void
ADI4SetValBit(uint32_t ui32Base,uint32_t ui32Reg,bool bWriteHigh,uint8_t ui8Mask,uint8_t ui8Val)656 ADI4SetValBit(uint32_t ui32Base, uint32_t ui32Reg, bool bWriteHigh,
657               uint8_t ui8Mask, uint8_t ui8Val)
658 {
659     uint32_t ui32RegOffset;
660 
661     // Check the arguments.
662     ASSERT(ADIBaseValid(ui32Base));
663     ASSERT(ui32Reg < ADI_SLAVE_REGS);
664     ASSERT(!(ui8Val & 0xF0));
665     ASSERT(!(ui8Mask & 0xF0));
666 
667     // Get the correct address of the first register used for setting bits
668     // in the ADI slave.
669     ui32RegOffset = ADI_O_MASK4B + (ui32Reg << 1) + (bWriteHigh ? 1 : 0);
670 
671     // Set the selected bits.
672     HWREGB(ui32Base + ui32RegOffset) = (ui8Mask << 4) | ui8Val;
673 }
674 
675 //*****************************************************************************
676 //
677 //! \brief Set a value on any bits inside an 8 bit register in the ADI slave.
678 //!
679 //! This function allows byte (8 bit) access to the ADI slave registers.
680 //!
681 //! Use this function to write any value in the range 0-7 bits aligned on a
682 //! byte boundary. Fx. for writing the value 0b101 to bits 1 and 3 the
683 //! \c ui16Val = 0x0A and the \c ui16Mask = 0x0E. Bits 0 and 5-7 will not be affected
684 //! by the operation, as the corresponding bits are not set in the
685 //! \c ui16Mask.
686 //!
687 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
688 //! enabled before calling this function.
689 //!
690 //! \param ui32Base is the base address of the ADI port.
691 //! \param ui32Reg is the Least Significant Register in the ADI slave that
692 //! will be affected by the write operation.
693 //! \param ui16Mask is the mask defining which of the 8 bit that should be
694 //! overwritten. The mask must be defined in the lower half of the 16 bits.
695 //! \param ui16Val is the value to write. The value must be defined in the lower
696 //! half of the 16 bits.
697 //!
698 //! \return None
699 //!
700 //! \sa ADI4SetValBit(), ADI16SetValBit()
701 //
702 //*****************************************************************************
703 __STATIC_INLINE void
ADI8SetValBit(uint32_t ui32Base,uint32_t ui32Reg,uint16_t ui16Mask,uint16_t ui16Val)704 ADI8SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint16_t ui16Mask,
705               uint16_t ui16Val)
706 {
707     uint32_t ui32RegOffset;
708 
709     // Check the arguments.
710     ASSERT(ADIBaseValid(ui32Base));
711     ASSERT(ui32Reg < ADI_SLAVE_REGS);
712     ASSERT(!(ui16Val & 0xFF00));
713     ASSERT(!(ui16Mask & 0xFF00));
714 
715     // Get the correct address of the first register used for setting bits
716     // in the ADI slave.
717     ui32RegOffset = ADI_O_MASK8B + (ui32Reg << 1);
718 
719     // Set the selected bits.
720     HWREGH(ui32Base + ui32RegOffset) = (ui16Mask << 8) | ui16Val;
721 }
722 
723 //*****************************************************************************
724 //
725 //! \brief Set a value on any bits inside an 2 x 8 bit register aligned on a
726 //! half-word (byte) boundary in the ADI slave.
727 //!
728 //! This function allows 2 byte (16 bit) access to the ADI slave registers.
729 //!
730 //! Use this function to write any value in the range 0-15 bits aligned on a
731 //! half-word (byte) boundary. Fx. for writing the value 0b101 to bits 1 and 3 the
732 //! \c ui32Val = 0x000A and the \c ui32Mask = 0x000E. Bits 0 and 5-15 will not
733 //! be affected by the operation, as the corresponding bits are not set
734 //! in the \c ui32Mask.
735 //!
736 //! \note AUX_ADI4_BASE : Both the AUX module and the clock for the AUX SMPH module must be
737 //! enabled before calling this function.
738 //!
739 //! \param ui32Base is the base address of the ADI port.
740 //! \param ui32Reg is the Least Significant Register in the ADI slave that
741 //! will be affected by the write operation.
742 //! \param ui32Mask is the mask defining which of the 16 bit that should be
743 //! overwritten. The mask must be defined in the lower half of the 32 bits.
744 //! \param ui32Val is the value to write. The value must be defined in the lower
745 //! half of the 32 bits.
746 //!
747 //! \return None
748 //!
749 //! \sa ADI4SetValBit(), ADI8SetValBit()
750 //
751 //*****************************************************************************
752 __STATIC_INLINE void
ADI16SetValBit(uint32_t ui32Base,uint32_t ui32Reg,uint32_t ui32Mask,uint32_t ui32Val)753 ADI16SetValBit(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask,
754                uint32_t ui32Val)
755 {
756     uint32_t ui32RegOffset;
757 
758     // Check the arguments.
759     ASSERT(ADIBaseValid(ui32Base));
760     ASSERT(ui32Reg < ADI_SLAVE_REGS);
761     ASSERT(!(ui32Val & 0xFFFF0000));
762     ASSERT(!(ui32Mask & 0xFFFF0000));
763 
764     // Get the correct address of the first register used for setting bits
765     // in the ADI slave.
766     ui32RegOffset = ADI_O_MASK16B + ((ui32Reg << 1) & 0xFC);
767 
768     // Set the selected bits.
769     HWREG(ui32Base + ui32RegOffset) = (ui32Mask << 16) | ui32Val;
770 }
771 
772 //*****************************************************************************
773 //
774 // Mark the end of the C bindings section for C++ compilers.
775 //
776 //*****************************************************************************
777 #ifdef __cplusplus
778 }
779 #endif
780 
781 #endif //  __ADI_H__
782 
783 //*****************************************************************************
784 //
785 //! Close the Doxygen group.
786 //! @}
787 //! @}
788 //
789 //*****************************************************************************
790