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

Functions

static void fastAdcDoneCB (ADCDriver *adcp)
 
static void fastAdcErrorCB (ADCDriver *, adcerror_t err)
 
static void fastAdcStartTrigger (GPTDriver *)
 

Variables

static ADCConversionGroup adcgrpcfgFast
 
static volatile NO_CACHE adcsample_t fastAdcSampleBuf [ADC_BUF_DEPTH_FAST *ADC_MAX_CHANNELS_COUNT]
 
AdcDevice fastAdcADC_FAST_DEVICE
 
static efitick_t lastTick = 0
 
static const PWMConfig pwmcfg
 
static const GPTConfig fast_adc_config
 

Function Documentation

◆ fastAdcDoneCB()

static void fastAdcDoneCB ( ADCDriver *  adcp)
static

Definition at line 134 of file adc_onchip_fast.cpp.

134 {
135 // State may not be complete if we get a callback for "half done"
136 if (adcIsBufferComplete(adcp)) {
137 efitick_t nowTick = getTimeNowNt();
138 efitick_t diff = nowTick - lastTick;
139 lastTick = nowTick;
140
141 engine->outputChannels.fastAdcPeriod = (uint32_t)diff;
143
144 onFastAdcComplete(adcp->samples);
145 }
146}
static efitick_t lastTick
TunerStudioOutputChannels outputChannels
Definition engine.h:109
efitick_t getTimeNowNt()
Definition efitime.cpp:19
static EngineAccessor engine
Definition engine.h:413
void onFastAdcComplete(adcsample_t *)
Definition hardware.cpp:275
Here is the call graph for this function:

◆ fastAdcErrorCB()

static void fastAdcErrorCB ( ADCDriver *  ,
adcerror_t  err 
)
static

Definition at line 148 of file adc_onchip_fast.cpp.

148 {
149 engine->outputChannels.fastAdcLastError = (uint8_t)err;
151 if (err == ADC_ERR_OVERFLOW) {
153 }
154 // TODO: restart?
155}
@ ADC_ERR_OVERFLOW

◆ fastAdcStartTrigger()

static void fastAdcStartTrigger ( GPTDriver )
static

Definition at line 178 of file adc_onchip_fast.cpp.

179{
180#if EFI_INTERNAL_ADC
181 /*
182 * Starts an asynchronous ADC conversion operation, the conversion
183 * will be executed in parallel to the current PWM cycle and will
184 * terminate before the next PWM cycle.
185 */
187#endif /* EFI_INTERNAL_ADC */
188}
AdcDevice fastAdc
void startConversionI(void)
Here is the call graph for this function:

Variable Documentation

◆ ADC_FAST_DEVICE

AdcDevice fastAdc& ADC_FAST_DEVICE

Definition at line 130 of file adc_onchip_fast.cpp.

Referenced by AdcDevice::startConversionI().

◆ adcgrpcfgFast

ADCConversionGroup adcgrpcfgFast
static

Definition at line 72 of file adc_onchip_fast.cpp.

72 {
73#if defined(EFI_INTERNAL_FAST_ADC_PWM)
74 .circular = TRUE,
75#elif defined (EFI_INTERNAL_FAST_ADC_GPT)
76 .circular = FALSE,
77#endif
78 .num_channels = 0,
79 .end_cb = fastAdcDoneCB,
80 .error_cb = fastAdcErrorCB,
81 /* HW dependent part.*/
82 .cr1 = 0,
83#if defined(EFI_INTERNAL_FAST_ADC_PWM)
84 /* HW start using TIM8 CC 1 event rising edge
85 * See "External trigger for regular channels" for magic 13 number
86 * NOTE: Currently only TIM8 in PWM mode is supported */
87 .cr2 = ADC_CR2_EXTEN_0 | (13 << ADC_CR2_EXTSEL_Pos),
88#elif defined (EFI_INTERNAL_FAST_ADC_GPT)
89 /* SW start through GPT callback and SW kick */
90 .cr2 = ADC_CR2_SWSTART,
91#endif
92 /**
93 * here we configure all possible channels for fast mode. Some channels would not actually
94 * be used hopefully that's fine to configure all possible channels.
95 *
96 */
97 // sample times for channels 10...18
98 .smpr1 =
99 ADC_SMPR1_SMP_AN10(ADC_SAMPLING_FAST) |
100 ADC_SMPR1_SMP_AN11(ADC_SAMPLING_FAST) |
101 ADC_SMPR1_SMP_AN12(ADC_SAMPLING_FAST) |
102 ADC_SMPR1_SMP_AN13(ADC_SAMPLING_FAST) |
103 ADC_SMPR1_SMP_AN14(ADC_SAMPLING_FAST) |
104 ADC_SMPR1_SMP_AN15(ADC_SAMPLING_FAST),
105 // In this field must be specified the sample times for channels 0...9
106 .smpr2 =
107 ADC_SMPR2_SMP_AN0(ADC_SAMPLING_FAST) |
108 ADC_SMPR2_SMP_AN1(ADC_SAMPLING_FAST) |
109 ADC_SMPR2_SMP_AN2(ADC_SAMPLING_FAST) |
110 ADC_SMPR2_SMP_AN3(ADC_SAMPLING_FAST) |
111 ADC_SMPR2_SMP_AN4(ADC_SAMPLING_FAST) |
112 ADC_SMPR2_SMP_AN5(ADC_SAMPLING_FAST) |
113 ADC_SMPR2_SMP_AN6(ADC_SAMPLING_FAST) |
114 ADC_SMPR2_SMP_AN7(ADC_SAMPLING_FAST) |
115 ADC_SMPR2_SMP_AN8(ADC_SAMPLING_FAST) |
116 ADC_SMPR2_SMP_AN9(ADC_SAMPLING_FAST),
117 .htr = 0,
118 .ltr = 0,
119 .sqr1 = 0, // Conversion group sequence 13...16 + sequence length
120 .sqr2 = 0, // Conversion group sequence 7...12
121 .sqr3 = 0, // Conversion group sequence 1...6
122#if ADC_MAX_CHANNELS_COUNT > 16
123 .sqr4 = 0, // Conversion group sequence 19...24
124 .sqr5 = 0 // Conversion group sequence 25...30
125#endif /* ADC_MAX_CHANNELS_COUNT */
126};
static void fastAdcDoneCB(ADCDriver *adcp)
static void fastAdcErrorCB(ADCDriver *, adcerror_t err)

Referenced by portInitAdc().

◆ fast_adc_config

const GPTConfig fast_adc_config
static
Initial value:
= {
.frequency = GPT_FREQ_FAST,
.callback = fastAdcStartTrigger,
.cr2 = 0,
.dier = 0,
}
static void fastAdcStartTrigger(GPTDriver *)

Definition at line 190 of file adc_onchip_fast.cpp.

190 {
191 .frequency = GPT_FREQ_FAST,
192 .callback = fastAdcStartTrigger,
193 .cr2 = 0,
194 .dier = 0,
195};

Referenced by AdcDevice::init().

◆ fastAdcSampleBuf

volatile NO_CACHE adcsample_t fastAdcSampleBuf[ADC_BUF_DEPTH_FAST *ADC_MAX_CHANNELS_COUNT]
static

Definition at line 128 of file adc_onchip_fast.cpp.

◆ lastTick

efitick_t lastTick = 0
static

Definition at line 132 of file adc_onchip_fast.cpp.

Referenced by fastAdcDoneCB().

◆ pwmcfg

const PWMConfig pwmcfg
static
Initial value:
= {
.frequency = GPT_FREQ_FAST * ADC_BUF_DEPTH_FAST,
.period = GPT_PERIOD_FAST,
.callback = nullptr,
.channels = {
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr}
},
.cr2 = 0,
.bdtr = 0,
.dier = 0,
}

Definition at line 159 of file adc_onchip_fast.cpp.

159 {
160 /* on each trigger event regular group of channels is converted,
161 * to get whole buffer filled we need ADC_BUF_DEPTH_FAST trigger events */
162 .frequency = GPT_FREQ_FAST * ADC_BUF_DEPTH_FAST,
163 .period = GPT_PERIOD_FAST,
164 .callback = nullptr,
165 .channels = {
166 {PWM_OUTPUT_ACTIVE_HIGH, nullptr},
167 {PWM_OUTPUT_ACTIVE_HIGH, nullptr},
168 {PWM_OUTPUT_ACTIVE_HIGH, nullptr},
169 {PWM_OUTPUT_ACTIVE_HIGH, nullptr}
170 },
171 .cr2 = 0,
172 .bdtr = 0,
173 .dier = 0,
174};

Referenced by AdcDevice::init().

Go to the source code of this file.