X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Farm%2Fdrv%2Fadc_at91.c;h=66d0bde9c2335c66417e1d6b25d888c2171ede8e;hb=9f1e77249c5475b19340e46b9903c66da6c6c937;hp=bb6a8d11ffd1409fe86d557a86d31e6d233714f1;hpb=055132222c4380c116e15f66a9ab7e1f561d329e;p=bertos.git diff --git a/bertos/cpu/arm/drv/adc_at91.c b/bertos/cpu/arm/drv/adc_at91.c index bb6a8d11..66d0bde9 100644 --- a/bertos/cpu/arm/drv/adc_at91.c +++ b/bertos/cpu/arm/drv/adc_at91.c @@ -40,7 +40,6 @@ * whit a loop the finishing of conversion. * * - * \version $Id$ * \author Daniele Basile */ @@ -84,9 +83,9 @@ * ADC ISR. * Simply signal the adc process that convertion is complete. */ - static void ISR_FUNC adc_conversion_end_irq(void) + static DECLARE_ISR(adc_conversion_end_irq) { - sig_signal(adc_process, SIG_ADC_COMPLETE); + sig_post(adc_process, SIG_ADC_COMPLETE); /* Inform hw that we have served the IRQ */ AIC_EOICR = 0; @@ -126,13 +125,13 @@ void adc_hw_select_ch(uint8_t ch) /** * Start an ADC convertion. * If a kernel is present, preempt until convertion is complete, otherwise - * a busy wait on ADCS bit is done. + * a busy wait on ADC_DRDY bit is done. */ uint16_t adc_hw_read(void) { - ASSERT(!(ADC_SR & ADC_EOC_MASK)); - #if CONFIG_KERN + /* Ensure ADC is not already in use by another process */ + ASSERT(adc_process == NULL); adc_process = proc_current(); #endif @@ -143,13 +142,19 @@ uint16_t adc_hw_read(void) // Ensure IRQs enabled. IRQ_ASSERT_ENABLED(); sig_wait(SIG_ADC_COMPLETE); + + /* Prevent race condition in case of preemptive kernel */ + uint16_t ret = ADC_LCDR; + MEMORY_BARRIER; + adc_process = NULL; + return ret; #else //Wait in polling until is done while (!(ADC_SR & BV(ADC_DRDY))); - #endif - //Return the last converted data - return(ADC_LCDR); + //Return the last converted data + return(ADC_LCDR); + #endif } /** @@ -178,6 +183,7 @@ void adc_hw_init(void) #endif /* \} */ + LOG_INFO("Computed ADC_CLOCK %ld\n", ADC_COMPUTED_CLOCK); LOG_INFO("prescaler[%ld], stup[%ld], shtim[%ld]\n",ADC_COMPUTED_PRESCALER, ADC_COMPUTED_STARTUPTIME, ADC_COMPUTED_SHTIME);