CC27xxDriverLibrary
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-2025 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_types.h"
50 #include "../inc/hw_memmap.h"
51 #include "../inc/hw_adc.h"
52 #include "../inc/hw_sys0.h"
53 
54 //*****************************************************************************
55 //
56 // If building with a C++ compiler, make all of the definitions in this header
57 // have a C binding.
58 //
59 //*****************************************************************************
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 //*****************************************************************************
65 //
66 // Values
67 //
68 //*****************************************************************************
69 
71 #define ADC_CLOCK_DIVIDER_1 ADC_CTL0_SCLKDIV_DIV_BY_1
72 
74 #define ADC_CLOCK_DIVIDER_2 ADC_CTL0_SCLKDIV_DIV_BY_2
75 
77 #define ADC_CLOCK_DIVIDER_4 ADC_CTL0_SCLKDIV_DIV_BY_4
78 
80 #define ADC_CLOCK_DIVIDER_8 ADC_CTL0_SCLKDIV_DIV_BY_8
81 
83 #define ADC_CLOCK_DIVIDER_16 ADC_CTL0_SCLKDIV_DIV_BY_16
84 
86 #define ADC_CLOCK_DIVIDER_24 ADC_CTL0_SCLKDIV_DIV_BY_24
87 
89 #define ADC_CLOCK_DIVIDER_32 ADC_CTL0_SCLKDIV_DIV_BY_32
90 
92 #define ADC_CLOCK_DIVIDER_48 ADC_CTL0_SCLKDIV_DIV_BY_48
93 
95 #define ADC_RESOLUTION_12_BIT ADC_CTL2_RES_BIT_12
96 
98 #define ADC_RESOLUTION_10_BIT ADC_CTL2_RES_BIT_10
99 
101 #define ADC_RESOLUTION_8_BIT ADC_CTL2_RES_BIT_8
102 
104 #define ADC_FIXED_REFERENCE_1V4 0
105 
107 #define ADC_FIXED_REFERENCE_2V5 1
108 
110 #define ADC_EXTERNAL_REFERENCE 2
111 
113 #define ADC_VDDS_REFERENCE 3
114 
117 #define ADC_POWER_DOWN_POLICY_AUTO ADC_CTL0_PWRDN_AUTO
118 
121 #define ADC_POWER_DOWN_POLICY_MANUAL ADC_CTL0_PWRDN_MANUAL
122 
125 #define ADC_SEQUENCE_REPEATSEQUENCE ADC_CTL1_CONSEQ_REPEATSEQUENCE
126 
128 #define ADC_SEQUENCE_REPEATSINGLE ADC_CTL1_CONSEQ_REPEATSINGLE
129 
132 #define ADC_SEQUENCE_SEQUENCE ADC_CTL1_CONSEQ_SEQUENCE
133 
136 #define ADC_SEQUENCE_SINGLE ADC_CTL1_CONSEQ_SINGLE
137 
140 #define ADC_SAMPLE_MODE_AUTO ADC_CTL1_SAMPMODE_AUTO
141 
147 #define ADC_SAMPLE_MODE_MANUAL ADC_CTL1_SAMPMODE_MANUAL
148 
153 #define ADC_TRIGGER_SOURCE_EVENT ADC_CTL1_TRIGSRC_EVENT
154 
161 #define ADC_TRIGGER_SOURCE_SOFTWARE ADC_CTL1_TRIGSRC_SOFTWARE
162 
167 #define ADC_TRIGGER_POLICY_AUTO_NEXT ADC_MEMCTL0_TRG_AUTO_NEXT
168 
170 #define ADC_TRIGGER_POLICY_TRIGGER_NEXT ADC_MEMCTL0_TRG_TRIGGER_NEXT
171 
173 #define ADC_INT_MEMRES_23 ADC_IMASK0_MEMRESIFG23
174 
176 #define ADC_INT_MEMRES_22 ADC_IMASK0_MEMRESIFG22
177 
179 #define ADC_INT_MEMRES_21 ADC_IMASK0_MEMRESIFG21
180 
182 #define ADC_INT_MEMRES_20 ADC_IMASK0_MEMRESIFG20
183 
185 #define ADC_INT_MEMRES_19 ADC_IMASK0_MEMRESIFG19
186 
188 #define ADC_INT_MEMRES_18 ADC_IMASK0_MEMRESIFG18
189 
191 #define ADC_INT_MEMRES_17 ADC_IMASK0_MEMRESIFG17
192 
194 #define ADC_INT_MEMRES_16 ADC_IMASK0_MEMRESIFG16
195 
197 #define ADC_INT_MEMRES_15 ADC_IMASK0_MEMRESIFG15
198 
200 #define ADC_INT_MEMRES_14 ADC_IMASK0_MEMRESIFG14
201 
203 #define ADC_INT_MEMRES_13 ADC_IMASK0_MEMRESIFG13
204 
206 #define ADC_INT_MEMRES_12 ADC_IMASK0_MEMRESIFG12
207 
209 #define ADC_INT_MEMRES_11 ADC_IMASK0_MEMRESIFG11
210 
212 #define ADC_INT_MEMRES_10 ADC_IMASK0_MEMRESIFG10
213 
215 #define ADC_INT_MEMRES_09 ADC_IMASK0_MEMRESIFG9
216 
218 #define ADC_INT_MEMRES_08 ADC_IMASK0_MEMRESIFG8
219 
221 #define ADC_INT_MEMRES_07 ADC_IMASK0_MEMRESIFG7
222 
224 #define ADC_INT_MEMRES_06 ADC_IMASK0_MEMRESIFG6
225 
227 #define ADC_INT_MEMRES_05 ADC_IMASK0_MEMRESIFG5
228 
230 #define ADC_INT_MEMRES_04 ADC_IMASK0_MEMRESIFG4
231 
233 #define ADC_INT_MEMRES_03 ADC_IMASK0_MEMRESIFG3
234 
236 #define ADC_INT_MEMRES_02 ADC_IMASK0_MEMRESIFG2
237 
239 #define ADC_INT_MEMRES_01 ADC_IMASK0_MEMRESIFG1
240 
242 #define ADC_INT_MEMRES_00 ADC_IMASK0_MEMRESIFG0
243 
245 #define ADC_INT_ASCDONE ADC_IMASK0_ASCDONE
246 
248 #define ADC_INT_UVIFG ADC_IMASK0_UVIFG
249 
251 #define ADC_INT_DMADONE ADC_IMASK0_DMADONE
252 
254 #define ADC_INT_INIFG ADC_IMASK0_INIFG
255 
257 #define ADC_INT_LOWIFG ADC_IMASK0_LOWIFG
258 
260 #define ADC_INT_HIGHIFG ADC_IMASK0_HIGHIFG
261 
263 #define ADC_INT_TOVIFG ADC_IMASK0_TOVIFG
264 
266 #define ADC_INT_OVIFG ADC_IMASK0_OVIFG
267 
268 //*****************************************************************************
269 //
270 // API Functions and prototypes
271 //
272 //*****************************************************************************
273 
274 //*****************************************************************************
275 //
304 //
305 //*****************************************************************************
306 extern void ADCSetSampleDuration(uint32_t clkDiv, uint16_t clkCycles);
307 
308 //*****************************************************************************
309 //
326 //
327 //*****************************************************************************
328 extern void ADCSetResolution(uint32_t resolution);
329 
330 //*****************************************************************************
331 //
349 //
350 //*****************************************************************************
351 extern void ADCSetInput(uint32_t reference, uint8_t channel, uint32_t index);
352 
353 //*****************************************************************************
354 //
365 //
366 //*****************************************************************************
367 extern void ADCSetMemctlRange(uint32_t start, uint32_t stop);
368 
369 //*****************************************************************************
370 //
380 //
381 //*****************************************************************************
382 extern void ADCSetPowerDownPolicy(uint32_t powerDownPolicy);
383 
384 //*****************************************************************************
385 //
399 //
400 //*****************************************************************************
401 extern void ADCSetSequence(uint32_t sequence);
402 
403 //*****************************************************************************
404 //
412 //
413 //*****************************************************************************
414 extern void ADCSetSamplingMode(uint32_t samplingMode);
415 
416 //*****************************************************************************
417 //
425 //
426 //*****************************************************************************
427 extern void ADCSetTriggerSource(uint32_t triggerSource);
428 
429 //*****************************************************************************
430 //
444 //
445 //*****************************************************************************
446 extern void ADCSetTriggerPolicy(uint32_t triggerPolicy, uint32_t index);
447 
448 //*****************************************************************************
449 //
459 //
460 //*****************************************************************************
462 {
463  HWREG(ADC_BASE + ADC_O_CTL1) |= ADC_CTL1_SC_START;
464 }
465 
466 //*****************************************************************************
467 //
476 //
477 //*****************************************************************************
479 {
480  HWREG(ADC_BASE + ADC_O_CTL1) &= ~ADC_CTL1_SC_M;
481 }
482 
483 //*****************************************************************************
484 //
499 //
500 //*****************************************************************************
502 {
503  HWREG(ADC_BASE + ADC_O_CTL0) |= ADC_CTL0_ENC_ON;
504 }
505 
506 //*****************************************************************************
507 //
516 //
517 //*****************************************************************************
519 {
520  HWREG(ADC_BASE + ADC_O_CTL0) &= ~ADC_CTL0_ENC_M;
521 }
522 
523 //*****************************************************************************
524 //
532 //
533 //*****************************************************************************
535 {
536  HWREG(ADC_BASE + ADC_O_CTL2) |= ADC_CTL2_DMAEN_EN;
537 }
538 
539 //*****************************************************************************
540 //
544 //
545 //*****************************************************************************
547 {
548  HWREG(ADC_BASE + ADC_O_CTL2) &= ~ADC_CTL2_DMAEN_M;
549 }
550 
551 //*****************************************************************************
552 //
562 //
563 //*****************************************************************************
564 __STATIC_INLINE uint32_t ADCReadResult(uint32_t index)
565 {
566 
567  while (HWREG(ADC_BASE + ADC_O_STA) & ADC_STA_BUSY_ACTIVE) {}
568 
569  /* Return data from result register */
570  return HWREG(ADC_BASE + ADC_O_MEMRES0 + (4 * index));
571 }
572 
573 //*****************************************************************************
574 //
585 //
586 //*****************************************************************************
588 {
589 
590  if (HWREG(ADC_BASE + ADC_O_STA) & ADC_STA_BUSY_ACTIVE)
591  {
592  return true;
593  }
594  else
595  {
596  return false;
597  }
598 }
599 
600 //*****************************************************************************
601 //
610 //
611 //*****************************************************************************
613 {
614  /* Return data from result register */
615  return HWREG(ADC_BASE + ADC_O_MEMRES0 + (4 * index));
616 }
617 
618 //*****************************************************************************
619 //
630 //
631 //*****************************************************************************
632 extern uint32_t ADCValueToMicrovolts(uint32_t adcCode, uint32_t bitResolution, uint32_t referenceVoltageMicroVolt);
633 
634 //*****************************************************************************
635 //
653 //
654 //*****************************************************************************
655 __STATIC_INLINE void ADCEnableInterrupt(uint32_t intFlags)
656 {
657  // Enable the specified interrupts.
658  HWREG(ADC_BASE + ADC_O_IMASK0) |= intFlags;
659 }
660 
661 //*****************************************************************************
662 //
680 //
681 //*****************************************************************************
682 __STATIC_INLINE void ADCDisableInterrupt(uint32_t intFlags)
683 {
684  // Disable the specified interrupts.
685  HWREG(ADC_BASE + ADC_O_IMASK0) &= ~(intFlags);
686 }
687 
688 //*****************************************************************************
689 //
704 //
705 //*****************************************************************************
707 {
708  return (HWREG(ADC_BASE + ADC_O_RIS0));
709 }
710 
711 //*****************************************************************************
712 //
727 //
728 //*****************************************************************************
730 {
731  return (HWREG(ADC_BASE + ADC_O_MIS0));
732 }
733 
734 //*****************************************************************************
735 //
770 //
771 //*****************************************************************************
772 __STATIC_INLINE void ADCClearInterrupt(uint32_t intFlags)
773 {
774  // Clear the requested interrupt sources
775  HWREG(ADC_BASE + ADC_O_ICLR0) = intFlags;
776 }
777 
778 //*****************************************************************************
779 //
797 //
798 //*****************************************************************************
799 extern uint32_t ADCAdjustValueForGain(uint32_t adcValue, uint32_t bitResolution, uint16_t gain);
800 
801 #ifndef DRIVERLIB_NS
802 //*****************************************************************************
803 //
804 // Below functions will only be compiled into the driverlib.a library and not
805 // the driverlib_ns.a library.
806 // Non-secure applications might be able to access some/all of these functions
807 // through veneers declared further below in the #else case.
808 //
809 //*****************************************************************************
810 
811 //*****************************************************************************
812 //
825 //
826 //*****************************************************************************
827 extern uint16_t ADCGetAdjustmentGain(uint32_t reference);
828 
829 //*****************************************************************************
830 //
841 //
842 //*****************************************************************************
843 extern void ADCSetAdjustmentOffset(uint32_t reference);
844 
845 #else
846 //*****************************************************************************
847 //
848 // Secure-only API functions available from non-secure context through
849 // veneers.
850 //
851 // These functions must be linked in from from the secure veneer library.
852 //
853 //*****************************************************************************
854 
855 extern uint16_t ADCGetAdjustmentGain_veneer(uint32_t reference);
856  #define ADCGetAdjustmentGain ADCGetAdjustmentGain_veneer
857 
858 extern void ADCSetAdjustmentOffset_veneer(uint32_t reference);
859  #define ADCSetAdjustmentOffset ADCSetAdjustmentOffset_veneer
860 
861 #endif
862 
863 //*****************************************************************************
864 //
865 // Mark the end of the C bindings section for C++ compilers.
866 //
867 //*****************************************************************************
868 #ifdef __cplusplus
869 }
870 #endif
871 
872 //*****************************************************************************
873 //
877 //
878 //*****************************************************************************
879 
880 #endif // __ADC_H__
void ADCSetAdjustmentOffset(uint32_t reference)
Write correct offset value to ADC-peripheral trim register.
Definition: adc.c:440
void ADCSetTriggerSource(uint32_t triggerSource)
Set ADC trigger source.
Definition: adc.c:180
__STATIC_INLINE uint32_t ADCReadResultNonBlocking(uint32_t index)
Read conversion result from ADC.
Definition: adc.h:612
void ADCSetSequence(uint32_t sequence)
Set conversion sequence.
Definition: adc.c:275
__STATIC_INLINE void ADCStartConversion(void)
Start conversion.
Definition: adc.h:461
uint16_t ADCGetAdjustmentGain(uint32_t reference)
Returns ADC gain value for given reference.
Definition: adc.c:385
__STATIC_INLINE uint32_t ADCReadResult(uint32_t index)
Read conversion result from ADC.
Definition: adc.h:564
__STATIC_INLINE uint32_t ADCRawInterruptStatus(void)
Gets the current raw interrupt status.
Definition: adc.h:706
uint32_t ADCValueToMicrovolts(uint32_t adcCode, uint32_t bitResolution, uint32_t referenceVoltageMicroVolt)
Convert ADC code to microvolts.
Definition: adc.c:335
void ADCSetInput(uint32_t reference, uint8_t channel, uint32_t index)
Sets the ADC reference source and input channel.
Definition: adc.c:97
uint32_t ADCAdjustValueForGain(uint32_t adcValue, uint32_t bitResolution, uint16_t gain)
Performs ADC value gain adjustment.
Definition: adc.c:299
void ADCSetSamplingMode(uint32_t samplingMode)
Set ADC sampling mode.
Definition: adc.c:156
__STATIC_INLINE void ADCStopConversion(void)
Stop sample phase of a conversion.
Definition: adc.h:478
__STATIC_INLINE void ADCDisableDmaTrigger(void)
Disable DMA trigger for data transfer.
Definition: adc.h:546
__STATIC_INLINE void ADCEnableDmaTrigger(void)
Enable DMA trigger for data transfer.
Definition: adc.h:534
__STATIC_INLINE void ADCDisableConversion(void)
Disable conversion.
Definition: adc.h:518
void ADCSetPowerDownPolicy(uint32_t powerDownPolicy)
Set power down policy.
Definition: adc.c:251
__STATIC_INLINE void ADCClearInterrupt(uint32_t intFlags)
Clears ADC interrupt sources.
Definition: adc.h:772
__STATIC_INLINE bool ADCIsBusy(void)
Check if ADC is busy.
Definition: adc.h:587
__STATIC_INLINE void ADCDisableInterrupt(uint32_t intFlags)
Disables individual ADC interrupt sources.
Definition: adc.h:682
void ADCSetSampleDuration(uint32_t clkDiv, uint16_t clkCycles)
Sets the clock-divider value, and sample duration.
Definition: adc.c:45
__STATIC_INLINE void ADCEnableInterrupt(uint32_t intFlags)
Enables individual ADC interrupt sources.
Definition: adc.h:655
__tz_c_veneer uint16_t ADCGetAdjustmentGain_veneer(uint32_t reference)
Definition: adc_veneers.c:41
__STATIC_INLINE uint32_t ADCMaskedInterruptStatus(void)
Gets the current masked interrupt status.
Definition: adc.h:729
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
void ADCSetResolution(uint32_t resolution)
Sets the ADC bit resolution.
Definition: adc.c:73
__tz_c_veneer void ADCSetAdjustmentOffset_veneer(uint32_t reference)
Definition: adc_veneers.c:46
__STATIC_INLINE void ADCEnableConversion(void)
Enable conversion.
Definition: adc.h:501
void ADCSetMemctlRange(uint32_t start, uint32_t stop)
Set start and stop control registers.
Definition: adc.c:228
void ADCSetTriggerPolicy(uint32_t triggerPolicy, uint32_t index)
Set ADC trigger policy.
Definition: adc.c:204