rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
fsl_adc12.c File Reference

Functions

static uint32_t ADC12_GetInstance (ADC_Type *base)
 Get instance number for ADC12 module.
 
static status_t ADC12_GetCalibrationStatus (ADC_Type *base)
 Check calibration failed status.
 
void ADC12_Init (ADC_Type *base, const adc12_config_t *config)
 Initialize the ADC12 module.
 
void ADC12_Deinit (ADC_Type *base)
 De-initialize the ADC12 module.
 
void ADC12_GetDefaultConfig (adc12_config_t *config)
 Gets an available pre-defined settings for converter's configuration.
 
void ADC12_SetChannelConfig (ADC_Type *base, uint32_t channelGroup, const adc12_channel_config_t *config)
 Configure the conversion channel.
 
uint32_t ADC12_GetChannelStatusFlags (ADC_Type *base, uint32_t channelGroup)
 Get the status flags of channel.
 
status_t ADC12_DoAutoCalibration (ADC_Type *base)
 Automate the hardware calibration.
 
void ADC12_SetHardwareCompareConfig (ADC_Type *base, const adc12_hardware_compare_config_t *config)
 Configure the hardware compare mode.
 
void ADC12_SetHardwareAverage (ADC_Type *base, adc12_hardware_average_mode_t mode)
 Set the hardware average mode.
 
uint32_t ADC12_GetStatusFlags (ADC_Type *base)
 Get the status flags of the converter.
 

Variables

static ADC_Type *const s_adc12Bases [] = ADC_BASE_PTRS
 Pointers to ADC12 bases for each instance.
 
static const clock_ip_name_t s_adc12Clocks [] = ADC12_CLOCKS
 Pointers to ADC12 clocks for each instance.
 

Function Documentation

◆ ADC12_GetCalibrationStatus()

static status_t ADC12_GetCalibrationStatus ( ADC_Type *  base)
static

Check calibration failed status.

Check if the calibration is failed by comparing the calibration result value with its limit range.

  1. Each calibration result value's limit range is: Symbol Min Typ Max
    OFS -48 -8 22 CLP9 -12 4 20 CLPX -16 0 16 CLPS 30 72 120 CLP0 CLPS-14 CLPS CLPS+14 CLP1 Typ1-16 Typ1=CLP0+CLP0 Typ1+16 CLP2 Typ2-20 Typ2=CLP1+CLP1-26 Typ2+20 CLP3 Typ3-36 Typ3=CLP2+CLP2 Typ3+36
  2. To get the accurate calibration value, following conditions should be met. 1). Enable hardware average and set average number to 32. 2). No parallel calibration of ADCs because they will disturb each other. 2). For VREFH pin on PCB, use 3 bypass capacitance in the range: 1uF, 100nF and 1nF and place them as close as possible to the VREFH pin.
    Parameters
    baseADC12 peripheral base address.
    Return values
    kStatus_SuccessCalibration is done successfully.
    kStatus_FailCalibration is failed.

Definition at line 92 of file fsl_adc12.c.

93{
94 /* Get raw calibration result. OFS, CLP9, CLPX are signed number. The highest position bit is the signal bit.
95 Other calibration value registers are unsigned number. */
96 int32_t OFS = (int32_t)((base->OFS & ADC_OFS_OFS_MASK) >> ADC_OFS_OFS_SHIFT);
97 int32_t CLP9 = (int32_t)((base->CLP9 & ADC_CLP9_CLP9_MASK) >> ADC_CLP9_CLP9_SHIFT);
98 int32_t CLPX = (int32_t)((base->CLPX & ADC_CLPX_CLPX_MASK) >> ADC_CLPX_CLPX_SHIFT);
99 uint32_t CLPS = ((base->CLPS & ADC_CLPS_CLPS_MASK) >> ADC_CLPS_CLPS_SHIFT);
100 uint32_t CLP0 = ((base->CLP0 & ADC_CLP0_CLP0_MASK) >> ADC_CLP0_CLP0_SHIFT);
101 uint32_t CLP1 = ((base->CLP1 & ADC_CLP1_CLP1_MASK) >> ADC_CLP1_CLP1_SHIFT);
102 uint32_t CLP2 = ((base->CLP2 & ADC_CLP2_CLP2_MASK) >> ADC_CLP2_CLP2_SHIFT);
103 uint32_t CLP3 = ((base->CLP3 & ADC_CLP3_CLP3_MASK) >> ADC_CLP3_CLP3_SHIFT);
104 uint32_t Typ1 = (CLP0 + CLP0);
105 uint32_t Typ2 = (CLP1 + CLP1 - 26U);
106 uint32_t Typ3 = (CLP2 + CLP2);
108
109 /* Transform raw calibration result to unified type int32_t when the conversion result value is signed number. */
110 OFS = ADC12_TRANSFORM_CALIBRATION_RESULT(OFS, 16);
111 CLP9 = ADC12_TRANSFORM_CALIBRATION_RESULT(CLP9, 7);
112 CLPX = ADC12_TRANSFORM_CALIBRATION_RESULT(CLPX, 7);
113
114 /* Check the calibration result value with its limit range. */
115
116 if ((OFS < -48) || (OFS > 22) || (CLP9 < -12) || (CLP9 > 20) || (CLPX < -16) || (CLPX > 16) || (CLPS < 30U) ||
117 (CLPS > 120U) || (CLP0 < (CLPS - 14U)) || (CLP0 > (CLPS + 14U)) || (CLP1 < (Typ1 - 16U)) ||
118 (CLP1 > (Typ1 + 16U)) || (CLP2 < (Typ2 - 20U)) || (CLP2 > (Typ2 + 20U)) || (CLP3 < (Typ3 - 36U)) ||
119 (CLP3 > (Typ3 + 36U)))
120 {
121 error = kStatus_Fail;
122 }
123
124 return error;
125}
int32_t status_t
Type used for all status and error return values.
Definition fsl_common.h:169
@ kStatus_Success
Definition fsl_common.h:159
@ kStatus_Fail
Definition fsl_common.h:160

Referenced by ADC12_GetStatusFlags().

Here is the caller graph for this function:

◆ ADC12_GetInstance()

static uint32_t ADC12_GetInstance ( ADC_Type *  base)
static

Get instance number for ADC12 module.

Parameters
baseADC12 peripheral base address

Definition at line 74 of file fsl_adc12.c.

75{
76 uint32_t instance;
77
78 /* Find the instance index from base address mappings. */
79 for (instance = 0; instance < ARRAY_SIZE(s_adc12Bases); instance++)
80 {
81 if (s_adc12Bases[instance] == base)
82 {
83 break;
84 }
85 }
86
87 assert(instance < ARRAY_SIZE(s_adc12Bases));
88
89 return instance;
90}
static BenchController instance
static ADC_Type *const s_adc12Bases[]
Pointers to ADC12 bases for each instance.
Definition fsl_adc12.c:65

Referenced by ADC12_Deinit(), and ADC12_Init().

Here is the caller graph for this function:

Variable Documentation

◆ s_adc12Bases

ADC_Type* const s_adc12Bases[] = ADC_BASE_PTRS
static

Pointers to ADC12 bases for each instance.

Definition at line 65 of file fsl_adc12.c.

Referenced by ADC12_GetInstance().

◆ s_adc12Clocks

const clock_ip_name_t s_adc12Clocks[] = ADC12_CLOCKS
static

Pointers to ADC12 clocks for each instance.

Definition at line 68 of file fsl_adc12.c.

Referenced by ADC12_Deinit(), and ADC12_Init().

Go to the source code of this file.