1 /* --COPYRIGHT--,BSD
2 * Copyright (c) 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 * --/COPYRIGHT--*/
32 /* Standard Includes */
33 #include <stdint.h>
34 #include <stdbool.h>
35
36 /* DriverLib Includes */
37 #include <ti/devices/msp432p4xx/driverlib/adc14.h>
38 #include <ti/devices/msp432p4xx/driverlib/debug.h>
39 #include <ti/devices/msp432p4xx/driverlib/interrupt.h>
40
41 /* Statics */
42 static volatile uint32_t* const _ctlRegs[32] =
43 { &ADC14->MCTL[0], &ADC14->MCTL[1], &ADC14->MCTL[2], &ADC14->MCTL[3],
44 &ADC14->MCTL[4], &ADC14->MCTL[5], &ADC14->MCTL[6], &ADC14->MCTL[7],
45 &ADC14->MCTL[8], &ADC14->MCTL[9], &ADC14->MCTL[10],
46 &ADC14->MCTL[11], &ADC14->MCTL[12], &ADC14->MCTL[13],
47 &ADC14->MCTL[14], &ADC14->MCTL[15], &ADC14->MCTL[16],
48 &ADC14->MCTL[17], &ADC14->MCTL[18], &ADC14->MCTL[19],
49 &ADC14->MCTL[20], &ADC14->MCTL[21], &ADC14->MCTL[22],
50 &ADC14->MCTL[23], &ADC14->MCTL[24], &ADC14->MCTL[25],
51 &ADC14->MCTL[26], &ADC14->MCTL[27], &ADC14->MCTL[28],
52 &ADC14->MCTL[29], &ADC14->MCTL[30], &ADC14->MCTL[31] };
53
_getIndexForMemRegister(uint32_t reg)54 static uint_fast8_t _getIndexForMemRegister(uint32_t reg)
55 {
56 switch (reg)
57 {
58 case ADC_MEM0:
59 return 0;
60 case ADC_MEM1:
61 return 1;
62 case ADC_MEM2:
63 return 2;
64 case ADC_MEM3:
65 return 3;
66 case ADC_MEM4:
67 return 4;
68 case ADC_MEM5:
69 return 5;
70 case ADC_MEM6:
71 return 6;
72 case ADC_MEM7:
73 return 7;
74 case ADC_MEM8:
75 return 8;
76 case ADC_MEM9:
77 return 9;
78 case ADC_MEM10:
79 return 10;
80 case ADC_MEM11:
81 return 11;
82 case ADC_MEM12:
83 return 12;
84 case ADC_MEM13:
85 return 13;
86 case ADC_MEM14:
87 return 14;
88 case ADC_MEM15:
89 return 15;
90 case ADC_MEM16:
91 return 16;
92 case ADC_MEM17:
93 return 17;
94 case ADC_MEM18:
95 return 18;
96 case ADC_MEM19:
97 return 19;
98 case ADC_MEM20:
99 return 20;
100 case ADC_MEM21:
101 return 21;
102 case ADC_MEM22:
103 return 22;
104 case ADC_MEM23:
105 return 23;
106 case ADC_MEM24:
107 return 24;
108 case ADC_MEM25:
109 return 25;
110 case ADC_MEM26:
111 return 26;
112 case ADC_MEM27:
113 return 27;
114 case ADC_MEM28:
115 return 28;
116 case ADC_MEM29:
117 return 29;
118 case ADC_MEM30:
119 return 30;
120 case ADC_MEM31:
121 return 31;
122 default:
123 ASSERT(false);
124 return ADC_INVALID_MEM;
125
126 }
127 }
128
129 //*****************************************************************************
130 //
131 //!
132 //! Returns a boolean value that tells if conversion is active/running or is
133 //! not acMSP432 ted.
134 //!
135 //! Originally a public function, but moved to static. External customers should
136 //! use the ADC14_isBusy function.
137 //!
138 //! \return true if conversion is active, false otherwise
139 //
140 //*****************************************************************************
ADCIsConversionRunning(void)141 static bool ADCIsConversionRunning(void)
142 {
143 return BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_BUSY_OFS);
144 }
145
ADC14_enableModule(void)146 void ADC14_enableModule(void)
147 {
148 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_ON_OFS) = 1;
149 }
150
ADC14_disableModule(void)151 bool ADC14_disableModule(void)
152 {
153 if (ADCIsConversionRunning())
154 return false;
155
156 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_ON_OFS) = 0;
157
158 return true;
159 }
160
ADC14_enableSampleTimer(uint32_t multiSampleConvert)161 bool ADC14_enableSampleTimer(uint32_t multiSampleConvert)
162 {
163 if (ADCIsConversionRunning())
164 return false;
165
166 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_SHP_OFS) = 1;
167
168 if (multiSampleConvert == ADC_MANUAL_ITERATION)
169 {
170 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_MSC_OFS) = 0;
171 } else
172 {
173 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_MSC_OFS) = 1;
174 }
175
176 return true;
177 }
178
ADC14_disableSampleTimer(void)179 bool ADC14_disableSampleTimer(void)
180 {
181 if (ADCIsConversionRunning())
182 return false;
183
184 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_SHP_OFS) = 0;
185
186 return true;
187 }
188
ADC14_initModule(uint32_t clockSource,uint32_t clockPredivider,uint32_t clockDivider,uint32_t internalChannelMask)189 bool ADC14_initModule(uint32_t clockSource, uint32_t clockPredivider,
190 uint32_t clockDivider, uint32_t internalChannelMask)
191 {
192 ASSERT(
193 clockSource == ADC_CLOCKSOURCE_ADCOSC
194 || clockSource == ADC_CLOCKSOURCE_SYSOSC
195 || clockSource == ADC_CLOCKSOURCE_ACLK
196 || clockSource == ADC_CLOCKSOURCE_MCLK
197 || clockSource == ADC_CLOCKSOURCE_SMCLK
198 || clockSource == ADC_CLOCKSOURCE_HSMCLK);
199
200 ASSERT(
201 clockPredivider == ADC_PREDIVIDER_1
202 || clockPredivider == ADC_PREDIVIDER_4
203 || clockPredivider == ADC_PREDIVIDER_32
204 || clockPredivider == ADC_PREDIVIDER_64);
205
206 ASSERT(
207 clockDivider == ADC_DIVIDER_1 || clockDivider == ADC_DIVIDER_2
208 || clockDivider == ADC_DIVIDER_3
209 || clockDivider == ADC_DIVIDER_4
210 || clockDivider == ADC_DIVIDER_5
211 || clockDivider == ADC_DIVIDER_6
212 || clockDivider == ADC_DIVIDER_7
213 || clockDivider == ADC_DIVIDER_8);
214
215 ASSERT(
216 !(internalChannelMask
217 & ~(ADC_MAPINTCH3 | ADC_MAPINTCH2 | ADC_MAPINTCH1
218 | ADC_MAPINTCH0 | ADC_TEMPSENSEMAP | ADC_BATTMAP)));
219
220 if (ADCIsConversionRunning())
221 return false;
222
223 ADC14->CTL0 = (ADC14->CTL0
224 & ~(ADC14_CTL0_PDIV_MASK | ADC14_CTL0_DIV_MASK | ADC14_CTL0_SSEL_MASK))
225 | clockDivider | clockPredivider | clockSource;
226
227 ADC14->CTL1 = (ADC14->CTL1
228 & ~(ADC_MAPINTCH3 | ADC_MAPINTCH2 | ADC_MAPINTCH1 | ADC_MAPINTCH0
229 | ADC_TEMPSENSEMAP | ADC_BATTMAP)) | internalChannelMask;
230
231 return true;
232 }
233
ADC14_setResolution(uint32_t resolution)234 void ADC14_setResolution(uint32_t resolution)
235 {
236 ASSERT(
237 resolution == ADC_8BIT || resolution == ADC_10BIT
238 || resolution == ADC_12BIT || resolution == ADC_14BIT);
239
240 ADC14->CTL1 = (ADC14->CTL1 & ~ADC14_CTL1_RES_MASK) | resolution;
241 }
242
ADC14_getResolution(void)243 uint_fast32_t ADC14_getResolution(void)
244 {
245 return ADC14->CTL1 & ADC14_CTL1_RES_MASK;
246 }
247
ADC14_setSampleHoldTrigger(uint32_t source,bool invertSignal)248 bool ADC14_setSampleHoldTrigger(uint32_t source, bool invertSignal)
249 {
250
251 ASSERT(
252 source == ADC_TRIGGER_ADCSC || source == ADC_TRIGGER_SOURCE1
253 || source == ADC_TRIGGER_SOURCE2
254 || source == ADC_TRIGGER_SOURCE3
255 || source == ADC_TRIGGER_SOURCE4
256 || source == ADC_TRIGGER_SOURCE5
257 || source == ADC_TRIGGER_SOURCE6
258 || source == ADC_TRIGGER_SOURCE7);
259
260 if (ADCIsConversionRunning())
261 return false;
262
263 if (invertSignal)
264 {
265 ADC14->CTL0 = (ADC14->CTL0
266 & ~(ADC14_CTL0_ISSH | ADC14_CTL0_SHS_MASK)) | source
267 | ADC14_CTL0_ISSH;
268 } else
269 {
270 ADC14->CTL0 = (ADC14->CTL0
271 & ~(ADC14_CTL0_ISSH | ADC14_CTL0_SHS_MASK)) | source;
272 }
273
274 return true;
275 }
276
ADC14_setSampleHoldTime(uint32_t firstPulseWidth,uint32_t secondPulseWidth)277 bool ADC14_setSampleHoldTime(uint32_t firstPulseWidth,
278 uint32_t secondPulseWidth)
279 {
280 ASSERT(
281 firstPulseWidth == ADC_PULSE_WIDTH_4
282 || firstPulseWidth == ADC_PULSE_WIDTH_8
283 || firstPulseWidth == ADC_PULSE_WIDTH_16
284 || firstPulseWidth == ADC_PULSE_WIDTH_32
285 || firstPulseWidth == ADC_PULSE_WIDTH_64
286 || firstPulseWidth == ADC_PULSE_WIDTH_96
287 || firstPulseWidth == ADC_PULSE_WIDTH_128
288 || firstPulseWidth == ADC_PULSE_WIDTH_192);
289
290 ASSERT(
291 secondPulseWidth == ADC_PULSE_WIDTH_4
292 || secondPulseWidth == ADC_PULSE_WIDTH_8
293 || secondPulseWidth == ADC_PULSE_WIDTH_16
294 || secondPulseWidth == ADC_PULSE_WIDTH_32
295 || secondPulseWidth == ADC_PULSE_WIDTH_64
296 || secondPulseWidth == ADC_PULSE_WIDTH_96
297 || secondPulseWidth == ADC_PULSE_WIDTH_128
298 || secondPulseWidth == ADC_PULSE_WIDTH_192);
299
300 if (ADCIsConversionRunning())
301 return false;
302
303 ADC14->CTL0 = (ADC14->CTL0
304 & ~(ADC14_CTL0_SHT0_MASK | ADC14_CTL0_SHT1_MASK)) | secondPulseWidth
305 | (firstPulseWidth >> 4);
306
307 return true;
308 }
309
ADC14_configureMultiSequenceMode(uint32_t memoryStart,uint32_t memoryEnd,bool repeatMode)310 bool ADC14_configureMultiSequenceMode(uint32_t memoryStart, uint32_t memoryEnd,
311 bool repeatMode)
312 {
313 uint32_t ii;
314
315 ASSERT(
316 _getIndexForMemRegister(memoryStart) != ADC_INVALID_MEM
317 && _getIndexForMemRegister(memoryEnd) != ADC_INVALID_MEM);
318
319 if (ADCIsConversionRunning())
320 return false;
321
322 /* Clearing out any lingering EOS */
323 for (ii = 0; ii < 32; ii++)
324 {
325 BITBAND_PERI(*(_ctlRegs[ii]), ADC14_MCTLN_EOS_OFS) = 0;
326 }
327
328 /* Setting Start/Stop locations */
329 BITBAND_PERI(
330 (*(_ctlRegs[_getIndexForMemRegister(memoryEnd)])),
331 ADC14_MCTLN_EOS_OFS) = 1;
332
333 ADC14->CTL1 = (ADC14->CTL1 & ~(ADC14_CTL1_CSTARTADD_MASK))
334 | (_getIndexForMemRegister(memoryStart) << 16);
335
336 /* Setting multiple sample mode */
337 if (!repeatMode)
338 {
339 ADC14->CTL0 = (ADC14->CTL0 & ~(ADC14_CTL0_CONSEQ_MASK))
340 | (ADC14_CTL0_CONSEQ_1);
341 } else
342 {
343 ADC14->CTL0 = (ADC14->CTL0 & ~(ADC14_CTL0_CONSEQ_MASK))
344 | (ADC14_CTL0_CONSEQ_3);
345 }
346
347 return true;
348 }
349
ADC14_configureSingleSampleMode(uint32_t memoryDestination,bool repeatMode)350 bool ADC14_configureSingleSampleMode(uint32_t memoryDestination,
351 bool repeatMode)
352 {
353 ASSERT(_getIndexForMemRegister(memoryDestination) != 32);
354
355 if (ADCIsConversionRunning())
356 return false;
357
358 /* Setting the destination register */
359 ADC14->CTL1 = (ADC14->CTL1 & ~(ADC14_CTL1_CSTARTADD_MASK))
360 | (_getIndexForMemRegister(memoryDestination) << 16);
361
362 /* Setting single sample mode */
363 if (!repeatMode)
364 {
365 ADC14->CTL0 = (ADC14->CTL0 & ~(ADC14_CTL0_CONSEQ_MASK))
366 | (ADC14_CTL0_CONSEQ_0);
367 } else
368 {
369 ADC14->CTL0 = (ADC14->CTL0 & ~(ADC14_CTL0_CONSEQ_MASK))
370 | (ADC14_CTL0_CONSEQ_2);
371 }
372
373 return true;
374 }
375
ADC14_enableConversion(void)376 bool ADC14_enableConversion(void)
377 {
378 if (ADCIsConversionRunning() || !BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_ON_OFS))
379 return false;
380
381 ADC14->CTL0 |= (ADC14_CTL0_ENC);
382
383 return true;
384 }
385
ADC14_toggleConversionTrigger(void)386 bool ADC14_toggleConversionTrigger(void)
387 {
388 if (!BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_ON_OFS))
389 return false;
390
391 if (BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_SC_OFS))
392 {
393 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_SC_OFS) = 0;
394 } else
395 {
396 BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_SC_OFS) = 1;
397 }
398
399 return true;
400 }
401
ADC14_disableConversion(void)402 void ADC14_disableConversion(void)
403 {
404 ADC14->CTL0 &= ~(ADC14_CTL0_SC | ADC14_CTL0_ENC);
405 }
406
ADC14_isBusy(void)407 bool ADC14_isBusy(void)
408 {
409 return BITBAND_PERI(ADC14->CTL0, ADC14_CTL0_BUSY_OFS);
410 }
411
ADC14_configureConversionMemory(uint32_t memorySelect,uint32_t refSelect,uint32_t channelSelect,bool differntialMode)412 bool ADC14_configureConversionMemory(uint32_t memorySelect, uint32_t refSelect,
413 uint32_t channelSelect, bool differntialMode)
414 {
415 uint32_t currentReg, ii;
416 uint32_t *curReg;
417
418 /* Initialization */
419 ii = 1;
420 currentReg = 0x01;
421
422 if (ADCIsConversionRunning())
423 return false;
424
425 while (memorySelect != 0)
426 {
427 if (!(memorySelect & ii))
428 {
429 ii = ii << 1;
430 continue;
431 }
432
433 currentReg = memorySelect & ii;
434 memorySelect &= ~ii;
435 ii = ii << 1;
436
437 curReg = (uint32_t*) _ctlRegs[_getIndexForMemRegister(currentReg)];
438
439 if (differntialMode)
440 {
441 (*curReg) = ((*curReg)
442 & ~(ADC14_MCTLN_VRSEL_MASK | ADC14_MCTLN_INCH_MASK
443 | ADC14_MCTLN_DIF))
444 | (channelSelect | refSelect | ADC14_MCTLN_DIF);
445 } else
446 {
447 (*curReg) = ((*curReg)
448 & ~(ADC14_MCTLN_VRSEL_MASK | ADC14_MCTLN_INCH_MASK
449 | ADC14_MCTLN_DIF)) | (channelSelect | refSelect);
450 }
451
452 }
453
454 return true;
455 }
456
ADC14_enableComparatorWindow(uint32_t memorySelect,uint32_t windowSelect)457 bool ADC14_enableComparatorWindow(uint32_t memorySelect, uint32_t windowSelect)
458 {
459 uint32_t currentReg, ii;
460 uint32_t *curRegPoint;
461
462 /* Initialization */
463 ii = 1;
464 currentReg = 0x01;
465
466 if (ADCIsConversionRunning())
467 return false;
468
469 while (memorySelect != 0)
470 {
471 if (!(memorySelect & ii))
472 {
473 ii = ii << 1;
474 continue;
475 }
476
477 currentReg = memorySelect & ii;
478 memorySelect &= ~ii;
479 ii = ii << 1;
480
481 curRegPoint =
482 (uint32_t*) _ctlRegs[_getIndexForMemRegister(currentReg)];
483
484 if (windowSelect == ADC_COMP_WINDOW0)
485 {
486 (*curRegPoint) = ((*curRegPoint)
487 & ~(ADC14_MCTLN_WINC | ADC14_MCTLN_WINCTH))
488 | (ADC14_MCTLN_WINC);
489 } else if (windowSelect == ADC_COMP_WINDOW1)
490 {
491 (*curRegPoint) |= ADC14_MCTLN_WINC | ADC14_MCTLN_WINCTH;
492 }
493
494 }
495
496 return true;
497 }
498
ADC14_disableComparatorWindow(uint32_t memorySelect)499 bool ADC14_disableComparatorWindow(uint32_t memorySelect)
500 {
501 uint32_t currentReg, ii;
502
503 /* Initialization */
504 ii = 1;
505 currentReg = 0x01;
506
507 if (ADCIsConversionRunning())
508 return false;
509
510 while (memorySelect != 0)
511 {
512 if (!(memorySelect & ii))
513 {
514 ii = ii << 1;
515 continue;
516 }
517
518 currentReg = memorySelect & ii;
519 memorySelect &= ~ii;
520 ii = ii << 1;
521
522 (*(_ctlRegs[_getIndexForMemRegister(currentReg)])) &=
523 ~ADC14_MCTLN_WINC;
524
525 }
526
527 return true;
528 }
529
ADC14_setComparatorWindowValue(uint32_t window,int16_t low,int16_t high)530 bool ADC14_setComparatorWindowValue(uint32_t window, int16_t low, int16_t high)
531 {
532 if (ADCIsConversionRunning())
533 return false;
534
535 if(BITBAND_PERI(ADC14->CTL1, ADC14_CTL1_DF_OFS))
536 {
537 low = ((low << 2) | (0x8000 & low)) & 0xFFFC;
538 high = ((high << 2) | (0x8000 & high)) & 0xFFFC;
539 }
540
541 if (window == ADC_COMP_WINDOW0)
542 {
543 ADC14->HI0 = (high);
544 ADC14->LO0 = (low);
545
546 } else if (window == ADC_COMP_WINDOW1)
547 {
548 ADC14->HI1 = (high);
549 ADC14->LO1 = (low);
550
551 } else
552 {
553 ASSERT(false);
554 return false;
555 }
556
557 return true;
558 }
559
ADC14_setResultFormat(uint32_t resultFormat)560 bool ADC14_setResultFormat(uint32_t resultFormat)
561 {
562 if (ADCIsConversionRunning())
563 return false;
564
565 if (resultFormat == ADC_UNSIGNED_BINARY)
566 {
567 BITBAND_PERI(ADC14->CTL1, ADC14_CTL1_DF_OFS) = 0;
568 } else if (resultFormat == ADC_SIGNED_BINARY)
569 {
570 BITBAND_PERI(ADC14->CTL1, ADC14_CTL1_DF_OFS) = 1;
571 } else
572 {
573 ASSERT(false);
574 }
575
576 return true;
577 }
578
ADC14_getResult(uint32_t memorySelect)579 uint_fast16_t ADC14_getResult(uint32_t memorySelect)
580 {
581 return *((uint16_t*) (_ctlRegs[_getIndexForMemRegister(memorySelect)]
582 + 0x20));
583 }
584
ADC14_getMultiSequenceResult(uint16_t * res)585 void ADC14_getMultiSequenceResult(uint16_t* res)
586 {
587 uint32_t *startAddr, *curAddr;
588 uint32_t ii;
589
590 startAddr = (uint32_t*) _ctlRegs[(ADC14->CTL1 & ADC14_CTL1_CSTARTADD_MASK)
591 >> 16];
592
593 curAddr = startAddr;
594
595 for (ii = 0; ii < 32; ii++)
596 {
597 res[ii] = *((uint16_t*)(curAddr + 32));
598
599 if (BITBAND_PERI((*curAddr), ADC14_MCTLN_EOS_OFS))
600 break;
601
602 if (curAddr == _ctlRegs[31])
603 curAddr = (uint32_t*) _ctlRegs[0];
604 else
605 curAddr++;
606 }
607
608 }
609
ADC14_getResultArray(uint32_t memoryStart,uint32_t memoryEnd,uint16_t * res)610 void ADC14_getResultArray(uint32_t memoryStart, uint32_t memoryEnd,
611 uint16_t* res)
612 {
613 uint32_t ii = 0;
614 uint32_t *firstPoint, *secondPoint;
615
616 bool foundEnd = false;
617
618 ASSERT(
619 _getIndexForMemRegister(memoryStart) != ADC_INVALID_MEM
620 && _getIndexForMemRegister(memoryEnd) != ADC_INVALID_MEM);
621
622 firstPoint = (uint32_t*) _ctlRegs[_getIndexForMemRegister(memoryStart)];
623 secondPoint = (uint32_t*) _ctlRegs[_getIndexForMemRegister(memoryEnd)];
624
625 while (!foundEnd)
626 {
627 if (firstPoint == secondPoint)
628 {
629 foundEnd = true;
630 }
631
632 res[ii] = *(((uint16_t*) firstPoint) + 0x40);
633
634 if (firstPoint == _ctlRegs[31])
635 firstPoint = (uint32_t*) _ctlRegs[0];
636 else
637 firstPoint += 0x04;
638 }
639 }
640
ADC14_enableReferenceBurst(void)641 bool ADC14_enableReferenceBurst(void)
642 {
643 if (ADCIsConversionRunning())
644 return false;
645
646 BITBAND_PERI(ADC14->CTL1, ADC14_CTL1_REFBURST_OFS) = 1;
647
648 return true;
649 }
650
ADC14_disableReferenceBurst(void)651 bool ADC14_disableReferenceBurst(void)
652 {
653 if (ADCIsConversionRunning())
654 return false;
655
656 BITBAND_PERI(ADC14->CTL1, ADC14_CTL1_REFBURST_OFS) = 0;
657
658 return true;
659 }
660
ADC14_setPowerMode(uint32_t adcPowerMode)661 bool ADC14_setPowerMode(uint32_t adcPowerMode)
662 {
663 if (ADCIsConversionRunning())
664 return false;
665
666 switch (adcPowerMode)
667 {
668 case ADC_UNRESTRICTED_POWER_MODE:
669 ADC14->CTL1 = (ADC14->CTL1 & ~(ADC14_CTL1_PWRMD_MASK))
670 | (ADC14_CTL1_PWRMD_0);
671 break;
672 case ADC_ULTRA_LOW_POWER_MODE:
673 ADC14->CTL1 = (ADC14->CTL1 & ~(ADC14_CTL1_PWRMD_MASK))
674 | (ADC14_CTL1_PWRMD_2);
675 break;
676 default:
677 ASSERT(false);
678 return false;
679 }
680
681 return true;
682 }
683
ADC14_enableInterrupt(uint_fast64_t mask)684 void ADC14_enableInterrupt(uint_fast64_t mask)
685 {
686 uint32_t stat = mask & 0xFFFFFFFF;
687
688 ADC14->IER0 |= stat;
689 stat = (mask >> 32);
690 ADC14->IER1 |= (stat);
691 }
692
ADC14_disableInterrupt(uint_fast64_t mask)693 void ADC14_disableInterrupt(uint_fast64_t mask)
694 {
695 uint32_t stat = mask & 0xFFFFFFFF;
696
697 ADC14->IER0 &= ~stat;
698 stat = (mask >> 32);
699 ADC14->IER1 &= ~(stat);
700 }
701
ADC14_getInterruptStatus(void)702 uint_fast64_t ADC14_getInterruptStatus(void)
703 {
704 uint_fast64_t status = ADC14->IFGR1;
705 return ((status << 32) | ADC14->IFGR0);
706 }
707
ADC14_getEnabledInterruptStatus(void)708 uint_fast64_t ADC14_getEnabledInterruptStatus(void)
709 {
710 uint_fast64_t stat = ADC14->IER1;
711
712 return ADC14_getInterruptStatus() & ((stat << 32) | ADC14->IER0);
713
714 }
715
ADC14_clearInterruptFlag(uint_fast64_t mask)716 void ADC14_clearInterruptFlag(uint_fast64_t mask)
717 {
718 uint32_t stat = mask & 0xFFFFFFFF;
719
720 ADC14->CLRIFGR0 |= stat;
721 stat = (mask >> 32);
722 ADC14->CLRIFGR1 |= (stat);
723 }
724
ADC14_registerInterrupt(void (* intHandler)(void))725 void ADC14_registerInterrupt(void (*intHandler)(void))
726 {
727 //
728 // Register the interrupt handler, returning an error if an error occurs.
729 //
730 Interrupt_registerInterrupt(INT_ADC14, intHandler);
731
732 //
733 // Enable the ADC interrupt.
734 //
735 Interrupt_enableInterrupt(INT_ADC14);
736 }
737
ADC14_unregisterInterrupt(void)738 void ADC14_unregisterInterrupt(void)
739 {
740 //
741 // Disable the interrupt.
742 //
743 Interrupt_disableInterrupt(INT_ADC14);
744
745 //
746 // Unregister the interrupt handler.
747 //
748 Interrupt_unregisterInterrupt(INT_ADC14);
749 }
750
751