CC23x0R5DriverLibrary
adc.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: adc.h
3  *
4  * Description: Prototypes and defines for the ADC API.
5  *
6  * Copyright (c) 2022 Texas Instruments Incorporated
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1) Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2) Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3) Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ******************************************************************************/
35 
36 #ifndef __ADC_H__
37 #define __ADC_H__
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #include <stdint.h>
49 #include "../inc/hw_adc.h"
50 #include "../inc/hw_fcfg.h"
51 #include "../inc/hw_memmap.h"
52 #include "../inc/hw_sys0.h"
53 #include "../inc/hw_types.h"
54 
55 //*****************************************************************************
56 //
57 // If building with a C++ compiler, make all of the definitions in this header
58 // have a C binding.
59 //
60 //*****************************************************************************
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 //*****************************************************************************
66 //
67 // Values
68 //
69 //*****************************************************************************
70 
72 #define ADC_CLOCK_DIVIDER_1 ADC_CTL0_SCLKDIV_DIV_BY_1
73 
75 #define ADC_CLOCK_DIVIDER_2 ADC_CTL0_SCLKDIV_DIV_BY_2
76 
78 #define ADC_CLOCK_DIVIDER_4 ADC_CTL0_SCLKDIV_DIV_BY_4
79 
81 #define ADC_CLOCK_DIVIDER_8 ADC_CTL0_SCLKDIV_DIV_BY_8
82 
84 #define ADC_CLOCK_DIVIDER_16 ADC_CTL0_SCLKDIV_DIV_BY_16
85 
87 #define ADC_CLOCK_DIVIDER_24 ADC_CTL0_SCLKDIV_DIV_BY_24
88 
90 #define ADC_CLOCK_DIVIDER_32 ADC_CTL0_SCLKDIV_DIV_BY_32
91 
93 #define ADC_CLOCK_DIVIDER_48 ADC_CTL0_SCLKDIV_DIV_BY_48
94 
96 #define ADC_RESOLUTION_12_BIT ADC_CTL2_RES_BIT_12
97 
99 #define ADC_RESOLUTION_10_BIT ADC_CTL2_RES_BIT_10
100 
102 #define ADC_RESOLUTION_8_BIT ADC_CTL2_RES_BIT_8
103 
105 #define ADC_FIXED_REFERENCE_1V4 0
106 
108 #define ADC_FIXED_REFERENCE_2V5 1
109 
111 #define ADC_EXTERNAL_REFERENCE 2
112 
114 #define ADC_VDDS_REFERENCE 3
115 
118 #define ADC_SEQUENCE_REPEATSEQUENCE ADC_CTL1_CONSEQ_REPEATSEQUENCE
119 
121 #define ADC_SEQUENCE_REPEATSINGLE ADC_CTL1_CONSEQ_REPEATSINGLE
122 
125 #define ADC_SEQUENCE_SEQUENCE ADC_CTL1_CONSEQ_SEQUENCE
126 
129 #define ADC_SEQUENCE_SINGLE ADC_CTL1_CONSEQ_SINGLE
130 
132 #define ADC_INT_MEMRES_23 ADC_IMASK0_MEMRESIFG23
133 
135 #define ADC_INT_MEMRES_22 ADC_IMASK0_MEMRESIFG22
136 
138 #define ADC_INT_MEMRES_21 ADC_IMASK0_MEMRESIFG21
139 
141 #define ADC_INT_MEMRES_20 ADC_IMASK0_MEMRESIFG20
142 
144 #define ADC_INT_MEMRES_19 ADC_IMASK0_MEMRESIFG19
145 
147 #define ADC_INT_MEMRES_18 ADC_IMASK0_MEMRESIFG18
148 
150 #define ADC_INT_MEMRES_17 ADC_IMASK0_MEMRESIFG17
151 
153 #define ADC_INT_MEMRES_16 ADC_IMASK0_MEMRESIFG16
154 
156 #define ADC_INT_MEMRES_15 ADC_IMASK0_MEMRESIFG15
157 
159 #define ADC_INT_MEMRES_14 ADC_IMASK0_MEMRESIFG14
160 
162 #define ADC_INT_MEMRES_13 ADC_IMASK0_MEMRESIFG13
163 
165 #define ADC_INT_MEMRES_12 ADC_IMASK0_MEMRESIFG12
166 
168 #define ADC_INT_MEMRES_11 ADC_IMASK0_MEMRESIFG11
169 
171 #define ADC_INT_MEMRES_10 ADC_IMASK0_MEMRESIFG10
172 
174 #define ADC_INT_MEMRES_09 ADC_IMASK0_MEMRESIFG9
175 
177 #define ADC_INT_MEMRES_08 ADC_IMASK0_MEMRESIFG8
178 
180 #define ADC_INT_MEMRES_07 ADC_IMASK0_MEMRESIFG7
181 
183 #define ADC_INT_MEMRES_06 ADC_IMASK0_MEMRESIFG6
184 
186 #define ADC_INT_MEMRES_05 ADC_IMASK0_MEMRESIFG5
187 
189 #define ADC_INT_MEMRES_04 ADC_IMASK0_MEMRESIFG4
190 
192 #define ADC_INT_MEMRES_03 ADC_IMASK0_MEMRESIFG3
193 
195 #define ADC_INT_MEMRES_02 ADC_IMASK0_MEMRESIFG2
196 
198 #define ADC_INT_MEMRES_01 ADC_IMASK0_MEMRESIFG1
199 
201 #define ADC_INT_MEMRES_00 ADC_IMASK0_MEMRESIFG0
202 
204 #define ADC_INT_ASCDONE ADC_IMASK0_ASCDONE
205 
207 #define ADC_INT_UVIFG ADC_IMASK0_UVIFG
208 
210 #define ADC_INT_DMADONE ADC_IMASK0_DMADONE
211 
213 #define ADC_INT_INIFG ADC_IMASK0_INIFG
214 
216 #define ADC_INT_LOWIFG ADC_IMASK0_LOWIFG
217 
219 #define ADC_INT_HIGHIFG ADC_IMASK0_HIGHIFG
220 
222 #define ADC_INT_TOVIFG ADC_IMASK0_TOVIFG
223 
225 #define ADC_INT_OVIFG ADC_IMASK0_OVIFG
226 
227 //*****************************************************************************
228 //
229 // API Functions and prototypes
230 //
231 //*****************************************************************************
232 
233 //*****************************************************************************
234 //
263 //
264 //*****************************************************************************
265 extern void ADCSetSampleDuration(uint32_t clkDiv, uint16_t clkCycles);
266 
267 //*****************************************************************************
268 //
285 //
286 //*****************************************************************************
287 extern void ADCSetResolution(uint32_t resolution);
288 
289 //*****************************************************************************
290 //
308 //
309 //*****************************************************************************
310 extern void ADCSetInput(uint32_t reference, uint8_t channel, uint32_t index);
311 
312 //*****************************************************************************
313 //
324 //
325 //*****************************************************************************
326 extern void ADCSetMemctlRange(uint32_t start, uint32_t stop);
327 
328 //*****************************************************************************
329 //
343 //
344 //*****************************************************************************
345 extern void ADCSetSequence(uint32_t sequence);
346 
347 //*****************************************************************************
348 //
359 //
360 //*****************************************************************************
361 extern void ADCManualTrigger(void);
362 
363 //*****************************************************************************
364 //
374 //
375 //*****************************************************************************
376 __STATIC_INLINE uint32_t ADCReadResult(uint32_t index)
377 {
378 
380 
381  /* Return data from result register */
382  return HWREG(ADC_BASE + ADC_O_MEMRES0 + (4 * index));
383 }
384 
385 //*****************************************************************************
386 //
397 //
398 //*****************************************************************************
400 {
401 
403  {
404  return true;
405  }
406  else
407  {
408  return false;
409  }
410 }
411 
412 //*****************************************************************************
413 //
422 //
423 //*****************************************************************************
425 {
426  /* Return data from result register */
427  return HWREG(ADC_BASE + ADC_O_MEMRES0 + (4 * index));
428 }
429 
430 //*****************************************************************************
431 //
442 //
443 //*****************************************************************************
444 extern uint32_t ADCValueToMicrovolts(uint32_t adcCode, uint32_t bitResolution, uint32_t referenceVoltageMicroVolt);
445 
446 //*****************************************************************************
447 //
465 //
466 //*****************************************************************************
467 __STATIC_INLINE void ADCEnableInterrupt(uint32_t intFlags)
468 {
469  // Enable the specified interrupts.
470  HWREG(ADC_BASE + ADC_O_IMASK0) |= intFlags;
471 }
472 
473 //*****************************************************************************
474 //
492 //
493 //*****************************************************************************
494 __STATIC_INLINE void ADCDisableInterrupt(uint32_t intFlags)
495 {
496  // Disable the specified interrupts.
497  HWREG(ADC_BASE + ADC_O_IMASK0) &= ~(intFlags);
498 }
499 
500 //*****************************************************************************
501 //
516 //
517 //*****************************************************************************
519 {
520  return (HWREG(ADC_BASE + ADC_O_RIS0));
521 }
522 
523 //*****************************************************************************
524 //
539 //
540 //*****************************************************************************
542 {
543  return (HWREG(ADC_BASE + ADC_O_MIS0));
544 }
545 
546 //*****************************************************************************
547 //
582 //
583 //*****************************************************************************
584 __STATIC_INLINE void ADCClearInterrupt(uint32_t intFlags)
585 {
586  // Clear the requested interrupt sources
587  HWREG(ADC_BASE + ADC_O_ICLR0) = intFlags;
588 }
589 
590 //*****************************************************************************
591 //
604 //
605 //*****************************************************************************
606 extern uint16_t ADCGetAdjustmentGain(uint32_t reference);
607 
608 //*****************************************************************************
609 //
620 //
621 //*****************************************************************************
622 extern void ADCSetAdjustmentOffset(uint32_t reference);
623 
624 //*****************************************************************************
625 //
640 //
641 //*****************************************************************************
642 extern uint32_t ADCAdjustValueForGain(uint32_t adcValue, uint32_t bitResolution, uint16_t gain);
643 
644 //*****************************************************************************
645 //
646 // Mark the end of the C bindings section for C++ compilers.
647 //
648 //*****************************************************************************
649 #ifdef __cplusplus
650 }
651 #endif
652 
653 //*****************************************************************************
654 //
658 //
659 //*****************************************************************************
660 
661 #endif // __ADC_H__
void ADCSetAdjustmentOffset(uint32_t reference)
Write correct offset value to ADC-peripheral trim register.
Definition: adc.c:345
__STATIC_INLINE uint32_t ADCReadResultNonBlocking(uint32_t index)
Read conversion result from ADC.
Definition: adc.h:424
void ADCSetSequence(uint32_t sequence)
Set conversion sequence.
Definition: adc.c:196
uint16_t ADCGetAdjustmentGain(uint32_t reference)
Returns ADC gain value for given reference.
Definition: adc.c:293
__STATIC_INLINE uint32_t ADCReadResult(uint32_t index)
Read conversion result from ADC.
Definition: adc.h:376
#define HWREG(x)
Definition: hw_types.h:79
#define __STATIC_INLINE
Definition: hw_types.h:58
#define ADC_O_MIS0
Definition: hw_adc.h:49
#define ADC_O_RIS0
Definition: hw_adc.h:46
__STATIC_INLINE uint32_t ADCRawInterruptStatus(void)
Gets the current raw interrupt status.
Definition: adc.h:518
#define ADC_O_MEMRES0
Definition: hw_adc.h:133
uint32_t ADCValueToMicrovolts(uint32_t adcCode, uint32_t bitResolution, uint32_t referenceVoltageMicroVolt)
Convert ADC code to microvolts.
Definition: adc.c:254
#define ADC_O_STA
Definition: hw_adc.h:145
#define ADC_O_ICLR0
Definition: hw_adc.h:55
void ADCSetInput(uint32_t reference, uint8_t channel, uint32_t index)
Sets the ADC reference source and input channel.
Definition: adc.c:90
uint32_t ADCAdjustValueForGain(uint32_t adcValue, uint32_t bitResolution, uint16_t gain)
Performs ADC value gain adjustment.
Definition: adc.c:218
__STATIC_INLINE void ADCClearInterrupt(uint32_t intFlags)
Clears ADC interrupt sources.
Definition: adc.h:584
__STATIC_INLINE bool ADCIsBusy(void)
Check if ADC is busy.
Definition: adc.h:399
__STATIC_INLINE void ADCDisableInterrupt(uint32_t intFlags)
Disables individual ADC interrupt sources.
Definition: adc.h:494
void ADCManualTrigger(void)
Triggers an ADC conversion.
Definition: adc.c:145
void ADCSetSampleDuration(uint32_t clkDiv, uint16_t clkCycles)
Sets the clock-divider value, and sample duration.
Definition: adc.c:43
__STATIC_INLINE void ADCEnableInterrupt(uint32_t intFlags)
Enables individual ADC interrupt sources.
Definition: adc.h:467
#define ADC_O_IMASK0
Definition: hw_adc.h:43
#define ADC_STA_BUSY_ACTIVE
Definition: hw_adc.h:2470
__STATIC_INLINE uint32_t ADCMaskedInterruptStatus(void)
Gets the current masked interrupt status.
Definition: adc.h:541
void ADCSetResolution(uint32_t resolution)
Sets the ADC bit resolution.
Definition: adc.c:68
void ADCSetMemctlRange(uint32_t start, uint32_t stop)
Set start and stop control registers.
Definition: adc.c:173
#define ADC_BASE
Definition: hw_memmap.h:66