ADCBufMSP432.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  */
42 #ifndef ti_drivers_adc_adcbufmsp432__include
43 #define ti_drivers_adc_adcbufmsp432__include
44 
45 #include <stdint.h>
46 #include <stdbool.h>
47 
48 #include <ti/devices/DeviceFamily.h>
49 #include <ti/devices/msp432p4xx/driverlib/sysctl_a.h>
50 #include <ti/drivers/ADCBuf.h>
51 #include <ti/drivers/dpl/HwiP.h>
52 #include <ti/drivers/dpl/SemaphoreP.h>
53 #include <ti/drivers/Power.h>
55 
56 #include <ti/devices/msp432p4xx/driverlib/adc14.h>
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 /* Add ADCBufMSP432_CMD_* macros here */
63 
77 #define ADCBufMSP432_CMD_ENTER_ADC_ULTRA_LOW_POWER_MODE ADCBuf_CMD_RESERVED + 1
78 
88 #define ADCBufMSP432_CMD_EXIT_ADC_ULTRA_LOW_POWER_MODE ADCBuf_CMD_RESERVED + 2
89 
92 /*
93  * ADCBuf port/pin defines for pin configuration. Ports P2, P3, and P7 are
94  * configurable through the port mapping controller. None of the port
95  * mappings support ADC.
96  * Channel specifies the ADC channel and ranges from 0 to 23.
97  * pin range: 0 - 7, port range: 0 - 15
98  *
99  *
100  * 15 - 10 9 8 7 - 4 3 - 0
101  * ---------------------------------
102  * | CHANNEL | X | X | PORT | PIN |
103  * ---------------------------------
104  *
105  * channel = pinConfig >> 10
106  * port = (pinConfig >> 4) & 0xf
107  * pin = 1 << (pinConfig & 0xf)
108  * moduleFunction = (pinConfig >> 8) & 0x3
109  *
110  * For non-configurable ports (bits 20 - 12 will be 0).
111  * Bits 8 and 9 hold the module function (PRIMARY, SECONDARY, or
112  * TERTIARY). All ADC modes are TERTIARY, so bits 8 and 9
113  * are 1.
114  *
115  * MAP_GPIO_setAsPeripheralModuleFunctionInputPin(port,
116  * pin, moduleFunction);
117  * or:
118  * MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(port,
119  * pin, moduleFunction);
120  *
121  */
122 /* Port 4 */
123 #define ADCBufMSP432_P4_0_A13 ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
124 #define ADCBufMSP432_P4_1_A12 ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
125 #define ADCBufMSP432_P4_2_A11 ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
126 #define ADCBufMSP432_P4_3_A10 ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
127 #define ADCBufMSP432_P4_4_A9 ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
128 #define ADCBufMSP432_P4_5_A8 ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
129 #define ADCBufMSP432_P4_6_A7 ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
130 #define ADCBufMSP432_P4_7_A6 ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
131 
132 /* Port 5 */
133 #define ADCBufMSP432_P5_0_A5 ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
134 #define ADCBufMSP432_P5_1_A4 ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
135 #define ADCBufMSP432_P5_2_A3 ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
136 #define ADCBufMSP432_P5_3_A2 ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
137 #define ADCBufMSP432_P5_4_A1 ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
138 #define ADCBufMSP432_P5_5_A0 ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
139 
140 /* Port 6 */
141 #define ADCBufMSP432_P6_0_A15 ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
142 #define ADCBufMSP432_P6_1_A14 ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
143 
144 /* Port 8 */
145 #define ADCBufMSP432_P8_2_A23 ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
146 #define ADCBufMSP432_P8_3_A22 ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
147 #define ADCBufMSP432_P8_4_A21 ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
148 #define ADCBufMSP432_P8_5_A20 ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
149 #define ADCBufMSP432_P8_6_A19 ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
150 #define ADCBufMSP432_P8_7_A18 ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
151 
152 /* Port 9 */
153 #define ADCBufMSP432_P9_0_A17 ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
154 #define ADCBufMSP432_P9_1_A16 ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */
155 
156 #define ADCBufMSP432_PIN_NONE 0
157 #define ADCBufMSP432_INTERNAL_SOURCE_PIN 0
158 
159 /*
160  * =============================================================================
161  * Constants
162  * =============================================================================
163  */
164 
165 /* ADC function table pointer */
167 
174 typedef enum {
175  ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS = ADC_VREFPOS_AVCC_VREFNEG_VSS,
176  ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS = ADC_VREFPOS_INTBUF_VREFNEG_VSS,
177  ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG = ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
178  ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG = ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
180 
188 typedef enum {
198 
205 typedef enum {
214 
220 typedef enum {
221  ADCBufMSP432_ADC_CLOCK = ADC_CLOCKSOURCE_ADCOSC,
222  ADCBufMSP432_SYSOSC_CLOCK = ADC_CLOCKSOURCE_SYSOSC,
223  ADCBufMSP432_ACLK_CLOCK = ADC_CLOCKSOURCE_ACLK,
224  ADCBufMSP432_MCLK_CLOCK = ADC_CLOCKSOURCE_MCLK,
225  ADCBufMSP432_SMCLK_CLOCK = ADC_CLOCKSOURCE_SMCLK,
226  ADCBufMSP432_HSMCLK_CLOCK = ADC_CLOCKSOURCE_HSMCLK
228 
235 typedef enum {
236  ADCBufMSP432_TIMER_TRIGGER = ADC_MANUAL_ITERATION,
237  ADCBufMSP432_SOFTWARE_AUTOMATIC_TRIGGER = ADC_AUTOMATIC_ITERATION,
239 
245 typedef enum {
246  ADCBufMSP432_SINGLE_ENDED = ADC_NONDIFFERENTIAL_INPUTS,
247  ADCBufMSP432_DIFFERENTIAL = ADC_DIFFERENTIAL_INPUTS
249 
255 typedef enum {
257  ADCBufMSP432_TEMPERATURE_MODE = ADC_TEMPSENSEMAP,
260 
269 typedef struct{
271  ADCBufMSP432_SamplingDuration samplingDuration;
273 
280 typedef struct {
282  uint_fast16_t adcPin;
284  ADCBufMSP432_ReferenceSource refSource;
287  uint32_t refVoltage;
289  ADCBufMSP432_DifferentialMode adcInputMode;
291  uint_fast16_t adcDifferentialPin;
293  ADCBufMSP432_InternalSourceMode adcInternalSource;
295 
328 typedef struct {
330  uint32_t intPriority;
336  uint8_t useDMA;
338  uint8_t dmaIntNum;
340  ADCBufMSP432_TriggerSource adcTriggerSource;
342  uint32_t timerDutyCycle;
344  ADCBufMSP432_ClockSource clockSource;
346 
352 typedef struct {
353  /* Notify finished ADC convert */
354  SemaphoreP_Handle convertComplete;
355  /* Hardware interrupt handle */
356  HwiP_Handle hwiHandle;
357 
358  /* PingPong flag indicates which sample buffer is active in the conversion */
359  uint_fast8_t pingpongFlag;
360  /* Count of sampling channels */
361  uint_fast8_t channelCount;
362  /* Ptr to ADC conversion struct array passed by user */
364  /* Callback function pointer */
366  /* Internal result buffer */
367  uint_fast16_t *intlResultBuf;
368 
369  /* Ptr to current active sampling buffer */
371  /* Internal dec. conversion buffer counter */
372  uint_fast16_t conversionSampleIdx;
373  /* Total sampling count per channel */
374  uint_fast16_t conversionSampleCount;
375 
385  ADCBufMSP432_SamplingDuration samplingDuration;
386 
387  /* Timer base address for trigger source */
388  uint32_t timerAddr;
389 
390  /* To determine if the ADC is open */
391  bool isOpen;
392  /* Channel mask used to initialize and track which internal sources are being used */
394  /*Temperature calibration for 30C*/
395  uint32_t tempCal30;
396  /*Temperature calibration for 80C*/
397  uint32_t tempCal85;
398  /*Temperature calibration conversion constant*/
400  /* DMA interrupt handle */
402  /* Struct holding params for DMA ping pong transfers */
404  /* Struct holding params for DMA transfers */
407 
408 #ifdef __cplusplus
409 }
410 #endif
411 
412 #endif /* ti_drivers_adc_ADCBufMSP432__include */
uint_fast16_t conversionSampleIdx
Definition: ADCBufMSP432.h:372
const ADCBuf_FxnTable ADCBufMSP432_fxnTable
ADCBufMSP432_DifferentialMode adcInputMode
Definition: ADCBufMSP432.h:289
Definition: ADCBufMSP432.h:193
Definition: ADCBufMSP432.h:246
Definition: ADCBufMSP432.h:224
UDMAMSP432 Transfer configuration.
Definition: UDMAMSP432.h:154
Definition: ADCBufMSP432.h:209
Definition: ADCBufMSP432.h:211
ADCBufMSP432_SamplingDuration samplingDuration
Definition: ADCBufMSP432.h:385
ADCBuf_Conversion * conversions
Definition: ADCBufMSP432.h:363
uint_fast8_t pingpongFlag
Definition: ADCBufMSP432.h:359
Definition: ADCBufMSP432.h:177
Definition: ADCBufMSP432.h:190
float tempCalDifference
Definition: ADCBufMSP432.h:399
uint32_t semaphoreTimeout
Definition: ADCBufMSP432.h:377
Definition: ADCBufMSP432.h:223
Definition: ADCBufMSP432.h:175
Definition: ADCBufMSP432.h:189
uint8_t useDMA
Definition: ADCBufMSP432.h:336
Definition: ADCBufMSP432.h:196
Power Manager.
Analog to Digital Conversion Buffer (ADCBuf) Input Driver.
bool isOpen
Definition: ADCBufMSP432.h:391
Definition: ADCBufMSP432.h:207
Definition: ADCBufMSP432.h:257
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:352
ADCBuf_Callback callBackFxn
Definition: ADCBufMSP432.h:365
Definition: ADCBufMSP432.h:226
SemaphoreP_Handle convertComplete
Definition: ADCBufMSP432.h:354
uint_fast16_t adcPin
Definition: ADCBufMSP432.h:282
ADCBufMSP432_SamplingDuration samplingDuration
Definition: ADCBufMSP432.h:271
Definition: ADCBufMSP432.h:237
ADCBufMSP432_ClockSource clockSource
Definition: ADCBufMSP432.h:344
UDMAMSP432 Ping Pong Transfer configuration.
Definition: UDMAMSP432.h:173
ADCBufMSP432_Channels * channelSetting
Definition: ADCBufMSP432.h:332
Definition: ADCBufMSP432.h:210
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:328
uint32_t samplingFrequency
Definition: ADCBufMSP432.h:379
Definition: ADCBufMSP432.h:191
Definition: ADCBufMSP432.h:258
uint32_t intPriority
Definition: ADCBufMSP432.h:330
Definition: ADCBufMSP432.h:225
Definition: ADCBufMSP432.h:208
Definition: ADCBufMSP432.h:195
ADCBufMSP432_TriggerSource adcTriggerSource
Definition: ADCBufMSP432.h:340
uint32_t refVoltage
Definition: ADCBufMSP432.h:287
Definition: ADCBufMSP432.h:192
uint8_t dmaIntNum
Definition: ADCBufMSP432.h:338
HwiP_Handle hwiHandle
Definition: ADCBufMSP432.h:356
uint_fast16_t adcDifferentialPin
Definition: ADCBufMSP432.h:291
The definition of an ADCBuf function table that contains the required set of functions to control a s...
Definition: ADCBuf.h:600
Definition: ADCBufMSP432.h:194
ADCBufMSP432_TimerReferenceSource adcTimerTriggerSource
Definition: ADCBufMSP432.h:334
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:205
ADCBufMSP432_SamplingDuration
ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold tim...
Definition: ADCBufMSP432.h:188
Definition: ADCBufMSP432.h:221
ADCBufMSP432_InternalSourceMode
ADCMSP432 Internal Source Mode These fields are used by ADCBufMSP432_HWAttrs to specify if a internal...
Definition: ADCBufMSP432.h:255
ADCBufMSP432_DifferentialMode
ADCMSP432 Differential Mode These fields are used by ADCBufMSP432_HWAttrs to specify if ADC different...
Definition: ADCBufMSP432.h:245
UDMAMSP432 Global configuration.
Definition: UDMAMSP432.h:127
uint32_t tempCal30
Definition: ADCBufMSP432.h:395
uint32_t timerAddr
Definition: ADCBufMSP432.h:388
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:220
uint_fast8_t channelCount
Definition: ADCBufMSP432.h:361
Definition: ADCBufMSP432.h:178
uint32_t internalSourceMask
Definition: ADCBufMSP432.h:393
uint32_t timerDutyCycle
Definition: ADCBufMSP432.h:342
uint_fast16_t * intlResultBuf
Definition: ADCBufMSP432.h:367
Definition: ADCBufMSP432.h:247
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
Definition: ADCBufMSP432.h:236
Definition: ADCBufMSP432.h:222
UDMAMSP432_PingPongTransfer pingpongDMATransfer
Definition: ADCBufMSP432.h:403
Definition: ADCBufMSP432.h:206
ADCBuf_Return_Mode returnMode
Definition: ADCBufMSP432.h:383
MSP432 specific extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:269
uint_fast16_t conversionSampleCount
Definition: ADCBufMSP432.h:374
void(* ADCBuf_Callback)(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel)
The definition of a callback function.
Definition: ADCBuf.h:391
ADCBufMSP432_ReferenceSource
ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference vol...
Definition: ADCBufMSP432.h:174
ADCBufMSP432_InternalSourceMode adcInternalSource
Definition: ADCBufMSP432.h:293
UDMAMSP432_Handle dmaHandle
Definition: ADCBufMSP432.h:401
Defines a conversion to be used with ADCBuf_convert().
Definition: ADCBuf.h:315
UDMAMSP432_Transfer dmaTransfer
Definition: ADCBufMSP432.h:405
ADCBufMSP432_ReferenceSource refSource
Definition: ADCBufMSP432.h:284
Definition: ADCBufMSP432.h:176
ADCBufMSP432_TriggerSource
ADCMSP432 trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the trigger source ...
Definition: ADCBufMSP432.h:235
Definition: ADCBufMSP432.h:256
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufMSP432.h:381
Definition: ADCBufMSP432.h:212
uint16_t * conversionSampleBuf
Definition: ADCBufMSP432.h:370
uint32_t tempCal85
Definition: ADCBufMSP432.h:397
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale