diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/include/dac.h | 11 | ||||
-rw-r--r-- | os/hal/src/dac.c | 42 |
2 files changed, 29 insertions, 24 deletions
diff --git a/os/hal/include/dac.h b/os/hal/include/dac.h index ac2396b1c..3d1157ae0 100644 --- a/os/hal/include/dac.h +++ b/os/hal/include/dac.h @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -64,10 +64,6 @@ /* Derived constants and error checks. */ /*===========================================================================*/ -#if DAC_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES && !NIL_USE_MUTEXES && !NIL_USE_SEMAPHORES -//#error "DAC_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES" -#endif - /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -118,7 +114,6 @@ typedef enum { */ #define _dac_reset_i(dacp) osalThreadResumeI(&(dacp)->thread, MSG_RESET) - /** * @brief Resumes a thread waiting for a conversion completion. * @@ -138,7 +133,7 @@ typedef enum { #define _dac_wakeup_isr(dacp) { \ osalSysLockFromISR(); \ osalThreadResumeI(&(dacp)->thread, MSG_OK); \ - osalSysUnlockFromISR(); \ + osalSysUnlockFromISR(); \ } /** @@ -151,7 +146,7 @@ typedef enum { #define _dac_timeout_isr(dacp) { \ osalSysLockFromISR(); \ osalThreadResumeI(&(dacp)->thread, MSG_TIMEOUT); \ - osalSysUnlockFromISR(); \ + osalSysUnlockFromISR(); \ } #else /* !DAC_USE_WAIT */ diff --git a/os/hal/src/dac.c b/os/hal/src/dac.c index 92297e520..42521c107 100644 --- a/os/hal/src/dac.c +++ b/os/hal/src/dac.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. @@ -97,11 +97,14 @@ void dacStart(DACDriver *dacp, const DACConfig *config) { osalDbgCheck((dacp != NULL) && (config != NULL)); osalSysLock(); + osalDbgAssert((dacp->state == DAC_STOP) || (dacp->state == DAC_READY), - "invalid state"); + "invalid state"); + dacp->config = config; dac_lld_start(dacp); dacp->state = DAC_READY; + osalSysUnlock(); } @@ -119,10 +122,13 @@ void dacStop(DACDriver *dacp) { osalDbgCheck(dacp != NULL); osalSysLock(); + osalDbgAssert((dacp->state == DAC_STOP) || (dacp->state == DAC_READY), - "invalid state"); + "invalid state"); + dac_lld_stop(dacp); dacp->state = DAC_STOP; + osalSysUnlock(); } @@ -177,11 +183,11 @@ void dacStartConversionI(DACDriver *dacp, osalDbgCheckClassI(); osalDbgCheck((dacp != NULL) && (grpp != NULL) && (samples != NULL) && - ((depth == 1) || ((depth & 1) == 0))); + ((depth == 1) || ((depth & 1) == 0))); osalDbgAssert((dacp->state == DAC_READY) || - (dacp->state == DAC_COMPLETE) || - (dacp->state == DAC_ERROR), - "not ready"); + (dacp->state == DAC_COMPLETE) || + (dacp->state == DAC_ERROR), + "not ready"); dacp->samples = samples; dacp->depth = depth; @@ -205,15 +211,18 @@ void dacStopConversion(DACDriver *dacp) { osalDbgCheck(dacp != NULL); osalSysLock(); + osalDbgAssert((dacp->state == DAC_READY) || - (dacp->state == DAC_ACTIVE), - "invalid state"); + (dacp->state == DAC_ACTIVE), + "invalid state"); + if (dacp->state != DAC_READY) { dac_lld_stop_conversion(dacp); dacp->grpp = NULL; dacp->state = DAC_READY; _dac_reset_s(dacp); } + osalSysUnlock(); } @@ -232,9 +241,9 @@ void dacStopConversionI(DACDriver *dacp) { osalDbgCheckClassI(); osalDbgCheck(dacp != NULL); osalDbgAssert((dacp->state == DAC_READY) || - (dacp->state == DAC_ACTIVE) || - (dacp->state == DAC_COMPLETE), - "invalid state"); + (dacp->state == DAC_ACTIVE) || + (dacp->state == DAC_COMPLETE), + "invalid state"); if (dacp->state != DAC_READY) { dac_lld_stop_conversion(dacp); @@ -259,11 +268,11 @@ void dacStopConversionI(DACDriver *dacp) { * @param[in] depth buffer depth (matrix rows number). The buffer depth * must be one or an even number. * @return The operation result. - * @retval RDY_OK Conversion finished. - * @retval RDY_RESET The conversion has been stopped using + * @retval MSG_OK Conversion finished. + * @retval MSG_RESET The conversion has been stopped using * @p acdStopConversion() or @p acdStopConversionI(), * the result buffer may contain incorrect data. - * @retval RDY_TIMEOUT The conversion has been stopped because an hardware + * @retval MSG_TIMEOUT The conversion has been stopped because an hardware * error. * * @api @@ -275,9 +284,10 @@ msg_t dacConvert(DACDriver *dacp, msg_t msg; osalSysLock(); - osalDbgAssert(dacp->thread == NULL, "already waiting"); + dacStartConversionI(dacp, grpp, samples, depth); msg = osalThreadSuspendS(&dacp->thread); + osalSysUnlock(); return msg; } |