git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16294 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
5a865d8d19
commit
eb6e882637
|
@ -48,13 +48,19 @@
|
|||
</configs>
|
||||
<macros>
|
||||
<macro name="__spi_getconf">
|
||||
<brief>Return a pointer to the configuration structure.</brief>
|
||||
<param name="ip">Pointer to the @p hal_sio_driver_c object.</param>
|
||||
<return>A pointer to the configuration structure.</return>
|
||||
<notapi />
|
||||
<implementation><![CDATA[((const hal_spi_config_t *)((ip)->config))]]></implementation>
|
||||
</macro>
|
||||
<macro name="__spi_getfield">
|
||||
<brief>Retrieves a configuration field.</brief>
|
||||
<param name="ip">Pointer to the @p hal_sio_driver_c object.</param>
|
||||
<param name="field">Configuration field to be retrieved.</param>
|
||||
<return>The field value.</return>
|
||||
<notapi />
|
||||
<implementation><![CDATA[
|
||||
((const hal_spi_config_t *)((ip)->config))->field]]></implementation>
|
||||
<implementation><![CDATA[(__spi_getconf(ip)->field)]]></implementation>
|
||||
</macro>
|
||||
</macros>
|
||||
<types>
|
||||
|
@ -184,7 +190,7 @@ osalDbgCheckClassI();
|
|||
|
||||
osalDbgCheck((self != NULL) && (n > 0U));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -253,7 +259,7 @@ osalDbgCheckClassI();
|
|||
osalDbgCheck((self != NULL) && (n > 0U) &&
|
||||
(rxbuf != NULL) && (txbuf != NULL));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -326,7 +332,7 @@ osalDbgCheckClassI();
|
|||
|
||||
osalDbgCheck((self != NULL) && (n > 0U) && (txbuf != NULL));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -395,7 +401,7 @@ osalDbgCheckClassI();
|
|||
|
||||
osalDbgCheck((self != NULL) && (n > 0U) && (rxbuf != NULL));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -722,34 +728,34 @@ spi_lld_unselect(self);]]></implementation>
|
|||
<method name="spiSelectX" ctype="void">
|
||||
<implementation><![CDATA[
|
||||
|
||||
palClearLine(__spi_getconf(self, ssline));]]></implementation>
|
||||
palClearLine(__spi_getfield(self, ssline));]]></implementation>
|
||||
</method>
|
||||
<method name="spiUnselectX" ctype="void">
|
||||
<implementation><![CDATA[
|
||||
|
||||
palSetLine(__spi_getconf(self, ssline));]]></implementation>
|
||||
palSetLine(__spi_getfield(self, ssline));]]></implementation>
|
||||
</method>
|
||||
<elseif check="SPI_SELECT_MODE == SPI_SELECT_MODE_PORT" />
|
||||
<method name="spiSelectX" ctype="void">
|
||||
<implementation><![CDATA[
|
||||
|
||||
palClearPort(__spi_getconf(self, ssport), __spi_getconf(self, ssmask));]]></implementation>
|
||||
palClearPort(__spi_getfield(self, ssport), __spi_getfield(self, ssmask));]]></implementation>
|
||||
</method>
|
||||
<method name="spiUnselectX" ctype="void">
|
||||
<implementation><![CDATA[
|
||||
|
||||
palSetPort(__spi_getconf(self, ssport), __spi_getconf(self, ssmask));]]></implementation>
|
||||
palSetPort(__spi_getfield(self, ssport), __spi_getfield(self, ssmask));]]></implementation>
|
||||
</method>
|
||||
<elseif check="SPI_SELECT_MODE == SPI_SELECT_MODE_PAD" />
|
||||
<method name="spiSelectX" ctype="void">
|
||||
<implementation><![CDATA[
|
||||
|
||||
palClearPad(__spi_getconf(self, ssport), __spi_getconf(self, sspad));]]></implementation>
|
||||
palClearPad(__spi_getfield(self, ssport), __spi_getfield(self, sspad));]]></implementation>
|
||||
</method>
|
||||
<method name="spiUnselectX" ctype="void">
|
||||
<implementation><![CDATA[
|
||||
|
||||
palSetPad(__spi_getconf(self, ssport), __spi_getconf(self, sspad));]]></implementation>
|
||||
palSetPad(__spi_getfield(self, ssport), __spi_getfield(self, sspad));]]></implementation>
|
||||
</method>
|
||||
</condition>
|
||||
<condition check="SPI_USE_SYNCHRONIZATION == TRUE">
|
||||
|
|
|
@ -113,6 +113,17 @@
|
|||
/* Module macros. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Return a pointer to the configuration structure.
|
||||
*
|
||||
* @param ip Pointer to the @p hal_sio_driver_c object.
|
||||
* @return A pointer to the configuration structure.
|
||||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define __spi_getconf(ip) \
|
||||
((const hal_spi_config_t *)((ip)->config))
|
||||
|
||||
/**
|
||||
* @brief Retrieves a configuration field.
|
||||
*
|
||||
|
@ -122,8 +133,8 @@
|
|||
*
|
||||
* @notapi
|
||||
*/
|
||||
#define __spi_getconf(ip, field) \
|
||||
((const hal_spi_config_t *)((ip)->config))->field
|
||||
#define __spi_getfield(ip, field) \
|
||||
(__spi_getconf(ip)->field)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Module data structures and types. */
|
||||
|
@ -408,14 +419,14 @@ CC_FORCE_INLINE
|
|||
static inline void spiSelectX(void *ip) {
|
||||
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
|
||||
|
||||
palClearLine(__spi_getconf(self, ssline));
|
||||
palClearLine(__spi_getfield(self, ssline));
|
||||
}
|
||||
|
||||
CC_FORCE_INLINE
|
||||
static inline void spiUnselectX(void *ip) {
|
||||
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
|
||||
|
||||
palSetLine(__spi_getconf(self, ssline));
|
||||
palSetLine(__spi_getfield(self, ssline));
|
||||
}
|
||||
|
||||
#elif SPI_SELECT_MODE == SPI_SELECT_MODE_PORT
|
||||
|
@ -423,14 +434,14 @@ CC_FORCE_INLINE
|
|||
static inline void spiSelectX(void *ip) {
|
||||
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
|
||||
|
||||
palClearPort(__spi_getconf(self, ssport), __spi_getconf(self, ssmask));
|
||||
palClearPort(__spi_getfield(self, ssport), __spi_getfield(self, ssmask));
|
||||
}
|
||||
|
||||
CC_FORCE_INLINE
|
||||
static inline void spiUnselectX(void *ip) {
|
||||
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
|
||||
|
||||
palSetPort(__spi_getconf(self, ssport), __spi_getconf(self, ssmask));
|
||||
palSetPort(__spi_getfield(self, ssport), __spi_getfield(self, ssmask));
|
||||
}
|
||||
|
||||
#elif SPI_SELECT_MODE == SPI_SELECT_MODE_PAD
|
||||
|
@ -438,14 +449,14 @@ CC_FORCE_INLINE
|
|||
static inline void spiSelectX(void *ip) {
|
||||
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
|
||||
|
||||
palClearPad(__spi_getconf(self, ssport), __spi_getconf(self, sspad));
|
||||
palClearPad(__spi_getfield(self, ssport), __spi_getfield(self, sspad));
|
||||
}
|
||||
|
||||
CC_FORCE_INLINE
|
||||
static inline void spiUnselectX(void *ip) {
|
||||
hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
|
||||
|
||||
palSetPad(__spi_getconf(self, ssport), __spi_getconf(self, sspad));
|
||||
palSetPad(__spi_getfield(self, ssport), __spi_getfield(self, sspad));
|
||||
}
|
||||
#endif /* SPI_SELECT_MODE == SPI_SELECT_MODE_LLD */
|
||||
|
||||
|
|
|
@ -126,16 +126,17 @@ SPIDriver SPID6;
|
|||
* @param[in] spip pointer to the @p SPIDriver object
|
||||
*/
|
||||
static void spi_lld_enable(SPIDriver *spip) {
|
||||
const hal_spi_config_t *config = __spi_getconf(spip);
|
||||
uint32_t cr1, cr2;
|
||||
|
||||
/* SPI setup.*/
|
||||
if (spip->config->slave) {
|
||||
cr1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE);
|
||||
cr2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
|
||||
if (config->slave) {
|
||||
cr1 = config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE);
|
||||
cr2 = config->cr2 | SPI_CR2_FRXTH | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
|
||||
}
|
||||
else {
|
||||
cr1 = (spip->config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE;
|
||||
cr2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
|
||||
cr1 = (config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE;
|
||||
cr2 = config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
|
||||
}
|
||||
|
||||
spip->spi->CR1 = cr1;
|
||||
|
@ -154,7 +155,7 @@ static void spi_lld_enable(SPIDriver *spip) {
|
|||
*/
|
||||
static void spi_lld_disable(SPIDriver *spip) {
|
||||
|
||||
if (!spip->config->slave) {
|
||||
if (!__spi_getfield(spip, slave)) {
|
||||
/* Master mode, stopping gracefully.*/
|
||||
|
||||
/* Stopping TX DMA channel.*/
|
||||
|
@ -246,7 +247,7 @@ static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags) {
|
|||
/* Reporting the failure.*/
|
||||
__spi_isr_error_code(spip, HAL_RET_HW_FAILURE);
|
||||
}
|
||||
else if (spip->config->circular) {
|
||||
else if (__spi_getfield(spip, circular)) {
|
||||
if ((flags & STM32_DMA_ISR_HTIF) != 0U) {
|
||||
/* Half buffer interrupt.*/
|
||||
__spi_isr_half_code(spip);
|
||||
|
@ -460,7 +461,7 @@ msg_t spi_lld_start(SPIDriver *spip) {
|
|||
spip->txsource = (uint32_t)STM32_SPI_FILLER_PATTERN;
|
||||
|
||||
/* If in stopped state then enables the SPI and DMA clocks.*/
|
||||
if (spip->state == SPI_STOP) {
|
||||
if (spip->state == DRV_STATE_STOP) {
|
||||
if (false) {
|
||||
}
|
||||
|
||||
|
@ -586,7 +587,7 @@ msg_t spi_lld_start(SPIDriver *spip) {
|
|||
}
|
||||
|
||||
/* Configuration-specific DMA setup.*/
|
||||
ds = spip->config->cr2 & SPI_CR2_DS;
|
||||
ds = __spi_getfield(spip, cr2) & SPI_CR2_DS;
|
||||
if (!ds || (ds <= (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0))) {
|
||||
/* Frame width is 8 bits or smaller.*/
|
||||
spip->rxdmamode = (spip->rxdmamode & ~STM32_DMA_CR_SIZE_MASK) |
|
||||
|
@ -602,7 +603,7 @@ msg_t spi_lld_start(SPIDriver *spip) {
|
|||
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
|
||||
}
|
||||
|
||||
if (spip->config->circular) {
|
||||
if (__spi_getfield(spip, circular)) {
|
||||
spip->rxdmamode |= (STM32_DMA_CR_CIRC | STM32_DMA_CR_HTIE);
|
||||
spip->txdmamode |= (STM32_DMA_CR_CIRC | STM32_DMA_CR_HTIE);
|
||||
}
|
||||
|
@ -895,9 +896,9 @@ uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
|
|||
* Byte size access (uint8_t *) for transactions that are <= 8-bit.
|
||||
* Halfword size access (uint16_t) for transactions that are <= 8-bit.
|
||||
*/
|
||||
if ((spip->config->cr2 & SPI_CR2_DS) <= (SPI_CR2_DS_2 |
|
||||
SPI_CR2_DS_1 |
|
||||
SPI_CR2_DS_0)) {
|
||||
if ((__spi_getfield(spip, cr2) & SPI_CR2_DS) <= (SPI_CR2_DS_2 |
|
||||
SPI_CR2_DS_1 |
|
||||
SPI_CR2_DS_0)) {
|
||||
volatile uint8_t *dr8p = (volatile uint8_t *)&spip->spi->DR;
|
||||
*dr8p = (uint8_t)frame;
|
||||
while ((spip->spi->SR & SPI_SR_RXNE) == 0U) {
|
||||
|
|
|
@ -210,7 +210,7 @@ msg_t spiStartIgnoreI(void *ip, size_t n) {
|
|||
|
||||
osalDbgCheck((self != NULL) && (n > 0U));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -283,7 +283,7 @@ msg_t spiStartExchangeI(void *ip, size_t n, const void *txbuf, void *rxbuf) {
|
|||
osalDbgCheck((self != NULL) && (n > 0U) &&
|
||||
(rxbuf != NULL) && (txbuf != NULL));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -357,7 +357,7 @@ msg_t spiStartSendI(void *ip, size_t n, const void *txbuf) {
|
|||
|
||||
osalDbgCheck((self != NULL) && (n > 0U) && (txbuf != NULL));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
@ -429,7 +429,7 @@ msg_t spiStartReceiveI(void *ip, size_t n, void *rxbuf) {
|
|||
|
||||
osalDbgCheck((self != NULL) && (n > 0U) && (rxbuf != NULL));
|
||||
#if SPI_SUPPORTS_CIRCULAR
|
||||
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U));
|
||||
osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
|
||||
#endif
|
||||
|
||||
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
|
||||
|
|
Loading…
Reference in New Issue