aboutsummaryrefslogtreecommitdiffstats
path: root/os/io/src/adc.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-29 08:40:11 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-29 08:40:11 +0000
commit544117e9eb5a5ca827f1fbf62814459503b36e9e (patch)
tree0fa5bc94f3f8939eb1a5f7986136e7048d9d881e /os/io/src/adc.c
parent3dc0fb372d94f4dc35150be02cc02ce582d55f41 (diff)
downloadChibiOS-544117e9eb5a5ca827f1fbf62814459503b36e9e.tar.gz
ChibiOS-544117e9eb5a5ca827f1fbf62814459503b36e9e.tar.bz2
ChibiOS-544117e9eb5a5ca827f1fbf62814459503b36e9e.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1347 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/src/adc.c')
-rw-r--r--os/io/src/adc.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/os/io/src/adc.c b/os/io/src/adc.c
index af4508ab7..c074c0224 100644
--- a/os/io/src/adc.c
+++ b/os/io/src/adc.c
@@ -24,8 +24,10 @@
* @{
*/
-#include <ch.h>
-#include <adc.h>
+#include "ch.h"
+#include "hal.h"
+
+#if CH_HAL_USE_ADC
/**
* @brief ADC Driver initialization.
@@ -132,7 +134,8 @@ bool_t adcStartConversion(ADCDriver *adcp,
chSysLock();
chDbgAssert((adcp->ad_state == ADC_READY) ||
- (adcp->ad_state == ADC_RUNNING),
+ (adcp->ad_state == ADC_RUNNING) ||
+ (adcp->ad_state == ADC_COMPLETE),
"adcStartConversion(), #1",
"invalid state");
if (adcp->ad_state == ADC_RUNNING) {
@@ -160,19 +163,26 @@ void adcStopConversion(ADCDriver *adcp) {
chSysLock();
chDbgAssert((adcp->ad_state == ADC_READY) ||
- (adcp->ad_state == ADC_RUNNING),
+ (adcp->ad_state == ADC_RUNNING) ||
+ (adcp->ad_state == ADC_COMPLETE),
"adcStopConversion(), #1",
"invalid state");
if (adcp->ad_state == ADC_RUNNING) {
adc_lld_stop_conversion(adcp);
adcp->ad_grpp = NULL;
adcp->ad_state = ADC_READY;
+ chSemResetI(&adcp->ad_sem, 0);
+ chSchRescheduleS();
}
+ else
+ adcp->ad_state = ADC_READY;
chSysUnlock();
}
/**
* @brief Waits for completion.
+ * @details If the conversion is not completed or not yet started then the
+ * invoking thread waits for a conversion completion event.
*
* @param[in] adcp pointer to the @p ADCDriver object
* @param[in] timeout the number of ticks before the operation timeouts,
@@ -181,17 +191,18 @@ void adcStopConversion(ADCDriver *adcp) {
* - @a TIME_INFINITE no timeout.
* .
* @return The operation result.
- * @retval RDY_OK conversion finished (or not started).
+ * @retval RDY_OK conversion finished.
* @retval RDY_TIMEOUT conversion not finished within the specified time.
*/
msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) {
chSysLock();
chDbgAssert((adcp->ad_state == ADC_READY) ||
- (adcp->ad_state == ADC_RUNNING),
+ (adcp->ad_state == ADC_RUNNING) ||
+ (adcp->ad_state == ADC_COMPLETE),
"adcWaitConversion(), #1",
"invalid state");
- if (adcp->ad_state == ADC_RUNNING) {
+ if (adcp->ad_state != ADC_COMPLETE) {
if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) {
chSysUnlock();
return RDY_TIMEOUT;
@@ -201,4 +212,6 @@ msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) {
return RDY_OK;
}
+#endif /* CH_HAL_USE_ADC */
+
/** @} */