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

This commit is contained in:
gdisirio 2009-11-05 19:55:58 +00:00
parent 345e693460
commit 9d2bdb6729
3 changed files with 94 additions and 3 deletions

View File

@ -50,7 +50,7 @@ void adcObjectInit(ADCDriver *adcp) {
* @brief Configures and activates the ADC peripheral.
*
* @param[in] adcp pointer to the @p ADCDriver object
* @param config pointer to the @p ADCConfig object
* @param[in] config pointer to the @p ADCConfig object
*/
void adcStart(ADCDriver *adcp, const ADCConfig *config) {
@ -80,4 +80,95 @@ void adcStop(ADCDriver *adcp) {
adcp->spd_state = ADC_STOP;
}
/**
* @brief Starts an ADC conversion.
*
* @param[in] adcp pointer to the @p ADCDriver object
* @param[in] grpp pointer to a @p ADCConversionGroup object
* @param[out] samples pointer to the samples buffer
* @return The operation status.
* @retval FALSE the conversion has been started.
* @retval TRUE the driver is busy, conversion not started.
*/
bool_t adcStartConversion(ADCDriver *adcp,
ADCConversionGroup *grpp,
void *samples) {
chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL),
"adcStartConversion");
chSysLock();
chDbgAssert((adcp->adc_state == ADC_READY) ||
(adcp->adc_state == ADC_RUNNING),
"adcStartConversion(), #1",
"invalid state");
if (adcp->adc_state == ADC_RUNNING) {
chSysUnlock();
return TRUE;
}
adc_lld_start_conversion(adcp, grpp, samples);
adcp->adc_state = ADC_RUNNING;
chSysUnlock();
return FALSE;
}
/**
* @brief Stops an ongoing conversion.
*
* @param[in] adcp pointer to the @p ADCDriver object
*/
void adcStopConversion(ADCDriver *adcp) {
chDbgCheck(adcp != NULL, "adcStopConversion");
chSysLock();
chDbgAssert((adcp->adc_state == ADC_READY) ||
(adcp->adc_state == ADC_RUNNING),
"adcStopConversion(), #1",
"invalid state");
adc_lld_start_conversion(adcp, grpp, samples);
adcp->adc_state = ADC_READY;
chSysUnlock();
}
/**
* @brief Waits for completion.
*
* @param[in] adcp pointer to the @p ADCDriver object
* @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
* .
* @return The operation result.
* @retval RDY_OK conversion not running.
* @retval RDY_RESET conversion finished.
* @retval RDY_TIMEOUT conversion not finished within the specified time.
*/
msg_t adcWaitConversion(ADCDriver *adcp, systme_t timeout) {
msg_t msg;
chSysLock();
chDbgAssert((adcp->adc_state == ADC_READY) ||
(adcp->adc_state == ADC_RUNNING),
"adcWaitConversion(), #1",
"invalid state");
if (adcp->adc_state == ADC_RUNNING)
msg = chSemWaitTimeoutS(&adcp->adc_sem, timeout);
else
msg = RDY_OK;
chSysUnlock();
return msg;
}
/** @} */

View File

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

View File

@ -55,7 +55,7 @@ void spiObjectInit(SPIDriver *spip) {
* @brief Configures and activates the SPI peripheral.
*
* @param[in] spip pointer to the @p SPIDriver object
* @param config pointer to the @p SPIConfig object
* @param[in] config pointer to the @p SPIConfig object
*/
void spiStart(SPIDriver *spip, const SPIConfig *config) {