aboutsummaryrefslogtreecommitdiffstats
path: root/os/io/adc.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-06 16:33:03 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-11-06 16:33:03 +0000
commit0521c90a445af93ea53f7d0e1847fa8a12a9c423 (patch)
tree93d57d723868a8d415c4ab981e977b20b8ec8977 /os/io/adc.c
parentaf65d01d0a76f9a0593dd36326c100d4f26f4c0d (diff)
downloadChibiOS-0521c90a445af93ea53f7d0e1847fa8a12a9c423.tar.gz
ChibiOS-0521c90a445af93ea53f7d0e1847fa8a12a9c423.tar.bz2
ChibiOS-0521c90a445af93ea53f7d0e1847fa8a12a9c423.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1270 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/adc.c')
-rw-r--r--os/io/adc.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/os/io/adc.c b/os/io/adc.c
index 0c215d61a..637820d5b 100644
--- a/os/io/adc.c
+++ b/os/io/adc.c
@@ -87,15 +87,24 @@ void adcStop(ADCDriver *adcp) {
* @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
+ * @param[in] depth buffer depth (matrix rows number). The buffer depth must
+ * be one or an even number.
* @return The operation status.
* @retval FALSE the conversion has been started.
- * @retval TRUE the driver is busy, conversion not started.
+ * @retval TRUE the driver is busy, conversion not started.
+ *
+ * @note The buffer is organized as a matrix of M*N elements where M is the
+ * channels number configured into the conversion group and N is the
+ * buffer depth. The samples are sequentially written into the buffer
+ * with no gaps.
*/
bool_t adcStartConversion(ADCDriver *adcp,
ADCConversionGroup *grpp,
- void *samples) {
+ void *samples,
+ size_t depth) {
- chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL),
+ chDbgCheck((adcp != NULL) && (grpp != NULL) && (samples != NULL) &&
+ ((depth == 1) || ((depth & 1) == 0)),
"adcStartConversion");
chSysLock();
@@ -149,12 +158,10 @@ void adcStopConversion(ADCDriver *adcp) {
* - @a TIME_INFINITE no timeout.
* .
* @return The operation result.
- * @retval RDY_OK conversion not running.
- * @retval RDY_RESET conversion finished.
+ * @retval RDY_OK conversion finished (or not started).
* @retval RDY_TIMEOUT conversion not finished within the specified time.
*/
msg_t adcWaitConversion(ADCDriver *adcp, systme_t timeout) {
- msg_t msg;
chSysLock();
@@ -163,13 +170,14 @@ msg_t adcWaitConversion(ADCDriver *adcp, systme_t timeout) {
"adcWaitConversion(), #1",
"invalid state");
- if (adcp->adc_state == ADC_RUNNING)
- msg = chSemWaitTimeoutS(&adcp->adc_sem, timeout);
- else
- msg = RDY_OK;
-
+ if (adcp->adc_state == ADC_RUNNING) {
+ if (chSemWaitTimeoutS(&adcp->adc_sem, timeout) == RDY_TIMEOUT) {
+ chSysUnlock();
+ return RDY_TIMEOUT;
+ }
+ }
chSysUnlock();
- return msg;
+ return RDY_OK;
}
/** @} */