AM263x MCU+ SDK  09.02.00
dac/v0/dac.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
42 #ifndef DAC_V0_H_
43 #define DAC_V0_H_
44 
45 //*****************************************************************************
46 //
47 // If building with a C++ compiler, make all of the definitions in this header
48 // have a C binding.
49 //
50 //*****************************************************************************
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #endif
55 
56 //*****************************************************************************
57 //
59 //
60 //*****************************************************************************
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <drivers/hw_include/hw_types.h>
65 #include <drivers/hw_include/cslr_soc.h>
66 #include <kernel/dpl/DebugP.h>
67 #include <drivers/hw_include/cslr_dac.h>
68 
69 //*****************************************************************************
70 //
71 // The following are defines for the reg parameter of the
72 // DAC_lockRegister() and DAC_isRegisterLocked() functions.
73 //
74 //*****************************************************************************
75 #define DAC_LOCK_CONTROL (0x1U)
76 #define DAC_LOCK_SHADOW (0x2U)
77 #define DAC_LOCK_OUTPUT (0x4U)
78 
79 //*****************************************************************************
80 //
83 //
84 //*****************************************************************************
85 typedef enum
86 {
88  DAC_REF_VDDA = 1
90 
91 //*****************************************************************************
92 //
94 //
95 //*****************************************************************************
96 typedef enum
97 {
99  DAC_LOAD_PWMSYNC = 4
101 
102 //*****************************************************************************
103 //
104 // Defines used by the driver
105 //
106 //*****************************************************************************
107 #define DAC_REG_BYTE_MASK (0xFFU)
108 #define DAC_LOCK_KEY (0xA000U)
109 
110 //*****************************************************************************
111 //
112 // Prototypes for the APIs.
113 //
114 //*****************************************************************************
115 //*****************************************************************************
116 //
124 //
125 //*****************************************************************************
126 static inline uint16_t
127 DAC_getRevision(uint32_t base)
128 {
129  //
130  // Get the revision value.
131  //
132  return(HW_RD_REG16(base + CSL_DAC_DACREV) & CSL_DAC_DACREV_REV_MASK);
133 }
134 
135 //*****************************************************************************
136 //
149 //
150 //*****************************************************************************
151 static inline void
153 {
154  //
155  // Set the reference voltage
156  //
157  HW_WR_REG16(base + CSL_DAC_DACCTL,
158  ((HW_RD_REG16(base + CSL_DAC_DACCTL) &
159  ~CSL_DAC_DACCTL_DACREFSEL_MASK) | (uint16_t)source));
160 }
161 
162 //*****************************************************************************
163 //
176 //
177 //*****************************************************************************
178 static inline void
179 DAC_setLoadMode(uint32_t base, DAC_LoadMode mode)
180 {
181  //
182  // Set the load mode
183  //
184  HW_WR_REG16(base + CSL_DAC_DACCTL,
185  ((HW_RD_REG16(base + CSL_DAC_DACCTL) &
186  ~CSL_DAC_DACCTL_LOADMODE_MASK) | (uint16_t)mode));
187 }
188 
189 //*****************************************************************************
190 //
203 //
204 //*****************************************************************************
205 static inline void
206 DAC_setPWMSyncSignal(uint32_t base, uint16_t signal)
207 {
208  //
209  // Check the arguments.
210  //
211  DebugP_assert((signal > 0U) && (signal < 33U));
212 
213  //
214  // Set the PWM sync signal
215  //
216  HW_WR_REG16(base + CSL_DAC_DACCTL,
217  ((HW_RD_REG16(base + CSL_DAC_DACCTL) &
218  ~CSL_DAC_DACCTL_SYNCSEL_MASK) |
219  ((uint16_t)(signal - 1U) << CSL_DAC_DACCTL_SYNCSEL_SHIFT)));
220 }
221 
222 //*****************************************************************************
223 //
231 //
232 //*****************************************************************************
233 static inline uint16_t
234 DAC_getActiveValue(uint32_t base)
235 {
236  //
237  // Get the active value
238  //
239  return(HW_RD_REG16(base + CSL_DAC_DACVALA) & CSL_DAC_DACVALA_DACVALA_MASK);
240 }
241 
242 //*****************************************************************************
243 //
252 //
253 //*****************************************************************************
254 static inline void
255 DAC_setShadowValue(uint32_t base, uint16_t value)
256 {
257  //
258  // Check the arguments.
259  //
260  DebugP_assert(value <= CSL_DAC_DACVALS_DACVALS_MASK);
261 
262  //
263  // Set the shadow value
264  //
265  HW_WR_REG16(base + CSL_DAC_DACVALS,
266  ((HW_RD_REG16(base + CSL_DAC_DACVALS) &
267  ~CSL_DAC_DACVALS_DACVALS_MASK) |
268  (uint16_t)(value & CSL_DAC_DACVALS_DACVALS_MASK)));
269 }
270 
271 //*****************************************************************************
272 //
280 //
281 //*****************************************************************************
282 static inline uint16_t
283 DAC_getShadowValue(uint32_t base)
284 {
285  //
286  // Get the shadow value
287  //
288  return(HW_RD_REG16(base + CSL_DAC_DACVALS) & CSL_DAC_DACVALS_DACVALS_MASK);
289 }
290 
291 //*****************************************************************************
292 //
303 //
304 //*****************************************************************************
305 static inline void
306 DAC_enableOutput(uint32_t base)
307 {
308  //
309  // Enable the output
310  //
311  HW_WR_REG16(base + CSL_DAC_DACOUTEN,
312  HW_RD_REG16(base + CSL_DAC_DACOUTEN) | CSL_DAC_DACOUTEN_DACOUTEN_MASK);
313 }
314 
315 //*****************************************************************************
316 //
324 //
325 //*****************************************************************************
326 static inline void
327 DAC_disableOutput(uint32_t base)
328 {
329  //
330  // Disable the output
331  //
332  HW_WR_REG16(base + CSL_DAC_DACOUTEN,
333  HW_RD_REG16(base + CSL_DAC_DACOUTEN) &
334  ~CSL_DAC_DACOUTEN_DACOUTEN_MASK);
335 }
336 
337 //*****************************************************************************
338 //
352 //
353 //*****************************************************************************
354 static inline void
355 DAC_setOffsetTrim(uint32_t base, int16_t offset)
356 {
357  //
358  // Check the arguments.
359  //
360  DebugP_assert((offset > -129) && (offset < 128));
361 
362  //
363  // Set the offset trim value
364  //
365  HW_WR_REG16(base + CSL_DAC_DACTRIM,
366  ((HW_RD_REG16(base + CSL_DAC_DACTRIM) &
367  ~CSL_DAC_DACTRIM_OFFSET_TRIM_MASK) | (int16_t)offset));
368 }
369 
370 //*****************************************************************************
371 //
379 //
380 //*****************************************************************************
381 static inline int16_t
382 DAC_getOffsetTrim(uint32_t base)
383 {
384  uint16_t value;
385 
386  //
387  // Get the sign-extended offset trim value
388  //
389  value = (HW_RD_REG16(base + CSL_DAC_DACTRIM) &
390  CSL_DAC_DACTRIM_OFFSET_TRIM_MASK);
391  value = ((value & (uint16_t)DAC_REG_BYTE_MASK) ^ (uint16_t)0x80) -
392  (uint16_t)0x80;
393 
394  return((int16_t)value);
395 }
396 
397 //*****************************************************************************
398 //
414 //
415 //*****************************************************************************
416 static inline void
417 DAC_lockRegister(uint32_t base, uint16_t reg)
418 {
419  //
420  // Check the arguments.
421  //
423  DAC_LOCK_OUTPUT)) == 0U);
424 
425  //
426  // Lock the specified registers
427  //
428  HW_WR_REG16(base + CSL_DAC_DACLOCK,
429  HW_RD_REG16(base + CSL_DAC_DACLOCK) |
430  (CSL_DAC_DACLOCK_KEY_MASK | reg));
431 }
432 
433 //*****************************************************************************
434 //
451 //
452 //*****************************************************************************
453 static inline bool
454 DAC_isRegisterLocked(uint32_t base, uint16_t reg)
455 {
456  //
457  // Check the arguments.
458  //
460  DAC_LOCK_OUTPUT)) == 0U);
461 
462  //
463  // Return the lock status on the specified registers
464  //
465  return(((HW_RD_REG16(base + CSL_DAC_DACLOCK) & reg) != 0U));
466 }
467 
468 //*****************************************************************************
469 //
487 //
488 //*****************************************************************************
489 extern void
490 DAC_tuneOffsetTrim(uint32_t base, Float32 referenceVoltage);
491 
492 //*****************************************************************************
493 //
494 // Close the Doxygen group.
496 //
497 //*****************************************************************************
498 
499 //*****************************************************************************
500 //
501 // Mark the end of the C bindings section for C++ compilers.
502 //
503 //*****************************************************************************
504 #ifdef __cplusplus
505 }
506 #endif
507 
508 #endif // DAC_V0_H_
DAC_setReferenceVoltage
static void DAC_setReferenceVoltage(uint32_t base, DAC_ReferenceVoltage source)
Definition: dac/v0/dac.h:152
DAC_ReferenceVoltage
DAC_ReferenceVoltage
Definition: dac/v0/dac.h:86
DAC_setShadowValue
static void DAC_setShadowValue(uint32_t base, uint16_t value)
Definition: dac/v0/dac.h:255
DAC_setLoadMode
static void DAC_setLoadMode(uint32_t base, DAC_LoadMode mode)
Definition: dac/v0/dac.h:179
DAC_lockRegister
static void DAC_lockRegister(uint32_t base, uint16_t reg)
Definition: dac/v0/dac.h:417
DAC_REF_VDDA
@ DAC_REF_VDDA
VDDA reference voltage (internal)
Definition: dac/v0/dac.h:88
DAC_LOCK_OUTPUT
#define DAC_LOCK_OUTPUT
Lock the output enable register.
Definition: dac/v0/dac.h:77
DAC_LOCK_CONTROL
#define DAC_LOCK_CONTROL
Header Files.
Definition: dac/v0/dac.h:75
DAC_disableOutput
static void DAC_disableOutput(uint32_t base)
Definition: dac/v0/dac.h:327
DAC_setPWMSyncSignal
static void DAC_setPWMSyncSignal(uint32_t base, uint16_t signal)
Definition: dac/v0/dac.h:206
DAC_REG_BYTE_MASK
#define DAC_REG_BYTE_MASK
Register Byte Mask.
Definition: dac/v0/dac.h:107
DAC_LoadMode
DAC_LoadMode
Values that can be passed to DAC_setLoadMode() as the mode parameter.
Definition: dac/v0/dac.h:97
DAC_isRegisterLocked
static bool DAC_isRegisterLocked(uint32_t base, uint16_t reg)
Definition: dac/v0/dac.h:454
DAC_REF_VREF
@ DAC_REF_VREF
VREF reference voltage (external)
Definition: dac/v0/dac.h:87
DAC_setOffsetTrim
static void DAC_setOffsetTrim(uint32_t base, int16_t offset)
Definition: dac/v0/dac.h:355
DAC_getShadowValue
static uint16_t DAC_getShadowValue(uint32_t base)
Definition: dac/v0/dac.h:283
DAC_LOAD_PWMSYNC
@ DAC_LOAD_PWMSYNC
Load on next PWMSYNC specified by SYNCSEL.
Definition: dac/v0/dac.h:99
DAC_LOAD_SYSCLK
@ DAC_LOAD_SYSCLK
Load on next SYSCLK.
Definition: dac/v0/dac.h:98
DAC_LOCK_SHADOW
#define DAC_LOCK_SHADOW
Lock the shadow value register.
Definition: dac/v0/dac.h:76
DAC_getOffsetTrim
static int16_t DAC_getOffsetTrim(uint32_t base)
Definition: dac/v0/dac.h:382
DAC_getRevision
static uint16_t DAC_getRevision(uint32_t base)
Definition: dac/v0/dac.h:127
DAC_tuneOffsetTrim
void DAC_tuneOffsetTrim(uint32_t base, Float32 referenceVoltage)
DebugP.h
DAC_getActiveValue
static uint16_t DAC_getActiveValue(uint32_t base)
Definition: dac/v0/dac.h:234
DAC_enableOutput
static void DAC_enableOutput(uint32_t base)
Definition: dac/v0/dac.h:306
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:177