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 
75 #define ADCBufMSP432_CMD_ENTER_ADC_ULTRA_LOW_POWER_MODE ADCBuf_CMD_RESERVED + 1
76 
85 #define ADCBufMSP432_CMD_EXIT_ADC_ULTRA_LOW_POWER_MODE ADCBuf_CMD_RESERVED + 2
86 
89 /*
90  * ADCBuf port/pin defines for pin configuration. Ports P2, P3, and P7 are
91  * configurable through the port mapping controller. None of the port
92  * mappings support ADC.
93  * Channel specifies the ADC channel and ranges from 0 to 23.
94  * pin range: 0 - 7, port range: 0 - 15
95  *
96  *
97  * 15 - 10 9 8 7 - 4 3 - 0
98  * ---------------------------------
99  * | CHANNEL | X | X | PORT | PIN |
100  * ---------------------------------
101  *
102  * channel = pinConfig >> 10
103  * port = (pinConfig >> 4) & 0xf
104  * pin = 1 << (pinConfig & 0xf)
105  * moduleFunction = (pinConfig >> 8) & 0x3
106  *
107  * For non-configurable ports (bits 20 - 12 will be 0).
108  * Bits 8 and 9 hold the module function (PRIMARY, SECONDARY, or
109  * TERTIARY). All ADC modes are TERTIARY, so bits 8 and 9
110  * are 1.
111  *
112  * MAP_GPIO_setAsPeripheralModuleFunctionInputPin(port,
113  * pin, moduleFunction);
114  * or:
115  * MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(port,
116  * pin, moduleFunction);
117  *
118  */
119 /* Port 4 */
120 #define ADCBufMSP432_P4_0_A13 ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
121 #define ADCBufMSP432_P4_1_A12 ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
122 #define ADCBufMSP432_P4_2_A11 ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
123 #define ADCBufMSP432_P4_3_A10 ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
124 #define ADCBufMSP432_P4_4_A9 ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
125 #define ADCBufMSP432_P4_5_A8 ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
126 #define ADCBufMSP432_P4_6_A7 ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
127 #define ADCBufMSP432_P4_7_A6 ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
128 
129 /* Port 5 */
130 #define ADCBufMSP432_P5_0_A5 ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
131 #define ADCBufMSP432_P5_1_A4 ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
132 #define ADCBufMSP432_P5_2_A3 ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
133 #define ADCBufMSP432_P5_3_A2 ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
134 #define ADCBufMSP432_P5_4_A1 ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
135 #define ADCBufMSP432_P5_5_A0 ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
136 
137 /* Port 6 */
138 #define ADCBufMSP432_P6_0_A15 ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
139 #define ADCBufMSP432_P6_1_A14 ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
140 
141 /* Port 8 */
142 #define ADCBufMSP432_P8_2_A23 ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
143 #define ADCBufMSP432_P8_3_A22 ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
144 #define ADCBufMSP432_P8_4_A21 ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
145 #define ADCBufMSP432_P8_5_A20 ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
146 #define ADCBufMSP432_P8_6_A19 ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
147 #define ADCBufMSP432_P8_7_A18 ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
148 
149 /* Port 9 */
150 #define ADCBufMSP432_P9_0_A17 ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
151 #define ADCBufMSP432_P9_1_A16 ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */
152 
153 #define ADCBufMSP432_PIN_NONE 0
154 #define ADCBufMSP432_INTERNAL_SOURCE_PIN 0
155 
156 /*
157  * =============================================================================
158  * Constants
159  * =============================================================================
160  */
161 
162 /* ADC function table pointer */
164 
172  ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS = ADC_VREFPOS_AVCC_VREFNEG_VSS,
173  ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS = ADC_VREFPOS_INTBUF_VREFNEG_VSS,
174  ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG = ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
175  ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG = ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
177 
195 
211 
218  ADCBufMSP432_ADC_CLOCK = ADC_CLOCKSOURCE_ADCOSC,
219  ADCBufMSP432_SYSOSC_CLOCK = ADC_CLOCKSOURCE_SYSOSC,
220  ADCBufMSP432_ACLK_CLOCK = ADC_CLOCKSOURCE_ACLK,
221  ADCBufMSP432_MCLK_CLOCK = ADC_CLOCKSOURCE_MCLK,
222  ADCBufMSP432_SMCLK_CLOCK = ADC_CLOCKSOURCE_SMCLK,
223  ADCBufMSP432_HSMCLK_CLOCK = ADC_CLOCKSOURCE_HSMCLK
225 
232  ADCBufMSP432_TIMER_TRIGGER = ADC_MANUAL_ITERATION,
233  ADCBufMSP432_SOFTWARE_AUTOMATIC_TRIGGER = ADC_AUTOMATIC_ITERATION,
235 
242  ADCBufMSP432_SINGLE_ENDED = ADC_NONDIFFERENTIAL_INPUTS,
243  ADCBufMSP432_DIFFERENTIAL = ADC_DIFFERENTIAL_INPUTS
245 
253  ADCBufMSP432_TEMPERATURE_MODE = ADC_TEMPSENSEMAP,
256 
265  ADCBufMSP432_SamplingDuration samplingDuration;
267 
274 typedef struct ADCBufMSP432_Channels {
275  uint_fast16_t adcPin;
276  ADCBufMSP432_ReferenceSource refSource;
277  uint32_t refVoltage;
282  ADCBufMSP432_DifferentialMode adcInputMode;
284  uint_fast16_t adcDifferentialPin;
287  ADCBufMSP432_InternalSourceMode adcInternalSource;
290 
323 typedef struct ADCBufMSP432_HWAttrs {
324  uint32_t intPriority;
327  uint8_t useDMA;
328  uint8_t dmaIntNum;
329  ADCBufMSP432_TriggerSource adcTriggerSource;
330  uint32_t timerDutyCycle;
331  ADCBufMSP432_ClockSource clockSource;
333 
339 typedef struct ADCBufMSP432_Object {
340  SemaphoreP_Handle convertComplete; /* Notify finished ADC convert */
341  HwiP_Handle hwiHandle; /* Hardware interrupt handle */
342 
343  uint_fast8_t pingpongFlag; /* PingPong flag indicates which sample buffer is active in the conversion */
344  uint_fast8_t channelCount; /* Count of sampling channels */
345  ADCBuf_Conversion *conversions; /* Ptr to ADC conversion struct array passed by user */
346  ADCBuf_Callback callBackFxn; /* Callback function pointer */
347  uint_fast16_t *intlResultBuf; /* Internal result buffer */
348 
349  uint16_t *conversionSampleBuf; /* Ptr to current active sampling buffer */
350  uint_fast16_t conversionSampleIdx; /* Internal dec. conversion buffer counter */
351  uint_fast16_t conversionSampleCount; /* Total sampling count per channel */
352 
353  uint32_t semaphoreTimeout;
354  uint32_t samplingFrequency;
357  ADCBufMSP432_SamplingDuration samplingDuration;
359  uint32_t timerAddr; /* Timer base address for trigger source */
360 
361  bool isOpen; /* To determine if the ADC is open */
362  uint32_t internalSourceMask; /* Channel mask used to initialize and track which internal sources are being used */
363  uint32_t tempCal30; /*Temperature calibration for 30C*/
364  uint32_t tempCal85; /*Temperature calibration for 80C*/
365  float tempCalDifference; /*Temperature calibration conversion constant*/
366  UDMAMSP432_Handle dmaHandle; /* DMA interrupt handle */
367  UDMAMSP432_PingPongTransfer pingpongDMATransfer; /* Struct holding params for DMA ping pong transfers */
368  UDMAMSP432_Transfer dmaTransfer; /* Struct holding params for DMA transfers */
370 
371 #ifdef __cplusplus
372 }
373 #endif
374 
375 #endif /* ti_drivers_adc_ADCBufMSP432__include */
uint_fast16_t conversionSampleIdx
Definition: ADCBufMSP432.h:350
const ADCBuf_FxnTable ADCBufMSP432_fxnTable
ADCBufMSP432_DifferentialMode adcInputMode
Definition: ADCBufMSP432.h:282
Definition: ADCBufMSP432.h:190
Definition: ADCBufMSP432.h:242
Definition: ADCBufMSP432.h:221
UDMAMSP432 Transfer configuration.
Definition: UDMAMSP432.h:154
Definition: ADCBufMSP432.h:206
Definition: ADCBufMSP432.h:208
ADCBufMSP432_SamplingDuration samplingDuration
Definition: ADCBufMSP432.h:357
ADCBuf_Conversion * conversions
Definition: ADCBufMSP432.h:345
uint_fast8_t pingpongFlag
Definition: ADCBufMSP432.h:343
Definition: ADCBufMSP432.h:174
struct ADCBufMSP432_HWAttrs ADCBufMSP432_HWAttrs
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:187
float tempCalDifference
Definition: ADCBufMSP432.h:365
uint32_t semaphoreTimeout
Definition: ADCBufMSP432.h:353
Definition: ADCBufMSP432.h:220
struct ADCBufMSP432_Object ADCBufMSP432_Object
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:172
Definition: ADCBufMSP432.h:186
uint8_t useDMA
Definition: ADCBufMSP432.h:327
Definition: ADCBufMSP432.h:193
Power Manager.
Analog to Digital Conversion Buffer (ADCBuf) Input Driver.
bool isOpen
Definition: ADCBufMSP432.h:361
Definition: ADCBufMSP432.h:204
Definition: ADCBufMSP432.h:253
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:339
ADCBuf_Callback callBackFxn
Definition: ADCBufMSP432.h:346
Definition: ADCBufMSP432.h:223
SemaphoreP_Handle convertComplete
Definition: ADCBufMSP432.h:340
uint_fast16_t adcPin
Definition: ADCBufMSP432.h:275
ADCBufMSP432_SamplingDuration samplingDuration
Definition: ADCBufMSP432.h:265
Definition: ADCBufMSP432.h:233
ADCBufMSP432_ClockSource clockSource
Definition: ADCBufMSP432.h:331
UDMAMSP432 Ping Pong Transfer configuration.
Definition: UDMAMSP432.h:173
ADCBufMSP432_Channels * channelSetting
Definition: ADCBufMSP432.h:325
Definition: ADCBufMSP432.h:207
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:323
uint32_t samplingFrequency
Definition: ADCBufMSP432.h:354
Definition: ADCBufMSP432.h:188
Definition: ADCBufMSP432.h:254
uint32_t intPriority
Definition: ADCBufMSP432.h:324
Definition: ADCBufMSP432.h:222
struct ADCBufMSP432_ParamsExtension ADCBufMSP432_ParamsExtension
MSP432 specfic extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:205
Definition: ADCBufMSP432.h:192
ADCBufMSP432_TriggerSource adcTriggerSource
Definition: ADCBufMSP432.h:329
uint32_t refVoltage
Definition: ADCBufMSP432.h:277
Definition: ADCBufMSP432.h:189
uint8_t dmaIntNum
Definition: ADCBufMSP432.h:328
HwiP_Handle hwiHandle
Definition: ADCBufMSP432.h:341
uint_fast16_t adcDifferentialPin
Definition: ADCBufMSP432.h:284
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:191
ADCBufMSP432_TimerReferenceSource adcTimerTriggerSource
Definition: ADCBufMSP432.h:326
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:202
ADCBufMSP432_SamplingDuration
ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold tim...
Definition: ADCBufMSP432.h:185
struct ADCBufMSP432_Channels ADCBufMSP432_Channels
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
Definition: ADCBufMSP432.h:218
ADCBufMSP432_InternalSourceMode
ADCMSP432 Internal Source Mode These fields are used by ADCBufMSP432_HWAttrs to specify if a internal...
Definition: ADCBufMSP432.h:251
ADCBufMSP432_DifferentialMode
ADCMSP432 Differential Mode These fields are used by ADCBufMSP432_HWAttrs to specify if ADC different...
Definition: ADCBufMSP432.h:241
UDMAMSP432 Global configuration.
Definition: UDMAMSP432.h:127
uint32_t tempCal30
Definition: ADCBufMSP432.h:363
uint32_t timerAddr
Definition: ADCBufMSP432.h:359
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
Definition: ADCBufMSP432.h:274
ADCBufMSP432_ClockSource
ADCMSP432 clock source These fields are used by ADCBufMSP432_HWAttrs to specify the clock source for ...
Definition: ADCBufMSP432.h:217
uint_fast8_t channelCount
Definition: ADCBufMSP432.h:344
Definition: ADCBufMSP432.h:175
uint32_t internalSourceMask
Definition: ADCBufMSP432.h:362
uint32_t timerDutyCycle
Definition: ADCBufMSP432.h:330
uint_fast16_t * intlResultBuf
Definition: ADCBufMSP432.h:347
Definition: ADCBufMSP432.h:243
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:232
Definition: ADCBufMSP432.h:219
UDMAMSP432_PingPongTransfer pingpongDMATransfer
Definition: ADCBufMSP432.h:367
Definition: ADCBufMSP432.h:203
ADCBuf_Return_Mode returnMode
Definition: ADCBufMSP432.h:356
MSP432 specfic extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:264
uint_fast16_t conversionSampleCount
Definition: ADCBufMSP432.h:351
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:171
ADCBufMSP432_InternalSourceMode adcInternalSource
Definition: ADCBufMSP432.h:287
UDMAMSP432_Handle dmaHandle
Definition: ADCBufMSP432.h:366
Defines a conversion to be used with ADCBuf_convert().
Definition: ADCBuf.h:315
UDMAMSP432_Transfer dmaTransfer
Definition: ADCBufMSP432.h:368
ADCBufMSP432_ReferenceSource refSource
Definition: ADCBufMSP432.h:276
Definition: ADCBufMSP432.h:173
ADCBufMSP432_TriggerSource
ADCMSP432 trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the trigger source ...
Definition: ADCBufMSP432.h:231
Definition: ADCBufMSP432.h:252
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufMSP432.h:355
Definition: ADCBufMSP432.h:209
uint16_t * conversionSampleBuf
Definition: ADCBufMSP432.h:349
uint32_t tempCal85
Definition: ADCBufMSP432.h:364
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale