iLLD_TC27xC  1.0
IfxVadc_Adc.h
Go to the documentation of this file.
1 /**
2  * \file IfxVadc_Adc.h
3  * \brief VADC ADC details
4  * \ingroup IfxLld_Vadc
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  * \defgroup IfxLld_Vadc_Adc_Usage How to use the VADC ADC Interface driver?
25  * \ingroup IfxLld_Vadc
26  *
27  * VADC comprises of independent analog channels with Analog/Digital converters to convert analog input to discrete digital output.
28  *
29  * In the following sections it will be described, how to integrate the driver into the application framework.
30  *
31  * \section IfxLld_Vadc_Adc_Preparation Preparation
32  * \subsection IfxLld_Vadc_Adc_Include Include Files
33  *
34  * Include following header file into your C code:
35  * \code
36  *
37  * #include <Vadc/Adc/IfxVadc_Adc.h>
38  *
39  * \endcode
40  *
41  * \subsection IfxLld_Vadc_Adc_Variables Variables
42  * \code
43  *
44  * // VADC handle
45  * IfxVadc_Adc vadc;
46  *
47  * \endcode
48  *
49  * \subsection IfxLld_Vadc_Adc_ModuleInitialisation Module Initialisation
50  * The module initialisation can be done in the same function:
51  * \code
52  * // create configuration
53  * IfxVadc_Adc_Config adcConfig;
54  * IfxVadc_Adc_initModuleConfig(&adcConfig, &MODULE_VADC);
55  *
56  * // initialize module
57  * // IfxVadc_Adc vadc; // declared globally
58  * IfxVadc_Adc_initModule(&vadc, &adcConfig);
59  * \endcode
60  *
61  *
62  * \subsection IfxLld_Vadc_Adc_GroupInitialisation Group Initialisation
63  * The group initialisation can be done in the same function:
64  * \code
65  * // create group config
66  * IfxVadc_Adc_GroupConfig adcGroupConfig;
67  * IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);
68  *
69  * // change group (default is GroupId_0, change to GroupId_3)
70  * adcGroupConfig.groupId = IfxVadc_GroupId_3;
71  *
72  * // IMPORTANT: usually we use the same group as master!
73  * adcGroupConfig.master = adcGroupConfig.groupId;
74  *
75  * // enable all arbiter request sources
76  * adcGroupConfig.arbiter.requestSlotQueueEnabled = TRUE; // enable Queue mode
77  * adcGroupConfig.arbiter.requestSlotScanEnabled = TRUE; // enable Scan mode
78  * adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE; // enable Background scan
79  *
80  * // enable all gates in "always" mode (no edge detection)
81  * adcGroupConfig.queueRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
82  * adcGroupConfig.scanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
83  * adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
84  *
85  * // initialize the group
86  * IfxVadc_Adc_Group adcGroup;
87  * IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
88  * \endcode
89  *
90  * \subsection IfxLld_Vadc_Adc_QueuedTransfers Queued Transfers
91  * Now, VADC is initialised. Here,Three channels are used for queued transfers
92  * \code
93  * // IMPORTANT: for deterministic results we have to disable the queue gate
94  * // while filling the queue, otherwise results could be output in the wrong order
95  * unsigned savedGate = adcGroup.module.vadc->G[adcGroup.groupId].QMR0.B.ENGT;
96  * adcGroup.module.vadc->G[adcGroup.groupId].QMR0.B.ENGT = 0;
97  *
98  * // create channel config
99  * IfxVadc_Adc_ChannelConfig adcChannelConfig[3];
100  * IfxVadc_Adc_Channel adcChannel[3];
101  *
102  * for(int chnIx=0; chnIx<3; ++chnIx) {
103  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig[chnIx], &adcGroup);
104  *
105  * adcChannelConfig[chnIx].channelId = (IfxVadc_ChannelId)(chnIx);
106  * adcChannelConfig[chnIx].resultRegister = IfxVadc_ChannelResult_1; // use result register #1 for all channels
107  *
108  * // initialize the channel
109  * IfxVadc_Adc_initChannel(&adcChannel[chnIx], &adcChannelConfig[chnIx]);
110  *
111  * // Add channel to queue with refill enabled
112  * IfxVadc_Adc_addToQueue(&adcChannel[chnIx], IFXVADC_QUEUE_REFILL);
113  *
114  * // restore previous gate config
115  * adcGroup.module.vadc->G[adcGroup.groupId].QMR0.B.ENGT = savedGate;
116  *
117  * // start the Queue
118  * IfxVadc_Adc_startQueue(&adcGroup); // just for the case that somebody copy&pastes the code - the queue has already been started in previous test
119  *
120  * // get 10 results for all 3 channels and store in temporary buffer
121  * // (the usage of a buffer is required, since the print statements used by the checks take more time than the conversions)
122  * Ifx_VADC_RES resultTrace[3*10];
123  * for(int i=0; i<3*10; ++i)
124  * {
125  * unsigned chnIx = i % 3;
126  *
127  * // wait for valid result
128  * Ifx_VADC_RES conversionResult;
129  * do {
130  * conversionResult = IfxVadc_Adc_getResult(&adcChannel[chnIx]);
131  * } while( !conversionResult.B.VF );
132  *
133  * // store result
134  * resultTrace[i] = conversionResult;
135  * }
136  *
137  * // stop the queue
138  * IfxVadc_Adc_clearQueue(&adcGroup);
139  *
140  * // check results in buffer
141  * // ...
142  * }
143  * \endcode
144  *
145  * \subsection IfxLld_Vadc_Adc_AutoScan Auto Scan
146  * Autoscan of 5 channels
147  * \code
148  * // now with group 0
149  * adcGroupConfig.groupId = IfxVadc_GroupId_0;
150  * adcGroupConfig.master = adcGroupConfig.groupId;
151  * adcGroupConfig.backgroundScanRequest.autoBackgroundScanEnabled = TRUE;
152  * adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
153  * adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE;
154  *
155  * // initialize the group
156  * //IfxVadc_Adc_Group adcGroup; // no need to create a new one
157  * IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
158  *
159  * {
160  * // create channel config
161  * IfxVadc_Adc_ChannelConfig adcChannelConfig[5];
162  * IfxVadc_Adc_Channel adcChannel[5];
163  *
164  * for(int chnIx=0; chnIx<5; ++chnIx) {
165  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig[chnIx], &adcGroup);
166  *
167  * adcChannelConfig[chnIx].channelId = (IfxVadc_ChannelId)(chnIx);
168  * adcChannelConfig[chnIx].resultRegister = (IfxVadc_ChannelResult)(chnIx); // use dedicated result register
169  *
170  * // initialize the channel
171  * IfxVadc_Adc_initChannel(&adcChannel[chnIx], &adcChannelConfig[chnIx]);
172  *
173  * // add to autoscan
174  * unsigned channels = (1 << adcChannelConfig[chnIx].channelId);
175  * unsigned mask = channels;
176  * boolean continuous = TRUE;
177  * IfxVadc_Adc_setScan(&adcGroup, channels, mask, continuous);
178  * }
179  *
180  * // start autoscan
181  * IfxVadc_Adc_startScan(&adcGroup);
182  *
183  * // check results
184  * for(int chnIx=0; chnIx<5; ++chnIx) {
185  * unsigned group = adcChannel[chnIx].group->groupId;
186  * unsigned channel = adcChannel[chnIx].channel;
187  *
188  * // wait for valid result
189  * Ifx_VADC_RES conversionResult;
190  * do {
191  * conversionResult = IfxVadc_Adc_getResult(&adcChannel[chnIx]);
192  * } while( !conversionResult.B.VF );
193  *
194  * // print result, check with expected value
195  * {
196  * unsigned expected = ((adcMaxPlus1Value * (VADC_COMMANDS_CHN_PER_VOLTAGE_GROUP*group + channel) * vStep) / (vRef-vGnd));
197  * result |= clib_trace(conversionResult.B.CHNR, channel);
198  * result |= clib_trace_tolerant(conversionResult.B.RESULT, expected, 5);
199  * }
200  * }
201  * }
202  * \endcode
203  *
204  * \subsection IfxLld_Vadc_Adc_BackGroundScan Background Scan
205  * Background Scan of 2 channels
206  *
207  * \code
208  * // create channel config
209  * IfxVadc_Adc_ChannelConfig adcChannelConfig[2];
210  * IfxVadc_Adc_Channel adcChannel[2];
211  *
212  * for(int chnIx=0; chnIx<2; ++chnIx)
213  * {
214  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig[chnIx], &adcGroup);
215  *
216  * adcChannelConfig[chnIx].channelId = (IfxVadc_ChannelId)(chnIx + 5);
217  * adcChannelConfig[chnIx].resultRegister = (IfxVadc_ChannelResult)(5 + chnIx); // use register #5 and 6 for results
218  * adcChannelConfig[chnIx].backgroundChannel = TRUE;
219  *
220  * // initialize the channel
221  * IfxVadc_Adc_initChannel(&adcChannel[chnIx], &adcChannelConfig[chnIx]);
222  *
223  * // add to background scan
224  * unsigned channels = (1 << adcChannelConfig[chnIx].channelId);
225  * unsigned mask = channels;
226  * IfxVadc_Adc_setBackgroundScan(&vadc, &adcGroup, channels, mask);
227  * }
228  *
229  * // start autoscan
230  * boolean continuous = TRUE;
231  * IfxVadc_Adc_startBackgroundScan(&vadc, continuous);
232  *
233  * // check results
234  * for(int chnIx=0; chnIx<2; ++chnIx)
235  * {
236  * unsigned group = adcChannel[chnIx].group->groupId;
237  * unsigned channel = adcChannel[chnIx].channel;
238  *
239  * // wait for valid result
240  * Ifx_VADC_RES conversionResult;
241  * do
242  * {
243  * conversionResult = IfxVadc_Adc_getResult(&adcChannel[chnIx]);
244  * } while( !conversionResult.B.VF );
245  *
246  * // check with expected value
247  * // ...
248  * }
249  * \endcode
250  *
251  * \defgroup IfxLld_Vadc_Adc Interface Driver
252  * \ingroup IfxLld_Vadc
253  * \defgroup IfxLld_Vadc_Adc_DataStructures Data Structures
254  * \ingroup IfxLld_Vadc_Adc
255  * \defgroup IfxLld_Vadc_Adc_Module Module Functions
256  * \ingroup IfxLld_Vadc_Adc
257  * \defgroup IfxLld_Vadc_Adc_Group Group Functions
258  * \ingroup IfxLld_Vadc_Adc
259  * \defgroup IfxLld_Vadc_Adc_Channel Channel Functions
260  * \ingroup IfxLld_Vadc_Adc
261  * \defgroup IfxLld_Vadc_Adc_Background_Autoscan Background Autoscan Functions
262  * \ingroup IfxLld_Vadc_Adc
263  * \defgroup IfxLld_Vadc_Adc_ChannelScan Channel Scan Functions
264  * \ingroup IfxLld_Vadc_Adc
265  * \defgroup IfxLld_Vadc_Adc_Queue Queue Functions
266  * \ingroup IfxLld_Vadc_Adc
267  * \defgroup IfxLld_Vadc_Adc_Clock Clock Functions
268  * \ingroup IfxLld_Vadc_Adc
269  * \defgroup IfxLld_Vadc_Adc_Interrupt Interrupt Functions
270  * \ingroup IfxLld_Vadc_Adc
271  * \defgroup IfxLld_Vadc_Adc_Variables Variables
272  * \ingroup IfxLld_Vadc_Adc
273  */
274 
275 #ifndef IFXVADC_ADC_H
276 #define IFXVADC_ADC_H 1
277 
278 /******************************************************************************/
279 /*----------------------------------Includes----------------------------------*/
280 /******************************************************************************/
281 
282 #include "Vadc/Std/IfxVadc.h"
283 
284 /******************************************************************************/
285 /*------------------------------Type Definitions------------------------------*/
286 /******************************************************************************/
287 
289 
290 /******************************************************************************/
291 /*-----------------------------Data Structures--------------------------------*/
292 /******************************************************************************/
293 
294 /** \addtogroup IfxLld_Vadc_Adc_DataStructures
295  * \{ */
296 /** \brief VADC handle data structure
297  */
298 typedef struct
299 {
300  Ifx_VADC *vadc; /**< \brief Specifies the pointer to the VADC module registers */
301 } IfxVadc_Adc;
302 
303 /** \brief Gating/Trigger configuration structure
304  */
305 typedef struct
306 {
307  IfxVadc_GatingSource gatingSource; /**< \brief Specifies used gate input for group */
308  IfxVadc_TriggerSource triggerSource; /**< \brief Specifies used Trigger input for group */
309  IfxVadc_GatingMode gatingMode; /**< \brief Specifies gating mode. High level, Low Level or Gating disabled */
310  IfxVadc_TriggerMode triggerMode; /**< \brief Specifies trigger mode. Rising, falling any edge leads to an trigger event */
312 
313 /** \} */
314 
315 /** \addtogroup IfxLld_Vadc_Adc_DataStructures
316  * \{ */
317 /** \brief Arbiter configuration structure.
318  */
319 typedef struct
320 {
321  IfxVadc_ArbitrationRounds arbiterRoundLength; /**< \brief Specifies arbiter round length. */
322  boolean requestSlotQueueEnabled; /**< \brief request queue if enabled. */
323  boolean requestSlotScanEnabled; /**< \brief request scan if enabled. */
324  boolean requestSlotBackgroundScanEnabled; /**< \brief request background scan if enabled. */
326 
327 /** \brief Background scan mode configuration structure.
328  */
329 typedef struct
330 {
331  boolean autoBackgroundScanEnabled; /**< \brief background autoscan functionality enable or disable. */
332  IfxVadc_Adc_GatingTriggerConfig triggerConfig; /**< \brief trigger and gating configuration. */
333  IfxVadc_RequestSlotPriority requestSlotPrio; /**< \brief priority of used background scan request slot. */
334  IfxVadc_RequestSlotStartMode requestSlotStartMode; /**< \brief start mode for request background scan source. */
336 
337 /** \brief Input class configuration structure
338  */
339 typedef struct
340 {
341  float32 sampleTime; /**< \brief Specifies the requested sample time for input class */
342  IfxVadc_ChannelResolution resolution; /**< \brief Specifies the conversion Mode 8,10,12Bit or 10bit fast compare */
344 
345 /** \brief Group handle data structure
346  */
347 typedef struct
348 {
349  IfxVadc_Adc module; /**< \brief The VADC handle structure */
350  Ifx_VADC_G *group; /**< \brief Pointer to the group registers */
351  IfxVadc_GroupId groupId; /**< \brief Specifies the group index */
353 
354 /** \brief Queue configuration structure
355  */
356 typedef struct
357 {
358  boolean flushQueueAfterInit; /**< \brief Specifies if the queue is flushed after configuration */
359  IfxVadc_Adc_GatingTriggerConfig triggerConfig; /**< \brief trigger and gating configuration. */
360  IfxVadc_RequestSlotPriority requestSlotPrio; /**< \brief priority of used queue request slot. */
361  IfxVadc_RequestSlotStartMode requestSlotStartMode; /**< \brief start mode for request queue source. */
363 
364 /** \brief Scan mode configuration structure.
365  */
366 typedef struct
367 {
368  boolean autoscanEnabled; /**< \brief Specifies autoscan functionality. */
369  IfxVadc_Adc_GatingTriggerConfig triggerConfig; /**< \brief Specifies trigger and gating configuration */
370  IfxVadc_RequestSlotPriority requestSlotPrio; /**< \brief priority of used scan request slot. */
371  IfxVadc_RequestSlotStartMode requestSlotStartMode; /**< \brief start mode for request scan source. */
373 
374 /** \} */
375 
376 /** \addtogroup IfxLld_Vadc_Adc_DataStructures
377  * \{ */
378 /** \brief Channel handle data structure
379  */
380 typedef struct
381 {
382  IfxVadc_ChannelId channel; /**< \brief Specifies the channel index */
383  IfxVadc_ChannelResult resultreg; /**< \brief Specifies allocated result register */
384  const IfxVadc_Adc_Group *group; /**< \brief Specifies the group of the channel */
386 
387 /** \brief Channel configuration structure
388  */
389 typedef struct
390 {
391  boolean globalResultUsage; /**< \brief Specifies storage in global result register */
392  boolean synchonize; /**< \brief Specifies synchronized conversion channel */
393  boolean backgroundChannel; /**< \brief Specifies channel is used as background channel */
394  boolean rightAlignedStorage; /**< \brief Specifies result is right aligned */
395  Ifx_Priority resultPriority; /**< \brief Interrupt priority of the result trigger interrupt, if 0 the interrupt is disable */
396  Ifx_Priority channelPriority; /**< \brief Interrupt priority of the channel trigger interrupt, if 0 the interrupt is disable */
397  IfxSrc_Tos resultServProvider; /**< \brief Interrupt service provider for the result trigger interrupt */
398  IfxSrc_Tos channelServProvider; /**< \brief Interrupt service provider for the channel trigger interrupt */
399  IfxVadc_SrcNr resultSrcNr; /**< \brief Service node of the result trigger */
400  IfxVadc_SrcNr channelSrcNr; /**< \brief Service node of the channel trigger */
401  IfxVadc_ChannelId channelId; /**< \brief Specifies the channel index */
402  IfxVadc_InputClasses inputClass; /**< \brief Specifies input class selection */
403  IfxVadc_ChannelReference reference; /**< \brief Specifies Reference selection */
404  IfxVadc_ChannelResult resultRegister; /**< \brief Specifies Result register selection */
405  IfxVadc_BoundarySelection lowerBoundary; /**< \brief Specifies lower boundary selection */
406  IfxVadc_BoundarySelection upperBoundary; /**< \brief Specifies upper boundary selection */
407  IfxVadc_BoundaryExtension boundaryMode; /**< \brief Specifies Standard mode of fast compare mode */
408  IfxVadc_LimitCheck limitCheck; /**< \brief Specifies boundary band selection upper/lower */
409  const IfxVadc_Adc_Group *group; /**< \brief Specifies pointer to the IfxVadc_Adc_Group group handle */
411 
412 /** \brief VADC module configuration structure
413  */
414 typedef struct
415 {
416  Ifx_VADC *vadc; /**< \brief Specifies the pointer to the VADC module registers */
417  uint32 moduleFrequency; /**< \brief Specifies digital ADC Frequency */
418  uint32 analogFrequency; /**< \brief Specifies analog ADC Frequency */
419  IfxVadc_Adc_ClassConfig inputClass[2]; /**< \brief Specifies the global conversion settings one and two */
420  boolean startupCalibration; /**< \brief Can be enabled to execute a startup calibration (disabled by default).
421  * Note that this option will also enable all converter groups.
422  * If this isn't desired, don't use this option, but execute IfxVadc_Adc_startupCalibration() after all ADC groups have been initialized. */
424 
425 /** \brief Group configuration structure
426  */
427 typedef struct
428 {
429  const IfxVadc_Adc *module; /**< \brief Specifies pointer to the IfxVadc_Adc module handle */
430  IfxVadc_GroupId groupId; /**< \brief Specifies the group/kernel id */
431  IfxVadc_GroupId master; /**< \brief Specifies the master group. If master is different from groupId, then the group is configured as slave. */
432  IfxVadc_Adc_ClassConfig inputClass[IFXVADC_NUMBER_OF_INPUTCLASS]; /**< \brief Specifies conversion settings one and two */
433  IfxVadc_Adc_ScanConfig scanRequest; /**< \brief Specifies scan mode configuration */
434  IfxVadc_Adc_QueueConfig queueRequest; /**< \brief Specifies queued mode configuration */
435  IfxVadc_Adc_BackgroundScanConfig backgroundScanRequest; /**< \brief Specifies back ground scan configuration */
436  boolean disablePostCalibration; /**< \brief Specifies if calibration after conversion (post calibration) should be disabled */
437  IfxVadc_Adc_ArbiterConfig arbiter; /**< \brief Arbiter configuration structure. */
439 
440 /** \} */
441 
442 /** \addtogroup IfxLld_Vadc_Adc_Module
443  * \{ */
444 
445 /******************************************************************************/
446 /*-------------------------Inline Function Prototypes-------------------------*/
447 /******************************************************************************/
448 
449 /** \brief Reset the VADC module
450  * \param vadc pointer to the VADC module
451  * \return None
452  *
453  * Example Usage :\ref IfxLld_Vadc_Adc_Usage
454  *
455  */
457 
458 /** \brief Get the current VADC configuration (e.g. VADC frequency)
459  * \param vadc pointer to the VADC module
460  * \param config pointer to the VADC module configuration
461  * \return None
462  *
463  * Example Usage :\ref IfxLld_Vadc_Adc_Usage
464  *
465  */
467 
468 /** \brief Get conversion result based on the Request Source. (Function does not care about the alignment)
469  * value = raw * gain + offset
470  * \param group pointer to the VADC group
471  * \param channel channel number
472  * \param sourceType type of request source
473  * \return scaled Conversion result
474  *
475  * \code
476  * // initialize module pointer
477  * IfxVadc_Adc vadc;
478  * vadc.vadc = &MODULE_VADC;
479  *
480  * // create group config
481  * IfxVadc_Adc_GroupConfig adcGroupConfig;
482  * IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);
483  *
484  * // change group (default is GroupId0, change to GroupId2)
485  * adcGroupConfig.groupId = IfxVadc_GroupId2;
486  * adcGroupConfig.scanRequest.autoscanEnable = TRUE;
487  *
488  * // initialize the group
489  * IfxVadc_Adc_Group adcGroup;
490  * IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
491  *
492  * // create channel config
493  * IfxVadc_Adc_ChannelConfig adcChannelConfig;
494  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig, &adcGroup);
495  *
496  * // change channel (default is ChannelId0, change to ChannelId2)
497  * adcChannelConfig.channelId = IfxVadc_ChannelId2;
498  *
499  * // initialize the channel
500  * IfxVadc_Adc_Channel adcChannel;
501  * IfxVadc_Adc_initChannel(&adcChannel, &adcChannelConfig);
502  *
503  * uint32 channels = (1 << 2); // enable channel #2
504  * uint32 mask = (1 << 7) | (1 << 2); // modify the selection for channel #7 and #2; channel #7 will be disabled
505  * boolean continuous = TRUE; // use continuous autoscan
506  *
507  * // configure wait for read mode
508  * IfxVadc_Adc_configureWaitForReadMode(&adcChannel, TRUE);
509  *
510  * // configure autoscan
511  * IfxVadc_Adc_setScan(&adcGroup, channels, mask, continuous);
512  *
513  * // start the autoscan
514  * IfxVadc_Adc_startScan(&adcGroup);
515  *
516  * // wait for valid result
517  * Ifx_VADC_RES resultChannel;
518  * do {
519  * resultChannel = IfxVadc_Adc_getResultBasedOnRequestSource(&adcGroup, IfxVadc_ChannelId2, IfxVadc_RequestSource_scan);
520  * } while( !resultChannel.B.VF );
521  * \endcode
522  *
523  */
525 
526 /******************************************************************************/
527 /*-------------------------Global Function Prototypes-------------------------*/
528 /******************************************************************************/
529 
530 /** \brief Initialise the VADC to run with the expected frequency and calibration
531  * \param vadc pointer to the VADC handle
532  * \param config pointer to the VADC configuration
533  * \return IfxVadc_Status
534  *
535  * \code
536  * // initialize module pointer
537  * IfxVadc_Adc vadc;
538  * vadc.vadc = &MODULE_VADC;
539  *
540  * // create module config
541  * IfxVadc_Adc_Config adcModuleConfig;
542  * IfxVadc_Adc_initModuleConfig(&adcModuleConfig, &vadc);
543  *
544  * IfxVadc_Adc_initModule(&vadc, &adcModuleConfig);
545  * \endcode
546  *
547  */
549 
550 /** \brief Initialise buffer with default VADC configuration
551  * \param config pointer to the VADC module configuration
552  * \param vadc pointer to the VADC
553  * \return None
554  *
555  * For coding example see: \ref IfxVadc_Adc_initModule
556  *
557  */
558 IFX_EXTERN void IfxVadc_Adc_initModuleConfig(IfxVadc_Adc_Config *config, Ifx_VADC *vadc);
559 
560 /** \} */
561 
562 /** \addtogroup IfxLld_Vadc_Adc_Group
563  * \{ */
564 
565 /******************************************************************************/
566 /*-------------------------Inline Function Prototypes-------------------------*/
567 /******************************************************************************/
568 
569 /** \brief Gets the current group register set
570  * \param group Group handle data structure
571  * \return Group register set
572  */
574 
575 /** \brief Get conversion result for the group
576  * \param group pointer to the VADC group
577  * \param results pointer to scaled conversion results
578  * \param resultOffset offset for the first result
579  * \param numResults number of results
580  * \return None
581  *
582  * \code
583  * // initialize module pointer
584  * IfxVadc_Adc vadc;
585  * vadc.vadc = &MODULE_VADC;
586  *
587  * // create group config
588  * IfxVadc_Adc_GroupConfig adcGroupConfig;
589  * IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);
590  *
591  * // change group (default is GroupId0, change to GroupId2)
592  * adcGroupConfig.groupId = IfxVadc_GroupId2;
593  * adcGroupConfig.scanRequest.autoscanEnabled = TRUE;
594  *
595  * // initialize the group
596  * IfxVadc_Adc_Group adcGroup;
597  * IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
598  *
599  * // create channel config
600  * IfxVadc_Adc_ChannelConfig adcChannelConfig2;
601  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig2, &adcGroup);
602  *
603  * // change channel (default is ChannelId0, change to ChannelId2)
604  * adcChannelConfig2.channelId = IfxVadc_ChannelId2;
605  *
606  * // initialize the channel
607  * IfxVadc_Adc_Channel adcChannel2;
608  * IfxVadc_Adc_initChannel(&adcChannel2, &adcChannelConfig2);
609  *
610  * // create channel config
611  * IfxVadc_Adc_ChannelConfig adcChannelConfig5;
612  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig5, &adcGroup);
613  *
614  * // change channel (default is ChannelId0, change to ChannelId5)
615  * adcChannelConfig5.channelId = IfxVadc_ChannelId5;
616  * // change channel result register (default is ChannelResult0, change to ChannelResult1)
617  * adcChannelConfig5.resultRegister = IfxVadc_ChannelResult1;
618  *
619  * // initialize the channel
620  * IfxVadc_Adc_Channel adcChannel5;
621  * IfxVadc_Adc_initChannel(&adcChannel5, &adcChannelConfig5);
622  *
623  * uint32 channels = (1 << 5) | (1 << 2); // enable channel #5 and #2
624  * uint32 mask = (1 << 7) | (1 << 5) | (1 << 2); // modify the selection for channel #7, #5 and #2; channel #7 will be disabled
625  * boolean continuous = TRUE; // continuous autoscan
626  *
627  * // configure wait for read mode
628  * IfxVadc_Adc_configureWaitForReadMode(&adcChannel2, TRUE);
629  * IfxVadc_Adc_configureWaitForReadMode(&adcChannel5, TRUE);
630  *
631  * // configure autoscan
632  * IfxVadc_Adc_setScan(&adcGroup, channels, mask, continuous);
633  *
634  * // start the autoscan
635  * IfxVadc_Adc_startScan(&adcGroup);
636  *
637  * // wait for conversion to finish
638  * IfxVadc_Status scanStatus;
639  * do
640  * {
641  * scanStatus = IfxVadc_Adc_getScanStatus(&adcGroup);
642  * } while(scanStatus==IfxVadc_Status_ChannelsStillPending);
643  *
644  * // fetch the 2 results of conversion for group 0
645  * Ifx_VADC_RES results[10];
646  * IfxVadc_Adc_getGroupResult(&adcGroup, results, 0, 2);
647  * \endcode
648  *
649  */
650 IFX_INLINE void IfxVadc_Adc_getGroupResult(IfxVadc_Adc_Group *group, Ifx_VADC_RES *results, uint32 resultOffset, uint32 numResults);
651 
652 /** \brief Gets the current group module register address
653  * \param group Group handle data structure
654  * \return Group module register base address
655  */
657 
658 /******************************************************************************/
659 /*-------------------------Global Function Prototypes-------------------------*/
660 /******************************************************************************/
661 
662 /** \brief Reset the VADC group
663  * \param group pointer to the VADC group
664  * \return None
665  *
666  * Example Usage :\ref IfxLld_Vadc_Adc_Usage
667  *
668  */
670 
671 /** \brief Get the current group configuration (e.g. vadc frequency)
672  * \param group pointer to the VADC group
673  * \param config pointer to the VADC group configuration
674  * \return None
675  *
676  * Example Usage :\ref IfxLld_Vadc_Adc_Usage
677  *
678  */
680 
681 /** \brief Initialise the VADC group (also autoscan and queue modes) Slave Groups must initialize first.
682  * \param group pointer to the VADC group
683  * \param config pointer to the VADC group configuration
684  * \return IfxVadc_Status
685  *
686  * \code
687  * // initialize module pointer
688  * IfxVadc_Adc vadc;
689  * vadc.vadc = &MODULE_VADC;
690  *
691  * // create group config
692  * IfxVadc_Adc_GroupConfig adcGroupConfig;
693  * IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);
694  *
695  * // change group (default is GroupId0, change to GroupId2)
696  * adcGroupConfig.groupId = IfxVadc_GroupId2;
697  *
698  * // initialize the group
699  * IfxVadc_Adc_Group adcGroup;
700  * IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
701  * \endcode
702  *
703  */
705 
706 /** \brief Initialise buffer with default VADC configuration
707  * \param config pointer to the VADC group configuration
708  * \param vadc pointer to the VADC module
709  * \return None
710  *
711  * For coding example see: \ref IfxVadc_Adc_initGroup
712  *
713  */
715 
716 /** \} */
717 
718 /** \addtogroup IfxLld_Vadc_Adc_Channel
719  * \{ */
720 
721 /******************************************************************************/
722 /*-------------------------Inline Function Prototypes-------------------------*/
723 /******************************************************************************/
724 
725 /** \brief pointer to the VADC channel
726  * \param channel pointer to the VADC channel
727  * \param waitForRead wait for read mode enabled/disable
728  * \return None
729  *
730  * For coding example see: \ref IfxVadc_Adc_getResultBasedOnRequestSource
731  *
732  */
733 IFX_INLINE void IfxVadc_Adc_configureWaitForReadMode(IfxVadc_Adc_Channel *channel, boolean waitForRead);
734 
735 /** \brief Get conversion result (Function does not care about the alignment)
736  * \param channel pointer to the VADC channel
737  * \return scaled Conversion result
738  *
739  * Here,Three channels are used for queued transfers
740  * \code
741  *
742  * // IMPORTANT: for deterministic results we have to disable the queue gate
743  * // while filling the queue, otherwise results could be output in the wrong order
744  * unsigned savedGate = adcGroup.module.vadc->G[adcGroup.groupId].QMR0.B.ENGT;
745  * adcGroup.module.vadc->G[adcGroup.groupId].QMR0.B.ENGT = 0;
746  *
747  * // create channel config
748  * IfxVadc_Adc_ChannelConfig adcChannelConfig[3];
749  * IfxVadc_Adc_Channel adcChannel[3];
750  *
751  * for(int chnIx=0; chnIx<3; ++chnIx) {
752  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig[chnIx], &adcGroup);
753  *
754  * adcChannelConfig[chnIx].channelId = (IfxVadc_ChannelId)(chnIx);
755  * adcChannelConfig[chnIx].resultRegister = IfxVadc_ChannelResult_1; // use result register #1 for all channels
756  *
757  * // initialize the channel
758  * IfxVadc_Adc_initChannel(&adcChannel[chnIx], &adcChannelConfig[chnIx]);
759  *
760  * // Add channel to queue with refill enabled
761  * IfxVadc_Adc_addToQueue(&adcChannel[chnIx], IFXVADC_QUEUE_REFILL);
762  *
763  * // restore previous gate config
764  * adcGroup.module.vadc->G[adcGroup.groupId].QMR0.B.ENGT = savedGate;
765  *
766  * // start the Queue
767  * IfxVadc_Adc_startQueue(&adcGroup); // just for the case that somebody copy&pastes the code - the queue has already been started in previous test
768  *
769  * // get 10 results for all 3 channels and store in temporary buffer
770  * // (the usage of a buffer is required, since the print statements used by the checks take more time than the conversions)
771  * Ifx_VADC_RES resultTrace[3*10];
772  * for(int i=0; i<3*10; ++i)
773  * {
774  * unsigned chnIx = i % 3;
775  * // wait for valid result
776  * Ifx_VADC_RES conversionResult;
777  * do {
778  * conversionResult = IfxVadc_Adc_getResult(&adcChannel[chnIx]);
779  * } while( !conversionResult.B.VF );
780  *
781  * // store result
782  * resultTrace[i] = conversionResult;
783  * }
784  *
785  * // stop the queue
786  * IfxVadc_Adc_clearQueue(&adcGroup);
787  *
788  * // check results in buffer
789  *
790  * \endcode
791  *
792  */
794 
795 /******************************************************************************/
796 /*-------------------------Global Function Prototypes-------------------------*/
797 /******************************************************************************/
798 
799 /** \brief Get the current channel configuration (e.g. sample settings)
800  * \param channel pointer to the VADC channel
801  * \param config pointer to the VADC channel configuration
802  * \return None
803  *
804  * Example Usage :\ref IfxLld_Vadc_Adc_Usage
805  *
806  */
808 
809 /** \brief Initialise one channel with given configuration
810  * \param channel pointer to the VADC channel
811  * \param config pointer to the VADC channel configuration
812  * \return IfxVadc_Status
813  *
814  * \code
815  * // create channel config
816  * IfxVadc_Adc_ChannelConfig adcChannelConfig;
817  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig, &adcGroup);
818  *
819  * // change channel (default is ChannelId0, change to ChannelId2)
820  * adcChannelConfig.channelId = IfxVadc_ChannelId2;
821  *
822  * // initialize the channel
823  * IfxVadc_Adc_Channel adcChannel;
824  * IfxVadc_Adc_initChannel(&adcChannel, &adcChannelConfig);
825  * \endcode
826  *
827  */
829 
830 /** \brief Initialise buffer with default channel configuration
831  * \param config pointer to the VADC channel configuration
832  * \param group pointer to the VADC group
833  * \return None
834  *
835  * For coding example see: \ref IfxVadc_Adc_initChannel
836  *
837  */
839 
840 /** \} */
841 
842 /** \addtogroup IfxLld_Vadc_Adc_Background_Autoscan
843  * \{ */
844 
845 /******************************************************************************/
846 /*-------------------------Inline Function Prototypes-------------------------*/
847 /******************************************************************************/
848 
849 /** \brief access function to enable/disable wait for read mode for global result register
850  * \param vadc pointer to the VADC module
851  * \param waitForRead wait for read mode enabled/disabled
852  * \return None
853  *
854  * For coding example see: \ref IfxVadc_Adc_getGlobalResult
855  *
856  */
858 
859 /** \brief Gives the background scan status for a group
860  * \param vadc pointer to the VADC module
861  * \return IfxVadc_Status
862  */
864 
865 /** \brief returns result stored in global result register
866  * \param vadc pointer to the VADC module
867  * \return global result register
868  *
869  * \code
870  * // initialize module pointer
871  * IfxVadc_Adc vadc;
872  * vadc.vadc = &MODULE_VADC;
873  *
874  * // create group config
875  * IfxVadc_Adc_GroupConfig adcGroupConfig;
876  * IfxVadc_Adc_initGroupConfig(&adcGroupConfig, &vadc);
877  *
878  * // change group (default is GroupId0, change to GroupId2)
879  * adcGroupConfig.groupId = IfxVadc_GroupId2;
880  * adcGroupConfig.master = adcGroupConfig.groupId ;
881  * adcGroupConfig.backgroundScanRequest.autoscanEnabled = TRUE;
882  * adcGroupConfig.arbiter.requestSlotBackgroundScanEnabled = TRUE;
883  * adcGroupConfig.backgroundScanRequest.triggerConfig.gatingMode = IfxVadc_GatingMode_always;
884  *
885  * // initialize the group
886  * IfxVadc_Adc_Group adcGroup;
887  * IfxVadc_Adc_initGroup(&adcGroup, &adcGroupConfig);
888  *
889  * // create channel config
890  * IfxVadc_Adc_ChannelConfig adcChannelConfig2;
891  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig2, &adcGroup);
892  * adcChannelConfig2.backgroundChannel = TRUE;
893  * adcChannelConfig2.globalResultUsage = TRUE;
894  * // change channel (default is ChannelId0, change to ChannelId2)
895  * adcChannelConfig2.channelId = IfxVadc_ChannelId2;
896  *
897  * // initialize the channel
898  * IfxVadc_Adc_Channel adcChannel2;
899  * IfxVadc_Adc_initChannel(&adcChannel2, &adcChannelConfig2);
900  *
901  * // create channel config
902  * IfxVadc_Adc_ChannelConfig adcChannelConfig5;
903  * IfxVadc_Adc_initChannelConfig(&adcChannelConfig5, &adcGroup);
904  * adcChannelConfig5.backgroundChannel = TRUE;
905  * adcChannelConfig5.globalResultUsage = TRUE;
906  * // change channel (default is ChannelId0, change to ChannelId5)
907  * adcChannelConfig5.channelId = IfxVadc_ChannelId5;
908  *
909  *
910  * // initialize the channel
911  * IfxVadc_Adc_Channel adcChannel5;
912  * IfxVadc_Adc_initChannel(&adcChannel5, &adcChannelConfig5);
913  *
914  * uint32 channels = (1 << 5) | (1 << 2); // enable channel #5 and #2
915  * uint32 mask = (1 << 7) | (1 << 5) | (1 << 2); // modify the selection for channel #7, #5 and #2; channel #7 will be disabled
916  * boolean continuous = TRUE; // disable continuous background scan
917  * //configure wait for read mode
918  * IfxVadc_Adc_configureWaitForReadModeForGlobalResultRegister(&vadc, TRUE);
919  *
920  * // configure background scan
921  * IfxVadc_Adc_setBackgroundScan(&vadc, &adcGroupConfig, channels, mask);
922  *
923  * // start the background scan
924  * IfxVadc_Adc_startBackgroundScan(&vadc, continuous);
925  *
926  * // wait for valid result for channel 2
927  * Ifx_VADC_GLOBRES resultChannel2;
928  * do {
929  * resultChannel2 = IfxVadc_Adc_getGlobalResult(&vadc);
930  * } while( !resultChannel2.B.VF );
931  *
932  * // wait for valid result for channel 5
933  * Ifx_VADC_GLOBRES resultChannel5;
934  * do {
935  * resultChannel5 = IfxVadc_Adc_getGlobalResult(&vadc);
936  * } while( !resultChannel5.B.VF );
937  * \endcode
938  *
939  */
940 IFX_INLINE Ifx_VADC_GLOBRES IfxVadc_Adc_getGlobalResult(IfxVadc_Adc *vadc);
941 
942 /** \brief configures a background scan; can also stop autoscan if all channels are 0
943  * \param vadc pointer to the VADC module
944  * \param group pointer to the VADC group
945  * \param channels specifies the channels which should be enabled/disabled
946  * \param mask specifies the channels which should be modified
947  * \return None
948  *
949  * For coding example see: \ref IfxVadc_Adc_getGlobalResult
950  *
951  */
953 
954 /** \brief Starts a background scan in either continuous or single shot conversion mode as per the parameter
955  * \param vadc pointer to the VADC module
956  * \param continuous continuous or single shot conversion
957  * \return None
958  *
959  * For coding example see: \ref IfxVadc_Adc_getGlobalResult
960  *
961  */
962 IFX_INLINE void IfxVadc_Adc_startBackgroundScan(IfxVadc_Adc *vadc, boolean continuous);
963 
964 /** \} */
965 
966 /** \addtogroup IfxLld_Vadc_Adc_ChannelScan
967  * \{ */
968 
969 /******************************************************************************/
970 /*-------------------------Inline Function Prototypes-------------------------*/
971 /******************************************************************************/
972 
973 /** \brief Gives the scan status for a group.
974  * \param group pointer to the VADC group
975  * \return IfxVadc_Status
976  *
977  * For coding example see: \ref IfxVadc_Adc_getResultBasedOnRequestSource
978  *
979  */
981 
982 /** \brief Configures an autoscan.
983  * \param group pointer to the VADC group
984  * \param channels specifies the channels which should be enabled/disabled
985  * \param mask specifies the channels which should be modified
986  * \param continuous specifies if single triggered or continuous autoscan
987  * \return None
988  *
989  * For coding example see: \ref IfxVadc_Adc_getResultBasedOnRequestSource
990  *
991  */
992 IFX_INLINE void IfxVadc_Adc_setScan(IfxVadc_Adc_Group *group, uint32 channels, uint32 mask, boolean continuous);
993 
994 /** \brief Starts an autoscan on the specified group
995  * \param group pointer to the VADC group
996  * \return None
997  *
998  * For coding example see: \ref IfxVadc_Adc_getResultBasedOnRequestSource
999  *
1000  */
1002 
1003 /** \} */
1004 
1005 /** \addtogroup IfxLld_Vadc_Adc_Queue
1006  * \{ */
1007 
1008 /******************************************************************************/
1009 /*-------------------------Inline Function Prototypes-------------------------*/
1010 /******************************************************************************/
1011 
1012 /** \brief Add an entry to the queue of a group for the specified channel with the following options set:
1013  * refill
1014  * source interrupt enable/disable
1015  * external trigger control
1016  * \param channel pointer to the VADC channel
1017  * \param options options for channel
1018  * \return None
1019  *
1020  * For coding example see: \ref IfxVadc_Adc_getResult
1021  *
1022  */
1024 
1025 /** \brief Flush the contents of the queue of a group
1026  * \param group pointer to the VADC group
1027  * \return None
1028  *
1029  * For coding example see: \ref IfxVadc_Adc_getResult
1030  *
1031  */
1033 
1034 /** \brief Gives the status of the Queue of a group by returning non zero value if the Queue is full
1035  * \param group pointer to the VADC group
1036  * \return Queue status
1037  *
1038  * For coding example see: \ref IfxVadc_Adc_getResult
1039  *
1040  */
1042 
1043 /** \brief Starts a queue of a group by generating a trigger event through software
1044  * \param group pointer to the VADC group
1045  * \return None
1046  *
1047  * For coding example see: \ref IfxVadc_Adc_getResult
1048  *
1049  */
1051 
1052 /** \} */
1053 
1054 /******************************************************************************/
1055 /*---------------------Inline Function Implementations------------------------*/
1056 /******************************************************************************/
1057 
1059 {
1060  Ifx_VADC *vadcSFR = vadc->vadc;
1061 
1062  IfxVadc_resetKernel(vadcSFR);
1063 }
1064 
1065 
1067 {
1068  config->vadc = vadc->vadc;
1071 }
1072 
1073 
1075 {
1076  return IfxVadc_getResultBasedOnRequestSource(group->module.vadc, group->group, channel, sourceType);
1077 }
1078 
1079 
1081 {
1082  return group->group;
1083 }
1084 
1085 
1086 IFX_INLINE void IfxVadc_Adc_getGroupResult(IfxVadc_Adc_Group *group, Ifx_VADC_RES *results, uint32 resultOffset, uint32 numResults)
1087 {
1088  IfxVadc_getGroupResult(group->group, results, resultOffset, numResults);
1089 }
1090 
1091 
1093 {
1094  return group->module.vadc;
1095 }
1096 
1097 
1099 {
1100  IfxVadc_configureWaitForReadMode(channel->group->group, channel->resultreg, waitForRead);
1101 }
1102 
1103 
1105 {
1106  return IfxVadc_getResult(channel->group->group, channel->resultreg);
1107 }
1108 
1109 
1111 {
1113 }
1114 
1115 
1117 {
1118  return IfxVadc_getBackgroundScanStatus(vadc->vadc);
1119 }
1120 
1121 
1123 {
1124  return IfxVadc_getGlobalResult(vadc->vadc);
1125 }
1126 
1127 
1129 {
1130  IfxVadc_setBackgroundScan(vadc->vadc, group->groupId, channels, mask);
1131 }
1132 
1133 
1135 {
1136  IfxVadc_startBackgroundScan(vadc->vadc, continuous);
1137 }
1138 
1139 
1141 {
1142  return IfxVadc_getScanStatus(group->group);
1143 }
1144 
1145 
1146 IFX_INLINE void IfxVadc_Adc_setScan(IfxVadc_Adc_Group *group, uint32 channels, uint32 mask, boolean continuous)
1147 {
1148  IfxVadc_setScan(group->group, channels, mask, continuous);
1149 }
1150 
1151 
1153 {
1154  IfxVadc_startScan(group->group);
1155 }
1156 
1157 
1159 {
1160  IfxVadc_addToQueue(channel->group->group, channel->channel, options);
1161 }
1162 
1163 
1165 {
1166  IfxVadc_clearQueue(group->group, TRUE);
1167 }
1168 
1169 
1171 {
1172  return IfxVadc_getQueueStatus(group->group);
1173 }
1174 
1175 
1177 {
1178  IfxVadc_startQueue(group->group);
1179 }
1180 
1181 
1182 #endif /* IFXVADC_ADC_H */