From 781b0b129cccbecba160effce8c4ddd68295b8b9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 11 Sep 2010 10:57:11 +0000 Subject: Fixed bug 3064204. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2175 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/adc.h | 13 +++++++++++-- os/hal/include/can.h | 2 ++ os/hal/platforms/STM32/adc_lld.c | 2 ++ os/hal/platforms/STM32/adc_lld.h | 10 ++++++---- os/hal/src/adc.c | 8 ++++++++ os/hal/templates/adc_lld.h | 10 ++++++---- 6 files changed, 35 insertions(+), 10 deletions(-) (limited to 'os/hal') diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h index 8b1bfd47b..8a2af908e 100644 --- a/os/hal/include/adc.h +++ b/os/hal/include/adc.h @@ -38,12 +38,19 @@ /* Driver pre-compile time settings. */ /*===========================================================================*/ +/** + * @brief Inclusion of the @p adcWaitConversion() function. + */ +#if !defined(ADC_USE_WAIT) || defined(__DOXYGEN__) +#define ADC_USE_WAIT TRUE +#endif + /*===========================================================================*/ /* Derived constants and error checks. */ /*===========================================================================*/ -#if !CH_USE_SEMAPHORES -#error "ADC driver requires CH_USE_SEMAPHORES" +#if ADC_USE_WAIT && !CH_USE_SEMAPHORES +#error "ADC driver requires CH_USE_SEMAPHORES when ADC_USE_WAIT is enabled" #endif /*===========================================================================*/ @@ -90,7 +97,9 @@ extern "C" { adccallback_t callback); void adcStopConversion(ADCDriver *adcp); void adcStopConversionI(ADCDriver *adcp); +#if ADC_USE_WAIT msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout); +#endif #ifdef __cplusplus } #endif diff --git a/os/hal/include/can.h b/os/hal/include/can.h index b503dd8e3..4a40fb952 100644 --- a/os/hal/include/can.h +++ b/os/hal/include/can.h @@ -62,7 +62,9 @@ /** * @brief Sleep mode related APIs inclusion switch. */ +#if !defined(CAN_USE_SLEEP_MODE) || defined(__DOXYGEN__) #define CAN_USE_SLEEP_MODE TRUE +#endif /*===========================================================================*/ /* Derived constants and error checks. */ diff --git a/os/hal/platforms/STM32/adc_lld.c b/os/hal/platforms/STM32/adc_lld.c index 9a506d150..fa748aa84 100644 --- a/os/hal/platforms/STM32/adc_lld.c +++ b/os/hal/platforms/STM32/adc_lld.c @@ -76,9 +76,11 @@ CH_IRQ_HANDLER(DMA1_Ch1_IRQHandler) { adc_lld_stop_conversion(&ADCD1); ADCD1.ad_grpp = NULL; ADCD1.ad_state = ADC_COMPLETE; +#if ADC_USE_WAIT chSysLockFromIsr(); chSemResetI(&ADCD1.ad_sem, 0); chSysUnlockFromIsr(); +#endif } /* Callback handling.*/ if (ADCD1.ad_callback != NULL) { diff --git a/os/hal/platforms/STM32/adc_lld.h b/os/hal/platforms/STM32/adc_lld.h index 2a91c9b4d..7fe219706 100644 --- a/os/hal/platforms/STM32/adc_lld.h +++ b/os/hal/platforms/STM32/adc_lld.h @@ -194,10 +194,6 @@ typedef struct { * @brief Current configuration data. */ const ADCConfig *ad_config; - /** - * @brief Synchronization semaphore. - */ - Semaphore ad_sem; /** * @brief Current callback function or @p NULL. */ @@ -214,6 +210,12 @@ typedef struct { * @brief Current conversion group pointer or @p NULL. */ const ADCConversionGroup *ad_grpp; +#if ADC_USE_WAIT + /** + * @brief Synchronization semaphore. + */ + Semaphore ad_sem; +#endif /* End of the mandatory fields.*/ /** * @brief Pointer to the ADCx registers block. diff --git a/os/hal/src/adc.c b/os/hal/src/adc.c index 23b096f3e..df8b05fd5 100644 --- a/os/hal/src/adc.c +++ b/os/hal/src/adc.c @@ -67,7 +67,9 @@ void adcObjectInit(ADCDriver *adcp) { adcp->ad_samples = NULL; adcp->ad_depth = 0; adcp->ad_grpp = NULL; +#if ADC_USE_WAIT chSemInit(&adcp->ad_sem, 0); +#endif } /** @@ -229,8 +231,10 @@ void adcStopConversion(ADCDriver *adcp) { adc_lld_stop_conversion(adcp); adcp->ad_grpp = NULL; adcp->ad_state = ADC_READY; +#if ADC_USE_WAIT chSemResetI(&adcp->ad_sem, 0); chSchRescheduleS(); +#endif } else adcp->ad_state = ADC_READY; @@ -258,12 +262,15 @@ void adcStopConversionI(ADCDriver *adcp) { adc_lld_stop_conversion(adcp); adcp->ad_grpp = NULL; adcp->ad_state = ADC_READY; +#if ADC_USE_WAIT chSemResetI(&adcp->ad_sem, 0); +#endif } else adcp->ad_state = ADC_READY; } +#if ADC_USE_WAIT || defined(__DOXYGEN__) /** * @brief Waits for completion. * @details If the conversion is not completed or not yet started then the @@ -296,6 +303,7 @@ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { chSysUnlock(); return RDY_OK; } +#endif /* ADC_USE_WAIT */ #endif /* CH_HAL_USE_ADC */ diff --git a/os/hal/templates/adc_lld.h b/os/hal/templates/adc_lld.h index d969b24e0..6486abb37 100644 --- a/os/hal/templates/adc_lld.h +++ b/os/hal/templates/adc_lld.h @@ -111,10 +111,6 @@ typedef struct { * @brief Current configuration data. */ const ADCConfig *ad_config; - /** - * @brief Synchronization semaphore. - */ - Semaphore ad_sem; /** * @brief Current callback function or @p NULL. */ @@ -131,6 +127,12 @@ typedef struct { * @brief Current conversion group pointer or @p NULL. */ const ADCConversionGroup *ad_grpp; +#if ADC_USE_WAIT + /** + * @brief Synchronization semaphore. + */ + Semaphore ad_sem; +#endif /* End of the mandatory fields.*/ } ADCDriver; -- cgit v1.2.3