]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/sys/_tms570_hydctr/ti_drv_adc.c
tms570_hydctr: Reconfigure ADC to 24 channels
[pes-rpp/rpp-lib.git] / rpp / src / sys / _tms570_hydctr / ti_drv_adc.c
1 /** @file adc.c
2 *   @brief ADC Driver Source File
3 *   @date 04.January.2012
4 *   @version 03.01.00
5 *
6 *   This file contains:
7 *   - API Funcions
8 *   - Interrupt Handlers
9 *   .
10 *   which are relevant for the ADC driver.
11 */
12
13 /* Include Files */
14 #include "sys/sys.h"
15
16
17 /** @fn void adcInit(void)
18 *   @brief Initializes ADC Driver
19 *
20 *   This function initializes the ADC driver.
21 *
22 */
23 void adcInit(void)
24 {
25     /** @b Initialize @b ADC1: */
26
27     /** - Reset ADC module */
28     adcREG1->RSTCR = 1U;
29     adcREG1->RSTCR = 0U;
30
31     /** - Enable 12-BIT ADC  */
32     adcREG1->OPMODECR |= 0x80000000U;
33
34     /** - Setup prescaler */
35     adcREG1->CLOCKCR = 100/(1*1000000000/RPP_VCLK1_FREQ);       /* 100 = cycle time in ns */
36
37     /** - Setup memory boundaries */
38     adcREG1->BNDCR  =(8U << 16U)|(8U + 12U);
39     adcREG1->BNDEND = 2U;
40
41     /** - Setup event group conversion mode
42     *     - Setup data format
43     *     - Enable/Disable channel id in conversion result
44     *     - Enable/Disable continuous conversion
45     */
46     adcREG1->GxMODECR[0U] = ADC_12_BIT
47                           | 0x00000000U
48                           | 0x00000000U;
49
50     /** - Setup event group hardware trigger
51      *     - Setup hardware trigger edge
52      *     - Setup hardware trigger source
53      */
54     adcREG1->G0SRC = 0x00000000U
55                    | ADC1_EVENT;
56
57     /** - Setup event group sample window */
58     adcREG1->G0SAMP = 0U;
59
60     /** - Setup event group sample discharge
61     *     - Setup discharge prescaler
62     *     - Enable/Disable discharge
63     */
64     adcREG1->G0SAMPDISEN = 0U << 8U
65                          | 0x00000000U;
66
67     /** - Setup group 1 conversion mode
68     *     - Setup data format
69     *     - Enable/Disable channel id in conversion result
70     *     - Enable/Disable continuous conversion
71     */
72     adcREG1->GxMODECR[1U] = ADC_12_BIT
73                           | 0x00000020U
74                           | 0x00000000U
75                           | 0x00000000U;
76
77     /** - Setup group 1 hardware trigger
78      *     - Setup hardware trigger edge
79      *     - Setup hardware trigger source
80      */
81     adcREG1->G1SRC = 0x00000000U
82                    | ADC1_EVENT;
83
84     /** - Setup group 1 sample window */
85     adcREG1->G1SAMP = 0U;
86
87     /** - Setup group 1 sample discharge
88     *     - Setup discharge prescaler
89     *     - Enable/Disable discharge
90     */
91     adcREG1->G1SAMPDISEN = 0U << 8U
92                          | 0x00000000U;
93
94     /** - Setup group 2 conversion mode
95      *     - Setup data format
96      *     - Enable/Disable channel id in conversion result
97      *     - Enable/Disable continuous conversion
98      */
99     adcREG1->GxMODECR[2U] = ADC_12_BIT
100                           | 0x00000020U
101                           | 0x00000000U
102                           | 0x00000000U;
103
104     /** - Setup group 2 hardware trigger
105     *     - Setup hardware trigger edge
106     *     - Setup hardware trigger source
107     */
108     adcREG1->G2SRC = 0x00000000U
109                    | ADC1_EVENT;
110
111     /** - Setup group 2 sample window */
112     adcREG1->G2SAMP = 0U;
113
114     /** - Setup group 2 sample discharge
115     *     - Setup discharge prescaler
116     *     - Enable/Disable discharge
117     */
118     adcREG1->G2SAMPDISEN = 0U << 8U
119                          | 0x00000000U;
120
121     /** - Enable ADC module */
122     adcREG1->OPMODECR |= 0x80140001U;
123
124     /** - Wait for buffer inialisation complete */
125     while ((adcREG1->BUFINIT) != 0) { /* Wait */ }
126
127     /** - Setup parity */
128     adcREG1->PARCR = 0x00000005U;
129
130
131
132     /** @b Initialize @b ADC2: */
133
134     /** - Reset ADC module */
135     adcREG2->RSTCR = 1U;
136     adcREG2->RSTCR = 0U;
137
138     /** - Enable 12-BIT ADC  */
139     adcREG2->OPMODECR |= 0x80000000U;
140
141     /** - Setup prescaler */
142     adcREG2->CLOCKCR = 7U;
143
144     /** - Setup memory boundaries */
145     adcREG2->BNDCR  =(8U << 16U)|(8U + 8U);
146     adcREG2->BNDEND = 2U;
147
148     /** - Setup event group conversion mode
149     *     - Setup data format
150     *     - Enable/Disable channel id in conversion result
151     *     - Enable/Disable continuous conversion
152     */
153     adcREG2->GxMODECR[0U] = ADC_12_BIT
154                           | 0x00000000U
155                           | 0x00000000U;
156
157     /** - Setup event group hardware trigger
158     *     - Setup hardware trigger edge
159     *     - Setup hardware trigger source
160     */
161     adcREG2->G0SRC = 0x00000000U
162                    | ADC2_EVENT;
163
164     /** - Setup event group sample window */
165     adcREG2->G0SAMP = 0U;
166
167     /** - Setup event group sample discharge
168     *     - Setup discharge prescaler
169     *     - Enable/Disable discharge
170     */
171     adcREG2->G0SAMPDISEN = 0U << 8U
172                          | 0x00000000U;
173
174     /** - Setup group 1 conversion mode
175     *     - Setup data format
176     *     - Enable/Disable channel id in conversion result
177     *     - Enable/Disable continuous conversion
178     */
179     adcREG2->GxMODECR[1U] = ADC_12_BIT
180                           | 0x00000020U
181                           | 0x00000000U
182                           | 0x00000000U;
183
184     /** - Setup group 1 hardware trigger
185     *     - Setup hardware trigger edge
186     *     - Setup hardware trigger source
187     */
188     adcREG2->G1SRC = 0x00000000U
189                    | ADC2_EVENT;
190
191
192     /** - Setup group 1 sample window */
193     adcREG2->G1SAMP = 0U;
194
195     /** - Setup group 1 sample discharge
196     *     - Setup discharge prescaler
197     *     - Enable/Disable discharge
198     */
199     adcREG2->G1SAMPDISEN = 0U << 8U
200                          | 0x00000000U;
201
202     /** - Setup group 2 conversion mode
203     *     - Setup data format
204     *     - Enable/Disable channel id in conversion result
205     *     - Enable/Disable continuous conversion
206     */
207     adcREG2->GxMODECR[2U] = ADC_12_BIT
208                           | 0x00000000U
209                           | 0x00000000U
210                           | 0x00000000U;
211
212     /** - Setup group 2 hardware trigger
213     *     - Setup hardware trigger edge
214     *     - Setup hardware trigger source
215     */
216     adcREG2->G2SRC = 0x00000000U
217                    | ADC2_EVENT;
218
219     /** - Setup group 2 sample window */
220     adcREG2->G2SAMP = 0U;
221
222     /** - Setup group 2 sample discharge
223     *     - Setup discharge prescaler
224     *     - Enable/Disable discharge
225     */
226     adcREG2->G2SAMPDISEN = 0U << 8U
227                          | 0x00000000U;
228
229     /** - Enable ADC module */
230     adcREG2->OPMODECR |= 0x80140001U;
231
232     /** - Wait for buffer inialisation complete */
233     while ((adcREG2->BUFINIT) != 0) { /* Wait */ }
234
235     /** - Setup parity */
236     adcREG2->PARCR = 0x00000005U;
237
238     /**   @note This function has to be called before the driver can be used.\n
239     *           This function has to be executed in priviledged mode.\n
240     */
241 }
242
243
244 /** - s_adcSelect is used as constant table for channel selection */
245 static const uint32_t s_adcSelect[2U][3U] =
246 {
247     // TODO configure another group for AD2IN[0,14,15]
248
249     // ADC1, Group0
250   //_BV( 0) |
251   //_BV( 1) |
252   //_BV( 2) |
253   //_BV( 3) |
254   //_BV( 4) |
255   //_BV( 5) |
256   //_BV( 6) |
257   //_BV( 7) |
258   //_BV( 8) |
259   //_BV( 9) |
260   //_BV(10) |
261   //_BV(11) |
262   //_BV(12) |
263   //_BV(13) |
264   //_BV(14) |
265   //_BV(15) |
266          0x0,
267
268
269     // ADC1, Group1
270     // AD1IN[0-23] used on the HydCtr board
271     _BV( 0) |
272     _BV( 1) |
273     _BV( 2) |
274     _BV( 3) |
275     _BV( 4) |
276     _BV( 5) |
277     _BV( 6) |
278     _BV( 7) |
279     _BV( 8) |
280     _BV( 9) |
281     _BV(10) |
282     _BV(11) |
283     _BV(12) |
284     _BV(13) |
285     _BV(14) |
286     _BV(15) |
287     _BV(16) |
288     _BV(17) |
289     _BV(18) |
290     _BV(19) |
291     _BV(20) |
292     _BV(21) |
293     _BV(22) |
294     _BV(23) |
295          0x0,
296
297     // ADC1, Group2
298   //_BV( 0) |
299   //_BV( 1) |
300   //_BV( 2) |
301   //_BV( 3) |
302   //_BV( 4) |
303   //_BV( 5) |
304   //_BV( 6) |
305   //_BV( 7) |
306   //_BV( 8) |
307   //_BV( 9) |
308   //_BV(10) |
309   //_BV(11) |
310   //_BV(12) |
311   //_BV(13) |
312   //_BV(14) |
313   //_BV(15) |
314          0x0,
315
316     // ADC2, Group0
317   //_BV( 0) |
318   //_BV( 1) |
319   //_BV( 2) |
320   //_BV( 3) |
321   //_BV( 4) |
322   //_BV( 5) |
323   //_BV( 6) |
324   //_BV( 7) |
325   //_BV( 8) |
326   //_BV( 9) |
327   //_BV(10) |
328   //_BV(11) |
329   //_BV(12) |
330   //_BV(13) |
331   //_BV(14) |
332   //_BV(15) |
333          0x0,
334
335     // ADC2, Group1
336     // AD2IN[0-7] used on HDK but the rpp layer is not ready for reading ADC2
337   //_BV( 0) |
338   //_BV( 1) |
339   //_BV( 2) |
340   //_BV( 3) |
341   //_BV( 4) |
342   //_BV( 5) |
343   //_BV( 6) |
344   //_BV( 7) |
345   //_BV( 8) |
346   //_BV( 9) |
347   //_BV(10) |
348   //_BV(11) |
349   //_BV(12) |
350   //_BV(13) |
351   //_BV(14) |
352   //_BV(15) |
353          0x0,
354
355     // ADC2, Group2
356   //_BV( 0) |
357   //_BV( 1) |
358   //_BV( 2) |
359   //_BV( 3) |
360   //_BV( 4) |
361   //_BV( 5) |
362   //_BV( 6) |
363   //_BV( 7) |
364   //_BV( 8) |
365   //_BV( 9) |
366   //_BV(10) |
367   //_BV(11) |
368   //_BV(12) |
369   //_BV(13) |
370   //_BV(14) |
371   //_BV(15) |
372          0x0
373 };
374
375                                       // ADC, Group
376 static const uint32_t s_adcFiFoSize[2U][3U] =
377 {
378     {0U, 24U, 0U},
379     {0U,  0U, 0U}
380 };
381
382 /** @fn void adcStartConversion(adcBASE_t *adc, uint32_t group)
383 *   @brief Starts an ADC conversion
384 *   @param[in] adc Pointer to ADC module:
385 *              - adcREG1: ADC1 module pointer
386 *              - adcREG2: ADC2 module pointer
387 *   @param[in] group Hardware group of ADC module:
388 *              - adcGROUP0: ADC event group
389 *              - adcGROUP1: ADC group 1
390 *              - adcGROUP2: ADC group 2
391 *
392 *   This function starts a conversion of the ADC hardware group.
393 *
394 *   @note The function adcInit has to be called before this function can be
395 *          used.
396 */
397 void adcStartConversion(adcBASE_t *adc, uint32_t group)
398 {
399     uint32_t index = adc == adcREG1 ? 0U : 1U;
400
401     // Setup FiFo size
402     //  - For ADC1 Group1 see tms570_trm.pdf p. 796 (788)
403     adc->GxINTCR[group] = s_adcFiFoSize[index][group];
404
405     // Start Conversion
406     //  - For ADC1 Group1 see tms570_trm.pdf p. 817 (809)
407     adc->GxSEL[group] = s_adcSelect[index][group];
408 }
409
410
411 /** @fn void adcStopConversion(adcBASE_t *adc, uint32_t group)
412 *   @brief Stops an ADC conversion
413 *   @param[in] adc Pointer to ADC module:
414 *              - adcREG1: ADC1 module pointer
415 *              - adcREG2: ADC2 module pointer
416 *   @param[in] group Hardware group of ADC module:
417 *              - adcGROUP0: ADC event group
418 *              - adcGROUP1: ADC group 1
419 *              - adcGROUP2: ADC group 2
420 *
421 *   This function stops a convesion of the ADC hardware group.
422 *
423 *   @note The function adcInit has to be called before this function can be
424 *          used.
425 */
426 void adcStopConversion(adcBASE_t *adc, uint32_t group)
427 {
428     /** - Stop Conversion */
429     adc->GxSEL[group] = 0U;
430 }
431
432
433 /**
434  * Resets FiFo read and write pointer.
435  *
436  * @param[in] adc       Pointer to ADC module:
437  *                          - adcREG1: ADC1 module pointer
438  *                          - adcREG2: ADC2 module pointer
439  * @param[in] group     Hardware group of ADC module:
440  *                          - adcGROUP0: ADC event group
441  *                          - adcGROUP1: ADC group 1
442  *                          - adcGROUP2: ADC group 2
443  *
444  * @note The function adcInit has to be called before this function can be
445  *        used.\n
446  *        The conversion should be stopped before calling this function.
447  *
448  */
449 void adcResetFiFo(adcBASE_t *adc, uint32_t group)
450 {
451     /** - Reset FiFo */
452     adc->GxFIFORESETCR[group] = 1U;
453 }
454
455
456
457 /**
458  * Gets converted a ADC values.
459  *
460  * @param[in] adc       Pointer to ADC module:
461  *                          - adcREG1: ADC1 module pointer
462  *                          - adcREG2: ADC2 module pointer
463  * @param[in] group     Hardware group of ADC module:
464  *                          - adcGROUP0: ADC event group
465  *                          - adcGROUP1: ADC group 1
466  *                          - adcGROUP2: ADC group 2
467  * @param[out] data Pointer to store ADC converted data.
468  *
469  * @return The function will return the number of converted values copied
470  *          into data buffer.
471  *
472  * @note The function adcInit has to be called before this function can be
473  *        used.\n
474  *        The user is responsible to initialize the message box.
475  *
476  */
477 uint32_t adcGetData(adcBASE_t *adc, uint32_t group, adcData_t *data)
478 {
479     uint32_t  i;
480     uint32_t  buf;
481     uint32_t  mode;
482     uint32_t  index = adc == adcREG1 ? 0U : 1U;
483     uint32_t  count;
484     if(adc->GxINTCR[group] >= 256U) {
485         count = s_adcFiFoSize[index][group];
486     } else {
487         count = s_adcFiFoSize[index][group] - (uint32_t)(adc->GxINTCR[group] & 0xFF);
488     }
489     adcData_t *ptr = data;
490
491     mode = ((adc->GxMODECR[group]) & 0x00000300U);
492
493     if(mode == ADC_12_BIT) {
494
495         // Get conversion data and channel/pin id
496         for (i = 0; i < count; i++) {
497             buf        = adc->GxBUF[group].BUF0;
498             ptr->value = (uint16_t)(buf & 0xFFFU);
499             ptr->id    = (uint32_t)((buf >> 16U) & 0x1FU);
500             ptr++;
501         }
502
503     } else {
504
505         // Get conversion data and channel/pin id
506         for (i = 0; i < count; i++) {
507             buf        = adc->GxBUF[group].BUF0;
508             ptr->value = (uint16_t)(buf & 0x3FFU);
509             ptr->id    = (uint32_t)((buf >> 10U) & 0x1FU);
510             ptr++;
511         }
512       }
513
514     adc->GxINTFLG[group] = 9U;
515
516     return count;
517 }
518
519
520 /**
521  * Checks if FiFo buffer is full.
522  *
523  * @param[in] adc       Pointer to ADC module:
524  *                          - adcREG1: ADC1 module pointer
525  *                          - adcREG2: ADC2 module pointer
526  * @param[in] group     Hardware group of ADC module:
527  *                          - adcGROUP0: ADC event group
528  *                          - adcGROUP1: ADC group 1
529  *                          - adcGROUP2: ADC group 2
530  *
531  * @return The function will return:
532  *                         - 0: When FiFo buffer is not full
533  *                         - 1: When FiFo buffer is full
534  *                         - 3: When FiFo buffer overflow occured
535  *
536  *
537  * @note The function adcInit has to be called before this function can be
538  *        used.
539  *
540  */
541 uint32_t adcIsFifoFull(adcBASE_t *adc, uint32_t group)
542 {
543     // Read FiFo flag
544     uint32_t flags = adc->GxINTFLG[group] & 3U;
545     return flags;
546 }
547
548
549 /**
550  * Checks if Conversion is complete.
551  *
552  * @param[in] adc       Pointer to ADC module:
553  *                          - adcREG1: ADC1 module pointer
554  *                          - adcREG2: ADC2 module pointer
555  * @param[in] group     Hardware group of ADC module:
556  *                          - adcGROUP0: ADC event group
557  *                          - adcGROUP1: ADC group 1
558  *                          - adcGROUP2: ADC group 2
559  * @return The function will return:
560  *                         - 0: When is not finished
561  *                         - 8: When conversion is complete
562  *
563  * @note The function adcInit has to be called before this function can be
564  *        used.
565 */
566 uint32_t adcIsConversionComplete(adcBASE_t *adc, uint32_t group)
567 {
568     uint32_t flags;
569
570     /** - Read conversion flags */
571     flags = adc->GxINTFLG[group] & 8U;
572
573     return flags;
574 }
575
576
577 /**
578  * Computes offset error using Calibration mode.
579  *
580  * @param[in] adc Pointer to ADC module:
581  *              - adcREG1: ADC1 module pointer
582  *              - adcREG2: ADC2 module pointer
583  *              - adcREG3: ADC3 module pointer
584  *
585  * @note The function adcInit has to be called before this function can be
586  *        used.
587  */
588 void adcCalibration(adcBASE_t *adc)
589 {
590     uint32_t conv_val[5] = {0, 0, 0, 0, 0}, loop_index = 0;
591     uint32_t offset_error = 0;
592     uint32_t backup_mode;
593
594     /** - Backup Mode before Calibration  */
595     backup_mode = adc->OPMODECR;
596
597     /** - Enable 12-BIT ADC  */
598     adcREG1->OPMODECR |= 0x80000000U;
599
600     /* Disable all channels for conversion */
601     adc->GxSEL[0]=0x00;
602     adc->GxSEL[1]=0x00;
603     adc->GxSEL[2]=0x00;
604
605     for(loop_index = 0; loop_index < 4; loop_index++) {
606
607         /* Disable Self Test and Calibration mode */
608         adc->CALCR = 0x0;
609
610         switch(loop_index) {
611
612             case 0 :    /* Test 1 : Bride En = 0 , HiLo =0 */
613                         adc->CALCR=0x0;
614                         break;
615
616             case 1 :    /* Test 1 : Bride En = 0 , HiLo =1 */
617                         adc->CALCR=0x0100;
618                         break;
619
620             case 2 :    /* Test 1 : Bride En = 1 , HiLo =0 */
621                         adc->CALCR=0x0200;
622                         break;
623
624             case 3 :    /* Test 1 : Bride En = 1 , HiLo =1 */
625                         adc->CALCR=0x0300;
626                         break;
627         }
628
629         /* Enable Calibration mode */
630         adc->CALCR |= 0x1;
631
632         /* Start calibration conversion */
633         adc->CALCR |= 0x00010000;
634
635         /* Wait for calibration conversion to complete */
636         while((adc->CALCR & 0x00010000) == 0x00010000);
637
638         /* Read converted value */
639         conv_val[loop_index] = adc->CALR;
640     }
641
642     /* Disable Self Test and Calibration mode */
643     adc->CALCR = 0x0;
644
645     /* Compute the Offset error correction value */
646     conv_val[4] = conv_val[0] + conv_val[1] + conv_val[2] + conv_val[3];
647
648     conv_val[4] = (conv_val[4] / 4);
649
650     offset_error=conv_val[4]-0x7FF;
651
652     /* Write the offset error to the Calibration register */
653     /* Load 2;s complement of the computed value to ADCALR register */
654     offset_error = ~offset_error;
655     offset_error = offset_error & 0xFFF;
656     offset_error = offset_error+1;
657
658     adc->CALR = offset_error;
659
660     // - Restore Mode after Calibration
661     adc->OPMODECR = backup_mode;
662 }
663
664
665 /** @fn void adcMidPointCalibration(adcBASE_t *adc)
666 *   @brief Computes offset error using Mid Point Calibration mode
667 *   @param[in] adc Pointer to ADC module:
668 *              - adcREG1: ADC1 module pointer
669 *              - adcREG2: ADC2 module pointer
670 *              - adcREG3: ADC3 module pointer
671 *   This function computes offset error using Mid Point Calibration mode
672 *
673 *   @note The function adcInit has to be called before this function can be
674 *          used.
675 */
676 uint32_t adcMidPointCalibration(adcBASE_t *adc)
677 {
678     uint32_t conv_val[3] = {0, 0, 0}, loop_index = 0;
679     uint32_t offset_error = 0;
680     uint32_t backup_mode;
681
682     /** - Backup Mode before Calibration  */
683     backup_mode = adc->OPMODECR;
684
685     /** - Enable 12-BIT ADC  */
686     adcREG1->OPMODECR |= 0x80000000U;
687
688     /* Disable all channels for conversion */
689     adc->GxSEL[0]=0x00;
690     adc->GxSEL[1]=0x00;
691     adc->GxSEL[2]=0x00;
692
693     for(loop_index=0;loop_index<2;loop_index++) {
694
695         /* Disable Self Test and Calibration mode */
696         adc->CALCR=0x0;
697
698         switch(loop_index) {
699
700             case 0 :    /* Test 1 : Bride En = 0 , HiLo =0 */
701                         adc->CALCR=0x0;
702                         break;
703
704             case 1 :    /* Test 1 : Bride En = 0 , HiLo =1 */
705                         adc->CALCR=0x0100;
706                         break;
707
708         }
709
710         /* Enable Calibration mode */
711         adc->CALCR |= 0x1;
712
713         /* Start calibration conversion */
714         adc->CALCR |= 0x00010000;
715
716         /* Wait for calibration conversion to complete */
717         while((adc->CALCR & 0x00010000) == 0x00010000);
718
719         /* Read converted value */
720         conv_val[loop_index]= adc->CALR;
721     }
722
723     /* Disable Self Test and Calibration mode */
724     adc->CALCR = 0x0;
725
726     /* Compute the Offset error correction value */
727     conv_val[2] = (conv_val[0]) + (conv_val[1]);
728
729     conv_val[2] = (conv_val[2] / 2);
730
731     offset_error = conv_val[2] - 0x7FF;
732
733     /* Write the offset error to the Calibration register           */
734     /* Load 2's complement of the computed value to ADCALR register */
735     offset_error = ~offset_error;
736     offset_error = offset_error & 0xFFF;
737     offset_error = offset_error + 1;
738
739     adc->CALR = offset_error;
740
741     // - Restore Mode after Calibration
742     adc->OPMODECR = backup_mode;
743
744     return offset_error;
745 }
746
747
748 /** @fn void adcEnableNotification(adcBASE_t *adc, uint32_t group)
749  *  @brief Enable notification
750  *  @param[in] adc Pointer to ADC module:
751  *             - adcREG1: ADC1 module pointer
752  *             - adcREG2: ADC2 module pointer
753  *             - adcREG3: ADC3 module pointer
754  *  @param[in] group Hardware group of ADC module:
755  *             - adcGROUP0: ADC event group
756  *             - adcGROUP1: ADC group 1
757  *             - adcGROUP2: ADC group 2
758  *
759  *  This function will enable the notification of a conversion.
760  *  In single conversion mode for conversion complete and
761  *  in continuous conversion mode when the FiFo buffer is full.
762  *
763  *  @note The function adcInit has to be called before this function can be
764  *         used.\n
765  *         This function should be called before the conversion is started.
766  */
767 void adcEnableNotification(adcBASE_t *adc, uint32_t group)
768 {
769     uint32_t notif = adc->GxMODECR[group] & 2U ? 1U : 8U;
770
771     adc->GxINTENA[group] = notif;
772 }
773
774
775 /** @fn void adcDisableNotification(adcBASE_t *adc, uint32_t group)
776  *  @brief Disable notification
777  *  @param[in] adc Pointer to ADC module:
778  *             - adcREG1: ADC1 module pointer
779  *             - adcREG2: ADC2 module pointer
780  *             - adcREG3: ADC3 module pointer
781  *  @param[in] group Hardware group of ADC module:
782  *             - adcGROUP0: ADC event group
783  *             - adcGROUP1: ADC group 1
784  *             - adcGROUP2: ADC group 2
785  *
786  *  This function will disable the notification of a conversion.
787  *
788  *  @note The function adcInit has to be called before this function can be
789  *         used.
790  */
791 void adcDisableNotification(adcBASE_t *adc, uint32_t group)
792 {
793     adc->GxINTENA[group] = 0U;
794 }
795
796
797 /** @fn void adc1Group0Interrupt(void)
798  *  @brief ADC1 Event Group Interrupt Handler
799  */
800 #pragma INTERRUPT(adc1Group0Interrupt, IRQ)
801 void adc1Group0Interrupt(void)
802 {
803     adcNotification(adcREG1, adcGROUP0);
804     adcREG1->GxINTFLG[0U] = _BV(3) | _BV(0);
805 }
806
807
808 /** @fn void adc1Group1Interrupt(void)
809  *  @brief ADC1 Group 1 Interrupt Handler
810  */
811 #pragma INTERRUPT(adc1Group1Interrupt, IRQ)
812 void adc1Group1Interrupt(void)
813 {
814     adcNotification(adcREG1, adcGROUP1);
815     // For ADC1 Group1 see tms570_trm.pdf p. 791 (783)
816     adcREG1->GxINTFLG[1U] = _BV(3) | _BV(0);
817 }
818
819
820 /** @fn void adc1Group2Interrupt(void)
821  *  @brief ADC1 Group 2 Interrupt Handler
822  */
823 #pragma INTERRUPT(adc1Group2Interrupt, IRQ)
824 void adc1Group2Interrupt(void)
825 {
826     adcNotification(adcREG1, adcGROUP2);
827     adcREG1->GxINTFLG[2U] = _BV(3) | _BV(0);;
828 }
829
830
831 /** @fn void adc2Group0Interrupt(void)
832  *  @brief ADC2 Event Group Interrupt Handler
833  */
834 #pragma INTERRUPT(adc2Group0Interrupt, IRQ)
835 void adc2Group0Interrupt(void)
836 {
837     adcNotification(adcREG2, adcGROUP0);
838     adcREG2->GxINTFLG[0U] = _BV(3) | _BV(0);
839 }
840
841
842 /** @fn void adc2Group1Interrupt(void)
843  *  @brief ADC2 Group 1 Interrupt Handler
844  */
845 #pragma INTERRUPT(adc2Group1Interrupt, IRQ)
846 void adc2Group1Interrupt(void)
847 {
848     adcNotification(adcREG2, adcGROUP1);
849     adcREG2->GxINTFLG[1U] = _BV(3) | _BV(0);
850 }
851
852
853 /** @fn void adc2Group2Interrupt(void)
854  *  @brief ADC2 Group 2 Interrupt Handler
855  */
856 #pragma INTERRUPT(adc2Group2Interrupt, IRQ)
857 void adc2Group2Interrupt(void)
858 {
859     adcNotification(adcREG2, adcGROUP2);
860     adcREG2->GxINTFLG[2U] = _BV(3) | _BV(0);
861 }
862