PDK API Guide for J721E
adc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Texas Instruments Incorporated 2015-2019
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  */
52 #ifndef CSL_ADC_H_
53 #define CSL_ADC_H_
54 
55 /* ========================================================================== */
56 /* Include Files */
57 /* ========================================================================== */
58 #include <ti/csl/cslr_adc.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 /* ========================================================================== */
65 /* Macros & Typedefs */
66 /* ========================================================================== */
70 #define ADC_INTR_STATUS_ALL (ADC_IRQSTATUS_END_OF_SEQUENCE_MASK | \
71  ADC_IRQSTATUS_FIFO0_THR_MASK | \
72  ADC_IRQSTATUS_FIFO0_OVERRUN_MASK | \
73  ADC_IRQSTATUS_FIFO0_UNDERFLOW_MASK | \
74  ADC_IRQSTATUS_FIFO1_THR_MASK | \
75  ADC_IRQSTATUS_FIFO1_OVERRUN_MASK | \
76  ADC_IRQSTATUS_FIFO1_UNDERFLOW_MASK | \
77  ADC_IRQSTATUS_OUT_OF_RANGE_MASK)
78 
81 #define ADC_INTR_ENABLE_ALL (ADC_IRQENABLE_SET_END_OF_SEQUENCE_MASK | \
82  ADC_IRQENABLE_SET_FIFO0_THR_MASK | \
83  ADC_IRQENABLE_SET_FIFO0_OVERRUN_MASK | \
84  ADC_IRQENABLE_SET_FIFO0_UNDERFLOW_MASK | \
85  ADC_IRQENABLE_SET_FIFO1_THR_MASK | \
86  ADC_IRQENABLE_SET_FIFO1_OVERRUN_MASK | \
87  ADC_IRQENABLE_SET_FIFO1_UNDERFLOW_MASK | \
88  ADC_IRQENABLE_SET_OUT_OF_RANGE_MASK)
89 
93 #define ADC_INTR_DISABLE_ALL (ADC_IRQENABLE_CLR_END_OF_SEQUENCE_MASK | \
94  ADC_IRQENABLE_CLR_FIFO0_THR_MASK | \
95  ADC_IRQENABLE_CLR_FIFO0_OVERRUN_MASK | \
96  ADC_IRQENABLE_CLR_FIFO0_UNDERFLOW_MASK | \
97  ADC_IRQENABLE_CLR_FIFO1_THR_MASK | \
98  ADC_IRQENABLE_CLR_FIFO1_OVERRUN_MASK | \
99  ADC_IRQENABLE_CLR_FIFO1_UNDERFLOW_MASK | \
100  ADC_IRQENABLE_CLR_OUT_OF_RANGE_MASK)
101 
105 #define ADC_INTR_ALL (ADC_INTR_STATUS_ALL)
106 
110 #define ADC_OPENDELAY_MAX (0x3FFFFU)
111 
115 #define ADC_SAMPLEDELAY_MAX (0xFFU)
116 
120 #define ADC_RANGE_MAX (0x3FFU)
121 
125 #define ADC_RANGE_MIN (0x0U)
126 
130 #define ADC_FIFO_SIZE (64U)
131 
135 #define ADC_RESLN_MAX (1024U)
136 
139 #define ADC_MAX_NUM_CHN (uint32_t)(8U)
140 /* ========================================================================== */
141 /* Structures and Enums */
142 /* ========================================================================== */
153 typedef uint32_t adcChannel_t;
154 
155 #define ADC_CHANNEL_1 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_1)
156 
157 #define ADC_CHANNEL_2 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_2)
158 
159 #define ADC_CHANNEL_3 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_3)
160 
161 #define ADC_CHANNEL_4 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_4)
162 
163 #define ADC_CHANNEL_5 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_5)
164 
165 #define ADC_CHANNEL_6 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_6)
166 
167 #define ADC_CHANNEL_7 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_7)
168 
169 #define ADC_CHANNEL_8 (ADC_STEPCONFIG_SEL_INM_SWC_CHANNEL_8)
170 
171 /* @} */
172 
181 typedef uint32_t adcStepId_t;
182 
183 #define ADC_STEP_1 (ADC_ADCSTAT_STEP_ID_STEP1)
184 
185 #define ADC_STEP_2 (ADC_ADCSTAT_STEP_ID_STEP2)
186 
187 #define ADC_STEP_3 (ADC_ADCSTAT_STEP_ID_STEP3)
188 
189 #define ADC_STEP_4 (ADC_ADCSTAT_STEP_ID_STEP4)
190 
191 #define ADC_STEP_5 (ADC_ADCSTAT_STEP_ID_STEP5)
192 
193 #define ADC_STEP_6 (ADC_ADCSTAT_STEP_ID_STEP6)
194 
195 #define ADC_STEP_7 (ADC_ADCSTAT_STEP_ID_STEP7)
196 
197 #define ADC_STEP_8 (ADC_ADCSTAT_STEP_ID_STEP8)
198 
199 #define ADC_STEP_9 (ADC_ADCSTAT_STEP_ID_STEP9)
200 
201 #define ADC_STEP_10 (ADC_ADCSTAT_STEP_ID_STEP10)
202 
203 #define ADC_STEP_11 (ADC_ADCSTAT_STEP_ID_STEP11)
204 
205 #define ADC_STEP_12 (ADC_ADCSTAT_STEP_ID_STEP12)
206 
207 #define ADC_STEP_13 (ADC_ADCSTAT_STEP_ID_STEP13)
208 
209 #define ADC_STEP_14 (ADC_ADCSTAT_STEP_ID_STEP14)
210 
211 #define ADC_STEP_15 (ADC_ADCSTAT_STEP_ID_STEP15)
212 
213 #define ADC_STEP_16 (ADC_ADCSTAT_STEP_ID_STEP16)
214 
215 /* @} */
216 
228 typedef uint32_t adcOperationMode_t;
229 
230 #define ADC_OPERATION_MODE_SINGLE_SHOT (ADC_STEPCONFIG_MODE_SW_EN_ONESHOT)
231 
232 #define ADC_OPERATION_MODE_CONTINUOUS (ADC_STEPCONFIG_MODE_SW_EN_CONTINUOUS)
233 
234 /* @} */
235 
246 typedef uint32_t adcAveraging_t;
247 
248 #define ADC_AVERAGING_NONE (ADC_STEPCONFIG_AVERAGING_NOAVG)
249 
250 #define ADC_AVERAGING_2_SAMPLES (ADC_STEPCONFIG_AVERAGING_2_SAMPLESAVG)
251 
252 #define ADC_AVERAGING_4_SAMPLES (ADC_STEPCONFIG_AVERAGING_4_SAMPLESAVG)
253 
254 #define ADC_AVERAGING_8_SAMPLES (ADC_STEPCONFIG_AVERAGING_8_SAMPLESAVG)
255 
256 #define ADC_AVERAGING_16_SAMPLES (ADC_STEPCONFIG_AVERAGING_16_SAMPLESAV)
257 
258 /* @} */
259 
268 typedef uint32_t adcFIFONum_t;
269 
270 #define ADC_FIFO_NUM_0 (0x0U)
271 
272 #define ADC_FIFO_NUM_1 (0x1U)
273 
274 /* @} */
275 
284 typedef uint32_t adcIntrSrc_t;
285 
286 #define ADC_INTR_SRC_END_OF_SEQUENCE (ADC_IRQENABLE_SET_END_OF_SEQUENCE_MASK)
287 
288 #define ADC_INTR_SRC_FIFO0_THRESHOLD (ADC_IRQENABLE_SET_FIFO0_THR_MASK)
289 
290 #define ADC_INTR_SRC_FIFO0_OVERRUN (ADC_IRQENABLE_SET_FIFO0_OVERRUN_MASK)
291 
292 #define ADC_INTR_SRC_FIFO0_UNDERFLOW (ADC_IRQENABLE_SET_FIFO0_UNDERFLOW_MASK)
293 
294 #define ADC_INTR_SRC_FIFO1_THRESHOLD (ADC_IRQENABLE_SET_FIFO1_THR_MASK)
295 
296 #define ADC_INTR_SRC_FIFO1_OVERRUN (ADC_IRQSTATUS_FIFO1_OVERRUN_MASK)
297 
298 #define ADC_INTR_SRC_FIFO1_UNDERFLOW (ADC_IRQENABLE_SET_FIFO1_UNDERFLOW_MASK)
299 
300 #define ADC_INTR_SRC_OUT_OF_RANGE (ADC_IRQENABLE_SET_OUT_OF_RANGE_MASK)
301 
302 /* @} */
303 
312 typedef uint32_t adcIdleMode_t;
313 
314 #define ADC_IDLE_MODE_FORCE_IDLE (ADC_SYSCONFIG_IDLEMODE_FORCE)
315 
316 #define ADC_IDLE_MODE_NO_IDLE (ADC_SYSCONFIG_IDLEMODE_NO_IDLE)
317 
318 #define ADC_IDLE_MODE_SMART_IDLE (ADC_SYSCONFIG_IDLEMODE_SMART_IDLE)
319 
320 /* @} */
321 
325 typedef struct adcRevisionId
326 {
327  uint32_t scheme;
329  uint32_t func;
331  uint32_t rtlRev;
333  uint32_t major;
335  uint32_t custom;
337  uint32_t minor;
340 
344 typedef struct adcStepConfig
345 {
346  uint32_t mode;
350  uint32_t channel;
354  uint32_t openDelay;
360  uint32_t sampleDelay;
370  uint32_t averaging;
374  uint32_t fifoNum;
379 
383 typedef struct adcSequencerStatus
384 {
385  uint32_t afeBusy;
390  uint32_t fsmBusy;
394  uint32_t stepId;
399 
400 /* ========================================================================== */
401 /* Global Variables */
402 /* ========================================================================== */
403 
404 /* None */
405 
406 /* ========================================================================== */
407 /* Function Declarations */
408 /* ========================================================================== */
418 void ADCPowerUp(uint32_t baseAddr, uint32_t powerUp);
419 
428 uint32_t AdcIsPoweredUp(uint32_t baseAddr);
429 
443 int32_t ADCSetClkDivider(uint32_t baseAddr, uint32_t clkDivider);
458 void ADCInit(uint32_t baseAddr,
459  uint32_t errCorrection,
460  uint32_t errOffset,
461  uint32_t calibration);
473 void ADCFIFODMAAccessEnable(uint32_t baseAddr,
474  uint32_t fifoNum,
475  uint32_t dmaLineEnable);
476 
488 int32_t ADCSetStepParams(uint32_t baseAddr,
489  uint32_t stepId,
490  const adcStepConfig_t *configParams);
491 
503 void ADCStepEnable(uint32_t baseAddr,
504  uint32_t stepId,
505  uint32_t stepEnable);
506 
513 void ADCClearAllSteps(uint32_t baseAddr);
514 
524 void ADCStart(uint32_t baseAddr, uint32_t adcEnable);
525 
538 void ADCStepIdTagEnable(uint32_t baseAddr, uint32_t stepIdTag);
539 
549 uint32_t ADCGetFIFOData(uint32_t baseAddr, uint32_t fifoNum);
550 
560 uint32_t ADCGetFIFOWordCount(uint32_t baseAddr, uint32_t fifoNum);
561 
577 int32_t ADCSetCPUFIFOThresholdLevel(uint32_t baseAddr,
578  uint32_t fifoNum,
579  uint32_t threshold);
580 
592 uint32_t ADCGetCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum);
593 
609 int32_t ADCSetDMAFIFOThresholdLevel(uint32_t baseAddr,
610  uint32_t fifoNum,
611  uint32_t threshold);
612 
623 uint32_t ADCGetDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum);
624 
634 void ADCEnableIntr(uint32_t baseAddr, uint32_t intrMask);
635 
644 void ADCDisableIntr(uint32_t baseAddr, uint32_t intrMask);
645 
653 void ADCWriteEOI(uint32_t baseAddr);
654 
662 uint32_t ADCGetIntrStatus(uint32_t baseAddr);
663 
672 void ADCClearIntrStatus(uint32_t baseAddr, uint32_t intrMask);
673 
681 uint32_t ADCGetIntrRawStatus(uint32_t baseAddr);
682 
692 int32_t ADCSetRange(uint32_t baseAddr, uint32_t highRange, uint32_t lowRange);
693 
703 void ADCGetRange(uint32_t baseAddr,
704  uint32_t *highRange,
705  uint32_t *lowRange);
706 
716 void ADCGetSequencerStatus(uint32_t baseAddr,
717  adcSequencerStatus_t *status);
718 
729 void ADCSetIdleMode(uint32_t baseAddr, uint32_t idleMode);
730 
740 void ADCGetRevisionId(uint32_t baseAddr, adcRevisionId_t *revId);
741 
742 #ifdef __cplusplus
743 }
744 
745 #endif /*extern "C" */
746 
747 #endif
748 
void ADCGetRevisionId(uint32_t baseAddr, adcRevisionId_t *revId)
This API is used get the ADC revision ID.
int32_t ADCSetRange(uint32_t baseAddr, uint32_t highRange, uint32_t lowRange)
This API is used to configure the range for ADC.
void ADCEnableIntr(uint32_t baseAddr, uint32_t intrMask)
This API is used to enable interrupts.
uint32_t major
Definition: adc.h:333
uint32_t averaging
Definition: adc.h:370
uint32_t fifoNum
Definition: adc.h:374
uint32_t sampleDelay
Definition: adc.h:360
uint32_t ADCGetIntrStatus(uint32_t baseAddr)
This API is used to get the pending interrupts.
void ADCGetSequencerStatus(uint32_t baseAddr, adcSequencerStatus_t *status)
This API is used to get the Sequencer status.
void ADCWriteEOI(uint32_t baseAddr)
This API is used for EOI for ADC.
uint32_t scheme
Definition: adc.h:327
uint32_t mode
Definition: adc.h:346
uint32_t adcOperationMode_t
Enum to select the ADC Operation Mode.
Definition: adc.h:228
Structure for reporting ADC sequencer status.
Definition: adc.h:383
uint32_t adcStepId_t
Enum to select the step for operation.
Definition: adc.h:181
uint32_t adcAveraging_t
Enum to number of samplings to average.
Definition: adc.h:246
uint32_t stepId
Definition: adc.h:394
uint32_t AdcIsPoweredUp(uint32_t baseAddr)
This function checks if the ADC module is powered up.
uint32_t ADCGetCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum)
This API will read and return threshold level for a FIFO.
uint32_t afeBusy
Definition: adc.h:385
void ADCClearAllSteps(uint32_t baseAddr)
This API will clear all the ADC steps.
void ADCStepEnable(uint32_t baseAddr, uint32_t stepId, uint32_t stepEnable)
This API will enable ADC step.
uint32_t ADCGetFIFOData(uint32_t baseAddr, uint32_t fifoNum)
This API will read and return FIFO data.
uint32_t rangeCheckEnable
Definition: adc.h:365
uint32_t ADCGetFIFOWordCount(uint32_t baseAddr, uint32_t fifoNum)
This API will return number of word present in the FIFO.
uint32_t adcIdleMode_t
Enum to configure ADC idle mode.Applicable for TDA3XX Only.
Definition: adc.h:312
void ADCInit(uint32_t baseAddr, uint32_t errCorrection, uint32_t errOffset, uint32_t calibration)
This API is used to initialize the ADC module.
int32_t ADCSetClkDivider(uint32_t baseAddr, uint32_t clkDivider)
This API will configure clock divider for the ADC Module.
uint32_t fsmBusy
Definition: adc.h:390
Structure for accessing Revision ID of ADC module.
Definition: adc.h:325
void ADCClearIntrStatus(uint32_t baseAddr, uint32_t intrMask)
This API is used to clear the interrupt status.
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.
Structure containing parameters for ADC step configuration.
Definition: adc.h:344
uint32_t custom
Definition: adc.h:335
void ADCPowerUp(uint32_t baseAddr, uint32_t powerUp)
This API will power up ADC Module.
void ADCFIFODMAAccessEnable(uint32_t baseAddr, uint32_t fifoNum, uint32_t dmaLineEnable)
This API will enable DMA access for FIFO.
uint32_t rtlRev
Definition: adc.h:331
int32_t ADCSetStepParams(uint32_t baseAddr, uint32_t stepId, const adcStepConfig_t *configParams)
This API will configure a step for analog to digital conversion.
void ADCGetRange(uint32_t baseAddr, uint32_t *highRange, uint32_t *lowRange)
This API is used to get the range for conversion.
uint32_t minor
Definition: adc.h:337
uint32_t openDelay
Definition: adc.h:354
void ADCDisableIntr(uint32_t baseAddr, uint32_t intrMask)
This API is used to disable interrupts.
int32_t ADCSetCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum, uint32_t threshold)
This API will configure threshold level for a FIFO.
uint32_t func
Definition: adc.h:329
uint32_t adcChannel_t
Enum to select the channel for input.
Definition: adc.h:153
uint32_t adcIntrSrc_t
Enum for ADC interrupts.
Definition: adc.h:284
void ADCSetIdleMode(uint32_t baseAddr, uint32_t idleMode)
This API is used to configure ADC idle mode.
void ADCStart(uint32_t baseAddr, uint32_t adcEnable)
This API will start ADC.
uint32_t ADCGetIntrRawStatus(uint32_t baseAddr)
This API is used to get the raw interrupt status.
int32_t ADCSetDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum, uint32_t threshold)
This API will configure DMA request level for a FIFO.
uint32_t adcFIFONum_t
Enum to select FIFO to store the data.
Definition: adc.h:268
uint32_t ADCGetDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum)
This API will read and return DMA request level for a FIFO.
uint32_t channel
Definition: adc.h:350