ADCBufLPF3.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2025, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file ADCBufLPF3.h
34  *
35  * @brief ADCBuf driver implementation for an LPF3 analog-to-digital
36  * converter
37  *
38  * # Driver include #
39  * The ADCBuf header file should be included in an application as follows:
40  * @code
41  * #include <ti/drivers/ADCBuf.h>
42  * #include <ti/drivers/adc/ADCBufLPF3.h>
43  * @endcode
44  *
45  * # Overview #
46  * This is an LPF3 specific implementation of the generic ADCBuf driver.
47  * The generic ADCBuf API specified in @ref ti/drivers/ADCBuf.h should be called
48  * by the application, not the device specific implementation in
49  * ti/drivers/adcbuf/ADCBufLPF3.c
50  *
51  * # General Behavior #
52  * The internal ADC sample timer is used to generate samples at a specified
53  * frequency and the DMA is used to fill a buffer with a specified size in the
54  * background. The application may execute other tasks while the hardware
55  * handles the conversions. In contrast to the standard ti/drivers/ADC driver,
56  * this driver allows for precise sampling of waveforms.
57  *
58  * | Driver | Number of samples needed in one call |
59  * |----------------|-----------------------------------------|
60  * | ADC.h | 1 |
61  * | ADCBuf.h | > 1 |
62  *
63  * The ADC drivers supports making between 1 and 1024 measurements once or
64  * continuous measuring with returned buffer sizes between 1 and 1024
65  * measurements.
66  *
67  * The ADCBuf driver is opened by calling #ADCBuf_open() which will
68  * set up interrupts and configure the internal components of the driver.
69  * However, the ADCBuf hardware or analog pins are not configured by calling
70  * #ADCBuf_open() since other software components might be using the ADC.
71  *
72  * In order to perform an ADC conversion, the application must call
73  * #ADCBuf_convert(). This call will request the ADC resource, configure the
74  * ADC, set up the DMA, and perform the requested ADC conversions on the
75  * selected DIO or internal signal.
76  *
77  * @warning If the ADCBUF driver is setup in ADCBuf_RECURRENCE_MODE_CONTINUOUS
78  * mode, the user must assure that the provided callback function is
79  * completed before the next conversion completes. If the next
80  * conversion completes before the callback function finishes, the DMA
81  * will clobber the previous buffer with new data.
82  *
83  * If the ADC is used by another component when the driver requests it at the
84  * start of the #ADCBuf_convert() call, the calling task will be put in blocked
85  * state until the ADC is available. If #ADCBuf_convert() is called from ISR
86  * context, the call will fail and return #ADCBuf_STATUS_ERROR.
87  * The ADC resource may be pre-acquired by calling the
88  * #ADCBufLPF3_acquireAdcSemaphore() function. The semaphore must be manually
89  * released again when done with the ADC by calling
90  * #ADCBufLPF3_releaseAdcSemaphore()
91  *
92  * # Error handling #
93  * The following errors may occur when opening the ADC without assertions enabled:
94  * - The ADC handle is already open.
95  *
96  * The following errors may occur when requesting an ADC conversion:
97  * - The ADC is currently already doing a conversion.
98  * - The ADC is not available.
99  *
100  * # Power Management #
101  * The TI Power management framework will try to put the device into the
102  * most power efficient mode whenever possible. Please see the technical
103  * reference manual for further details on each power mode.
104  *
105  * While converting, the ADCBufLPF3 driver sets a power constraint to keep
106  * the device out of standby. When the conversion has finished, the power
107  * constraint is released. The driver also sets a dependency on the DMA to
108  * enable background transfers from the ADC FIFO to memory.
109  * The following statements are valid:
110  * - After #ADCBuf_convert(): the device cannot enter standby.
111  * - After #ADCBuf_convertCancel(): the device can enter standby.
112  * - After a conversion finishes: the device can enter standby.
113  *
114  *
115  * # Supported Functions #
116  * | API function | Description |
117  * |---------------------------------------|-----------------------------------------------------------------------|
118  * | #ADCBuf_init() | Initialize ADC driver |
119  * | #ADCBuf_open() | Open the ADC driver and configure driver |
120  * | #ADCBuf_convert() | Perform ADC conversion |
121  * | #ADCBuf_convertCancel() | Cancel ongoing ADC conversion |
122  * | #ADCBuf_close() | Close ADC driver |
123  * | #ADCBuf_Params_init() | Initialise ADCBuf_Params structure to default values |
124  * | #ADCBuf_getResolution() | Get the resolution of the ADC of the current device |
125  * | #ADCBuf_adjustRawValues() | Adjust the values in a returned buffer for manufacturing tolerances |
126  * | #ADCBuf_convertAdjustedToMicroVolts() | Convert a buffer of adjusted values to microvolts |
127  * | #ADCBufLPF3_acquireAdcSemaphore() | Manually pre-acquire ADC semaphore |
128  * | #ADCBufLPF3_releaseAdcSemaphore() | Release ADC semaphore previously manually pre-acquired using |
129  *
130  * # Supported Sampling Frequencies
131  * | Reference | Resolution | Min Frequency | Max Frequency |
132  * |------------------|------------|-----------------|---------------|
133  * | External or VDDS | 8-bit | 978 sps | 1600 ksps |
134  * | External or VDDS | 10-bit | 978 sps | 1330 ksps |
135  * | External or VDDS | 12-bit | 977 sps | 1200 ksps |
136  * | Internal | 8-bit | 976 sps | 400 ksps |
137  * | Internal | 10-bit | 975 sps | 308 ksps |
138  * | Internal | 12-bit | 975 sps | 267 ksps |
139  *
140  * # Not Supported Functionality #
141  * - Performing conversions on multiple channels simultaneously is not
142  * supported. In other words, the parameter @c channelCount must always be
143  * set to 1 when calling #ADCBuf_convert(). For the same reason, the value
144  * of the @c completedChannel argument in the #ADCBuf_Callback will always
145  * be 0.
146  * - It is not supported to have multiple ADCBuf instances open at the same
147  * time. You must close the currently open instance (if any) before trying
148  * to open another instance.
149  * It is suggested to only have one ADCBuf instances.
150  *
151  * # Used Resources #
152  * - The ADC Peripheral
153  * - 2 DMA channels
154  * - One "data" channel is used to copy the samples from the ADC to memory
155  * - The channel is selected using the relevant data DMA fields in
156  * #ADCBufLPF3_HWAttrs:
157  * - #ADCBufLPF3_HWAttrs.dataDmaTableEntryPri
158  * - #ADCBufLPF3_HWAttrs.dataDmaTableEntryAlt
159  * - #ADCBufLPF3_HWAttrs.dataDmaChannelMask
160  * - #ADCBufLPF3_HWAttrs.dataDmaSubscriberId
161  * - Another "auxiliary" channel is used to re-configure the ADC to generate
162  * DMA triggers for the data DMA channel after each data DMA transfer. This
163  * is needed because the ADC disables generation of DMA triggers when a DMA
164  * transfer completes. So in continuos mode, the generation of DMA triggers
165  * must be re-enabled, and it must be re-enabled within one sample period to
166  * not cause any overflow. To be able to re-enable triggers quickly enough,
167  * the auxiliary DMA channel is used.
168  * - The channel is selected using the relevant auxiliary DMA fields in
169  * #ADCBufLPF3_HWAttrs:
170  * - #ADCBufLPF3_HWAttrs.auxDmaTableEntryPri
171  * - #ADCBufLPF3_HWAttrs.auxDmaChannelMask
172  * - #ADCBufLPF3_HWAttrs.auxDmaSubscriberId
173  *
174  ******************************************************************************
175  */
176 
177 #ifndef ti_drivers_adcbuf_adcbufLPF3__include
178 #define ti_drivers_adcbuf_adcbufLPF3__include
179 
180 #include <stdint.h>
181 #include <stdbool.h>
182 
183 /* Driver includes */
184 #include <ti/drivers/ADC.h>
185 #include <ti/drivers/Power.h>
186 #include <ti/drivers/ADCBuf.h>
187 #include <ti/drivers/adc/ADCLPF3.h>
188 #include <ti/drivers/dma/UDMALPF3.h>
189 
190 /* Kernel includes */
191 #include <ti/drivers/dpl/HwiP.h>
192 #include <ti/drivers/dpl/SwiP.h>
193 #include <ti/drivers/dpl/ClockP.h>
195 
196 /* Driverlib includes */
197 #include <ti/devices/DeviceFamily.h>
198 #include DeviceFamily_constructPath(inc/hw_memmap.h)
199 #include DeviceFamily_constructPath(inc/hw_adc.h)
200 #include DeviceFamily_constructPath(inc/hw_types.h)
201 #include DeviceFamily_constructPath(driverlib/adc.h)
202 #include DeviceFamily_constructPath(driverlib/evtsvt.h)
203 
204 #ifdef __cplusplus
205 extern "C" {
206 #endif
207 
220 #define ADCBufLPF3_STATUS_UNDERFLOW (ADCBuf_STATUS_RESERVED - 0)
221 
234 #define ADCBufLPF3_STATUS_OVERFLOW (ADCBuf_STATUS_RESERVED - 1)
235 
251 #define ADCBufLPF3_STATUS_UNDERFLOW_AND_OVERFLOW (ADCBuf_STATUS_RESERVED - 2)
252 
253 #define ADCBufLPF3_BYTES_PER_SAMPLE 2
254 
255 /*
256  * =============================================================================
257  * Constants
258  * =============================================================================
259  */
260 
261 /* ADCBuf function table */
263 
264 /*
265  * =============================================================================
266  * Enumerations
267  * =============================================================================
268  */
269 
273 typedef enum
274 {
279 
280 /*
281  * =============================================================================
282  * Structs
283  * =============================================================================
284  */
285 
290 typedef struct
291 {
293  uint_fast32_t refVoltage;
297  uint8_t adcInputDIO;
303 
342 typedef struct
343 {
345  volatile uDMAControlTableEntry *dataDmaTableEntryPri;
346 
348  volatile uDMAControlTableEntry *dataDmaTableEntryAlt;
349 
353  volatile uDMAControlTableEntry *auxDmaTableEntryPri;
354 
360 
363 
366 
369 
374 
379 
383  uint8_t intPriority;
384 
389  uint8_t adcRefPosDIO;
390 
395  uint8_t adcRefNegDIO;
397 
403 typedef struct
404 {
420  ADCBufLPF3_ConversionStatus conversionStatus;
426  bool isOpen;
430 
431 /*
432  * =============================================================================
433  * Functions
434  * =============================================================================
435  */
436 
464 bool ADCBufLPF3_acquireAdcSemaphore(ADCBuf_Handle handle, uint32_t timeout);
465 
481 
482 #ifdef __cplusplus
483 }
484 #endif
485 
486 #endif /* ti_drivers_adcbuf_ADCBufLPF3__include */
uint8_t intPriority
Definition: ADCBufLPF3.h:383
uint32_t dataDmaSubscriberId
Definition: ADCBufLPF3.h:373
uint32_t semaphoreTimeout
Definition: ADCBufLPF3.h:416
struct ADCBufLPF3_Object * ADCBufLPF3_Handle
HwiP structure.
Definition: HwiP.h:166
Definition: ADCBufLPF3.h:276
uint8_t adcRefPosDIO
Definition: ADCBufLPF3.h:389
Clock interface for the RTOS Porting Interface.
SemaphoreP_Struct conversionSemaphore
Definition: ADCBufLPF3.h:406
Power Manager.
Analog to Digital Conversion Buffer (ADCBuf) Input Driver.
ADCLPF3_Reference_Source
Specifies the source of the ADC reference voltage.
Definition: ADCLPF3.h:98
Table entry that maps a virtual adc channel to the corresponding hardware configuration.
Definition: ADCBufLPF3.h:290
HwiP_Struct hwi
Definition: ADCBufLPF3.h:410
uint32_t auxDmaSubscriberId
Definition: ADCBufLPF3.h:378
bool ADCBufLPF3_acquireAdcSemaphore(ADCBuf_Handle handle, uint32_t timeout)
Function to acquire the semaphore that arbitrates access to the ADC.
volatile uDMAControlTableEntry * dataDmaTableEntryPri
Definition: ADCBufLPF3.h:345
ADCBuf_Return_Mode returnMode
Definition: ADCBufLPF3.h:422
ADCBufLPF3 Object.
Definition: ADCBufLPF3.h:403
Semaphore module for the RTOS Porting Interface.
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufLPF3.h:424
Analog to Digital Conversion (ADC) Input Driver.
uint8_t adcInputDIO
Definition: ADCBufLPF3.h:297
uint32_t samplingFrequency
Definition: ADCBufLPF3.h:418
The definition of an ADCBuf function table that contains the required set of functions to control a s...
Definition: ADCBuf.h:598
Software Interrupt module for the RTOS Porting Interface.
Definition: ADCBufLPF3.h:277
ADCLPF3_Reference_Source refSource
Definition: ADCBufLPF3.h:301
ADC driver&#39;s custom configuration structure.
Definition: ADCBuf.h:629
ADCBuf_Callback callbackFxn
Definition: ADCBufLPF3.h:412
uint8_t internalChannel
Definition: ADCBufLPF3.h:299
bool userAcquiredAdcSemaphore
Definition: ADCBufLPF3.h:428
const ADCBuf_FxnTable ADCBufLPF3_fxnTable
Definition: ADCBufLPF3.h:275
uint32_t * activeSampleBuffer
Definition: ADCBufLPF3.h:414
uint_fast32_t refVoltage
Definition: ADCBufLPF3.h:293
ADCBuf_Recurrence_Mode
Recurrence behavior of a ADCBuf_Conversion specified in the ADCBuf_Params.
Definition: ADCBuf.h:406
ADCBuf_Return_Mode
Return behavior for ADCBuf_convert() specified in the ADCBuf_Params.
Definition: ADCBuf.h:448
volatile uDMAControlTableEntry * auxDmaTableEntryPri
Definition: ADCBufLPF3.h:353
volatile uDMAControlTableEntry * dataDmaTableEntryAlt
Definition: ADCBufLPF3.h:348
ADCBufLPF3_ConversionStatus
Conversion status used internally by the ADCBufLPF3 driver.
Definition: ADCBufLPF3.h:273
bool ADCBufLPF3_releaseAdcSemaphore(ADCBuf_Handle handle)
This function releases the ADC semaphore if it was pre it is in the possession of the ADCBuf instance...
ADCBufLPF3_ConversionStatus conversionStatus
Definition: ADCBufLPF3.h:420
uint8_t adcRefNegDIO
Definition: ADCBufLPF3.h:395
UDMALPF3 driver implementation.
Defines a conversion to be used with ADCBuf_convert().
Definition: ADCBuf.h:314
uint32_t auxDmaChannelMask
Definition: ADCBufLPF3.h:368
ADCLPF3_Resolution_Bits resolutionBits
Definition: ADCBufLPF3.h:362
ADCBuf_Conversion * currentConversion
Definition: ADCBufLPF3.h:408
bool isOpen
Definition: ADCBufLPF3.h:426
Hardware Interrupt module for the RTOS Porting Interface.
ADC driver implementation for the ADC peripheral on Low Power F3 devices.
ADCLPF3_Resolution_Bits
Resolution of ADC-conversion.
Definition: ADCLPF3.h:75
uint32_t dataDmaChannelMask
Definition: ADCBufLPF3.h:365
void(* ADCBuf_Callback)(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel, int_fast16_t status)
The definition of a callback function.
Definition: ADCBuf.h:392
ADCBufLPF3 Hardware Attributes.
Definition: ADCBufLPF3.h:342
SemaphoreP structure.
Definition: SemaphoreP.h:84
ADCBufLPF3_AdcChannelLutEntry const * adcChannelLut
Definition: ADCBufLPF3.h:359
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale