ADCBuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019, 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 ADCBuf.h
34  * @brief Analog to Digital Conversion Buffer (ADCBuf) Input Driver
35  *
36  * @anchor ti_drivers_ADCBuf_Overview
37  * # Overview
38  *
39  * The ADCBuf driver allows you to sample and convert analog signals
40  * at a specified frequency. The resulting samples are placed in
41  * a buffer provided by the application. The driver can either take @p N
42  * samples once or continuously sample by double-buffering and providing a
43  * callback to process each finished buffer.
44  *
45  * <hr>
46  * @anchor ti_drivers_ADCBuf_Usage
47  * # Usage
48  *
49  * This documentation provides a basic @ref ti_drivers_ADCBuf_Synopsis
50  * "usage summary" and a set of @ref ti_drivers_ADCBuf_Examples "examples"
51  * in the form of commented code fragments. Detailed descriptions of the
52  * APIs are provided in subsequent sections.
53  *
54  * @anchor ti_drivers_ADCBuf_Synopsis
55  * ## Synopsis
56  * @anchor ti_drivers_ADCBuf_Synopsis_Code
57  * @code
58  * // Import ADCBuf Driver definitions
59  * #include <ti/drivers/ADCBuf.h>
60  *
61  * // Define name for ADCBuf channel index
62  * #define PIEZOMETER_OUT 0
63  *
64  * // Create buffer for samples
65  * #define ADCBUFFERSIZE 10
66  * uint16_t buffer[ADCBUFFERSIZE];
67  * uint32_t microvoltBuffer[ADCBUFFERSIZE];
68  *
69  * // One time init of ADCBuf driver
70  * ADCBuf_init();
71  *
72  * // Initialize optional ADCBuf parameters
73  * ADCBuf_Params params;
74  * ADCBuf_Params_init(&params);
75  * params.returnMode = ADCBuf_RETURN_MODE_BLOCKING;
76  * params.recurrenceMode = ADCBuf_RECURRENCE_MODE_ONE_SHOT;
77  *
78  * // Open ADCBuf driver
79  * adcBuf = ADCBuf_open(CONFIG_ADCBUF0, &params);
80  *
81  * // Setup conversion structure
82  * ADCBuf_Conversion conversion = {0};
83  * conversion.samplesRequestedCount = ADCBUFFERSIZE;
84  * conversion.sampleBuffer = buffer;
85  * conversion.adcChannel = PIEZOMETER_OUT;
86  *
87  * // Start ADCBuf conversion
88  * ADCBuf_convert(adcBuf, &conversion, 1)
89  *
90  * // Adjust raw ADC values and convert them to microvolts
91  * ADCBuf_adjustRawValues(handle, buffer, ADCBUFFERSIZE, PIEZOMETER_OUT);
92  * ADCBuf_convertAdjustedToMicroVolts(handle, PIEZOMETER_OUT, buffer,
93  * microvoltBuffer, ADCBUFFERSIZE);
94  *
95  * // Close ADCBuf driver
96  * ADCBuf_close(adcbuf);
97  * @endcode
98  *
99  * <hr>
100  * @anchor ti_drivers_ADCBuf_Examples
101  * # Examples
102  *
103  * @li @ref ti_drivers_ADCBuf_Examples_open "Opening an ADCBuf instance"
104  * @li @ref ti_drivers_ADCBuf_Examples_blocking "Using a blocking conversion"
105  * @li @ref ti_drivers_ADCBuf_Examples_callback "Using a callback conversion"
106  *
107  * @anchor ti_drivers_ADCBuf_Examples_open
108  * ## Opening an ADCBuf instance
109  *
110  * @code
111  * ADCBuf_Handle adcBufHandle;
112  * ADCBuf_Params adcBufParams;
113  *
114  * ADCBuf_init();
115  *
116  * ADCBuf_Params_init(&adcBufParams);
117  *
118  * adcBufHandle = ADCBuf_open(0, &adcBufParams);
119  * if (adcBufHandle == NULL)
120  * {
121  * //ADCBuf_open() failed.
122  * while (1) {}
123  * }
124  * @endcode
125  *
126  * @anchor ti_drivers_ADCBuf_Examples_blocking
127  * ## Using a blocking conversion
128  *
129  * @code
130  * ADCBuf_Handle adcbuf;
131  * ADCBuf_Params params;
132  *
133  * ADCBuf_init();
134  *
135  * ADCBuf_Params_init(&params);
136  * params.returnMode = ADCBuf_RETURN_MODE_BLOCKING;
137  * params.recurrenceMode = ADCBuf_RECURRENCE_MODE_ONE_SHOT;
138  * adcbuf = ADCBuf_open(0, &params);
139  * if (adcbuf != NULL)
140  * {
141  * ADCBuf_Conversion conversion = {0};
142  * conversion.adcChannel = PIEZOMETER_OUT;
143  * conversion.sampleBuffer = buffer;
144  * conversion.samplesRequestedCount = ADCBUFFERSIZE;
145  *
146  * if (ADCBuf_convert(adcbuf, &conversion, 1) != ADCBuf_STATUS_SUCCESS)
147  * {
148  * // ADCBuf_conver() failed
149  * }
150  * }
151  * @endcode
152  *
153  * @anchor ti_drivers_ADCBuf_Examples_callback
154  * ## Using a callback conversion
155  *
156  * @code
157  * // ADCBuf callback function
158  * void adcBufCallbackFxn(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
159  * void *buffer, uint32_t channel);
160  *
161  * main()
162  * {
163  * ADCBuf_Handle adcbuf;
164  * ADCBuf_Params params;
165  *
166  * ADCBuf_init();
167  *
168  * ADCBuf_Params_init(&params);
169  * params.returnMode = ADCBuf_RETURN_MODE_CALLBACK;
170  * params.recurrenceMode = ADCBuf_RECURRENCE_MODE_ONE_SHOT;
171  * params.callbackFxn = adcBufCallbackFxn;
172  * adcbuf = ADCBuf_open(0, &params);
173  *
174  * ADCBuf_Conversion conversion = {0};
175  * conversion.adcChannel = PIEZOMETER_OUT;
176  * conversion.sampleBuffer = buffer;
177  * conversion.samplesRequestedCount = ADCBUFFERSIZE;
178  *
179  * if (ADCBuf_convert(adcbuf, &conversion, 1) != ADCBuf_STATUS_SUCCESS)
180  * {
181  * // ADCBuf_convert() failed
182  * }
183  *
184  * // Pend on a semaphore
185  * }
186  *
187  * void adcBufCallbackFxn(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
188  * void *buffer, uint32_t channel)
189  * {
190  * // Adjust raw ADC values and convert them to microvolts
191  * ADCBuf_adjustRawValues(handle, buffer, ADCBUFFERSIZE,
192  * channel);
193  * ADCBuf_convertAdjustedToMicroVolts(handle, channel,
194  * buffer, microvoltBuffer, ADCBUFFERSIZE);
195  *
196  * // Post a semaphore
197  * }
198  *
199  * @endcode
200  *
201  * <hr>
202  * @anchor ti_drivers_ADCBuf_Configuration
203  * # Configuration
204  *
205  * Refer to the @ref driver_configuration "Driver's Configuration" section
206  * for driver configuration information.
207  * <hr>
208  ******************************************************************************
209  */
210 
211 #ifndef ti_drivers_adcbuf__include
212 #define ti_drivers_adcbuf__include
213 
214 #include <stdint.h>
215 
216 #ifdef __cplusplus
217 extern "C" {
218 #endif
219 
237 #define ADCBuf_CMD_RESERVED (32)
238 
251 #define ADCBuf_STATUS_RESERVED (-32)
252 
262 #define ADCBuf_STATUS_SUCCESS (0)
263 
270 #define ADCBuf_STATUS_ERROR (-1)
271 
279 #define ADCBuf_STATUS_UNDEFINEDCMD (-2)
280 
285 #define ADCBuf_STATUS_UNSUPPORTED (-3)
286 
296 /* Add ADCBuf_CMD_<commands> here */
297 
307 
315 typedef struct
316 {
324 
331 
342 
353  void *arg;
354 
360  uint32_t adcChannel;
362 
391 typedef void (*ADCBuf_Callback) (ADCBuf_Handle handle,
392  ADCBuf_Conversion *conversion,
393  void *completedADCBuffer,
394  uint32_t completedChannel);
395 
404 typedef enum
405 {
417 
436 
446 typedef enum
447 {
459 
473 
482 typedef struct
483 {
496  uint32_t blockingTimeout;
497 
504 
506  ADCBuf_Return_Mode returnMode;
507 
513 
515  ADCBuf_Recurrence_Mode recurrenceMode;
516 
518  void *custom;
519 } ADCBuf_Params;
520 
526 typedef void (*ADCBuf_CloseFxn) (ADCBuf_Handle handle);
527 
533 typedef ADCBuf_Handle (*ADCBuf_OpenFxn) (ADCBuf_Handle handle,
534  const ADCBuf_Params *params);
535 
541 typedef int_fast16_t (*ADCBuf_ControlFxn) (ADCBuf_Handle handle,
542  uint_fast8_t cmd,
543  void *arg);
549 typedef void (*ADCBuf_InitFxn) (ADCBuf_Handle handle);
550 
556 typedef int_fast16_t (*ADCBuf_ConvertFxn) (ADCBuf_Handle handle,
557  ADCBuf_Conversion conversions[],
558  uint_fast8_t channelCount);
564 typedef int_fast16_t (*ADCBuf_ConvertCancelFxn)(ADCBuf_Handle handle);
565 
571 typedef uint_fast8_t (*ADCBuf_GetResolutionFxn) (ADCBuf_Handle handle);
572 
578 typedef int_fast16_t (*ADCBuf_adjustRawValuesFxn)(ADCBuf_Handle handle,
579  void *sampleBuffer,
580  uint_fast16_t sampleCount,
581  uint32_t adcChannel);
582 
588 typedef int_fast16_t (*ADCBuf_convertAdjustedToMicroVoltsFxn) (
589  ADCBuf_Handle handle,
590  uint32_t adcChannel,
591  void *adjustedSampleBuffer,
592  uint32_t outputMicroVoltBuffer[],
593  uint_fast16_t sampleCount);
594 
600 typedef struct
601 {
603  ADCBuf_CloseFxn closeFxn;
605  ADCBuf_ControlFxn controlFxn;
607  ADCBuf_InitFxn initFxn;
609  ADCBuf_OpenFxn openFxn;
611  ADCBuf_ConvertFxn convertFxn;
614  ADCBuf_ConvertCancelFxn convertCancelFxn;
616  ADCBuf_GetResolutionFxn getResolutionFxn;
619  ADCBuf_adjustRawValuesFxn adjustRawValuesFxn;
621  ADCBuf_convertAdjustedToMicroVoltsFxn convertAdjustedToMicroVoltsFxn;
623 
631 typedef struct ADCBuf_Config_
632 {
636 
638  void *object;
639 
642  void const *hwAttrs;
643 } ADCBuf_Config;
644 
656 extern void ADCBuf_close(ADCBuf_Handle handle);
657 
680 extern int_fast16_t ADCBuf_control(ADCBuf_Handle handle,
681  uint_fast16_t cmd,
682  void *cmdArg);
683 
689 extern void ADCBuf_init(void);
690 
705 extern void ADCBuf_Params_init(ADCBuf_Params *params);
706 
719 extern ADCBuf_Handle ADCBuf_open(uint_least8_t index, ADCBuf_Params *params);
720 
747 extern int_fast16_t ADCBuf_convert(ADCBuf_Handle handle,
748  ADCBuf_Conversion conversions[],
749  uint_fast8_t channelCount);
750 
761 extern int_fast16_t ADCBuf_convertCancel(ADCBuf_Handle handle);
762 
772 extern uint_fast8_t ADCBuf_getResolution(ADCBuf_Handle handle);
773 
796 extern int_fast16_t ADCBuf_adjustRawValues(ADCBuf_Handle handle,
797  void *sampleBuf,
798  uint_fast16_t sampleCount,
799  uint32_t adcChan);
800 
821 extern int_fast16_t ADCBuf_convertAdjustedToMicroVolts(
822  ADCBuf_Handle handle,
823  uint32_t adcChan,
824  void *adjustedSampleBuffer,
825  uint32_t outputMicroVoltBuffer[],
826  uint_fast16_t sampleCount);
827 
828 #ifdef __cplusplus
829 }
830 #endif
831 #endif /* ti_drivers_adcbuf__include */
const ADCBuf_FxnTable * fxnTablePtr
Definition: ADCBuf.h:635
uint16_t samplesRequestedCount
Definition: ADCBuf.h:323
void * sampleBuffer
Definition: ADCBuf.h:330
void ADCBuf_close(ADCBuf_Handle handle)
Function to close an ADCBuf driver instance.
int_fast16_t ADCBuf_adjustRawValues(ADCBuf_Handle handle, void *sampleBuf, uint_fast16_t sampleCount, uint32_t adcChan)
Adjust a raw ADC output buffer. The function does the adjustment in-place.
int_fast16_t ADCBuf_control(ADCBuf_Handle handle, uint_fast16_t cmd, void *cmdArg)
Function performs implementation specific features on a driver instance.
struct ADCBuf_Config_ * ADCBuf_Handle
A handle that is returned from an ADCBuf_open() call.
Definition: ADCBuf.h:306
void ADCBuf_init(void)
Function to initialize the ADCBuf driver.
uint_fast8_t ADCBuf_getResolution(ADCBuf_Handle handle)
Returns the resolution in bits of the specified ADCBuf instance.
uint32_t blockingTimeout
Definition: ADCBuf.h:496
uint32_t samplingFrequency
Definition: ADCBuf.h:503
Definition: ADCBuf.h:416
uint32_t adcChannel
Definition: ADCBuf.h:360
void * custom
Definition: ADCBuf.h:518
void * object
Definition: ADCBuf.h:638
ADCBuf parameters used with ADCBuf_open().
Definition: ADCBuf.h:482
struct ADCBuf_Config_ ADCBuf_Config
ADC driver&#39;s custom configuration structure.
The definition of an ADCBuf function table that contains the required set of functions to control a s...
Definition: ADCBuf.h:600
void const * hwAttrs
Definition: ADCBuf.h:642
ADC driver&#39;s custom configuration structure.
Definition: ADCBuf.h:631
int_fast16_t ADCBuf_convertAdjustedToMicroVolts(ADCBuf_Handle handle, uint32_t adcChan, void *adjustedSampleBuffer, uint32_t outputMicroVoltBuffer[], uint_fast16_t sampleCount)
Convert an adjusted ADC output buffer to microvolts.
ADCBuf_Recurrence_Mode
Recurrence behavior of a ADCBuf_Conversion specified in the ADCBuf_Params.
Definition: ADCBuf.h:404
ADCBuf_Return_Mode
Return behavior for ADCBuf_convert() specified in the ADCBuf_Params.
Definition: ADCBuf.h:446
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBuf.h:515
Definition: ADCBuf.h:458
int_fast16_t ADCBuf_convertCancel(ADCBuf_Handle handle)
Cancels all ADCBuf conversions in progress.
void * arg
Definition: ADCBuf.h:353
void(* ADCBuf_Callback)(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel)
The definition of a callback function.
Definition: ADCBuf.h:391
Definition: ADCBuf.h:471
Defines a conversion to be used with ADCBuf_convert().
Definition: ADCBuf.h:315
Definition: ADCBuf.h:434
void ADCBuf_Params_init(ADCBuf_Params *params)
Initialize an ADCBuf_Params structure to its default values.
ADCBuf_Callback callbackFxn
Definition: ADCBuf.h:512
ADCBuf_Handle ADCBuf_open(uint_least8_t index, ADCBuf_Params *params)
This function opens a given ADCBuf peripheral.
void * sampleBufferTwo
Definition: ADCBuf.h:341
ADCBuf_Return_Mode returnMode
Definition: ADCBuf.h:506
int_fast16_t ADCBuf_convert(ADCBuf_Handle handle, ADCBuf_Conversion conversions[], uint_fast8_t channelCount)
Starts ADCBuf conversions on one or more channels.
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale