Improved ADC and SPI driver models.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2426 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
d973c3f25a
commit
c852dcb3c9
|
@ -187,17 +187,9 @@ int main(int argc, char **argv) {
|
|||
*/
|
||||
spiStart(&SPID1, &spicfg);
|
||||
|
||||
/*
|
||||
* Initializes the ADC driver 1.
|
||||
* The pin PC0 on the port GPIOC is programmed as analog input.
|
||||
*/
|
||||
adcStart(&ADCD1, &adccfg);
|
||||
palSetGroupMode(GPIOC, PAL_PORT_BIT(0), PAL_MODE_INPUT_ANALOG);
|
||||
|
||||
/*
|
||||
* Initializes the PWM driver 1, re-routes the TIM3 outputs, programs the
|
||||
* pins as alternate functions and finally enables channels with zero
|
||||
* initial duty cycle.
|
||||
* pins as alternate functions.
|
||||
* Note, the AFIO access routes the TIM3 output pins on the PC6...PC9
|
||||
* where the LEDs are connected.
|
||||
*/
|
||||
|
@ -206,6 +198,14 @@ int main(int argc, char **argv) {
|
|||
palSetGroupMode(GPIOC, PAL_PORT_BIT(GPIOC_LED3) | PAL_PORT_BIT(GPIOC_LED4),
|
||||
PAL_MODE_STM32_ALTERNATE_PUSHPULL);
|
||||
|
||||
/*
|
||||
* Initializes the ADC driver 1 and performs a conversion.
|
||||
* The pin PC0 on the port GPIOC is programmed as analog input.
|
||||
*/
|
||||
adcStart(&ADCD1, &adccfg);
|
||||
palSetGroupMode(GPIOC, PAL_PORT_BIT(0), PAL_MODE_INPUT_ANALOG);
|
||||
adcConvert(&ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH);
|
||||
|
||||
/*
|
||||
* Creates the example thread.
|
||||
*/
|
||||
|
|
|
@ -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); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
|
|
@ -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); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -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.*/
|
||||
|
|
|
@ -78,6 +78,8 @@
|
|||
- FIX: Fixed typo in board name (bug 3113574)(backported to 2.0.7).
|
||||
- FIX: Fixed defective event wait functions with timeout (bug 3113443)
|
||||
(backported to 2.0.7).
|
||||
- NEW: More improvements to the ADC and SPI drivers, now synchronous
|
||||
operations can also have callbacks, optimized ISR code paths.
|
||||
- NEW: Added to the STM32 ADC driver the macros for easy handling of the
|
||||
sampling time for each channel.
|
||||
- NEW: Greatly simplified the STM32 PWM driver implementation.
|
||||
|
|
Loading…
Reference in New Issue