AM64x MCU+ SDK  08.02.00
adc/v0/adc.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 
50 #ifndef ADC_V0_H_
51 #define ADC_V0_H_
52 
53 /* ========================================================================== */
54 /* Include Files */
55 /* ========================================================================== */
56 
57 #include <drivers/hw_include/cslr.h>
58 #include <drivers/hw_include/cslr_adc.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* ========================================================================== */
65 /* Macros & Typedefs */
66 /* ========================================================================== */
67 
69 #define ADC_INTR_STATUS_ALL (ADC_IRQSTATUS_END_OF_SEQUENCE_MASK | \
70  ADC_IRQSTATUS_FIFO0_THR_MASK | \
71  ADC_IRQSTATUS_FIFO0_OVERRUN_MASK | \
72  ADC_IRQSTATUS_FIFO0_UNDERFLOW_MASK | \
73  ADC_IRQSTATUS_FIFO1_THR_MASK | \
74  ADC_IRQSTATUS_FIFO1_OVERRUN_MASK | \
75  ADC_IRQSTATUS_FIFO1_UNDERFLOW_MASK | \
76  ADC_IRQSTATUS_OUT_OF_RANGE_MASK)
77 
78 #define ADC_INTR_ENABLE_ALL (ADC_IRQENABLE_SET_END_OF_SEQUENCE_MASK | \
79  ADC_IRQENABLE_SET_FIFO0_THR_MASK | \
80  ADC_IRQENABLE_SET_FIFO0_OVERRUN_MASK | \
81  ADC_IRQENABLE_SET_FIFO0_UNDERFLOW_MASK | \
82  ADC_IRQENABLE_SET_FIFO1_THR_MASK | \
83  ADC_IRQENABLE_SET_FIFO1_OVERRUN_MASK | \
84  ADC_IRQENABLE_SET_FIFO1_UNDERFLOW_MASK | \
85  ADC_IRQENABLE_SET_OUT_OF_RANGE_MASK)
86 
87 #define ADC_INTR_DISABLE_ALL (ADC_IRQENABLE_CLR_END_OF_SEQUENCE_MASK | \
88  ADC_IRQENABLE_CLR_FIFO0_THR_MASK | \
89  ADC_IRQENABLE_CLR_FIFO0_OVERRUN_MASK | \
90  ADC_IRQENABLE_CLR_FIFO0_UNDERFLOW_MASK | \
91  ADC_IRQENABLE_CLR_FIFO1_THR_MASK | \
92  ADC_IRQENABLE_CLR_FIFO1_OVERRUN_MASK | \
93  ADC_IRQENABLE_CLR_FIFO1_UNDERFLOW_MASK | \
94  ADC_IRQENABLE_CLR_OUT_OF_RANGE_MASK)
95 
96 #define ADC_INTR_ALL (ADC_INTR_STATUS_ALL)
97 
99 #define ADC_OPENDELAY_MAX (0x3FFFFU)
100 
101 #define ADC_SAMPLEDELAY_MAX (0xFFU)
102 
103 #define ADC_RANGE_MAX (0x3FFU)
104 
105 #define ADC_RANGE_MIN (0x0U)
106 
108 #define ADC_FIFO_SIZE (64U)
109 
110 #define ADC_MAX_NUM_CHN (uint32_t)(8U)
111 
113 #define ADC_GET_RANGE(bit) (((uint32_t) 1U) << (bit))
114 
115 /* ========================================================================== */
116 /* Structures and Enums */
117 /* ========================================================================== */
118 
129 typedef uint32_t adcChannel_t;
130 
131 #define ADC_CHANNEL_1 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_1)
132 
133 #define ADC_CHANNEL_2 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_2)
134 
135 #define ADC_CHANNEL_3 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_3)
136 
137 #define ADC_CHANNEL_4 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_4)
138 
139 #define ADC_CHANNEL_5 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_5)
140 
141 #define ADC_CHANNEL_6 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_6)
142 
143 #define ADC_CHANNEL_7 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_7)
144 
145 #define ADC_CHANNEL_8 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_8)
146 
157 typedef uint32_t adcStepId_t;
158 
159 #define ADC_STEP_1 (ADC_ADCSTAT_STEP_ID_STEP1)
160 
161 #define ADC_STEP_2 (ADC_ADCSTAT_STEP_ID_STEP2)
162 
163 #define ADC_STEP_3 (ADC_ADCSTAT_STEP_ID_STEP3)
164 
165 #define ADC_STEP_4 (ADC_ADCSTAT_STEP_ID_STEP4)
166 
167 #define ADC_STEP_5 (ADC_ADCSTAT_STEP_ID_STEP5)
168 
169 #define ADC_STEP_6 (ADC_ADCSTAT_STEP_ID_STEP6)
170 
171 #define ADC_STEP_7 (ADC_ADCSTAT_STEP_ID_STEP7)
172 
173 #define ADC_STEP_8 (ADC_ADCSTAT_STEP_ID_STEP8)
174 
175 #define ADC_STEP_9 (ADC_ADCSTAT_STEP_ID_STEP9)
176 
177 #define ADC_STEP_10 (ADC_ADCSTAT_STEP_ID_STEP10)
178 
179 #define ADC_STEP_11 (ADC_ADCSTAT_STEP_ID_STEP11)
180 
181 #define ADC_STEP_12 (ADC_ADCSTAT_STEP_ID_STEP12)
182 
183 #define ADC_STEP_13 (ADC_ADCSTAT_STEP_ID_STEP13)
184 
185 #define ADC_STEP_14 (ADC_ADCSTAT_STEP_ID_STEP14)
186 
187 #define ADC_STEP_15 (ADC_ADCSTAT_STEP_ID_STEP15)
188 
189 #define ADC_STEP_16 (ADC_ADCSTAT_STEP_ID_STEP16)
190 
204 typedef uint32_t adcOperationMode_t;
205 
206 #define ADC_OPERATION_MODE_SINGLE_SHOT (ADC_STEPCONFIG_MODE_SW_EN_ONESHOT)
207 
208 #define ADC_OPERATION_MODE_CONTINUOUS (ADC_STEPCONFIG_MODE_SW_EN_CONTINUOUS)
209 
222 typedef uint32_t adcAveraging_t;
223 
224 #define ADC_AVERAGING_NONE (ADC_STEPCONFIG_AVERAGING_NOAVG)
225 
226 #define ADC_AVERAGING_2_SAMPLES (ADC_STEPCONFIG_AVERAGING_2_SAMPLESAVG)
227 
228 #define ADC_AVERAGING_4_SAMPLES (ADC_STEPCONFIG_AVERAGING_4_SAMPLESAVG)
229 
230 #define ADC_AVERAGING_8_SAMPLES (ADC_STEPCONFIG_AVERAGING_8_SAMPLESAVG)
231 
232 #define ADC_AVERAGING_16_SAMPLES (ADC_STEPCONFIG_AVERAGING_16_SAMPLESAV)
233 
244 typedef uint32_t adcFIFONum_t;
245 
246 #define ADC_FIFO_NUM_0 (0x0U)
247 
248 #define ADC_FIFO_NUM_1 (0x1U)
249 
260 typedef uint32_t adcIntrSrc_t;
261 
262 #define ADC_INTR_SRC_END_OF_SEQUENCE (ADC_IRQENABLE_SET_END_OF_SEQUENCE_MASK)
263 
264 #define ADC_INTR_SRC_FIFO0_THRESHOLD (ADC_IRQENABLE_SET_FIFO0_THR_MASK)
265 
266 #define ADC_INTR_SRC_FIFO0_OVERRUN (ADC_IRQENABLE_SET_FIFO0_OVERRUN_MASK)
267 
268 #define ADC_INTR_SRC_FIFO0_UNDERFLOW (ADC_IRQENABLE_SET_FIFO0_UNDERFLOW_MASK)
269 
270 #define ADC_INTR_SRC_FIFO1_THRESHOLD (ADC_IRQENABLE_SET_FIFO1_THR_MASK)
271 
272 #define ADC_INTR_SRC_FIFO1_OVERRUN (ADC_IRQSTATUS_FIFO1_OVERRUN_MASK)
273 
274 #define ADC_INTR_SRC_FIFO1_UNDERFLOW (ADC_IRQENABLE_SET_FIFO1_UNDERFLOW_MASK)
275 
276 #define ADC_INTR_SRC_OUT_OF_RANGE (ADC_IRQENABLE_SET_OUT_OF_RANGE_MASK)
277 
288 typedef uint32_t adcIdleMode_t;
289 
290 #define ADC_IDLE_MODE_FORCE_IDLE (ADC_SYSCONFIG_IDLEMODE_FORCE)
291 
292 #define ADC_IDLE_MODE_NO_IDLE (ADC_SYSCONFIG_IDLEMODE_NO_IDLE)
293 
294 #define ADC_IDLE_MODE_SMART_IDLE (ADC_SYSCONFIG_IDLEMODE_SMART_IDLE)
295 
301 typedef struct adcRevisionId
302 {
303  uint32_t scheme;
305  uint32_t func;
307  uint32_t rtlRev;
309  uint32_t major;
311  uint32_t custom;
313  uint32_t minor;
316 
320 typedef struct adcStepConfig
321 {
322  uint32_t mode;
326  uint32_t channel;
330  uint32_t openDelay;
336  uint32_t sampleDelay;
346  uint32_t averaging;
350  uint32_t fifoNum;
355 
359 typedef struct adcSequencerStatus
360 {
361  uint32_t afeBusy;
366  uint32_t fsmBusy;
370  uint32_t stepId;
375 
376 /* ========================================================================== */
377 /* Global Variables Declarations */
378 /* ========================================================================== */
379 
380 /* None */
381 
382 /* ========================================================================== */
383 /* Function Declarations */
384 /* ========================================================================== */
385 
393 void ADCPowerUp(uint32_t baseAddr, uint32_t powerUp);
394 
403 uint32_t AdcIsPoweredUp(uint32_t baseAddr);
404 
417 int32_t ADCSetClkDivider(uint32_t baseAddr, uint32_t clkDivider);
418 
430 void ADCInit(uint32_t baseAddr,
431  uint32_t errCorrection,
432  uint32_t errOffset,
433  uint32_t calibration);
434 
444 void ADCFIFODMAAccessEnable(uint32_t baseAddr,
445  uint32_t fifoNum,
446  uint32_t dmaLineEnable);
447 
459 int32_t ADCSetStepParams(uint32_t baseAddr,
460  uint32_t stepId,
461  const adcStepConfig_t *configParams);
462 
472 void ADCStepEnable(uint32_t baseAddr,
473  uint32_t stepId,
474  uint32_t stepEnable);
475 
481 void ADCClearAllSteps(uint32_t baseAddr);
482 
490 void ADCStart(uint32_t baseAddr, uint32_t adcEnable);
491 
502 void ADCStepIdTagEnable(uint32_t baseAddr, uint32_t stepIdTag);
503 
513 uint32_t ADCGetFIFOData(uint32_t baseAddr, uint32_t fifoNum);
514 
524 uint32_t ADCGetFIFOWordCount(uint32_t baseAddr, uint32_t fifoNum);
525 
541 int32_t ADCSetCPUFIFOThresholdLevel(uint32_t baseAddr,
542  uint32_t fifoNum,
543  uint32_t threshold);
544 
556 uint32_t ADCGetCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum);
557 
573 int32_t ADCSetDMAFIFOThresholdLevel(uint32_t baseAddr,
574  uint32_t fifoNum,
575  uint32_t threshold);
576 
587 uint32_t ADCGetDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum);
588 
596 void ADCEnableIntr(uint32_t baseAddr, uint32_t intrMask);
597 
604 void ADCDisableIntr(uint32_t baseAddr, uint32_t intrMask);
605 
611 void ADCWriteEOI(uint32_t baseAddr);
612 
620 uint32_t ADCGetIntrStatus(uint32_t baseAddr);
621 
628 void ADCClearIntrStatus(uint32_t baseAddr, uint32_t intrMask);
629 
637 uint32_t ADCGetIntrRawStatus(uint32_t baseAddr);
638 
648 int32_t ADCSetRange(uint32_t baseAddr, uint32_t highRange, uint32_t lowRange);
649 
657 void ADCGetRange(uint32_t baseAddr,
658  uint32_t *highRange,
659  uint32_t *lowRange);
660 
668 void ADCGetSequencerStatus(uint32_t baseAddr,
669  adcSequencerStatus_t *status);
670 
679 void ADCSetIdleMode(uint32_t baseAddr, uint32_t idleMode);
680 
688 void ADCGetRevisionId(uint32_t baseAddr, adcRevisionId_t *revId);
689 
690 /* ========================================================================== */
691 /* Static Function Definitions */
692 /* ========================================================================== */
693 
694 /* None */
695 
696 #ifdef __cplusplus
697 }
698 #endif
699 
700 #endif /* #ifndef ADC_V0_H_ */
701 
ADCInit
void ADCInit(uint32_t baseAddr, uint32_t errCorrection, uint32_t errOffset, uint32_t calibration)
This API is used to initialize the ADC module.
ADCSetIdleMode
void ADCSetIdleMode(uint32_t baseAddr, uint32_t idleMode)
This API is used to configure ADC idle mode.
ADCEnableIntr
void ADCEnableIntr(uint32_t baseAddr, uint32_t intrMask)
This API is used to enable interrupts.
adcSequencerStatus_t::fsmBusy
uint32_t fsmBusy
Definition: adc/v0/adc.h:366
ADCFIFODMAAccessEnable
void ADCFIFODMAAccessEnable(uint32_t baseAddr, uint32_t fifoNum, uint32_t dmaLineEnable)
This API will enable DMA access for FIFO.
adcStepConfig_t::sampleDelay
uint32_t sampleDelay
Definition: adc/v0/adc.h:336
adcOperationMode_t
uint32_t adcOperationMode_t
Enum to select the ADC Operation Mode.
Definition: adc/v0/adc.h:204
adcStepConfig_t::fifoNum
uint32_t fifoNum
Definition: adc/v0/adc.h:350
adcStepConfig_t::mode
uint32_t mode
Definition: adc/v0/adc.h:322
ADCGetFIFOData
uint32_t ADCGetFIFOData(uint32_t baseAddr, uint32_t fifoNum)
This API will read and return FIFO data.
ADCSetStepParams
int32_t ADCSetStepParams(uint32_t baseAddr, uint32_t stepId, const adcStepConfig_t *configParams)
This API will configure a step for analog to digital conversion.
ADCStart
void ADCStart(uint32_t baseAddr, uint32_t adcEnable)
This API will start ADC.
ADCGetIntrRawStatus
uint32_t ADCGetIntrRawStatus(uint32_t baseAddr)
This API is used to get the raw interrupt status.
adcRevisionId_t
Structure for accessing Revision ID of ADC module.
Definition: adc/v0/adc.h:302
adcStepConfig_t::averaging
uint32_t averaging
Definition: adc/v0/adc.h:346
ADCDisableIntr
void ADCDisableIntr(uint32_t baseAddr, uint32_t intrMask)
This API is used to disable interrupts.
adcStepConfig_t
Structure containing parameters for ADC step configuration.
Definition: adc/v0/adc.h:321
ADCGetDMAFIFOThresholdLevel
uint32_t ADCGetDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum)
This API will read and return DMA request level for a FIFO.
adcFIFONum_t
uint32_t adcFIFONum_t
Enum to select FIFO to store the data.
Definition: adc/v0/adc.h:244
adcRevisionId_t::custom
uint32_t custom
Definition: adc/v0/adc.h:311
ADCGetSequencerStatus
void ADCGetSequencerStatus(uint32_t baseAddr, adcSequencerStatus_t *status)
This API is used to get the Sequencer status.
adcStepConfig_t::rangeCheckEnable
uint32_t rangeCheckEnable
Definition: adc/v0/adc.h:341
adcSequencerStatus_t::afeBusy
uint32_t afeBusy
Definition: adc/v0/adc.h:361
adcRevisionId_t::scheme
uint32_t scheme
Definition: adc/v0/adc.h:303
adcSequencerStatus_t::stepId
uint32_t stepId
Definition: adc/v0/adc.h:370
adcRevisionId_t::rtlRev
uint32_t rtlRev
Definition: adc/v0/adc.h:307
adcStepId_t
uint32_t adcStepId_t
Enum to select the step for operation.
Definition: adc/v0/adc.h:157
ADCGetRange
void ADCGetRange(uint32_t baseAddr, uint32_t *highRange, uint32_t *lowRange)
This API is used to get the range for conversion.
ADCStepIdTagEnable
void ADCStepIdTagEnable(uint32_t baseAddr, uint32_t stepIdTag)
This API is used to configure the ADC module for storing step ID along with ADC data.
ADCClearAllSteps
void ADCClearAllSteps(uint32_t baseAddr)
This API will clear all the ADC steps.
ADCPowerUp
void ADCPowerUp(uint32_t baseAddr, uint32_t powerUp)
This API will power up ADC Module.
ADCGetCPUFIFOThresholdLevel
uint32_t ADCGetCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum)
This API will read and return threshold level for a FIFO.
ADCGetRevisionId
void ADCGetRevisionId(uint32_t baseAddr, adcRevisionId_t *revId)
This API is used get the ADC revision ID.
adcRevisionId_t::minor
uint32_t minor
Definition: adc/v0/adc.h:313
ADCSetClkDivider
int32_t ADCSetClkDivider(uint32_t baseAddr, uint32_t clkDivider)
This API will configure clock divider for the ADC Module.
adcIntrSrc_t
uint32_t adcIntrSrc_t
Enum for ADC interrupts.
Definition: adc/v0/adc.h:260
ADCWriteEOI
void ADCWriteEOI(uint32_t baseAddr)
This API is used for EOI for ADC.
adcRevisionId_t::func
uint32_t func
Definition: adc/v0/adc.h:305
ADCSetRange
int32_t ADCSetRange(uint32_t baseAddr, uint32_t highRange, uint32_t lowRange)
This API is used to configure the range for ADC.
adcStepConfig_t::openDelay
uint32_t openDelay
Definition: adc/v0/adc.h:330
ADCClearIntrStatus
void ADCClearIntrStatus(uint32_t baseAddr, uint32_t intrMask)
This API is used to clear the interrupt status.
ADCSetCPUFIFOThresholdLevel
int32_t ADCSetCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum, uint32_t threshold)
This API will configure threshold level for a FIFO.
ADCGetFIFOWordCount
uint32_t ADCGetFIFOWordCount(uint32_t baseAddr, uint32_t fifoNum)
This API will return number of word present in the FIFO.
ADCStepEnable
void ADCStepEnable(uint32_t baseAddr, uint32_t stepId, uint32_t stepEnable)
This API will enable ADC step.
adcChannel_t
uint32_t adcChannel_t
Enum to select the channel for input.
Definition: adc/v0/adc.h:129
adcRevisionId_t::major
uint32_t major
Definition: adc/v0/adc.h:309
adcIdleMode_t
uint32_t adcIdleMode_t
Enum to configure ADC idle mode.Applicable for TDA3XX Only.
Definition: adc/v0/adc.h:288
ADCGetIntrStatus
uint32_t ADCGetIntrStatus(uint32_t baseAddr)
This API is used to get the pending interrupts.
ADCSetDMAFIFOThresholdLevel
int32_t ADCSetDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum, uint32_t threshold)
This API will configure DMA request level for a FIFO.
AdcIsPoweredUp
uint32_t AdcIsPoweredUp(uint32_t baseAddr)
This function checks if the ADC module is powered up.
adcAveraging_t
uint32_t adcAveraging_t
Enum to number of samplings to average.
Definition: adc/v0/adc.h:222
adcStepConfig_t::channel
uint32_t channel
Definition: adc/v0/adc.h:326
adcSequencerStatus_t
Structure for reporting ADC sequencer status.
Definition: adc/v0/adc.h:360