diff options
Diffstat (limited to 'os/hal/src/dac.c')
-rw-r--r-- | os/hal/src/dac.c | 118 |
1 files changed, 56 insertions, 62 deletions
diff --git a/os/hal/src/dac.c b/os/hal/src/dac.c index 3ab09f27c..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. @@ -26,7 +26,6 @@ * @{ */ -#include "ch.h" #include "hal.h" #if HAL_USE_DAC || defined(__DOXYGEN__) @@ -78,11 +77,7 @@ void dacObjectInit(DACDriver *dacp) { dacp->thread = NULL; #endif /* DAC_USE_WAIT */ #if DAC_USE_MUTUAL_EXCLUSION -#if CH_USE_MUTEXES - chMtxInit(&dacp->mutex); -#else - chSemInit(&dacp->semaphore, 1); -#endif + osalMutexObjectInit(&dacp->mutex); #endif /* DAC_USE_MUTUAL_EXCLUSION */ #if defined(DAC_DRIVER_EXT_INIT_HOOK) DAC_DRIVER_EXT_INIT_HOOK(dacp); @@ -99,15 +94,18 @@ void dacObjectInit(DACDriver *dacp) { */ void dacStart(DACDriver *dacp, const DACConfig *config) { - chDbgCheck((dacp != NULL) && (config != NULL), "dacStart"); + osalDbgCheck((dacp != NULL) && (config != NULL)); + + osalSysLock(); + + osalDbgAssert((dacp->state == DAC_STOP) || (dacp->state == DAC_READY), + "invalid state"); - chSysLock(); - chDbgAssert((dacp->state == DAC_STOP) || (dacp->state == DAC_READY), - "dacStart(), #1", "invalid state"); dacp->config = config; dac_lld_start(dacp); dacp->state = DAC_READY; - chSysUnlock(); + + osalSysUnlock(); } /** @@ -121,14 +119,17 @@ void dacStart(DACDriver *dacp, const DACConfig *config) { */ void dacStop(DACDriver *dacp) { - chDbgCheck(dacp != NULL, "dacStop"); + osalDbgCheck(dacp != NULL); + + osalSysLock(); + + osalDbgAssert((dacp->state == DAC_STOP) || (dacp->state == DAC_READY), + "invalid state"); - chSysLock(); - chDbgAssert((dacp->state == DAC_STOP) || (dacp->state == DAC_READY), - "dacStop(), #1", "invalid state"); dac_lld_stop(dacp); dacp->state = DAC_STOP; - chSysUnlock(); + + osalSysUnlock(); } /** @@ -152,9 +153,9 @@ void dacStartConversion(DACDriver *dacp, const dacsample_t *samples, size_t depth) { - chSysLock(); + osalSysLock(); dacStartConversionI(dacp, grpp, samples, depth); - chSysUnlock(); + osalSysUnlock(); } /** @@ -180,14 +181,13 @@ void dacStartConversionI(DACDriver *dacp, const dacsample_t *samples, size_t depth) { - chDbgCheckClassI(); - chDbgCheck((dacp != NULL) && (grpp != NULL) && (samples != NULL) && - ((depth == 1) || ((depth & 1) == 0)), - "dacStartConversionI"); - chDbgAssert((dacp->state == DAC_READY) || - (dacp->state == DAC_COMPLETE) || - (dacp->state == DAC_ERROR), - "dacStartConversionI(), #1", "not ready"); + osalDbgCheckClassI(); + osalDbgCheck((dacp != NULL) && (grpp != NULL) && (samples != NULL) && + ((depth == 1) || ((depth & 1) == 0))); + osalDbgAssert((dacp->state == DAC_READY) || + (dacp->state == DAC_COMPLETE) || + (dacp->state == DAC_ERROR), + "not ready"); dacp->samples = samples; dacp->depth = depth; @@ -208,19 +208,22 @@ void dacStartConversionI(DACDriver *dacp, */ void dacStopConversion(DACDriver *dacp) { - chDbgCheck(dacp != NULL, "dacStopConversion"); + osalDbgCheck(dacp != NULL); + + osalSysLock(); + + osalDbgAssert((dacp->state == DAC_READY) || + (dacp->state == DAC_ACTIVE), + "invalid state"); - chSysLock(); - chDbgAssert((dacp->state == DAC_READY) || - (dacp->state == DAC_ACTIVE), - "dacStopConversion(), #1", "invalid state"); if (dacp->state != DAC_READY) { dac_lld_stop_conversion(dacp); dacp->grpp = NULL; dacp->state = DAC_READY; _dac_reset_s(dacp); } - chSysUnlock(); + + osalSysUnlock(); } /** @@ -235,12 +238,12 @@ void dacStopConversion(DACDriver *dacp) { */ void dacStopConversionI(DACDriver *dacp) { - chDbgCheckClassI(); - chDbgCheck(dacp != NULL, "dacStopConversionI"); - chDbgAssert((dacp->state == DAC_READY) || - (dacp->state == DAC_ACTIVE) || - (dacp->state == DAC_COMPLETE), - "dacStopConversionI(), #1", "invalid state"); + osalDbgCheckClassI(); + osalDbgCheck(dacp != NULL); + osalDbgAssert((dacp->state == DAC_READY) || + (dacp->state == DAC_ACTIVE) || + (dacp->state == DAC_COMPLETE), + "invalid state"); if (dacp->state != DAC_READY) { dac_lld_stop_conversion(dacp); @@ -265,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 @@ -280,12 +283,12 @@ msg_t dacConvert(DACDriver *dacp, size_t depth) { msg_t msg; - chSysLock(); - chDbgAssert(dacp->thread == NULL, "dacConvert(), #1", "already waiting"); + osalSysLock(); + dacStartConversionI(dacp, grpp, samples, depth); - _dac_wait_s(dacp); - msg = chThdSelf()->p_u.rdymsg; - chSysUnlock(); + msg = osalThreadSuspendS(&dacp->thread); + + osalSysUnlock(); return msg; } #endif /* DAC_USE_WAIT */ @@ -304,13 +307,9 @@ msg_t dacConvert(DACDriver *dacp, */ void dacAcquireBus(DACDriver *dacp) { - chDbgCheck(dacp != NULL, "dacAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&dacp->mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&dacp->semaphore); -#endif + osalDbgCheck(dacp != NULL); + + osalMutexLock(&dacp->mutex); } /** @@ -324,14 +323,9 @@ void dacAcquireBus(DACDriver *dacp) { */ void dacReleaseBus(DACDriver *dacp) { - chDbgCheck(dacp != NULL, "dacReleaseBus"); - -#if CH_USE_MUTEXES - (void)dacp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&dacp->semaphore); -#endif + osalDbgCheck(dacp != NULL); + + osalMutexUnlock(&dacp->mutex); } #endif /* DAC_USE_MUTUAL_EXCLUSION */ |