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 ++++++++----------- os/hal/platforms/AT91SAM7/spi_lld.h | 3 --- os/hal/platforms/LPC11xx/spi_lld.h | 3 --- os/hal/platforms/LPC13xx/spi_lld.h | 3 --- os/hal/platforms/LPC214x/spi_lld.h | 3 --- os/hal/platforms/STM32/adc_lld.h | 3 --- os/hal/platforms/STM32/spi_lld.h | 3 --- os/hal/platforms/STM8S/spi_lld.h | 3 --- os/hal/src/spi.c | 8 ++++---- os/hal/templates/adc_lld.h | 3 --- os/hal/templates/spi_lld.h | 3 --- 12 files changed, 18 insertions(+), 52 deletions(-) (limited to 'os/hal') 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); \ } \ } diff --git a/os/hal/platforms/AT91SAM7/spi_lld.h b/os/hal/platforms/AT91SAM7/spi_lld.h index 6243e66fa..3b0bfaaba 100644 --- a/os/hal/platforms/AT91SAM7/spi_lld.h +++ b/os/hal/platforms/AT91SAM7/spi_lld.h @@ -126,9 +126,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/platforms/LPC11xx/spi_lld.h b/os/hal/platforms/LPC11xx/spi_lld.h index c7af31697..64f87c679 100644 --- a/os/hal/platforms/LPC11xx/spi_lld.h +++ b/os/hal/platforms/LPC11xx/spi_lld.h @@ -227,9 +227,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/platforms/LPC13xx/spi_lld.h b/os/hal/platforms/LPC13xx/spi_lld.h index bf94a824e..63a233f18 100644 --- a/os/hal/platforms/LPC13xx/spi_lld.h +++ b/os/hal/platforms/LPC13xx/spi_lld.h @@ -227,9 +227,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/platforms/LPC214x/spi_lld.h b/os/hal/platforms/LPC214x/spi_lld.h index 5f5d45823..50226cf4a 100644 --- a/os/hal/platforms/LPC214x/spi_lld.h +++ b/os/hal/platforms/LPC214x/spi_lld.h @@ -98,9 +98,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/platforms/STM32/adc_lld.h b/os/hal/platforms/STM32/adc_lld.h index c6ba26c05..0850b62f4 100644 --- a/os/hal/platforms/STM32/adc_lld.h +++ b/os/hal/platforms/STM32/adc_lld.h @@ -161,9 +161,6 @@ typedef struct { adc_channels_num_t acg_num_channels; /** * @brief Callback function associated to the group or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ adccallback_t acg_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/platforms/STM32/spi_lld.h b/os/hal/platforms/STM32/spi_lld.h index d46035ec0..9e29c5d68 100644 --- a/os/hal/platforms/STM32/spi_lld.h +++ b/os/hal/platforms/STM32/spi_lld.h @@ -186,9 +186,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/platforms/STM8S/spi_lld.h b/os/hal/platforms/STM8S/spi_lld.h index e4a963d67..cbcd2fd62 100644 --- a/os/hal/platforms/STM8S/spi_lld.h +++ b/os/hal/platforms/STM8S/spi_lld.h @@ -86,9 +86,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/src/spi.c b/os/hal/src/spi.c index 4d9749962..d1102cc6e 100644 --- a/os/hal/src/spi.c +++ b/os/hal/src/spi.c @@ -295,7 +295,7 @@ void spiIgnore(SPIDriver *spip, size_t n) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiIgnore(), #2", "has callback"); spiStartIgnoreI(spip, n); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -329,7 +329,7 @@ void spiExchange(SPIDriver *spip, size_t n, chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiExchange(), #2", "has callback"); spiStartExchangeI(spip, n, txbuf, rxbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -360,7 +360,7 @@ void spiSend(SPIDriver *spip, size_t n, const void *txbuf) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiSend(), #2", "has callback"); spiStartSendI(spip, n, txbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } @@ -391,7 +391,7 @@ void spiReceive(SPIDriver *spip, size_t n, void *rxbuf) { chDbgAssert(spip->spd_config->spc_endcb == NULL, "spiReceive(), #2", "has callback"); spiStartReceiveI(spip, n, rxbuf); - _spi_wait(spip); + _spi_wait_s(spip); chSysUnlock(); } #endif /* SPI_USE_WAIT */ diff --git a/os/hal/templates/adc_lld.h b/os/hal/templates/adc_lld.h index c85a1bd77..54d78fd44 100644 --- a/os/hal/templates/adc_lld.h +++ b/os/hal/templates/adc_lld.h @@ -93,9 +93,6 @@ typedef struct { adc_channels_num_t acg_num_channels; /** * @brief Callback function associated to the group or @p NULL. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ adccallback_t acg_endcb; /* End of the mandatory fields.*/ diff --git a/os/hal/templates/spi_lld.h b/os/hal/templates/spi_lld.h index 4e7d7b81b..e985aa727 100644 --- a/os/hal/templates/spi_lld.h +++ b/os/hal/templates/spi_lld.h @@ -67,9 +67,6 @@ typedef void (*spicallback_t)(SPIDriver *spip); typedef struct { /** * @brief Operation complete callback. - * @note In order to use synchronous functions this field must be set to - * @p NULL, callbacks and synchronous operations are mutually - * exclusive. */ spicallback_t spc_endcb; /* End of the mandatory fields.*/ -- cgit v1.2.3