]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blob - rpp/src/sys/_tms570_hydctr/ti_drv_adc.c
Trigger context switch after ADC interrupts
[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 + 8U);
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-15] used on the HDK
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          0x0,
288
289     // ADC1, Group2
290   //_BV( 0) |
291   //_BV( 1) |
292   //_BV( 2) |
293   //_BV( 3) |
294   //_BV( 4) |
295   //_BV( 5) |
296   //_BV( 6) |
297   //_BV( 7) |
298   //_BV( 8) |
299   //_BV( 9) |
300   //_BV(10) |
301   //_BV(11) |
302   //_BV(12) |
303   //_BV(13) |
304   //_BV(14) |
305   //_BV(15) |
306          0x0,
307
308     // ADC2, Group0
309   //_BV( 0) |
310   //_BV( 1) |
311   //_BV( 2) |
312   //_BV( 3) |
313   //_BV( 4) |
314   //_BV( 5) |
315   //_BV( 6) |
316   //_BV( 7) |
317   //_BV( 8) |
318   //_BV( 9) |
319   //_BV(10) |
320   //_BV(11) |
321   //_BV(12) |
322   //_BV(13) |
323   //_BV(14) |
324   //_BV(15) |
325          0x0,
326
327     // ADC2, Group1
328     // AD2IN[0-7] used on HDK but the rpp layer is not ready for reading ADC2
329   //_BV( 0) |
330   //_BV( 1) |
331   //_BV( 2) |
332   //_BV( 3) |
333   //_BV( 4) |
334   //_BV( 5) |
335   //_BV( 6) |
336   //_BV( 7) |
337   //_BV( 8) |
338   //_BV( 9) |
339   //_BV(10) |
340   //_BV(11) |
341   //_BV(12) |
342   //_BV(13) |
343   //_BV(14) |
344   //_BV(15) |
345          0x0,
346
347     // ADC2, Group2
348   //_BV( 0) |
349   //_BV( 1) |
350   //_BV( 2) |
351   //_BV( 3) |
352   //_BV( 4) |
353   //_BV( 5) |
354   //_BV( 6) |
355   //_BV( 7) |
356   //_BV( 8) |
357   //_BV( 9) |
358   //_BV(10) |
359   //_BV(11) |
360   //_BV(12) |
361   //_BV(13) |
362   //_BV(14) |
363   //_BV(15) |
364          0x0
365 };
366
367                                       // ADC, Group
368 static const uint32_t s_adcFiFoSize[2U][3U] =
369 {
370     {0U, 16U, 0U},
371     {0U,  0U, 0U}
372 };
373
374 /** @fn void adcStartConversion(adcBASE_t *adc, uint32_t group)
375 *   @brief Starts an ADC conversion
376 *   @param[in] adc Pointer to ADC module:
377 *              - adcREG1: ADC1 module pointer
378 *              - adcREG2: ADC2 module pointer
379 *   @param[in] group Hardware group of ADC module:
380 *              - adcGROUP0: ADC event group
381 *              - adcGROUP1: ADC group 1
382 *              - adcGROUP2: ADC group 2
383 *
384 *   This function starts a conversion of the ADC hardware group.
385 *
386 *   @note The function adcInit has to be called before this function can be
387 *          used.
388 */
389 void adcStartConversion(adcBASE_t *adc, uint32_t group)
390 {
391     uint32_t index = adc == adcREG1 ? 0U : 1U;
392
393     // Setup FiFo size
394     //  - For ADC1 Group1 see tms570_trm.pdf p. 796 (788)
395     adc->GxINTCR[group] = s_adcFiFoSize[index][group];
396
397     // Start Conversion
398     //  - For ADC1 Group1 see tms570_trm.pdf p. 817 (809)
399     adc->GxSEL[group] = s_adcSelect[index][group];
400 }
401
402
403 /** @fn void adcStopConversion(adcBASE_t *adc, uint32_t group)
404 *   @brief Stops an ADC conversion
405 *   @param[in] adc Pointer to ADC module:
406 *              - adcREG1: ADC1 module pointer
407 *              - adcREG2: ADC2 module pointer
408 *   @param[in] group Hardware group of ADC module:
409 *              - adcGROUP0: ADC event group
410 *              - adcGROUP1: ADC group 1
411 *              - adcGROUP2: ADC group 2
412 *
413 *   This function stops a convesion of the ADC hardware group.
414 *
415 *   @note The function adcInit has to be called before this function can be
416 *          used.
417 */
418 void adcStopConversion(adcBASE_t *adc, uint32_t group)
419 {
420     /** - Stop Conversion */
421     adc->GxSEL[group] = 0U;
422 }
423
424
425 /**
426  * Resets FiFo read and write pointer.
427  *
428  * @param[in] adc       Pointer to ADC module:
429  *                          - adcREG1: ADC1 module pointer
430  *                          - adcREG2: ADC2 module pointer
431  * @param[in] group     Hardware group of ADC module:
432  *                          - adcGROUP0: ADC event group
433  *                          - adcGROUP1: ADC group 1
434  *                          - adcGROUP2: ADC group 2
435  *
436  * @note The function adcInit has to be called before this function can be
437  *        used.\n
438  *        The conversion should be stopped before calling this function.
439  *
440  */
441 void adcResetFiFo(adcBASE_t *adc, uint32_t group)
442 {
443     /** - Reset FiFo */
444     adc->GxFIFORESETCR[group] = 1U;
445 }
446
447
448
449 /**
450  * Gets converted a ADC values.
451  *
452  * @param[in] adc       Pointer to ADC module:
453  *                          - adcREG1: ADC1 module pointer
454  *                          - adcREG2: ADC2 module pointer
455  * @param[in] group     Hardware group of ADC module:
456  *                          - adcGROUP0: ADC event group
457  *                          - adcGROUP1: ADC group 1
458  *                          - adcGROUP2: ADC group 2
459  * @param[out] data Pointer to store ADC converted data.
460  *
461  * @return The function will return the number of converted values copied
462  *          into data buffer.
463  *
464  * @note The function adcInit has to be called before this function can be
465  *        used.\n
466  *        The user is responsible to initialize the message box.
467  *
468  */
469 uint32_t adcGetData(adcBASE_t *adc, uint32_t group, adcData_t *data)
470 {
471     uint32_t  i;
472     uint32_t  buf;
473     uint32_t  mode;
474     uint32_t  index = adc == adcREG1 ? 0U : 1U;
475     uint32_t  count;
476     if(adc->GxINTCR[group] >= 256U) {
477         count = s_adcFiFoSize[index][group];
478     } else {
479         count = s_adcFiFoSize[index][group] - (uint32_t)(adc->GxINTCR[group] & 0xFF);
480     }
481     adcData_t *ptr = data;
482
483     mode = ((adc->GxMODECR[group]) & 0x00000300U);
484
485     if(mode == ADC_12_BIT) {
486
487         // Get conversion data and channel/pin id
488         for (i = 0; i < count; i++) {
489             buf        = adc->GxBUF[group].BUF0;
490             ptr->value = (uint16_t)(buf & 0xFFFU);
491             ptr->id    = (uint32_t)((buf >> 16U) & 0x1FU);
492             ptr++;
493         }
494
495     } else {
496
497         // Get conversion data and channel/pin id
498         for (i = 0; i < count; i++) {
499             buf        = adc->GxBUF[group].BUF0;
500             ptr->value = (uint16_t)(buf & 0x3FFU);
501             ptr->id    = (uint32_t)((buf >> 10U) & 0x1FU);
502             ptr++;
503         }
504       }
505
506     adc->GxINTFLG[group] = 9U;
507
508     return count;
509 }
510
511
512 /**
513  * Checks if FiFo buffer is full.
514  *
515  * @param[in] adc       Pointer to ADC module:
516  *                          - adcREG1: ADC1 module pointer
517  *                          - adcREG2: ADC2 module pointer
518  * @param[in] group     Hardware group of ADC module:
519  *                          - adcGROUP0: ADC event group
520  *                          - adcGROUP1: ADC group 1
521  *                          - adcGROUP2: ADC group 2
522  *
523  * @return The function will return:
524  *                         - 0: When FiFo buffer is not full
525  *                         - 1: When FiFo buffer is full
526  *                         - 3: When FiFo buffer overflow occured
527  *
528  *
529  * @note The function adcInit has to be called before this function can be
530  *        used.
531  *
532  */
533 uint32_t adcIsFifoFull(adcBASE_t *adc, uint32_t group)
534 {
535     // Read FiFo flag
536     uint32_t flags = adc->GxINTFLG[group] & 3U;
537     return flags;
538 }
539
540
541 /**
542  * Checks if Conversion is complete.
543  *
544  * @param[in] adc       Pointer to ADC module:
545  *                          - adcREG1: ADC1 module pointer
546  *                          - adcREG2: ADC2 module pointer
547  * @param[in] group     Hardware group of ADC module:
548  *                          - adcGROUP0: ADC event group
549  *                          - adcGROUP1: ADC group 1
550  *                          - adcGROUP2: ADC group 2
551  * @return The function will return:
552  *                         - 0: When is not finished
553  *                         - 8: When conversion is complete
554  *
555  * @note The function adcInit has to be called before this function can be
556  *        used.
557 */
558 uint32_t adcIsConversionComplete(adcBASE_t *adc, uint32_t group)
559 {
560     uint32_t flags;
561
562     /** - Read conversion flags */
563     flags = adc->GxINTFLG[group] & 8U;
564
565     return flags;
566 }
567
568
569 /**
570  * Computes offset error using Calibration mode.
571  *
572  * @param[in] adc Pointer to ADC module:
573  *              - adcREG1: ADC1 module pointer
574  *              - adcREG2: ADC2 module pointer
575  *              - adcREG3: ADC3 module pointer
576  *
577  * @note The function adcInit has to be called before this function can be
578  *        used.
579  */
580 void adcCalibration(adcBASE_t *adc)
581 {
582     uint32_t conv_val[5] = {0, 0, 0, 0, 0}, loop_index = 0;
583     uint32_t offset_error = 0;
584     uint32_t backup_mode;
585
586     /** - Backup Mode before Calibration  */
587     backup_mode = adc->OPMODECR;
588
589     /** - Enable 12-BIT ADC  */
590     adcREG1->OPMODECR |= 0x80000000U;
591
592     /* Disable all channels for conversion */
593     adc->GxSEL[0]=0x00;
594     adc->GxSEL[1]=0x00;
595     adc->GxSEL[2]=0x00;
596
597     for(loop_index = 0; loop_index < 4; loop_index++) {
598
599         /* Disable Self Test and Calibration mode */
600         adc->CALCR = 0x0;
601
602         switch(loop_index) {
603
604             case 0 :    /* Test 1 : Bride En = 0 , HiLo =0 */
605                         adc->CALCR=0x0;
606                         break;
607
608             case 1 :    /* Test 1 : Bride En = 0 , HiLo =1 */
609                         adc->CALCR=0x0100;
610                         break;
611
612             case 2 :    /* Test 1 : Bride En = 1 , HiLo =0 */
613                         adc->CALCR=0x0200;
614                         break;
615
616             case 3 :    /* Test 1 : Bride En = 1 , HiLo =1 */
617                         adc->CALCR=0x0300;
618                         break;
619         }
620
621         /* Enable Calibration mode */
622         adc->CALCR |= 0x1;
623
624         /* Start calibration conversion */
625         adc->CALCR |= 0x00010000;
626
627         /* Wait for calibration conversion to complete */
628         while((adc->CALCR & 0x00010000) == 0x00010000);
629
630         /* Read converted value */
631         conv_val[loop_index] = adc->CALR;
632     }
633
634     /* Disable Self Test and Calibration mode */
635     adc->CALCR = 0x0;
636
637     /* Compute the Offset error correction value */
638     conv_val[4] = conv_val[0] + conv_val[1] + conv_val[2] + conv_val[3];
639
640     conv_val[4] = (conv_val[4] / 4);
641
642     offset_error=conv_val[4]-0x7FF;
643
644     /* Write the offset error to the Calibration register */
645     /* Load 2;s complement of the computed value to ADCALR register */
646     offset_error = ~offset_error;
647     offset_error = offset_error & 0xFFF;
648     offset_error = offset_error+1;
649
650     adc->CALR = offset_error;
651
652     // - Restore Mode after Calibration
653     adc->OPMODECR = backup_mode;
654 }
655
656
657 /** @fn void adcMidPointCalibration(adcBASE_t *adc)
658 *   @brief Computes offset error using Mid Point Calibration mode
659 *   @param[in] adc Pointer to ADC module:
660 *              - adcREG1: ADC1 module pointer
661 *              - adcREG2: ADC2 module pointer
662 *              - adcREG3: ADC3 module pointer
663 *   This function computes offset error using Mid Point Calibration mode
664 *
665 *   @note The function adcInit has to be called before this function can be
666 *          used.
667 */
668 uint32_t adcMidPointCalibration(adcBASE_t *adc)
669 {
670     uint32_t conv_val[3] = {0, 0, 0}, loop_index = 0;
671     uint32_t offset_error = 0;
672     uint32_t backup_mode;
673
674     /** - Backup Mode before Calibration  */
675     backup_mode = adc->OPMODECR;
676
677     /** - Enable 12-BIT ADC  */
678     adcREG1->OPMODECR |= 0x80000000U;
679
680     /* Disable all channels for conversion */
681     adc->GxSEL[0]=0x00;
682     adc->GxSEL[1]=0x00;
683     adc->GxSEL[2]=0x00;
684
685     for(loop_index=0;loop_index<2;loop_index++) {
686
687         /* Disable Self Test and Calibration mode */
688         adc->CALCR=0x0;
689
690         switch(loop_index) {
691
692             case 0 :    /* Test 1 : Bride En = 0 , HiLo =0 */
693                         adc->CALCR=0x0;
694                         break;
695
696             case 1 :    /* Test 1 : Bride En = 0 , HiLo =1 */
697                         adc->CALCR=0x0100;
698                         break;
699
700         }
701
702         /* Enable Calibration mode */
703         adc->CALCR |= 0x1;
704
705         /* Start calibration conversion */
706         adc->CALCR |= 0x00010000;
707
708         /* Wait for calibration conversion to complete */
709         while((adc->CALCR & 0x00010000) == 0x00010000);
710
711         /* Read converted value */
712         conv_val[loop_index]= adc->CALR;
713     }
714
715     /* Disable Self Test and Calibration mode */
716     adc->CALCR = 0x0;
717
718     /* Compute the Offset error correction value */
719     conv_val[2] = (conv_val[0]) + (conv_val[1]);
720
721     conv_val[2] = (conv_val[2] / 2);
722
723     offset_error = conv_val[2] - 0x7FF;
724
725     /* Write the offset error to the Calibration register           */
726     /* Load 2's complement of the computed value to ADCALR register */
727     offset_error = ~offset_error;
728     offset_error = offset_error & 0xFFF;
729     offset_error = offset_error + 1;
730
731     adc->CALR = offset_error;
732
733     // - Restore Mode after Calibration
734     adc->OPMODECR = backup_mode;
735
736     return offset_error;
737 }
738
739
740 /** @fn void adcEnableNotification(adcBASE_t *adc, uint32_t group)
741  *  @brief Enable notification
742  *  @param[in] adc Pointer to ADC module:
743  *             - adcREG1: ADC1 module pointer
744  *             - adcREG2: ADC2 module pointer
745  *             - adcREG3: ADC3 module pointer
746  *  @param[in] group Hardware group of ADC module:
747  *             - adcGROUP0: ADC event group
748  *             - adcGROUP1: ADC group 1
749  *             - adcGROUP2: ADC group 2
750  *
751  *  This function will enable the notification of a conversion.
752  *  In single conversion mode for conversion complete and
753  *  in continuous conversion mode when the FiFo buffer is full.
754  *
755  *  @note The function adcInit has to be called before this function can be
756  *         used.\n
757  *         This function should be called before the conversion is started.
758  */
759 void adcEnableNotification(adcBASE_t *adc, uint32_t group)
760 {
761     uint32_t notif = adc->GxMODECR[group] & 2U ? 1U : 8U;
762
763     adc->GxINTENA[group] = notif;
764 }
765
766
767 /** @fn void adcDisableNotification(adcBASE_t *adc, uint32_t group)
768  *  @brief Disable notification
769  *  @param[in] adc Pointer to ADC module:
770  *             - adcREG1: ADC1 module pointer
771  *             - adcREG2: ADC2 module pointer
772  *             - adcREG3: ADC3 module pointer
773  *  @param[in] group Hardware group of ADC module:
774  *             - adcGROUP0: ADC event group
775  *             - adcGROUP1: ADC group 1
776  *             - adcGROUP2: ADC group 2
777  *
778  *  This function will disable the notification of a conversion.
779  *
780  *  @note The function adcInit has to be called before this function can be
781  *         used.
782  */
783 void adcDisableNotification(adcBASE_t *adc, uint32_t group)
784 {
785     adc->GxINTENA[group] = 0U;
786 }
787
788
789 /** @fn void adc1Group0Interrupt(void)
790  *  @brief ADC1 Event Group Interrupt Handler
791  */
792 #pragma INTERRUPT(adc1Group0Interrupt, IRQ)
793 void adc1Group0Interrupt(void)
794 {
795     portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
796     adcNotification(adcREG1, adcGROUP0, &xHigherPriorityTaskWoken);
797     adcREG1->GxINTFLG[0U] = _BV(3) | _BV(0);
798     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
799 }
800
801
802 /** @fn void adc1Group1Interrupt(void)
803  *  @brief ADC1 Group 1 Interrupt Handler
804  */
805 #pragma INTERRUPT(adc1Group1Interrupt, IRQ)
806 void adc1Group1Interrupt(void)
807 {
808     portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
809     adcNotification(adcREG1, adcGROUP1, &xHigherPriorityTaskWoken);
810     // For ADC1 Group1 see tms570_trm.pdf p. 791 (783)
811     adcREG1->GxINTFLG[1U] = _BV(3) | _BV(0);
812     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
813 }
814
815
816 /** @fn void adc1Group2Interrupt(void)
817  *  @brief ADC1 Group 2 Interrupt Handler
818  */
819 #pragma INTERRUPT(adc1Group2Interrupt, IRQ)
820 void adc1Group2Interrupt(void)
821 {
822     portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
823     adcNotification(adcREG1, adcGROUP2, &xHigherPriorityTaskWoken);
824     adcREG1->GxINTFLG[2U] = _BV(3) | _BV(0);;
825     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
826 }
827
828
829 /** @fn void adc2Group0Interrupt(void)
830  *  @brief ADC2 Event Group Interrupt Handler
831  */
832 #pragma INTERRUPT(adc2Group0Interrupt, IRQ)
833 void adc2Group0Interrupt(void)
834 {
835     portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
836     adcNotification(adcREG2, adcGROUP0, &xHigherPriorityTaskWoken);
837     adcREG2->GxINTFLG[0U] = _BV(3) | _BV(0);
838     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
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     portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
849     adcNotification(adcREG2, adcGROUP1, &xHigherPriorityTaskWoken);
850     adcREG2->GxINTFLG[1U] = _BV(3) | _BV(0);
851     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
852 }
853
854
855 /** @fn void adc2Group2Interrupt(void)
856  *  @brief ADC2 Group 2 Interrupt Handler
857  */
858 #pragma INTERRUPT(adc2Group2Interrupt, IRQ)
859 void adc2Group2Interrupt(void)
860 {
861     portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
862     adcNotification(adcREG2, adcGROUP2, &xHigherPriorityTaskWoken);
863     adcREG2->GxINTFLG[2U] = _BV(3) | _BV(0);
864     portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
865 }
866