S32 SDK
adc_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
37 #include <stddef.h>
38 #include "adc_driver.h"
39 #include "adc_hal.h"
40 
41 /*******************************************************************************
42  * Variables
43  ******************************************************************************/
44 
45 /* Table of base addresses for ADC instances. */
47 
48 /*FUNCTION**********************************************************************
49  *
50  * Function Name : ADC_DRV_InitConverterStruct
51  * Description : This function initializes the members of the adc_converter_config_t
52  * structure to default values (Reference Manual resets). This function should be called
53  * on a structure before using it to configure the converter (ADC_DRV_ConfigConverter), otherwise all members
54  * must be written (initialized) by the caller. This function insures that all members are written
55  * with safe values, so the user can modify only the desired members.
56  *
57  * Implements : ADC_DRV_InitConverterStruct_Activity
58  *END**************************************************************************/
60 {
61  DEV_ASSERT(config != NULL);
62 
63  config->clockDivide = ADC_CLK_DIVIDE_1;
64  config->sampleTime = (uint8_t)0x0CU;
66  config->inputClock = ADC_CLK_ALT_1;
67  config->trigger = ADC_TRIGGER_SOFTWARE;
68  config->dmaEnable = false;
70  config->continuousConvEnable = false;
71 }
72 
73 /*FUNCTION**********************************************************************
74  *
75  * Function Name : ADC_DRV_ConfigConverter
76  * Description : This function configures the ADC converter with the options
77  * provided in the configuration structure.
78  *
79  * Implements : ADC_DRV_ConfigConverter_Activity
80  *END**************************************************************************/
81 void ADC_DRV_ConfigConverter(const uint32_t instance,
82  const adc_converter_config_t * const config)
83 {
84  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
85  DEV_ASSERT(config != NULL);
86 
87  ADC_Type * const base = s_adcBase[instance];
88  ADC_HAL_SetClockDivide(base, config->clockDivide);
89  ADC_HAL_SetSampleTime(base, config->sampleTime);
90  ADC_HAL_SetResolution(base, config->resolution);
91  ADC_HAL_SetInputClock(base, config->inputClock);
92  ADC_HAL_SetTriggerMode(base, config->trigger);
93  ADC_HAL_SetDMAEnableFlag(base, config->dmaEnable);
96 }
97 
98 /*FUNCTION**********************************************************************
99  *
100  * Function Name : ADC_DRV_GetConverterConfig
101  * Description : This functions returns the current converter configuration in
102  * the form of a configuration structure.
103  *
104  * Implements : ADC_DRV_GetConverterConfig_Activity
105  *END**************************************************************************/
106 void ADC_DRV_GetConverterConfig(const uint32_t instance,
107  adc_converter_config_t * const config)
108 {
109  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
110  DEV_ASSERT(config != NULL);
111 
112  const ADC_Type * const base = s_adcBase[instance];
113  config->clockDivide = ADC_HAL_GetClockDivide(base);
114  config->sampleTime = ADC_HAL_GetSampleTime(base);
115  config->resolution = ADC_HAL_GetResolution(base);
116  config->inputClock = ADC_HAL_GetInputClock(base);
117  config->trigger = ADC_HAL_GetTriggerMode(base);
118  config->dmaEnable = ADC_HAL_GetDMAEnableFlag(base);
119  config->voltageRef = ADC_HAL_GetVoltageReference(base);
121 }
122 
123 /*FUNCTION**********************************************************************
124  *
125  * Function Name : ADC_DRV_Reset
126  * Description : This function writes all the internal ADC registers with
127  * their Reference Manual reset values.
128  *
129  * Implements : ADC_DRV_Reset_Activity
130  *END**************************************************************************/
131 void ADC_DRV_Reset(const uint32_t instance)
132 {
133  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
134 
135  ADC_Type * const base = s_adcBase[instance];
136  ADC_HAL_Init(base);
137 }
138 
139 /*FUNCTION**********************************************************************
140  *
141  * Function Name : ADC_DRV_InitHwCompareStruct
142  * Description : This function initializes the Hardware Compare configuration
143  * structure to default values (Reference Manual resets). This function should be
144  * called before configuring the Hardware Compare feature (ADC_DRV_ConfigHwCompare),
145  * otherwise all members must be written by the caller. This function insures that all
146  * members are written with safe values, so the user can modify the desired members.
147  *
148  * Implements : ADC_DRV_InitHwCompareStruct_Activity
149  *END**************************************************************************/
151 {
152  DEV_ASSERT(config != NULL);
153 
154  config->compareEnable = false;
155  config->compareGreaterThanEnable = false;
156  config->compareRangeFuncEnable = false;
157  config->compVal1 = 0U;
158  config->compVal2 = 0U;
159 }
160 
161 /*FUNCTION**********************************************************************
162  *
163  * Function Name : ADC_DRV_ConfigHwCompare
164  * Description : This functions sets the configuration for the Hardware
165  * Compare feature using the configuration structure.
166  *
167  * Implements : ADC_DRV_ConfigHwCompare_Activity
168  *END**************************************************************************/
169 void ADC_DRV_ConfigHwCompare(const uint32_t instance,
170  const adc_compare_config_t * const config)
171 {
172  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
173  DEV_ASSERT(config != NULL);
174 
175  ADC_Type * const base = s_adcBase[instance];
181 }
182 
183 /*FUNCTION**********************************************************************
184  *
185  * Function Name : ADC_DRV_GetHwCompareConfig
186  * Description : This function returns the configuration for the Hardware
187  * Compare feature.
188  *
189  * Implements : ADC_DRV_GetHwCompareConfig_Activity
190  *END**************************************************************************/
191 void ADC_DRV_GetHwCompareConfig(const uint32_t instance,
192  adc_compare_config_t * const config)
193 {
194  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
195  DEV_ASSERT(config != NULL);
196 
197  const ADC_Type * const base = s_adcBase[instance];
203 }
204 
205 /*FUNCTION**********************************************************************
206  *
207  * Function Name : ADC_DRV_InitHwAverageStruct
208  * Description : This function initializes the Hardware Average configuration
209  * structure to default values (Reference Manual resets). This function should be
210  * called before configuring the Hardware Average feature (ADC_DRV_ConfigHwAverage),
211  * otherwise all members must be written by the caller. This function insures that all
212  * members are written with safe values, so the user can modify the desired members.
213  *
214  * Implements : ADC_DRV_InitHwAverageStruct_Activity
215  *END**************************************************************************/
217 {
218  DEV_ASSERT(config != NULL);
219 
220  config->hwAvgEnable = false;
221  config->hwAverage = ADC_AVERAGE_4;
222 }
223 
224 /*FUNCTION**********************************************************************
225  *
226  * Function Name : ADC_DRV_ConfigHwAverage
227  * Description : This function sets the configuration for the Hardware
228  * Average feature.
229  *
230  * Implements : ADC_DRV_ConfigHwAverage_Activity
231  *END**************************************************************************/
232 void ADC_DRV_ConfigHwAverage(const uint32_t instance,
233  const adc_average_config_t * const config)
234 {
235  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
236  DEV_ASSERT(config != NULL);
237 
238  ADC_Type * const base = s_adcBase[instance];
240  ADC_HAL_SetHwAverageMode(base, config->hwAverage);
241 }
242 
243 /*FUNCTION**********************************************************************
244  *
245  * Function Name : ADC_DRV_GetHwAverageConfig
246  * Description : This function returns the configuration for the Hardware
247  * Average feature.
248  *
249  * Implements : ADC_DRV_GetHwAverageConfig_Activity
250  *END**************************************************************************/
251 void ADC_DRV_GetHwAverageConfig(const uint32_t instance,
252  adc_average_config_t * const config)
253 {
254  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
255  DEV_ASSERT(config != NULL);
256 
257  const ADC_Type * const base = s_adcBase[instance];
259  config->hwAverage = ADC_HAL_GetHwAverageMode(base);
260 }
261 
262 /*FUNCTION**********************************************************************
263  *
264  * Function Name : ADC_DRV_InitChanStruct
265  * Description : This function initializes the control channel
266  * configuration structure to default values (Reference Manual resets). This function should
267  * be called on a structure before using it to configure a channel (ADC_DRV_ConfigChan), otherwise
268  * all members must be written by the caller. This function insures that all members are written
269  * with safe values, so the user can modify only the desired members.
270  *
271  * Implements : ADC_DRV_InitChanStruct_Activity
272  *END**************************************************************************/
274 {
275  DEV_ASSERT(config != NULL);
276 
277  config->interruptEnable = false;
279 }
280 
281 /*FUNCTION**********************************************************************
282  *
283  * Function Name : ADC_DRV_ConfigChan
284  * Description : This function sets a control channel configuration.
285  * In Software Trigger mode, only control channel (chanIndex) 0 can start conversions.
286  *
287  * Implements : ADC_DRV_ConfigChan_Activity
288  *END**************************************************************************/
289 void ADC_DRV_ConfigChan(const uint32_t instance,
290  const uint8_t chanIndex,
291  const adc_chan_config_t * const config)
292 {
293  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
294  DEV_ASSERT(chanIndex < ADC_SC1_COUNT);
295  DEV_ASSERT(config != NULL);
296 
297  ADC_Type * const base = s_adcBase[instance];
298  ADC_HAL_SetChanInterruptEnableFlag(base, chanIndex, config->interruptEnable);
299  ADC_HAL_SetInputChannel(base, chanIndex, config->channel);
300 }
301 
302 /*FUNCTION**********************************************************************
303  *
304  * Function Name : ADC_DRV_GetChanConfig
305  * Description : This function returns the current configuration for a control
306  * channel.
307  *
308  * Implements : ADC_DRV_GetChanConfig_Activity
309  *END**************************************************************************/
310 void ADC_DRV_GetChanConfig(const uint32_t instance,
311  const uint8_t chanIndex,
312  adc_chan_config_t * const config)
313 {
314  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
315  DEV_ASSERT(chanIndex < ADC_SC1_COUNT);
316  DEV_ASSERT(config != NULL);
317 
318  const ADC_Type * const base = s_adcBase[instance];
319  config->interruptEnable = ADC_HAL_GetChanInterruptEnableFlag(base, chanIndex);
320  config->channel = ADC_HAL_GetInputChannel(base, chanIndex);
321 }
322 
323 /*FUNCTION**********************************************************************
324  *
325  * Function Name : ADC_DRV_WaitConvDone
326  * Description : This functions waits for a conversion to complete by
327  * continuously polling the Conversion Active Flag.
328  *
329  * Implements : ADC_DRV_WaitConvDone_Activity
330  *END**************************************************************************/
331 void ADC_DRV_WaitConvDone(const uint32_t instance)
332 {
333  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
334 
335  const ADC_Type * const base = s_adcBase[instance];
336  while (ADC_HAL_GetConvActiveFlag(base) == true)
337  {
338  /* Wait for conversion to finish */
339  }
340 }
341 
342 /*FUNCTION**********************************************************************
343  *
344  * Function Name : ADC_DRV_GetChanResult
345  * Description : This function returns the conversion result from a
346  * control channel.
347  *
348  * Implements : ADC_DRV_GetChanResult_Activity
349  *END**************************************************************************/
350 void ADC_DRV_GetChanResult(const uint32_t instance,
351  const uint8_t chanIndex,
352  uint16_t * const result)
353 {
354  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
355  DEV_ASSERT(chanIndex < ADC_R_COUNT);
356  DEV_ASSERT(result != NULL);
357 
358  const ADC_Type * const base = s_adcBase[instance];
359  *result = ADC_HAL_GetChanResult(base, chanIndex);
360 }
361 
362 /*FUNCTION**********************************************************************
363  *
364  * Function Name : ADC_DRV_AutoCalibration
365  * Description : This functions executes an Auto-Calibration sequence. It
366  * is recommended to run this sequence before using the ADC converter.
367  *
368  * Implements : ADC_DRV_AutoCalibration_Activity
369  *END**************************************************************************/
370 void ADC_DRV_AutoCalibration(const uint32_t instance)
371 {
372  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
373 
374  ADC_Type * const base = s_adcBase[instance];
375  /* set hardware average to maximum and set software trigger*/
376  bool hwavgen = ADC_HAL_GetHwAverageEnableFlag(base);
380  ADC_HAL_SetHwAverageEnableFlag(base, true);
382 
383  base->CLPS = 0x00u;
384  base->CLP3 = 0x00u;
385  base->CLP2 = 0x00u;
386  base->CLP1 = 0x00u;
387  base->CLP0 = 0x00u;
388  base->CLPX = 0x00u;
389  base->CLP9 = 0x00u;
390 
391  /* start calibration */
394  {
395  /* Wait for calibration to finish */
396  }
397 
398  /* restore hardware average and trigger settings*/
399  ADC_HAL_SetHwAverageEnableFlag(base, hwavgen);
400  ADC_HAL_SetHwAverageMode(base, hwavg);
401  ADC_HAL_SetTriggerMode(base, trig);
402 }
403 
404 /*FUNCTION**********************************************************************
405  *
406  * Function Name : ADC_DRV_InitUserCalibrationStruct
407  * Description : This function initializes the User Calibration configuration
408  * structure to default values (Reference Manual resets). This function should be called
409  * on a structure before using it to configure the User Calibration feature (ADC_DRV_ConfigUserCalibration),
410  * otherwise all members must be written by the caller. This function insures that all members are written
411  * with safe values, so the user can modify only the desired members.
412  *
413  * Implements : ADC_DRV_InitUserCalibrationStruct_Activity
414  *END**************************************************************************/
416 {
417  DEV_ASSERT(config != NULL);
418 
419  config->userGain = (uint16_t)4U;
420  config->userOffset = (uint16_t)0U;
421 }
422 
423 /*FUNCTION**********************************************************************
424  *
425  * Function Name : ADC_DRV_ConfigUserCalibration
426  * Description : This function sets the configuration for the user calibration
427  * registers.
428  *
429  * Implements : ADC_DRV_ConfigUserCalibration_Activity
430  *END**************************************************************************/
431 void ADC_DRV_ConfigUserCalibration(const uint32_t instance,
432  const adc_calibration_t * const config)
433 {
434  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
435  DEV_ASSERT(config != NULL);
436 
437  ADC_Type * const base = s_adcBase[instance];
438  ADC_HAL_SetUserGainValue(base, config->userGain);
439  ADC_HAL_SetUserOffsetValue(base, config->userOffset);
440 }
441 
442 /*FUNCTION**********************************************************************
443  *
444  * Function Name : ADC_DRV_GetUserCalibration
445  * Description : This function returns the current user calibration
446  * register values.
447  *
448  * Implements : ADC_DRV_GetUserCalibration_Activity
449  *END**************************************************************************/
450 void ADC_DRV_GetUserCalibration(const uint32_t instance,
451  adc_calibration_t * const config)
452 {
453  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
454  DEV_ASSERT(config != NULL);
455 
456  const ADC_Type * const base = s_adcBase[instance];
457  config->userGain = ADC_HAL_GetUserGainValue(base);
458  config->userOffset = ADC_HAL_GetUserOffsetValue(base);
459 }
460 
461 /*FUNCTION**********************************************************************
462  *
463  * Function Name : ADC_DRV_GetInterruptNumber
464  * Description : This function returns the interrupt number for the specified ADC instance.
465  *
466  * Implements : ADC_DRV_GetInterruptNumber_Activity
467  *END**************************************************************************/
468 IRQn_Type ADC_DRV_GetInterruptNumber(const uint32_t instance)
469 {
470  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
471 
472  static const IRQn_Type adcIrqId[ADC_INSTANCE_COUNT] = ADC_IRQS;
473  IRQn_Type irqId = adcIrqId[instance];
474 
475  return irqId;
476 }
477 
478 /*FUNCTION**********************************************************************
479  *
480  * Function Name : ADC_DRV_ClearLatchedTriggers
481  * Description : This function clears all trigger latched flags of the ADC instance.
482  *
483  * Implements : ADC_DRV_ClearLatchedTriggers_Activity
484  *END**************************************************************************/
485 void ADC_DRV_ClearLatchedTriggers(const uint32_t instance,
486  const adc_latch_clear_t clearMode)
487 {
488  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
489  DEV_ASSERT((clearMode == ADC_LATCH_CLEAR_WAIT) || (clearMode == ADC_LATCH_CLEAR_FORCE));
490 
491  ADC_Type * const base = s_adcBase[instance];
492  if (clearMode == ADC_LATCH_CLEAR_FORCE)
493  {
495  }
496 
497  while (ADC_HAL_GetTriggerLatchFlags(base) != 0u)
498  {
499  /* Wait for latched triggers to be processed */
500  }
501 }
502 
503 /*FUNCTION**********************************************************************
504  *
505  * Function Name : ADC_DRV_ClearTriggerErrors
506  * Description : This function clears all trigger error flags of the ADC instance.
507  *
508  * Implements : ADC_DRV_ClearTriggerErrors_Activity
509  *END**************************************************************************/
510 void ADC_DRV_ClearTriggerErrors(const uint32_t instance)
511 {
512  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
513 
514  ADC_Type * const base = s_adcBase[instance];
516 }
517 
518 /*FUNCTION**********************************************************************
519  *
520  * Function Name : ADC_DRV_GetTriggerErrorFlags
521  * Description : This function returns the trigger error flags bits of the ADC instance.
522  *
523  * Implements : ADC_DRV_GetTriggerErrorFlags_Activity
524  *END**************************************************************************/
525 uint32_t ADC_DRV_GetTriggerErrorFlags(const uint32_t instance)
526 {
527  DEV_ASSERT(instance < ADC_INSTANCE_COUNT);
528 
529  const ADC_Type * const base = s_adcBase[instance];
530  uint32_t trig_errors = ADC_HAL_GetTriggerErrorFlags(base);
531 
532  return trig_errors;
533 }
534 
535 /******************************************************************************
536  * EOF
537  *****************************************************************************/
#define ADC_INPUTCHAN_DISABLED
static ADC_Type *const s_adcBase[ADC_INSTANCE_COUNT]
Definition: adc_driver.c:46
static void ADC_HAL_SetContinuousConvFlag(ADC_Type *const baseAddr, const bool state)
Sets the Continuous Conversion Flag state.
Definition: adc_hal.h:588
static bool ADC_HAL_GetHwAverageEnableFlag(const ADC_Type *const baseAddr)
Gets the Hardware Average Enable Flag state.
Definition: adc_hal.h:832
Defines the user calibration configuration.
Definition: adc_driver.h:109
static uint16_t ADC_HAL_GetChanResult(const ADC_Type *const baseAddr, const uint8_t chanIndex)
Gets the conversion result for the selected measurement channel.
Definition: adc_hal.h:1236
static void ADC_HAL_SetChanInterruptEnableFlag(ADC_Type *const baseAddr, const uint8_t chanIndex, const bool state)
Sets the Channel Interrupt Enable to a new state.
Definition: adc_hal.h:1102
__IO uint32_t CLPS
Definition: S32K144.h:424
uint32_t ADC_DRV_GetTriggerErrorFlags(const uint32_t instance)
This function returns the trigger error flags bits of the ADC instance.
Definition: adc_driver.c:525
void ADC_DRV_AutoCalibration(const uint32_t instance)
Executes an Auto-Calibration.
Definition: adc_driver.c:370
static void ADC_HAL_SetSampleTime(ADC_Type *const baseAddr, uint8_t sampletime)
Sets the Sample time in AD clock cycles.
Definition: adc_hal.h:294
static bool ADC_HAL_GetHwCompareGtEnableFlag(const ADC_Type *const baseAddr)
Gets the Hardware Compare Greater Than Enable Flag state.
Definition: adc_hal.h:660
adc_voltage_reference_t voltageRef
Definition: adc_driver.h:52
void ADC_DRV_GetHwAverageConfig(const uint32_t instance, adc_average_config_t *const config)
Gets the current Hardware Average configuration.
Definition: adc_driver.c:251
static void ADC_HAL_SetUserOffsetValue(ADC_Type *const baseAddr, const uint16_t value)
Sets the User Offset Register value.
Definition: adc_hal.h:1052
void ADC_DRV_InitHwCompareStruct(adc_compare_config_t *const config)
Initializes the Hardware Compare configuration structure.
Definition: adc_driver.c:150
void ADC_DRV_InitHwAverageStruct(adc_average_config_t *const config)
Initializes the Hardware Average configuration structure.
Definition: adc_driver.c:216
static adc_trigger_t ADC_HAL_GetTriggerMode(const ADC_Type *const baseAddr)
Gets the ADC Trigger Mode.
Definition: adc_hal.h:431
static bool ADC_HAL_GetConvActiveFlag(const ADC_Type *const baseAddr)
Gets the Conversion Active Flag.
Definition: adc_hal.h:204
void ADC_DRV_ConfigConverter(const uint32_t instance, const adc_converter_config_t *const config)
Configures the converter with the given configuration structure.
Definition: adc_driver.c:81
static uint16_t ADC_HAL_GetHwCompareComp2Value(const ADC_Type *const baseAddr)
Gets the Compare Register 2 value.
Definition: adc_hal.h:786
static void ADC_HAL_SetInputClock(ADC_Type *const baseAddr, const adc_input_clock_t inputClock)
Sets the AD Clock Input configuration.
Definition: adc_hal.h:405
static void ADC_HAL_SetCalibrationActiveFlag(ADC_Type *const baseAddr, const bool state)
Sets the Calibration Active Flag state.
Definition: adc_hal.h:953
adc_input_clock_t inputClock
Definition: adc_driver.h:49
void ADC_DRV_ConfigUserCalibration(const uint32_t instance, const adc_calibration_t *const config)
Configures the User Calibration feature with the given configuration structure.
Definition: adc_driver.c:431
static void ADC_HAL_SetClockDivide(ADC_Type *const baseAddr, const adc_clk_divide_t clockDivide)
Sets the ADC clock divider configuration.
Definition: adc_hal.h:250
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K144.h:269
void ADC_DRV_Reset(const uint32_t instance)
Resets the converter (sets all configurations to reset values)
Definition: adc_driver.c:131
__IO uint32_t CLP9
Definition: S32K144.h:430
adc_clk_divide_t clockDivide
Definition: adc_driver.h:46
void ADC_DRV_GetChanResult(const uint32_t instance, const uint8_t chanIndex, uint16_t *const result)
Gets the last result for the selected control channel.
Definition: adc_driver.c:350
#define ADC_R_COUNT
Definition: S32K144.h:405
uint16_t userGain
Definition: adc_driver.h:111
Defines the hardware average configuration.
Definition: adc_driver.h:81
adc_trigger_t trigger
Definition: adc_driver.h:50
void ADC_DRV_ConfigChan(const uint32_t instance, const uint8_t chanIndex, const adc_chan_config_t *const config)
Configures the selected control channel with the given configuration structure.
Definition: adc_driver.c:289
static bool ADC_HAL_GetContinuousConvFlag(const ADC_Type *const baseAddr)
Gets the Continuous Conversion Flag state.
Definition: adc_hal.h:566
void ADC_DRV_ConfigHwCompare(const uint32_t instance, const adc_compare_config_t *const config)
Configures the Hardware Compare feature with the given configuration structure.
Definition: adc_driver.c:169
#define DEV_ASSERT(x)
Definition: devassert.h:78
void ADC_DRV_GetChanConfig(const uint32_t instance, const uint8_t chanIndex, adc_chan_config_t *const config)
Gets the current control channel configuration for the selected channel index.
Definition: adc_driver.c:310
static uint16_t ADC_HAL_GetUserGainValue(const ADC_Type *const baseAddr)
Gets the User Gain Register value.
Definition: adc_hal.h:975
__IO uint32_t CLP3
Definition: S32K144.h:425
__IO uint32_t CLP0
Definition: S32K144.h:428
void ADC_DRV_InitChanStruct(adc_chan_config_t *const config)
Initializes the control channel configuration structure.
Definition: adc_driver.c:273
__IO uint32_t CLP2
Definition: S32K144.h:426
void ADC_DRV_InitConverterStruct(adc_converter_config_t *const config)
Initializes the converter configuration structure.
Definition: adc_driver.c:59
void ADC_DRV_ClearTriggerErrors(const uint32_t instance)
Clear all latch trigger error.
Definition: adc_driver.c:510
static void ADC_HAL_ClearLatchTriggers(ADC_Type *const baseAddr)
Clear the latched triggers.
Definition: adc_hal.h:1263
void ADC_DRV_GetConverterConfig(const uint32_t instance, adc_converter_config_t *const config)
Gets the current converter configuration.
Definition: adc_driver.c:106
static bool ADC_HAL_GetHwCompareRangeEnableFlag(const ADC_Type *const baseAddr)
Gets the Hardware Compare Range Enable state.
Definition: adc_hal.h:703
static void ADC_HAL_SetUserGainValue(ADC_Type *const baseAddr, const uint16_t value)
Sets the User Gain Register value.
Definition: adc_hal.h:995
void ADC_DRV_InitUserCalibrationStruct(adc_calibration_t *const config)
Initializes the User Calibration configuration structure.
Definition: adc_driver.c:415
__IO uint32_t CLP1
Definition: S32K144.h:427
static void ADC_HAL_SetHwAverageEnableFlag(ADC_Type *const baseAddr, const bool state)
Sets the Hardware Average Enable Flag state.
Definition: adc_hal.h:852
IRQn_Type ADC_DRV_GetInterruptNumber(const uint32_t instance)
Returns the interrupt number for the ADC instance.
Definition: adc_driver.c:468
static uint32_t ADC_HAL_GetTriggerLatchFlags(const ADC_Type *const baseAddr)
Get the trigger latch flags bits.
Definition: adc_hal.h:1310
static adc_inputchannel_t ADC_HAL_GetInputChannel(const ADC_Type *const baseAddr, const uint8_t chanIndex)
Gets the configured input channel for the selected measurement channel.
Definition: adc_hal.h:1146
static void ADC_HAL_SetResolution(ADC_Type *const baseAddr, const adc_resolution_t resolution)
Sets the Resolution Mode configuration.
Definition: adc_hal.h:357
Defines the converter configuration.
Definition: adc_driver.h:44
static void ADC_HAL_SetHwCompareComp1Value(ADC_Type *const baseAddr, const uint16_t value)
Sets the Compare Register 1 value.
Definition: adc_hal.h:766
static uint32_t ADC_HAL_GetTriggerErrorFlags(const ADC_Type *const baseAddr)
Get the trigger latch error flags.
Definition: adc_hal.h:1278
static void ADC_HAL_ClearTriggerErrorFlags(ADC_Type *const baseAddr)
Clear the latch trigger error flags.
Definition: adc_hal.h:1295
#define ADC_INSTANCE_COUNT
Definition: S32K144.h:441
void ADC_HAL_Init(ADC_Type *const baseAddr)
Initializes the ADC instance to reset values.
Definition: adc_hal.c:45
adc_average_t
Hardware average selection Implements : adc_average_t_Class.
Definition: adc_hal.h:110
__IO uint32_t CLPX
Definition: S32K144.h:429
static void ADC_HAL_SetHwCompareGtEnableFlag(ADC_Type *const baseAddr, const bool state)
Sets the Hardware Compare Greater Than Enable Flag state.
Definition: adc_hal.h:681
static void ADC_HAL_SetInputChannel(ADC_Type *const baseAddr, const uint8_t chanIndex, const adc_inputchannel_t inputChan)
Sets the input channel configuration for the measurement channel.
Definition: adc_hal.h:1190
static adc_clk_divide_t ADC_HAL_GetClockDivide(const ADC_Type *const baseAddr)
Gets the current ADC clock divider configuration.
Definition: adc_hal.h:227
static bool ADC_HAL_GetDMAEnableFlag(const ADC_Type *const baseAddr)
Gets the DMA Enable Flag state.
Definition: adc_hal.h:477
static adc_average_t ADC_HAL_GetHwAverageMode(const ADC_Type *const baseAddr)
Gets the Hardware Average Mode.
Definition: adc_hal.h:878
void ADC_DRV_GetUserCalibration(const uint32_t instance, adc_calibration_t *const config)
Gets the current User Calibration configuration.
Definition: adc_driver.c:450
static uint16_t ADC_HAL_GetUserOffsetValue(const ADC_Type *const baseAddr)
Gets the User Offset Register value.
Definition: adc_hal.h:1030
#define ADC_BASE_PTRS
Definition: S32K144.h:456
static void ADC_HAL_SetTriggerMode(ADC_Type *const baseAddr, const adc_trigger_t trigger)
Sets the ADC Trigger Mode.
Definition: adc_hal.h:456
adc_trigger_t
Trigger type selection Implements : adc_trigger_t_Class.
Definition: adc_hal.h:90
static void ADC_HAL_SetHwCompareEnableFlag(ADC_Type *const baseAddr, const bool state)
Sets the Hardware Compare Enable Flag state.
Definition: adc_hal.h:638
static void ADC_HAL_SetHwCompareRangeEnableFlag(ADC_Type *const baseAddr, const bool state)
Sets the Hardware Compare Range Enable state.
Definition: adc_hal.h:724
static adc_voltage_reference_t ADC_HAL_GetVoltageReference(const ADC_Type *const baseAddr)
Gets the ADC Reference Voltage selection.
Definition: adc_hal.h:520
static void ADC_HAL_SetHwCompareComp2Value(ADC_Type *const baseAddr, const uint16_t value)
Sets the Compare Register 2 value.
Definition: adc_hal.h:805
#define ADC_IRQS
Definition: S32K144.h:462
static uint16_t ADC_HAL_GetHwCompareComp1Value(const ADC_Type *const baseAddr)
Gets the Compare Register 1 value.
Definition: adc_hal.h:747
static void ADC_HAL_SetVoltageReference(ADC_Type *const baseAddr, const adc_voltage_reference_t voltageRef)
Sets the ADC Reference Voltage selection.
Definition: adc_hal.h:543
static adc_resolution_t ADC_HAL_GetResolution(const ADC_Type *const baseAddr)
Gets the Resolution Mode configuration.
Definition: adc_hal.h:319
bool compareGreaterThanEnable
Definition: adc_driver.h:67
adc_average_t hwAverage
Definition: adc_driver.h:84
void ADC_DRV_ClearLatchedTriggers(const uint32_t instance, const adc_latch_clear_t clearMode)
Clear latched triggers under processing.
Definition: adc_driver.c:485
static adc_input_clock_t ADC_HAL_GetInputClock(const ADC_Type *const baseAddr)
Gets the AD Clock Input configuration.
Definition: adc_hal.h:381
static void ADC_HAL_SetDMAEnableFlag(ADC_Type *const baseAddr, const bool state)
Sets the DMA Enable Flag state.
Definition: adc_hal.h:497
adc_latch_clear_t
Defines the trigger latch clear method Implements : adc_latch_clear_t_Class.
Definition: adc_driver.h:119
static uint8_t ADC_HAL_GetSampleTime(const ADC_Type *const baseAddr)
Gets the Sample time in AD clock cycles.
Definition: adc_hal.h:272
static void ADC_HAL_SetHwAverageMode(ADC_Type *const baseAddr, const adc_average_t averageMode)
Sets the Hardware Average Mode.
Definition: adc_hal.h:903
void ADC_DRV_WaitConvDone(const uint32_t instance)
Waits for a conversion/calibration to finish.
Definition: adc_driver.c:331
static bool ADC_HAL_GetChanInterruptEnableFlag(const ADC_Type *const baseAddr, const uint8_t chanIndex)
Gets the Channel Interrupt Enable state.
Definition: adc_hal.h:1079
#define ADC_SC1_COUNT
Definition: S32K144.h:404
adc_resolution_t resolution
Definition: adc_driver.h:48
uint16_t userOffset
Definition: adc_driver.h:112
void ADC_DRV_GetHwCompareConfig(const uint32_t instance, adc_compare_config_t *const config)
Gets the current Hardware Compare configuration.
Definition: adc_driver.c:191
static bool ADC_HAL_GetCalibrationActiveFlag(const ADC_Type *const baseAddr)
Gets the Calibration Active Flag state.
Definition: adc_hal.h:933
static bool ADC_HAL_GetHwCompareEnableFlag(const ADC_Type *const baseAddr)
Gets the Hardware Compare Enable Flag state.
Definition: adc_hal.h:618
void ADC_DRV_ConfigHwAverage(const uint32_t instance, const adc_average_config_t *const config)
Configures the Hardware Average feature with the given configuration structure.
Definition: adc_driver.c:232
Defines the hardware compare configuration.
Definition: adc_driver.h:64
adc_inputchannel_t channel
Definition: adc_driver.h:98
Defines the control channel configuration.
Definition: adc_driver.h:95