ADCBufMSP432E4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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  */
32 /*!****************************************************************************
33  * @file ADCBufMSP432E4.h
34  *
35  * @brief ADCBuf driver implementation for a MSP432E4 analog-to-digital
36  * converter
37  *
38  * # Overview #
39  * This driver takes \p n samples using the ADC and stores the results in a
40  * buffer. This implementation supports both #ADCBuf_RECURRENCE_MODE_ONE_SHOT
41  * and #ADCBuf_RECURRENCE_MODE_CONTINUOUS. The ADCBuf_MSP432E4 driver
42  * supports use of both ADC peripherals and their sample sequencers.
43  *
44  * # General Behavior #
45  * The MSP342E4 microcontroller has two ADC modules and each ADC module has
46  * four sample sequencers, SS0-SS3, that control and capture sample data.
47  * Sequencer priority can be initialized in #ADCBufMSP432E4_HWAttrsV1 by
48  * creating an array that holds the corresponding #ADCBufMSP432E4_SequencePriorities.
49  *
50  * To initialize the sequencers, in the board file "MSP_EXP432E401Y.c"/board.h
51  * - Specify the sequencer to use by setting ".adcSequence" in the array
52  * #ADCBufMSP432E4_Channels for each channel/sequencer combination needed.
53  * - Change the sequencer priority for each sequencer to be used in the array
54  * #ADCBufMSP432E4_SequencePriorities.
55  *
56  * @anchor ti_drivers_adcbuf_ADCBufMSP432E4_SequencePriorities
57  * ## Sequencer Priorities - #ADCBufMSP432E4_SequencePriorities
58  *
59  * @code
60  * static ADCBufMSP432E4_SequencePriorities seqPriorities[ADCBufMSP432E4_SEQUENCER_COUNT] = {
61  * ADCBufMSP432E4_Priority_0,
62  * ADCBufMSP432E4_Seq_Disable,
63  * ADCBufMSP432E4_Seq_Disable,
64  * ADCBufMSP432E4_Seq_Disable
65  * };
66  * @endcode
67  *
68  * The MSP432E4 ADC sample sequencers can be triggered by several
69  * different types of software and hardware events. The driver currently
70  * only supports #ADCBufMSP432E4_SOFTWARE_AUTOMATIC_TRIGGER and
71  * #ADCBufMSP432E4_TIMER_TRIGGER trigger sources. Multiple sequencers
72  * can share the same trigger source. An unique #ADCBufMSP432E4_TriggerSource
73  * array can be defined for each ADCBuf instance. That is, each
74  * #ADCBufMSP432E4_HWAttrsV1.adcTriggerSource can point to a unique
75  * #ADCBufMSP432E4_TriggerSource array.
76  *
77  * The application is responsible for defining a #ADCBufMSP432E4_Channels
78  * array. Each index corresponds to a ADC channel configuration. A unique
79  * #ADCBufMSP432E4_Channels array can be defined for each ADCBuf instance.
80  * That is, each #ADCBufMSP432E4_HWAttrsV1.channelSetting can point to a unique
81  * #ADCBufMSP432E4_Channels array.
82  *
83  * The #ADCBufMSP432E4_Channels array lets the user select the #ADCBufMSP432E4_Sequencer,
84  * #ADCBufMSP432E4_DifferentialMode, the differential pins if needed, MSP432E4
85  * specific ADC modes like #ADCBufMSP432E4_TEMPERATURE_MODE that let the user
86  * configure the internal temperature mode
87  *
88  * @anchor ti_drivers_adcbuf_ADCBufMSP432E4_ADCBufMSP432E4_Channels
89  * ## Channel section - #ADCBufMSP432E4_Channels
90  * @code
91  * ADCBufMSP432E4_Channels adcBuf0MSP432E4Channels[ADCBUF0CHANNELCOUNT] = {
92  * {
93  * .adcPin = ADCBufMSP432E4_PE_3_A0,
94  * .adcSequence = ADCBufMSP432E4_Seq_0,
95  * .adcInputMode = ADCBufMSP432E4_SINGLE_ENDED,
96  * .adcDifferentialPin = ADCBufMSP432E4_PIN_NONE,
97  * .adcInternalSource = ADCBufMSP432E4_INTERNAL_SOURCE_MODE_OFF,
98  * .refVoltage = 3300000
99  * },
100  * {
101  * .adcPin = ADCBufMSP432E4_PE_2_A1,
102  * .adcSequence = ADCBufMSP432E4_Seq_1,
103  * .adcInputMode = ADCBufMSP432E4_SINGLE_ENDED,
104  * .adcDifferentialPin = ADCBufMSP432E4_PIN_NONE,
105  * .adcInternalSource = ADCBufMSP432E4_INTERNAL_SOURCE_MODE_OFF,
106  * .refVoltage = 3300000
107  * },
108  * @endcode
109  *
110  * Please refer to #ADCBufMSP432E4_HWAttrsV1 structure for other hardware
111  * dependent configuration settings Some examples include voltage reference
112  * source selection and optional DMA usage.
113  *
114  * This driver supports various modes of operation and sampling.
115  * #ADCBufMSP432E4_HWAttrsV1.useDMA can be set to \p 1 to improve performance.
116  * Additionally, samples can be performed using #ADCBufMSP432E4_DIFFERENTIAL
117  * or #ADCBufMSP432E4_TEMPERATURE_MODE modes.
118  *
119 
120  *
121  * In the application,
122  * - Call ADCBuf_init() once per ADC module.
123  * - Each ADC module requires a separate ADCBuf_open() call.
124  * - Create and initialize "ADCBuf_Conversion" object for each sequencer.
125  * - To make each sequencer sample multiple channels, create the conversion
126  * object as an array, example ADCBuf_Conversion continuousConversion[2]
127  * and initialize each channel within the conversion object.
128  *
129  * Refer to @ref ADCBuf.h for a complete description of APIs & example use.
130  *
131  ******************************************************************************
132  */
133 
134 #ifndef ti_drivers_adcbuf_ADCBufMSP432E4__include
135 #define ti_drivers_adcbuf_ADCBufMSP432E4__include
136 
137 #include <stdint.h>
138 #include <stdbool.h>
139 
140 #include <ti/drivers/ADCBuf.h>
141 #include <ti/drivers/dpl/HwiP.h>
142 #include <ti/drivers/dpl/SemaphoreP.h>
144 #include <ti/devices/msp432e4/driverlib/adc.h>
145 
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149 
150 /*
151  * ADCBuf port/pin defines for pin configuration. Ports B, D, E, and K are
152  * configurable through the port mapping controller. None of the port
153  * mappings support ADC.
154  * Channel specifies the ADC channel and ranges from 0 to 23.
155  * pin range: 0 - 7, port range: 0 - 15
156  *
157  * 31-24 23-16 15-8 7-0
158  * -------------------------------------------
159  * | RESERVED | CHANNEL | PORT | PIN |
160  * -------------------------------------------
161  *
162  * channel = (((config) >> 16) & 0x10F)
163  * port = (((config << 4) & 0x000FF000) | 0x40000000)
164  * pin = ((config) & 0xFF)
165  *
166  */
167 
180 #define ADCBufMSP432E4_PB_4_A10 ((10 << 16) | 0x5910)
181 
186 #define ADCBufMSP432E4_PB_5_A11 ((11 << 16) | 0x5920)
187 
193 #define ADCBufMSP432E4_PD_0_A15 ((15 << 16) | 0x5B01)
194 
199 #define ADCBufMSP432E4_PD_1_A14 ((14 << 16) | 0x5B02)
200 
205 #define ADCBufMSP432E4_PD_2_A13 ((13 << 16) | 0x5B04)
206 
211 #define ADCBufMSP432E4_PD_3_A12 ((12 << 16) | 0x5B08)
212 
217 #define ADCBufMSP432E4_PD_4_A7 ((7 << 16) | 0x5B10)
218 
223 #define ADCBufMSP432E4_PD_5_A6 ((6 << 16) | 0x5B20)
224 
229 #define ADCBufMSP432E4_PD_6_A5 ((5 << 16) | 0x5B40)
230 
235 #define ADCBufMSP432E4_PD_7_A4 ((4 << 16) | 0x5B80)
236 
241 #define ADCBufMSP432E4_PE_0_A3 ((3 << 16) | 0x5C01)
242 
247 #define ADCBufMSP432E4_PE_1_A2 ((2 << 16) | 0x5C02)
248 
253 #define ADCBufMSP432E4_PE_2_A1 ((1 << 16) | 0x5C04)
254 
259 #define ADCBufMSP432E4_PE_3_A0 ((0 << 16) | 0x5C08)
260 
265 #define ADCBufMSP432E4_PE_4_A9 ((9 << 16) | 0x5C10)
266 
271 #define ADCBufMSP432E4_PE_5_A8 ((8 << 16) | 0x5C20)
272 
277 #define ADCBufMSP432E4_PE_6_A20 (((20-16) << 16) | 0x5C40 | 0x01000000)
278 
283 #define ADCBufMSP432E4_PE_7_A21 (((21-16) << 16) | 0x5C80 | 0x01000000)
284 
289 #define ADCBufMSP432E4_PK_0_A16 (((16-16) << 16) | 0x6101 | 0x01000000)
290 
295 #define ADCBufMSP432E4_PK_1_A17 (((17-16) << 16) | 0x6102 | 0x01000000)
296 
301 #define ADCBufMSP432E4_PK_2_A18 (((18-16) << 16) | 0x6104 | 0x01000000)
302 
307 #define ADCBufMSP432E4_PK_3_A19 (((19-16) << 16) | 0x6108 | 0x01000000)
308 
313 #define ADCBufMSP432E4_PP_6_A23 (((23-16) << 16) | 0x6540 | 0x01000000)
314 
319 #define ADCBufMSP432E4_PP_7_A22 (((22-16) << 16) | 0x6580 | 0x01000000)
320 
325 #define ADCBufMSP432E4_PIN_NONE 0
326 
330 #define MSP432E4_NUM_ADC_CHANNELS (24)
331 
333 #define ADCBufMSP432E4_SEQUENCER_COUNT 4
334 
335 /* ADC function table pointer */
337 
365 typedef enum {
368 
371 
374 
377 
381 
393 typedef enum {
396 
399 
402 
406 
415 typedef enum {
418 
426 
435 typedef enum {
438 
446 
474 typedef enum {
484 
491  ADCBufMSP432E4_TIMER_TRIGGER = ADC_TRIGGER_TIMER,
493 
507 typedef enum {
510 
513 
516 
519 
522 
525 
528 
531 
534 
537 
540 
543 
546 
549 
552 
556 
565 typedef enum {
568 
571 
574 
577 
580 
583 
587 
595 typedef enum {
598 
602 
611 typedef struct {
613  ADCBufMSP432E4_SamplingDuration samplingDuration;
615 
661 typedef struct {
663  uint32_t refVoltage;
664 
666  uint32_t adcPin;
667 
670 
676  ADCBufMSP432E4_DifferentialMode adcInputMode;
677 
682  ADCBufMSP432E4_InternalSourceMode adcInternalSource;
683 
691 
741 typedef struct {
743  uint32_t intPriority;
744 
746  uint32_t adcBase;
747 
754  uint32_t adcTimerSource;
755 
758 
760  ADCBufMSP432E4_TriggerSource *adcTriggerSource;
761 
766  ADCBufMSP432E4_Phase modulePhase;
767 
769  ADCBufMSP432E4_ReferenceSource refSource;
770 
773 
778  uint8_t useDMA;
780 
781 /*
782  * @brief ADCBufMSP432E4 Object
783  *
784  * The application must not access any member variables of this structure!
785  */
786 typedef struct {
787  /* Grants exclusive access to ADC */
788  SemaphoreP_Handle mutex;
789  /* Notify finished ADC convert */
790  SemaphoreP_Handle convertComplete;
791 
792  /* Hardware interrupt handles, one per sequencer */
793  HwiP_Handle sequencerHwiHandles[4];
794 
795  /* PingPong flag indicates which sample buffer is active in the conversion */
796  uint_fast8_t pingpongFlag[4];
797  /* Count of sampling channels */
798  uint_fast8_t channelCount[4];
799  ADCBuf_Conversion *conversions[4];
800 
801  /* Callback function pointer */
803 
804  uint16_t *sampleBuffer[4];
805  /* Internal dec. conversion buffer counter */
806  uint_fast16_t sampleIndex[4];
807  /* Total sampling count per channel */
808  uint_fast16_t sampleCount[4];
809 
810  /* ADC sampling duration */
811  ADCBufMSP432E4_SamplingDuration samplingDuration;
812  /* Timeout for read semaphore in ADCBuf_RETURN_MODE_BLOCKING */
814  /* Frequency in Hz at which the ADC is triggered */
816  /* Should we convert continuously or one-shot */
818  /* Mode for all conversions */
821  /* To determine if the ADC is open */
822  bool isOpen;
824 
825 #ifdef __cplusplus
826 }
827 #endif
828 
829 #endif /* ti_drivers_adcbuf_ADCBufMSP432E4__include */
Definition: ADCBufMSP432E4.h:524
Definition: ADCBufMSP432E4.h:521
Definition: ADCBufMSP432E4.h:373
MSP432E4 ADCBuf_Params Parameter Extensions.
Definition: ADCBufMSP432E4.h:611
Definition: ADCBufMSP432E4.h:398
UDMAMSP432E4 Global configuration.
Definition: UDMAMSP432E4.h:143
ADCBufMSP432E4 Channel Settings.
Definition: ADCBufMSP432E4.h:661
Definition: ADCBufMSP432E4.h:579
ADCBufMSP432E4_InternalSourceMode
ADCBufMSP432E4 Internal Source Mode.
Definition: ADCBufMSP432E4.h:415
const ADCBuf_FxnTable ADCBufMSP432E4_fxnTable
SemaphoreP_Handle convertComplete
Definition: ADCBufMSP432E4.h:790
uint32_t adcBase
Definition: ADCBufMSP432E4.h:746
ADCBufMSP432E4_Sequencer
ADCBufMSP432E4 Sequencer.
Definition: ADCBufMSP432E4.h:393
uDMA driver implementation for MSP432E4.
ADCBuf_Callback callBackFxn
Definition: ADCBufMSP432E4.h:802
Analog to Digital Conversion Buffer (ADCBuf) Input Driver.
UDMAMSP432E4_Handle dmaHandle
Definition: ADCBufMSP432E4.h:820
Definition: ADCBufMSP432E4.h:437
Definition: ADCBufMSP432E4.h:424
Definition: ADCBufMSP432E4.h:573
Definition: ADCBufMSP432E4.h:527
Definition: ADCBufMSP432E4.h:542
uint8_t useDMA
Definition: ADCBufMSP432E4.h:778
uint32_t adcDifferentialPin
Definition: ADCBufMSP432E4.h:689
Definition: ADCBufMSP432E4.h:536
Definition: ADCBufMSP432E4.h:376
uint32_t intPriority
Definition: ADCBufMSP432E4.h:743
Definition: ADCBufMSP432E4.h:404
Definition: ADCBufMSP432E4.h:533
Definition: ADCBufMSP432E4.h:509
SemaphoreP_Handle mutex
Definition: ADCBufMSP432E4.h:788
Definition: ADCBufMSP432E4.h:379
Definition: ADCBufMSP432E4.h:548
Definition: ADCBufMSP432E4.h:530
uint32_t refVoltage
Definition: ADCBufMSP432E4.h:663
ADCBufMSP432E4_Phase
ADCBufMSP432E4 phase delay.
Definition: ADCBufMSP432E4.h:507
ADCBufMSP432E4_SequencePriorities
ADCBufMSP432E4 Sequencer Priorities.
Definition: ADCBufMSP432E4.h:365
Definition: ADCBufMSP432E4.h:600
bool isOpen
Definition: ADCBufMSP432E4.h:822
Definition: ADCBufMSP432E4.h:554
Definition: ADCBufMSP432E4.h:491
The definition of an ADCBuf function table that contains the required set of functions to control a s...
Definition: ADCBuf.h:600
ADCBufMSP432E4_InternalSourceMode adcInternalSource
Definition: ADCBufMSP432E4.h:682
uint32_t adcTimerSource
Definition: ADCBufMSP432E4.h:754
ADCBuf_Recurrence_Mode recurrenceMode
Definition: ADCBufMSP432E4.h:817
Definition: ADCBufMSP432E4.h:551
ADCBufMSP432E4_SequencePriorities * sequencePriority
Definition: ADCBufMSP432E4.h:772
ADCBufMSP432E4_DifferentialMode
ADCBufMSP432E4 Differential Mode.
Definition: ADCBufMSP432E4.h:435
Definition: ADCBufMSP432E4.h:576
ADCBufMSP432E4_Sequencer adcSequence
Definition: ADCBufMSP432E4.h:669
Definition: ADCBufMSP432E4.h:515
Definition: ADCBufMSP432E4.h:395
ADCBufMSP432E4_Phase modulePhase
Definition: ADCBufMSP432E4.h:766
ADCBufMSP432E4_ReferenceSource
ADCBufMSP432E4 Reference Source.
Definition: ADCBufMSP432E4.h:595
Definition: ADCBufMSP432E4.h:367
Definition: ADCBufMSP432E4.h:539
Definition: ADCBufMSP432E4.h:417
ADCBuf_Recurrence_Mode
Recurrence behavior of a ADCBuf_Conversion specified in the ADCBuf_Params.
Definition: ADCBuf.h:404
ADCBufMSP432E4_SamplingDuration samplingDuration
Definition: ADCBufMSP432E4.h:613
ADCBuf_Return_Mode
Return behavior for ADCBuf_convert() specified in the ADCBuf_Params.
Definition: ADCBuf.h:446
ADCBufMSP432E4_ReferenceSource refSource
Definition: ADCBufMSP432E4.h:769
Definition: ADCBufMSP432E4.h:582
ADCBufMSP432E4_SamplingDuration samplingDuration
Definition: ADCBufMSP432E4.h:811
ADCBufMSP432E4_SamplingDuration
ADCMSP432E4 Sampling Duration.
Definition: ADCBufMSP432E4.h:565
ADCBufMSP432E4_DifferentialMode adcInputMode
Definition: ADCBufMSP432E4.h:676
Definition: ADCBufMSP432E4.h:567
uint32_t semaphoreTimeout
Definition: ADCBufMSP432E4.h:813
ADCBufMSP432E4_TriggerSource
ADCBufMSP432E4 Trigger Source.
Definition: ADCBufMSP432E4.h:474
Definition: ADCBufMSP432E4.h:401
Definition: ADCBufMSP432E4.h:597
Definition: ADCBufMSP432E4.h:512
void(* ADCBuf_Callback)(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel)
The definition of a callback function.
Definition: ADCBuf.h:391
Definition: ADCBufMSP432E4.h:545
uint32_t samplingFrequency
Definition: ADCBufMSP432E4.h:815
Definition: ADCBufMSP432E4.h:570
Definition: ADCBufMSP432E4.h:444
Defines a conversion to be used with ADCBuf_convert().
Definition: ADCBuf.h:315
uint32_t adcPin
Definition: ADCBufMSP432E4.h:666
Definition: ADCBufMSP432E4.h:518
ADCBufMSP432E4 Hardware attributes.
Definition: ADCBufMSP432E4.h:741
ADCBufMSP432E4_Channels * channelSetting
Definition: ADCBufMSP432E4.h:757
Definition: ADCBufMSP432E4.h:483
Definition: ADCBufMSP432E4.h:370
Definition: ADCBufMSP432E4.h:786
ADCBufMSP432E4_TriggerSource * adcTriggerSource
Definition: ADCBufMSP432E4.h:760
Definition: ADCBufMSP432E4.h:585
ADCBuf_Return_Mode returnMode
Definition: ADCBufMSP432E4.h:819
© Copyright 1995-2019, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale