ADCBufMSP432.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018, 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  */
49 #ifndef ti_drivers_adc_adcbufmsp432__include
50 #define ti_drivers_adc_adcbufmsp432__include
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #include <stdint.h>
57 #include <stdbool.h>
58 
59 #include <ti/devices/DeviceFamily.h>
60 #include <ti/devices/msp432p4xx/driverlib/sysctl_a.h>
61 #include <ti/drivers/ADCBuf.h>
62 #include <ti/drivers/dpl/HwiP.h>
63 #include <ti/drivers/dpl/SemaphoreP.h>
64 #include <ti/drivers/Power.h>
66 
67 #include <ti/devices/msp432p4xx/driverlib/adc14.h>
68 /* Add ADCBufMSP432_CMD_* macros here */
69 
81 #define ADCBufMSP432_CMD_ENTER_ADC_ULTRA_LOW_POWER_MODE ADCBuf_CMD_RESERVED + 1
82 
91 #define ADCBufMSP432_CMD_EXIT_ADC_ULTRA_LOW_POWER_MODE ADCBuf_CMD_RESERVED + 2
92 
95 /*
96  * ADCBuf port/pin defines for pin configuration. Ports P2, P3, and P7 are
97  * configurable through the port mapping controller. None of the port
98  * mappings support ADC.
99  * Channel specifies the ADC channel and ranges from 0 to 23.
100  * pin range: 0 - 7, port range: 0 - 15
101  *
102  *
103  * 15 - 10 9 8 7 - 4 3 - 0
104  * ---------------------------------
105  * | CHANNEL | X | X | PORT | PIN |
106  * ---------------------------------
107  *
108  * channel = pinConfig >> 10
109  * port = (pinConfig >> 4) & 0xf
110  * pin = 1 << (pinConfig & 0xf)
111  * moduleFunction = (pinConfig >> 8) & 0x3
112  *
113  * For non-configurable ports (bits 20 - 12 will be 0).
114  * Bits 8 and 9 hold the module function (PRIMARY, SECONDARY, or
115  * TERTIARY). All ADC modes are TERTIARY, so bits 8 and 9
116  * are 1.
117  *
118  * MAP_GPIO_setAsPeripheralModuleFunctionInputPin(port,
119  * pin, moduleFunction);
120  * or:
121  * MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(port,
122  * pin, moduleFunction);
123  *
124  */
125 /* Port 4 */
126 #define ADCBufMSP432_P4_0_A13 ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
127 #define ADCBufMSP432_P4_1_A12 ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
128 #define ADCBufMSP432_P4_2_A11 ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
129 #define ADCBufMSP432_P4_3_A10 ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
130 #define ADCBufMSP432_P4_4_A9 ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
131 #define ADCBufMSP432_P4_5_A8 ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
132 #define ADCBufMSP432_P4_6_A7 ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
133 #define ADCBufMSP432_P4_7_A6 ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
134 
135 /* Port 5 */
136 #define ADCBufMSP432_P5_0_A5 ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
137 #define ADCBufMSP432_P5_1_A4 ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
138 #define ADCBufMSP432_P5_2_A3 ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
139 #define ADCBufMSP432_P5_3_A2 ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
140 #define ADCBufMSP432_P5_4_A1 ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
141 #define ADCBufMSP432_P5_5_A0 ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
142 
143 /* Port 6 */
144 #define ADCBufMSP432_P6_0_A15 ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
145 #define ADCBufMSP432_P6_1_A14 ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
146 
147 /* Port 8 */
148 #define ADCBufMSP432_P8_2_A23 ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
149 #define ADCBufMSP432_P8_3_A22 ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
150 #define ADCBufMSP432_P8_4_A21 ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
151 #define ADCBufMSP432_P8_5_A20 ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
152 #define ADCBufMSP432_P8_6_A19 ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
153 #define ADCBufMSP432_P8_7_A18 ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
154 
155 /* Port 9 */
156 #define ADCBufMSP432_P9_0_A17 ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
157 #define ADCBufMSP432_P9_1_A16 ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */
158 
159 #define ADCBufMSP432_PIN_NONE 0
160 #define ADCBufMSP432_INTERNAL_SOURCE_PIN 0
161 
162 /*
163  * =============================================================================
164  * Constants
165  * =============================================================================
166  */
167 
168 /* ADC function table pointer */
170 
178  ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS = ADC_VREFPOS_AVCC_VREFNEG_VSS,
179  ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS = ADC_VREFPOS_INTBUF_VREFNEG_VSS,
180  ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG = ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
181  ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG = ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
183 
201 
217 
224  ADCBufMSP432_ADC_CLOCK = ADC_CLOCKSOURCE_ADCOSC,
225  ADCBufMSP432_SYSOSC_CLOCK = ADC_CLOCKSOURCE_SYSOSC,
226  ADCBufMSP432_ACLK_CLOCK = ADC_CLOCKSOURCE_ACLK,
227  ADCBufMSP432_MCLK_CLOCK = ADC_CLOCKSOURCE_MCLK,
228  ADCBufMSP432_SMCLK_CLOCK = ADC_CLOCKSOURCE_SMCLK,
229  ADCBufMSP432_HSMCLK_CLOCK = ADC_CLOCKSOURCE_HSMCLK
231 
238  ADCBufMSP432_TIMER_TRIGGER = ADC_MANUAL_ITERATION,
239  ADCBufMSP432_SOFTWARE_AUTOMATIC_TRIGGER = ADC_AUTOMATIC_ITERATION,
241 
248  ADCBufMSP432_SINGLE_ENDED = ADC_NONDIFFERENTIAL_INPUTS,
249  ADCBufMSP432_DIFFERENTIAL = ADC_DIFFERENTIAL_INPUTS
251 
259  ADCBufMSP432_TEMPERATURE_MODE = ADC_TEMPSENSEMAP,
262 
271  ADCBufMSP432_SamplingDuration samplingDuration;
273 
280 typedef struct ADCBufMSP432_Channels {
281  uint_fast16_t adcPin;
282  ADCBufMSP432_ReferenceSource refSource;
283  uint32_t refVoltage;
288  ADCBufMSP432_DifferentialMode adcInputMode;
290  uint_fast16_t adcDifferentialPin;
293  ADCBufMSP432_InternalSourceMode adcInternalSource;
296 
329 typedef struct ADCBufMSP432_HWAttrs {
330  uint32_t intPriority;
333  uint8_t useDMA;
334  uint8_t dmaIntNum;
335  ADCBufMSP432_TriggerSource adcTriggerSource;
336  uint32_t timerDutyCycle;
337  ADCBufMSP432_ClockSource clockSource;
339 
345 typedef struct ADCBufMSP432_Object {
346  SemaphoreP_Handle convertComplete; /* Notify finished ADC convert */
347  HwiP_Handle hwiHandle; /* Hardware interrupt handle */
348 
349  uint_fast8_t pingpongFlag; /* PingPong flag indicates which sample buffer is active in the conversion */
350  uint_fast8_t channelCount; /* Count of sampling channels */
351  ADCBuf_Conversion *conversions; /* Ptr to ADC conversion struct array passed by user */
352  ADCBuf_Callback callBackFxn; /* Callback function pointer */
353  uint_fast16_t *intlResultBuf; /* Internal result buffer */
354 
355  uint16_t *conversionSampleBuf; /* Ptr to current active sampling buffer */
356  uint_fast16_t conversionSampleIdx; /* Internal dec. conversion buffer counter */
357  uint_fast16_t conversionSampleCount; /* Total sampling count per channel */
358 
359  uint32_t semaphoreTimeout;
360  uint32_t samplingFrequency;
363  ADCBufMSP432_SamplingDuration samplingDuration;
365  uint32_t timerAddr; /* Timer base address for trigger source */
366 
367  bool isOpen; /* To determine if the ADC is open */
368  uint32_t internalSourceMask; /* Channel mask used to initialize and track which internal sources are being used */
369  uint32_t tempCal30; /*Temperature calibration for 30C*/
370  uint32_t tempCal85; /*Temperature calibration for 80C*/
371  float tempCalDifference; /*Temperature calibration conversion constant*/
372  UDMAMSP432_Handle dmaHandle; /* DMA interrupt handle */
373  UDMAMSP432_PingPongTransfer pingpongDMATransfer; /* Struct holding params for DMA ping pong transfers */
374  UDMAMSP432_Transfer dmaTransfer; /* Struct holding params for DMA transfers */
376 
377 #ifdef __cplusplus
378 }
379 #endif
380 
381 #endif /* ti_drivers_adc_ADCBufMSP432__include */
uint_fast16_t conversionSampleIdx
Definition: ADCBufMSP432.h:356
const ADCBuf_FxnTable ADCBufMSP432_fxnTable
ADCBufMSP432_DifferentialMode adcInputMode
Definition: ADCBufMSP432.h:288
Definition: ADCBufMSP432.h:196
Definition: ADCBufMSP432.h:248
Definition: ADCBufMSP432.h:227
UDMAMSP432 Transfer configuration.
Definition: UDMAMSP432.h:154
Definition: ADCBufMSP432.h:212
Definition: ADCBufMSP432.h:214
ADCBufMSP432_SamplingDuration samplingDuration
Definition: ADCBufMSP432.h:363
ADCBuf_Conversion * conversions
Definition: ADCBufMSP432.h:351
enum ADCBuf_Recurrence_Mode_ ADCBuf_Recurrence_Mode
ADC trigger mode settings.
uint_fast8_t pingpongFlag
Definition: ADCBufMSP432.h:349
Definition: ADCBufMSP432.h:180
struct ADCBufMSP432_HWAttrs ADCBufMSP432_HWAttrs
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:193
float tempCalDifference
Definition: ADCBufMSP432.h:371
uint32_t semaphoreTimeout
Definition: ADCBufMSP432.h:359
Definition: ADCBufMSP432.h:226
An ADCBuf_Conversion data structure is used with ADCBuf_convert(). It indicates which channel to perf...
Definition: ADCBuf.h:237
struct ADCBufMSP432_Object ADCBufMSP432_Object
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:178
Definition: ADCBufMSP432.h:192
uint8_t useDMA
Definition: ADCBufMSP432.h:333
Definition: ADCBufMSP432.h:199
Power Manager interface.
ADCBuf driver interface.
enum ADCBuf_Return_Mode_ ADCBuf_Return_Mode
ADC return mode settings.
bool isOpen
Definition: ADCBufMSP432.h:367
Definition: ADCBufMSP432.h:210
Definition: ADCBufMSP432.h:259
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:345
ADCBuf_Callback callBackFxn
Definition: ADCBufMSP432.h:352
Definition: ADCBufMSP432.h:229
SemaphoreP_Handle convertComplete
Definition: ADCBufMSP432.h:346
uint_fast16_t adcPin
Definition: ADCBufMSP432.h:281
ADCBufMSP432_SamplingDuration samplingDuration
Definition: ADCBufMSP432.h:271
Definition: ADCBufMSP432.h:239
ADCBufMSP432_ClockSource clockSource
Definition: ADCBufMSP432.h:337
UDMAMSP432 Ping Pong Transfer configuration.
Definition: UDMAMSP432.h:173
ADCBufMSP432_Channels * channelSetting
Definition: ADCBufMSP432.h:331
Definition: ADCBufMSP432.h:213
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:329
uint32_t samplingFrequency
Definition: ADCBufMSP432.h:360
Definition: ADCBufMSP432.h:194
Definition: ADCBufMSP432.h:260
uint32_t intPriority
Definition: ADCBufMSP432.h:330
Definition: ADCBufMSP432.h:228
The definition of an ADCBuf function table that contains the required set of functions to control a s...
Definition: ADCBuf.h:385
struct ADCBufMSP432_ParamsExtension ADCBufMSP432_ParamsExtension
MSP432 specfic extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:211
Definition: ADCBufMSP432.h:198
ADCBufMSP432_TriggerSource adcTriggerSource
Definition: ADCBufMSP432.h:335
uint32_t refVoltage
Definition: ADCBufMSP432.h:283
Definition: ADCBufMSP432.h:195
uint8_t dmaIntNum
Definition: ADCBufMSP432.h:334
HwiP_Handle hwiHandle
Definition: ADCBufMSP432.h:347
uint_fast16_t adcDifferentialPin
Definition: ADCBufMSP432.h:290
Definition: ADCBufMSP432.h:197
ADCBufMSP432_TimerReferenceSource adcTimerTriggerSource
Definition: ADCBufMSP432.h:332
uDMA driver implementation for MSP432.
ADCBufMSP432_TimerReferenceSource
ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Cap...
Definition: ADCBufMSP432.h:208
ADCBufMSP432_SamplingDuration
ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold tim...
Definition: ADCBufMSP432.h:191
struct ADCBufMSP432_Channels ADCBufMSP432_Channels
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
Definition: ADCBufMSP432.h:224
ADCBufMSP432_InternalSourceMode
ADCMSP432 Internal Source Mode These fields are used by ADCBufMSP432_HWAttrs to specify if a internal...
Definition: ADCBufMSP432.h:257
ADCBufMSP432_DifferentialMode
ADCMSP432 Differential Mode These fields are used by ADCBufMSP432_HWAttrs to specify if ADC different...
Definition: ADCBufMSP432.h:247
UDMAMSP432 Global configuration.
Definition: UDMAMSP432.h:127
uint32_t tempCal30
Definition: ADCBufMSP432.h:369
uint32_t timerAddr
Definition: ADCBufMSP432.h:365
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
Definition: ADCBufMSP432.h:280
ADCBufMSP432_ClockSource
ADCMSP432 clock source These fields are used by ADCBufMSP432_HWAttrs to specify the clock source for ...
Definition: ADCBufMSP432.h:223
uint_fast8_t channelCount
Definition: ADCBufMSP432.h:350
Definition: ADCBufMSP432.h:181
uint32_t internalSourceMask
Definition: ADCBufMSP432.h:368
uint32_t timerDutyCycle
Definition: ADCBufMSP432.h:336
uint_fast16_t * intlResultBuf
Definition: ADCBufMSP432.h:353
Definition: ADCBufMSP432.h:249
Definition: ADCBufMSP432.h:238
Definition: ADCBufMSP432.h:225
UDMAMSP432_PingPongTransfer pingpongDMATransfer
Definition: ADCBufMSP432.h:373
Definition: ADCBufMSP432.h:209
ADCBuf_Return_Mode returnMode
Definition: ADCBufMSP432.h:362
MSP432 specfic extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:270
uint_fast16_t conversionSampleCount
Definition: ADCBufMSP432.h:357
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:251
ADCBufMSP432_ReferenceSource
ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference vol...
Definition: ADCBufMSP432.h:177
ADCBufMSP432_InternalSourceMode adcInternalSource
Definition: ADCBufMSP432.h:293
UDMAMSP432_Handle dmaHandle
Definition: ADCBufMSP432.h:372
UDMAMSP432_Transfer dmaTransfer
Definition: ADCBufMSP432.h:374
ADCBufMSP432_ReferenceSource refSource
Definition: ADCBufMSP432.h:282
Definition: ADCBufMSP432.h:179
ADCBufMSP432_TriggerSource
ADCMSP432 trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the trigger source ...
Definition: ADCBufMSP432.h:237
Definition: ADCBufMSP432.h:258
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufMSP432.h:361
Definition: ADCBufMSP432.h:215
uint16_t * conversionSampleBuf
Definition: ADCBufMSP432.h:355
uint32_t tempCal85
Definition: ADCBufMSP432.h:370
© Copyright 1995-2018, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale