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

This commit is contained in:
gdisirio 2009-11-28 20:09:14 +00:00
parent eb2bcc41f2
commit 2f43c85736
3 changed files with 15 additions and 7 deletions

View File

@ -40,7 +40,8 @@ typedef enum {
ADC_UNINIT = 0, /**< @brief Not initialized. */ ADC_UNINIT = 0, /**< @brief Not initialized. */
ADC_STOP = 1, /**< @brief Stopped. */ ADC_STOP = 1, /**< @brief Stopped. */
ADC_READY = 2, /**< @brief Ready. */ ADC_READY = 2, /**< @brief Ready. */
ADC_RUNNING = 3 /**< @brief Conversion running. */ ADC_RUNNING = 3, /**< @brief Conversion running. */
ADC_COMPLETE = 4 /**< @brief Conversion complete.*/
} adcstate_t; } adcstate_t;
#include "adc_lld.h" #include "adc_lld.h"

View File

@ -75,7 +75,7 @@ CH_IRQ_HANDLER(Vector6C) {
/* End conversion.*/ /* End conversion.*/
adc_lld_stop_conversion(&ADCD1); adc_lld_stop_conversion(&ADCD1);
ADCD1.ad_grpp = NULL; ADCD1.ad_grpp = NULL;
ADCD1.ad_state = ADC_READY; ADCD1.ad_state = ADC_COMPLETE;
chSysLockFromIsr(); chSysLockFromIsr();
chSemResetI(&ADCD1.ad_sem, 0); chSemResetI(&ADCD1.ad_sem, 0);
chSysUnlockFromIsr(); chSysUnlockFromIsr();

View File

@ -134,7 +134,8 @@ bool_t adcStartConversion(ADCDriver *adcp,
chSysLock(); chSysLock();
chDbgAssert((adcp->ad_state == ADC_READY) || chDbgAssert((adcp->ad_state == ADC_READY) ||
(adcp->ad_state == ADC_RUNNING), (adcp->ad_state == ADC_RUNNING) ||
(adcp->ad_state == ADC_COMPLETE),
"adcStartConversion(), #1", "adcStartConversion(), #1",
"invalid state"); "invalid state");
if (adcp->ad_state == ADC_RUNNING) { if (adcp->ad_state == ADC_RUNNING) {
@ -162,7 +163,8 @@ void adcStopConversion(ADCDriver *adcp) {
chSysLock(); chSysLock();
chDbgAssert((adcp->ad_state == ADC_READY) || chDbgAssert((adcp->ad_state == ADC_READY) ||
(adcp->ad_state == ADC_RUNNING), (adcp->ad_state == ADC_RUNNING) ||
(adcp->ad_state == ADC_COMPLETE),
"adcStopConversion(), #1", "adcStopConversion(), #1",
"invalid state"); "invalid state");
if (adcp->ad_state == ADC_RUNNING) { if (adcp->ad_state == ADC_RUNNING) {
@ -172,11 +174,15 @@ void adcStopConversion(ADCDriver *adcp) {
chSemResetI(&adcp->ad_sem, 0); chSemResetI(&adcp->ad_sem, 0);
chSchRescheduleS(); chSchRescheduleS();
} }
else
adcp->ad_state = ADC_READY;
chSysUnlock(); chSysUnlock();
} }
/** /**
* @brief Waits for completion. * @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] adcp pointer to the @p ADCDriver object
* @param[in] timeout the number of ticks before the operation timeouts, * @param[in] timeout the number of ticks before the operation timeouts,
@ -185,17 +191,18 @@ void adcStopConversion(ADCDriver *adcp) {
* - @a TIME_INFINITE no timeout. * - @a TIME_INFINITE no timeout.
* . * .
* @return The operation result. * @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. * @retval RDY_TIMEOUT conversion not finished within the specified time.
*/ */
msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) { msg_t adcWaitConversion(ADCDriver *adcp, systime_t timeout) {
chSysLock(); chSysLock();
chDbgAssert((adcp->ad_state == ADC_READY) || chDbgAssert((adcp->ad_state == ADC_READY) ||
(adcp->ad_state == ADC_RUNNING), (adcp->ad_state == ADC_RUNNING) ||
(adcp->ad_state == ADC_COMPLETE),
"adcWaitConversion(), #1", "adcWaitConversion(), #1",
"invalid state"); "invalid state");
if (adcp->ad_state == ADC_RUNNING) { if (adcp->ad_state != ADC_COMPLETE) {
if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) { if (chSemWaitTimeoutS(&adcp->ad_sem, timeout) == RDY_TIMEOUT) {
chSysUnlock(); chSysUnlock();
return RDY_TIMEOUT; return RDY_TIMEOUT;