ADCBufMSP432.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, 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 
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 
69 /*
70  * ADCBuf port/pin defines for pin configuration. Ports P2, P3, and P7 are
71  * configurable through the port mapping controller. None of the port
72  * mappings support ADC.
73  * Channel specifies the ADC channel and ranges from 0 to 23.
74  * pin range: 0 - 7, port range: 0 - 15
75  *
76  *
77  * 15 - 10 9 8 7 - 4 3 - 0
78  * ---------------------------------
79  * | CHANNEL | X | X | PORT | PIN |
80  * ---------------------------------
81  *
82  * channel = pinConfig >> 10
83  * port = (pinConfig >> 4) & 0xf
84  * pin = 1 << (pinConfig & 0xf)
85  * moduleFunction = (pinConfig >> 8) & 0x3
86  *
87  * For non-configurable ports (bits 20 - 12 will be 0).
88  * Bits 8 and 9 hold the module function (PRIMARY, SECONDARY, or
89  * TERTIARY). All ADC modes are TERTIARY, so bits 8 and 9
90  * are 1.
91  *
92  * MAP_GPIO_setAsPeripheralModuleFunctionInputPin(port,
93  * pin, moduleFunction);
94  * or:
95  * MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(port,
96  * pin, moduleFunction);
97  *
98  */
99 /* Port 4 */
100 #define ADCBufMSP432_P4_0_A13 ((13 << 10) | 0x0340) /* ch 13, port 4, pin 0 */
101 #define ADCBufMSP432_P4_1_A12 ((12 << 10) | 0x0341) /* ch 12, port 4, pin 1 */
102 #define ADCBufMSP432_P4_2_A11 ((11 << 10) | 0x0342) /* ch 11, port 4, pin 2 */
103 #define ADCBufMSP432_P4_3_A10 ((10 << 10) | 0x0343) /* ch 10, port 4, pin 3 */
104 #define ADCBufMSP432_P4_4_A9 ((9 << 10) | 0x0344) /* ch 9, port 4, pin 4 */
105 #define ADCBufMSP432_P4_5_A8 ((8 << 10) | 0x0345) /* ch 8, port 4, pin 5 */
106 #define ADCBufMSP432_P4_6_A7 ((7 << 10) | 0x0346) /* ch 7, port 4, pin 6 */
107 #define ADCBufMSP432_P4_7_A6 ((6 << 10) | 0x0347) /* ch 6, port 4, pin 7 */
108 
109 /* Port 5 */
110 #define ADCBufMSP432_P5_0_A5 ((5 << 10) | 0x0350) /* ch 5, port 5, pin 0 */
111 #define ADCBufMSP432_P5_1_A4 ((4 << 10) | 0x0351) /* ch 4, port 5, pin 1 */
112 #define ADCBufMSP432_P5_2_A3 ((3 << 10) | 0x0352) /* ch 3, port 5, pin 2 */
113 #define ADCBufMSP432_P5_3_A2 ((2 << 10) | 0x0353) /* ch 2, port 5, pin 3 */
114 #define ADCBufMSP432_P5_4_A1 ((1 << 10) | 0x0354) /* ch 1, port 5, pin 4 */
115 #define ADCBufMSP432_P5_5_A0 ((0 << 10) | 0x0355) /* ch 0, port 5, pin 5 */
116 
117 /* Port 6 */
118 #define ADCBufMSP432_P6_0_A15 ((15 << 10) | 0x0360) /* ch 15, port 6, pin 0 */
119 #define ADCBufMSP432_P6_1_A14 ((14 << 10) | 0x0361) /* ch 14, port 6, pin 1 */
120 
121 /* Port 8 */
122 #define ADCBufMSP432_P8_2_A23 ((23 << 10) | 0x0382) /* ch 23, port 8, pin 2 */
123 #define ADCBufMSP432_P8_3_A22 ((22 << 10) | 0x0383) /* ch 22, port 8, pin 3 */
124 #define ADCBufMSP432_P8_4_A21 ((21 << 10) | 0x0384) /* ch 21, port 8, pin 4 */
125 #define ADCBufMSP432_P8_5_A20 ((20 << 10) | 0x0385) /* ch 20, port 8, pin 5 */
126 #define ADCBufMSP432_P8_6_A19 ((19 << 10) | 0x0386) /* ch 19, port 8, pin 6 */
127 #define ADCBufMSP432_P8_7_A18 ((18 << 10) | 0x0387) /* ch 18, port 8, pin 7 */
128 
129 /* Port 9 */
130 #define ADCBufMSP432_P9_0_A17 ((17 << 10) | 0x0390) /* ch 17, port 9, pin 0 */
131 #define ADCBufMSP432_P9_1_A16 ((16 << 10) | 0x0391) /* ch 16, port 9, pin 1 */
132 
133 /*
134  * =============================================================================
135  * Constants
136  * =============================================================================
137  */
138 
139 /* ADC function table pointer */
141 
149  ADCBufMSP432_VREFPOS_AVCC_VREFNEG_VSS = ADC_VREFPOS_AVCC_VREFNEG_VSS,
150  ADCBufMSP432_VREFPOS_INTBUF_VREFNEG_VSS = ADC_VREFPOS_INTBUF_VREFNEG_VSS,
151  ADCBufMSP432_VREFPOS_EXTPOS_VREFNEG_EXTNEG = ADC_VREFPOS_EXTPOS_VREFNEG_EXTNEG,
152  ADCBufMSP432_VREFPOS_EXTBUF_VREFNEG_EXTNEG = ADC_VREFPOS_EXTBUF_VREFNEG_EXTNEG
154 
172 
188 
189 
198  ADCBufMSP432_Sampling_Duration samplingDuration;
200 
207 typedef struct ADCBufMSP432_Channels {
208  uint_fast16_t adcPin;
209  ADCBufMSP432_Reference_Source refSource;
210  uint32_t refVoltage;
212 
237 typedef struct ADCBufMSP432_HWAttrs {
238  uint32_t intPriority;
243 
249 typedef struct ADCBufMSP432_Object {
250  SemaphoreP_Handle mutex; /* Grants exclusive access to ADC */
251  SemaphoreP_Handle convertComplete; /* Notify finished ADC convert */
252  HwiP_Handle hwiHandle; /* Hardware interrupt handle */
253 
254  uint_fast8_t pingpongFlag; /* PingPong flag indicates which sample buffer is active in the conversion */
255  uint_fast8_t channelCount; /* Count of sampling channels */
256  ADCBuf_Conversion *conversions; /* Ptr to ADC conversion struct array passed by user */
257  ADCBuf_Callback callBackFxn; /* Callback function pointer */
258  uint_fast16_t *intlResultBuf; /* Internal result buffer */
259 
260  uint16_t *conversionSampleBuf; /* Ptr to current active sampling buffer */
261  uint_fast16_t conversionSampleIdx; /* Internal dec. conversion buffer counter */
262  uint_fast16_t conversionSampleCount; /* Total sampling count per channel */
263 
264  uint32_t semaphoreTimeout;
265  uint32_t samplingFrequency;
268  ADCBufMSP432_Sampling_Duration samplingDuration;
270  uint32_t timerAddr; /* Timer base address for trigger source */
271 
272  bool isOpen; /* To determine if the ADC is open */
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 
279 #endif /* ti_drivers_adc_ADCBufMSP432__include */
uint_fast16_t conversionSampleIdx
Definition: ADCBufMSP432.h:261
Definition: ADCBufMSP432.h:185
const ADCBuf_FxnTable ADCBufMSP432_fxnTable
Definition: ADCBufMSP432.h:166
Definition: ADCBufMSP432.h:149
Definition: ADCBufMSP432.h:164
ADCBuf_Conversion * conversions
Definition: ADCBufMSP432.h:256
enum ADCBuf_Recurrence_Mode_ ADCBuf_Recurrence_Mode
ADC trigger mode settings.
uint_fast8_t pingpongFlag
Definition: ADCBufMSP432.h:254
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:264
An ADCBuf_Conversion data structure is used with ADCBuf_convert(). It indicates which channel to perf...
Definition: ADCBuf.h:237
Definition: ADCBufMSP432.h:168
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:198
ADCBufMSP432_Timer_Reference_Source
ADCMSP432 timer trigger source These fields are used by ADCBufMSP432_HWAttrs to specify the Timer Cap...
Definition: ADCBufMSP432.h:179
Definition: ADCBufMSP432.h:181
bool isOpen
Definition: ADCBufMSP432.h:272
ADCBufMSP432_Sampling_Duration
ADCMSP432 sampling duration These fields define the MSP432 ADC sampling duration (sample and hold tim...
Definition: ADCBufMSP432.h:162
ADCBufMSP432 Object.
Definition: ADCBufMSP432.h:249
ADCBuf_Callback callBackFxn
Definition: ADCBufMSP432.h:257
SemaphoreP_Handle convertComplete
Definition: ADCBufMSP432.h:251
uint_fast16_t adcPin
Definition: ADCBufMSP432.h:208
Definition: ADCBufMSP432.h:163
Definition: ADCBufMSP432.h:151
Definition: ADCBufMSP432.h:183
Definition: ADCBufMSP432.h:186
Definition: ADCBufMSP432.h:150
ADCBufMSP432_Channels * channelSetting
Definition: ADCBufMSP432.h:239
ADCBufMSP432 Hardware attributes These fields are populated by PinMux tool but user is allowed to cha...
Definition: ADCBufMSP432.h:237
Definition: ADCBufMSP432.h:180
uint32_t samplingFrequency
Definition: ADCBufMSP432.h:265
ADCBufMSP432_Sampling_Duration samplingDuration
Definition: ADCBufMSP432.h:268
Definition: ADCBufMSP432.h:152
uint32_t intPriority
Definition: ADCBufMSP432.h:238
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.
ADCBufMSP432_Reference_Source
ADCMSP432 reference source These fields are used by ADCBufMSP432_HWAttrs to specify the reference vol...
Definition: ADCBufMSP432.h:148
uint32_t refVoltage
Definition: ADCBufMSP432.h:210
HwiP_Handle hwiHandle
Definition: ADCBufMSP432.h:252
uDMA driver implementation for MSP432.
Definition: ADCBufMSP432.h:182
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:240
uint32_t timerAddr
Definition: ADCBufMSP432.h:270
ADCMSP432 Channel setting These fields define channel-specific settings: GPIO and reference voltage...
Definition: ADCBufMSP432.h:207
uint_fast8_t channelCount
Definition: ADCBufMSP432.h:255
uint_fast16_t * intlResultBuf
Definition: ADCBufMSP432.h:258
SemaphoreP_Handle mutex
Definition: ADCBufMSP432.h:250
Definition: ADCBufMSP432.h:165
ADCBuf_Return_Mode returnMode
Definition: ADCBufMSP432.h:267
Definition: ADCBufMSP432.h:184
MSP432 specfic extension to ADCBuf_Params.
Definition: ADCBufMSP432.h:197
uint_fast16_t conversionSampleCount
Definition: ADCBufMSP432.h:262
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
Definition: ADCBufMSP432.h:167
ADCBufMSP432_Reference_Source refSource
Definition: ADCBufMSP432.h:209
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufMSP432.h:266
uint16_t * conversionSampleBuf
Definition: ADCBufMSP432.h:260
Copyright 2017, Texas Instruments Incorporated