git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2251 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2010-10-12 17:59:47 +00:00
parent 935e2fb27f
commit eaaf043cda
3 changed files with 17 additions and 26 deletions

View File

@ -66,9 +66,9 @@ CH_IRQ_HANDLER(DMA1_Ch1_IRQHandler) {
dmaClearChannel(STM32_DMA1, STM32_DMA_CHANNEL_1); dmaClearChannel(STM32_DMA1, STM32_DMA_CHANNEL_1);
if ((isr & DMA_ISR_HTIF1) != 0) { if ((isr & DMA_ISR_HTIF1) != 0) {
/* Half transfer processing.*/ /* Half transfer processing.*/
if (ADCD1.ad_grpp->acg_callback != NULL) { if (ADCD1.ad_grpp->acg_endcb != NULL) {
/* Invokes the callback passing the 1st half of the buffer.*/ /* Invokes the callback passing the 1st half of the buffer.*/
ADCD1.ad_grpp->acg_callback(&ADCD1, ADCD1.ad_samples, ADCD1.ad_depth / 2); ADCD1.ad_grpp->acg_endcb(&ADCD1, ADCD1.ad_samples, ADCD1.ad_depth / 2);
} }
} }
if ((isr & DMA_ISR_TCIF1) != 0) { if ((isr & DMA_ISR_TCIF1) != 0) {
@ -80,20 +80,25 @@ CH_IRQ_HANDLER(DMA1_Ch1_IRQHandler) {
ADCD1.ad_state = ADC_COMPLETE; ADCD1.ad_state = ADC_COMPLETE;
#if ADC_USE_WAIT #if ADC_USE_WAIT
chSysLockFromIsr(); chSysLockFromIsr();
chSemResetI(&ADCD1.ad_sem, 0); if (ADCD1.ad_thread != NULL) {
Thread *tp = ADCD1.ad_thread;
ADCD1.ad_thread = NULL;
tp->p_u.rdymsg = RDY_OK;
chSchReadyI(tp);
}
chSysUnlockFromIsr(); chSysUnlockFromIsr();
#endif #endif
} }
/* Callback handling.*/ /* Callback handling.*/
if (ADCD1.ad_grpp->acg_callback != NULL) { if (ADCD1.ad_grpp->acg_endcb != NULL) {
if (ADCD1.ad_depth > 1) { if (ADCD1.ad_depth > 1) {
/* Invokes the callback passing the 2nd half of the buffer.*/ /* Invokes the callback passing the 2nd half of the buffer.*/
size_t half = ADCD1.ad_depth / 2; size_t half = ADCD1.ad_depth / 2;
ADCD1.ad_grpp->acg_callback(&ADCD1, ADCD1.ad_samples + half, half); ADCD1.ad_grpp->acg_endcb(&ADCD1, ADCD1.ad_samples + half, half);
} }
else { else {
/* Invokes the callback passing the whole buffer.*/ /* Invokes the callback passing the whole buffer.*/
ADCD1.ad_grpp->acg_callback(&ADCD1, ADCD1.ad_samples, ADCD1.ad_depth); ADCD1.ad_grpp->acg_endcb(&ADCD1, ADCD1.ad_samples, ADCD1.ad_depth);
} }
} }
} }

View File

@ -268,8 +268,7 @@ msg_t adcConvert(ADCDriver *adcp,
msg_t msg; msg_t msg;
chSysLock(); chSysLock();
chDbgAssert(adcp->ad_config->ac_endcb == NULL, chDbgAssert(grpp->acg_endcb == NULL, "adcConvert(), #1", "has callback");
"adcConvert(), #1", "has callback");
adcStartConversionI(adcp, grpp, samples, depth); adcStartConversionI(adcp, grpp, samples, depth);
(adcp)->ad_thread = chThdSelf(); (adcp)->ad_thread = chThdSelf();
chSchGoSleepS(THD_STATE_SUSPENDED); chSchGoSleepS(THD_STATE_SUSPENDED);

View File

@ -29,7 +29,6 @@
static const ADCConfig adccfg = {}; static const ADCConfig adccfg = {};
static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH]; static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
static Thread *adctp;
/* /*
* ADC streaming callback. * ADC streaming callback.
@ -66,20 +65,6 @@ static const ADCConversionGroup adcgrpcfg = {
ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) | ADC_SQR3_SQ0_N(ADC_CHANNEL_IN10) ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11) | ADC_SQR3_SQ0_N(ADC_CHANNEL_IN10)
}; };
/*
* ADC continuous conversion thread.
*/
static WORKING_AREA(adc_continuous_wa, 256);
static msg_t adc_continuous_thread(void *p){
(void)p;
adcStart(&ADCD1, &adccfg);
adcStartConversion(&ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH);
adcWaitConversion(&ADCD1, TIME_INFINITE);
adcStop(&ADCD1);
return 0;
}
/* /*
* Red LEDs blinker thread, times are in milliseconds. * Red LEDs blinker thread, times are in milliseconds.
*/ */
@ -118,15 +103,17 @@ int main(int argc, char **argv) {
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/* /*
* Creates the ADC continuous conversion test thread. * Starts an ADC continuous conversion.
*/ */
adctp = chThdCreateStatic(adc_continuous_wa, sizeof(adc_continuous_wa), adcStart(&ADCD1, &adccfg);
NORMALPRIO + 10, adc_continuous_thread, NULL); adcStartConversion(&ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH);
/* /*
* Normal main() thread activity, in this demo it does nothing. * Normal main() thread activity, in this demo it does nothing.
*/ */
while (TRUE) { while (TRUE) {
if (palReadPad(IOPORT1, GPIOA_BUTTON))
adcStopConversion(&ADCD1);
chThdSleepMilliseconds(500); chThdSleepMilliseconds(500);
} }
return 0; return 0;