SimpleLink MCU SDK Driver APIs  tidrivers_msp43x_3_01_01_03
ADCBufMSP432.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, 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  */
167 #ifndef ti_drivers_adc_adcbufmsp432__include
168 #define ti_drivers_adc_adcbufmsp432__include
169 
170 #ifdef __cplusplus
171 extern "C" {
172 #endif
173 
174 #include <stdint.h>
175 #include <stdbool.h>
176 
177 
178 #include <ti/drivers/ADCBuf.h>
179 #include <ti/drivers/dpl/HwiP.h>
180 #include <ti/drivers/dpl/SemaphoreP.h>
181 #include <ti/drivers/Power.h>
183 
184 #include <ti/devices/msp432p4xx/driverlib/adc14.h>
185 
186 /*
187  * ADCBuf port/pin defines for pin configuration. Ports P2, P3, and P7 are
188  * configurable through the port mapping controller. None of the port
189  * mappings support ADC.
190  * Channel specifies the ADC channel and ranges from 0 to 23.
191  * pin range: 0 - 7, port range: 0 - 15
192  *
193  *
194  * 15 - 10 9 8 7 - 4 3 - 0
195  * ---------------------------------
196  * | CHANNEL | X | X | PORT | PIN |
197  * ---------------------------------
198  *
199  * channel = pinConfig >> 10
200  * port = (pinConfig >> 4) & 0xf
201  * pin = 1 << (pinConfig & 0xf)
202  * moduleFunction = (pinConfig >> 8) & 0x3
203  *
204  * For non-configurable ports (bits 20 - 12 will be 0).
205  * Bits 8 and 9 hold the module function (PRIMARY, SECONDARY, or
206  * TERTIARY). All ADC modes are TERTIARY, so bits 8 and 9
207  * are 1.
208  *
209  * MAP_GPIO_setAsPeripheralModuleFunctionInputPin(port,
210  * pin, moduleFunction);
211  * or:
212  * MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(port,
213  * pin, moduleFunction);
214  *
215  */
216 /* Port 4 */
217 #define ADCBufMSP432_P4_0_A13 ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
218 #define ADCBufMSP432_P4_1_A12 ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
219 #define ADCBufMSP432_P4_2_A11 ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
220 #define ADCBufMSP432_P4_3_A10 ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
221 #define ADCBufMSP432_P4_4_A9 ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
222 #define ADCBufMSP432_P4_5_A8 ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
223 #define ADCBufMSP432_P4_6_A7 ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
224 #define ADCBufMSP432_P4_7_A6 ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
225 
226 /* Port 5 */
227 #define ADCBufMSP432_P5_0_A5 ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
228 #define ADCBufMSP432_P5_1_A4 ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
229 #define ADCBufMSP432_P5_2_A3 ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
230 #define ADCBufMSP432_P5_3_A2 ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
231 #define ADCBufMSP432_P5_4_A1 ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
232 #define ADCBufMSP432_P5_5_A0 ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
233 
234 /* Port 6 */
235 #define ADCBufMSP432_P6_0_A15 ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
236 #define ADCBufMSP432_P6_1_A14 ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
237 
238 /* Port 8 */
239 #define ADCBufMSP432_P8_2_A23 ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
240 #define ADCBufMSP432_P8_3_A22 ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
241 #define ADCBufMSP432_P8_4_A21 ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
242 #define ADCBufMSP432_P8_5_A20 ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
243 #define ADCBufMSP432_P8_6_A19 ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
244 #define ADCBufMSP432_P8_7_A18 ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
245 
246 /* Port 9 */
247 #define ADCBufMSP432_P9_0_A17 ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
248 #define ADCBufMSP432_P9_1_A16 ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */
249 
250 /*
251  * =============================================================================
252  * Constants
253  * =============================================================================
254  */
255 
256 /* ADC function table pointer */
258 
266  ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS = ADC_VREFPOS_AVCC_VREFNEG_VSS,
267  ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS = ADC_VREFPOS_INTBUF_VREFNEG_VSS,
268  ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG = ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
269  ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG = ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
271 
289 
305 
306 
317 
324 typedef struct ADCBufMSP432_Channels {
325  uint_fast16_t adcPin;
327  uint32_t refVoltage;
329 
354 typedef struct ADCBufMSP432_HWAttrs {
355  uint32_t intPriority;
360 
366 typedef struct ADCBufMSP432_Object {
367  SemaphoreP_Handle mutex; /* Grants exclusive access to ADC */
368  SemaphoreP_Handle convertComplete; /* Notify finished ADC convert */
369  HwiP_Handle hwiHandle; /* Hardware interrupt handle */
370 
371  uint_fast8_t pingpongFlag; /* PingPong flag indicates which sample buffer is active in the conversion */
372  uint_fast8_t channelCount; /* Count of sampling channels */
373  ADCBuf_Conversion *conversions; /* Ptr to ADC conversion struct array passed by user */
374  ADCBuf_Callback callBackFxn; /* Callback function pointer */
375  uint_fast16_t *intlResultBuf; /* Internal result buffer */
376 
377  uint16_t *conversionSampleBuf; /* Ptr to current active sampling buffer */
378  uint_fast16_t conversionSampleIdx; /* Internal dec. conversion buffer counter */
379  uint_fast16_t conversionSampleCount; /* Total sampling count per channel */
380 
381  uint32_t semaphoreTimeout;
382  uint32_t samplingFrequency;
387  uint32_t timerAddr; /* Timer base address for trigger source */
388 
389  bool isOpen; /* To determine if the ADC is open */
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif /* ti_drivers_adc_ADCBufMSP432__include */
uint_fast16_t conversionSampleIdx
Definition: ADCBufMSP432.h:378
Definition: ADCBufMSP432.h:302
const ADCBuf_FxnTable ADCBufMSP432_fxnTable
Definition: ADCBufMSP432.h:283
Definition: ADCBufMSP432.h:266
Definition: ADCBufMSP432.h:281
ADCBuf_Conversion * conversions
Definition: ADCBufMSP432.h:373
enum ADCBuf_Recurrence_Mode_ ADCBuf_Recurrence_Mode
ADC trigger mode settings.
uint_fast8_t pingpongFlag
Definition: ADCBufMSP432.h:371
struct ADCBufMSP432_HWAttrs ADCBufMSP432_HWAttrs
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
uint32_t semaphoreTimeout
Definition: ADCBufMSP432.h:381
An ADCBuf_Conversion data structure is used with ADCBuf_convert(). It indicates which channel to perf...
Definition: ADCBuf.h:239
Definition: ADCBufMSP432.h:285
struct ADCBufMSP432_Object ADCBufMSP432_Object
ADCBufMSP432 Object.
Power manager interface.
ADCBuf driver interface.
enum ADCBuf_Return_Mode_ ADCBuf_Return_Mode
ADC return mode settings.
ADCBufMSP432_Sampling_Duration samplingDuration
Definition: ADCBufMSP432.h:315
ADCBufMSP432_Timer_Reference_Source
ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Cap...
Definition: ADCBufMSP432.h:296
Definition: ADCBufMSP432.h:298
bool isOpen
Definition: ADCBufMSP432.h:389
ADCBufMSP432_Sampling_Duration
ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold tim...
Definition: ADCBufMSP432.h:279
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:366
ADCBuf_Callback callBackFxn
Definition: ADCBufMSP432.h:374
SemaphoreP_Handle convertComplete
Definition: ADCBufMSP432.h:368
uint_fast16_t adcPin
Definition: ADCBufMSP432.h:325
Definition: ADCBufMSP432.h:280
Definition: ADCBufMSP432.h:268
Definition: ADCBufMSP432.h:300
Definition: ADCBufMSP432.h:303
Definition: ADCBufMSP432.h:267
ADCBufMSP432_Channels * channelSetting
Definition: ADCBufMSP432.h:356
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:354
Definition: ADCBufMSP432.h:297
uint32_t samplingFrequency
Definition: ADCBufMSP432.h:382
ADCBufMSP432_Sampling_Duration samplingDuration
Definition: ADCBufMSP432.h:385
Definition: ADCBufMSP432.h:269
uint32_t intPriority
Definition: ADCBufMSP432.h:355
The definition of an ADCBuf function table that contains the required set of functions to control a s...
Definition: ADCBuf.h:387
struct ADCBufMSP432_ParamsExtension ADCBufMSP432_ParamsExtension
MSP432 specfic extension to ADCBuf_Params.
ADCBufMSP432_Reference_Source
ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference vol...
Definition: ADCBufMSP432.h:265
uint32_t refVoltage
Definition: ADCBufMSP432.h:327
HwiP_Handle hwiHandle
Definition: ADCBufMSP432.h:369
uDMA driver implementation for MSP432.
Definition: ADCBufMSP432.h:299
struct ADCBufMSP432_Channels ADCBufMSP432_Channels
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
ADCBufMSP432_Timer_Reference_Source adcTimerTriggerSource
Definition: ADCBufMSP432.h:357
uint32_t timerAddr
Definition: ADCBufMSP432.h:387
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
Definition: ADCBufMSP432.h:324
uint_fast8_t channelCount
Definition: ADCBufMSP432.h:372
uint_fast16_t * intlResultBuf
Definition: ADCBufMSP432.h:375
SemaphoreP_Handle mutex
Definition: ADCBufMSP432.h:367
Definition: ADCBufMSP432.h:282
ADCBuf_Return_Mode returnMode
Definition: ADCBufMSP432.h:384
Definition: ADCBufMSP432.h:301
MSP432 specfic extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:314
uint_fast16_t conversionSampleCount
Definition: ADCBufMSP432.h:379
void(* ADCBuf_Callback)(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel)
The definition of a callback function used by the ADC driver when used in ADCBuf_RETURN_MODE_CALLBACK...
Definition: ADCBuf.h:253
Definition: ADCBufMSP432.h:284
ADCBufMSP432_Reference_Source refSource
Definition: ADCBufMSP432.h:326
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufMSP432.h:383
uint16_t * conversionSampleBuf
Definition: ADCBufMSP432.h:377
Copyright 2016, Texas Instruments Incorporated