aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-05 19:55:58 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-05 19:55:58 +0000
commit9d2bdb6729532f2090769c203ddbd73b4b94cb6a (patch)
tree0b35df8fb8a2bc47d828221dbeded8873e399af2
parent345e69346056fde8e9a806b03a71c1ad78e5784b (diff)
downloadChibiOS-9d2bdb6729532f2090769c203ddbd73b4b94cb6a.tar.gz
ChibiOS-9d2bdb6729532f2090769c203ddbd73b4b94cb6a.tar.bz2
ChibiOS-9d2bdb6729532f2090769c203ddbd73b4b94cb6a.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1268 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/io/adc.c93
-rw-r--r--os/io/adc.h2
-rw-r--r--os/io/spi.c2
3 files changed, 94 insertions, 3 deletions
diff --git a/os/io/adc.c b/os/io/adc.c
index 8b4123bcd..1860f88aa 100644
--- a/os/io/adc.c
+++ b/os/io/adc.c
@@ -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;
+}
+
/** @} */
diff --git a/os/io/adc.h b/os/io/adc.h
index 628191c4f..a7506f636 100644
--- a/os/io/adc.h
+++ b/os/io/adc.h
@@ -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"
diff --git a/os/io/spi.c b/os/io/spi.c
index 231fc7ad2..10eabb87e 100644
--- a/os/io/spi.c
+++ b/os/io/spi.c
@@ -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) {