From c852dcb3c960198f49c5fdd8619a6d5d581d9136 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 25 Nov 2010 18:32:45 +0000 Subject: Improved ADC and SPI driver models. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2426 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/adc.h | 16 ++++++---------- os/hal/include/spi.h | 19 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) (limited to 'os/hal/include') diff --git a/os/hal/include/adc.h b/os/hal/include/adc.h index 48f9d9ff6..0b55d0d15 100644 --- a/os/hal/include/adc.h +++ b/os/hal/include/adc.h @@ -122,22 +122,21 @@ typedef enum { * * @notapi */ -#define _adc_wakeup_i(adcp) { \ - chSysLockFromIsr(); \ - (adcp)->ad_grpp = NULL; \ +#define _adc_wakeup_isr(adcp) { \ if ((adcp)->ad_thread != NULL) { \ Thread *tp = (adcp)->ad_thread; \ (adcp)->ad_thread = NULL; \ + chSysLockFromIsr(); \ tp->p_u.rdymsg = RDY_OK; \ chSchReadyI(tp); \ + chSysUnlockFromIsr(); \ } \ - chSysUnlockFromIsr(); \ } #else /* !ADC_USE_WAIT */ #define _adc_reset_i(adcp) #define _adc_reset_s(adcp) -#define _adc_wakeup(adcp) +#define _adc_wakeup_isr(adcp) #endif /* !ADC_USE_WAIT */ /** @@ -192,11 +191,7 @@ typedef enum { else { \ /* End conversion.*/ \ adc_lld_stop_conversion(adcp); \ - if ((adcp)->ad_grpp->acg_endcb == NULL) { \ - (adcp)->ad_state = ADC_READY; \ - _adc_wakeup_i(adcp); \ - } \ - else { \ + if ((adcp)->ad_grpp->acg_endcb != NULL) { \ (adcp)->ad_state = ADC_COMPLETE; \ if ((adcp)->ad_depth > 1) { \ /* Invokes the callback passing the 2nd half of the buffer.*/ \ @@ -212,6 +207,7 @@ typedef enum { (adcp)->ad_state = ADC_READY; \ } \ (adcp)->ad_grpp = NULL; \ + _adc_wakeup_isr(adcp); \ } \ } diff --git a/os/hal/include/spi.h b/os/hal/include/spi.h index 93aba4980..a563b262c 100644 --- a/os/hal/include/spi.h +++ b/os/hal/include/spi.h @@ -214,7 +214,7 @@ typedef enum { * * @notapi */ -#define _spi_wait(spip) { \ +#define _spi_wait_s(spip) { \ chDbgAssert((spip)->spd_thread == NULL, \ "_spi_wait(), #1", "already waiting"); \ (spip)->spd_thread = chThdSelf(); \ @@ -228,18 +228,18 @@ typedef enum { * * @notapi */ -#define _spi_wakeup(spip) { \ - chSysLockFromIsr(); \ +#define _spi_wakeup_isr(spip) { \ if ((spip)->spd_thread != NULL) { \ Thread *tp = (spip)->spd_thread; \ (spip)->spd_thread = NULL; \ + chSysLockFromIsr(); \ chSchReadyI(tp); \ + chSysUnlockFromIsr(); \ } \ - chSysUnlockFromIsr(); \ } #else /* !SPI_USE_WAIT */ -#define _spi_wakeup(spip) -#define _spi_wait(spip) +#define _spi_wait_s(spip) +#define _spi_wakeup_isr(spip) #endif /* !SPI_USE_WAIT */ /** @@ -261,11 +261,8 @@ typedef enum { (spip)->spd_state = SPI_COMPLETE; \ (spip)->spd_config->spc_endcb(spip); \ if ((spip)->spd_state == SPI_COMPLETE) \ - (spip)->spd_state = SPI_READY; \ - } \ - else { \ - (spip)->spd_state = SPI_READY; \ - _spi_wakeup(spip); \ + (spip)->spd_state = SPI_READY; \ + _spi_wakeup_isr(spip); \ } \ } -- cgit v1.2.3