git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@16294 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2023-06-18 16:15:13 +00:00
parent 5a865d8d19
commit eb6e882637
4 changed files with 55 additions and 37 deletions

View File

@ -48,13 +48,19 @@
</configs> </configs>
<macros> <macros>
<macro name="__spi_getconf"> <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> <brief>Retrieves a configuration field.</brief>
<param name="ip">Pointer to the @p hal_sio_driver_c object.</param> <param name="ip">Pointer to the @p hal_sio_driver_c object.</param>
<param name="field">Configuration field to be retrieved.</param> <param name="field">Configuration field to be retrieved.</param>
<return>The field value.</return> <return>The field value.</return>
<notapi /> <notapi />
<implementation><![CDATA[ <implementation><![CDATA[(__spi_getconf(ip)->field)]]></implementation>
((const hal_spi_config_t *)((ip)->config))->field]]></implementation>
</macro> </macro>
</macros> </macros>
<types> <types>
@ -184,7 +190,7 @@ osalDbgCheckClassI();
osalDbgCheck((self != NULL) && (n > 0U)); osalDbgCheck((self != NULL) && (n > 0U));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
@ -253,7 +259,7 @@ osalDbgCheckClassI();
osalDbgCheck((self != NULL) && (n > 0U) && osalDbgCheck((self != NULL) && (n > 0U) &&
(rxbuf != NULL) && (txbuf != NULL)); (rxbuf != NULL) && (txbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
@ -326,7 +332,7 @@ osalDbgCheckClassI();
osalDbgCheck((self != NULL) && (n > 0U) && (txbuf != NULL)); osalDbgCheck((self != NULL) && (n > 0U) && (txbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
@ -395,7 +401,7 @@ osalDbgCheckClassI();
osalDbgCheck((self != NULL) && (n > 0U) && (rxbuf != NULL)); osalDbgCheck((self != NULL) && (n > 0U) && (rxbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");
@ -722,34 +728,34 @@ spi_lld_unselect(self);]]></implementation>
<method name="spiSelectX" ctype="void"> <method name="spiSelectX" ctype="void">
<implementation><![CDATA[ <implementation><![CDATA[
palClearLine(__spi_getconf(self, ssline));]]></implementation> palClearLine(__spi_getfield(self, ssline));]]></implementation>
</method> </method>
<method name="spiUnselectX" ctype="void"> <method name="spiUnselectX" ctype="void">
<implementation><![CDATA[ <implementation><![CDATA[
palSetLine(__spi_getconf(self, ssline));]]></implementation> palSetLine(__spi_getfield(self, ssline));]]></implementation>
</method> </method>
<elseif check="SPI_SELECT_MODE == SPI_SELECT_MODE_PORT" /> <elseif check="SPI_SELECT_MODE == SPI_SELECT_MODE_PORT" />
<method name="spiSelectX" ctype="void"> <method name="spiSelectX" ctype="void">
<implementation><![CDATA[ <implementation><![CDATA[
palClearPort(__spi_getconf(self, ssport), __spi_getconf(self, ssmask));]]></implementation> palClearPort(__spi_getfield(self, ssport), __spi_getfield(self, ssmask));]]></implementation>
</method> </method>
<method name="spiUnselectX" ctype="void"> <method name="spiUnselectX" ctype="void">
<implementation><![CDATA[ <implementation><![CDATA[
palSetPort(__spi_getconf(self, ssport), __spi_getconf(self, ssmask));]]></implementation> palSetPort(__spi_getfield(self, ssport), __spi_getfield(self, ssmask));]]></implementation>
</method> </method>
<elseif check="SPI_SELECT_MODE == SPI_SELECT_MODE_PAD" /> <elseif check="SPI_SELECT_MODE == SPI_SELECT_MODE_PAD" />
<method name="spiSelectX" ctype="void"> <method name="spiSelectX" ctype="void">
<implementation><![CDATA[ <implementation><![CDATA[
palClearPad(__spi_getconf(self, ssport), __spi_getconf(self, sspad));]]></implementation> palClearPad(__spi_getfield(self, ssport), __spi_getfield(self, sspad));]]></implementation>
</method> </method>
<method name="spiUnselectX" ctype="void"> <method name="spiUnselectX" ctype="void">
<implementation><![CDATA[ <implementation><![CDATA[
palSetPad(__spi_getconf(self, ssport), __spi_getconf(self, sspad));]]></implementation> palSetPad(__spi_getfield(self, ssport), __spi_getfield(self, sspad));]]></implementation>
</method> </method>
</condition> </condition>
<condition check="SPI_USE_SYNCHRONIZATION == TRUE"> <condition check="SPI_USE_SYNCHRONIZATION == TRUE">

View File

@ -113,6 +113,17 @@
/* Module macros. */ /* 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. * @brief Retrieves a configuration field.
* *
@ -122,8 +133,8 @@
* *
* @notapi * @notapi
*/ */
#define __spi_getconf(ip, field) \ #define __spi_getfield(ip, field) \
((const hal_spi_config_t *)((ip)->config))->field (__spi_getconf(ip)->field)
/*===========================================================================*/ /*===========================================================================*/
/* Module data structures and types. */ /* Module data structures and types. */
@ -408,14 +419,14 @@ CC_FORCE_INLINE
static inline void spiSelectX(void *ip) { static inline void spiSelectX(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)ip; hal_spi_driver_c *self = (hal_spi_driver_c *)ip;
palClearLine(__spi_getconf(self, ssline)); palClearLine(__spi_getfield(self, ssline));
} }
CC_FORCE_INLINE CC_FORCE_INLINE
static inline void spiUnselectX(void *ip) { static inline void spiUnselectX(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)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 #elif SPI_SELECT_MODE == SPI_SELECT_MODE_PORT
@ -423,14 +434,14 @@ CC_FORCE_INLINE
static inline void spiSelectX(void *ip) { static inline void spiSelectX(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)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 CC_FORCE_INLINE
static inline void spiUnselectX(void *ip) { static inline void spiUnselectX(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)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 #elif SPI_SELECT_MODE == SPI_SELECT_MODE_PAD
@ -438,14 +449,14 @@ CC_FORCE_INLINE
static inline void spiSelectX(void *ip) { static inline void spiSelectX(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)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 CC_FORCE_INLINE
static inline void spiUnselectX(void *ip) { static inline void spiUnselectX(void *ip) {
hal_spi_driver_c *self = (hal_spi_driver_c *)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 */ #endif /* SPI_SELECT_MODE == SPI_SELECT_MODE_LLD */

View File

@ -126,16 +126,17 @@ SPIDriver SPID6;
* @param[in] spip pointer to the @p SPIDriver object * @param[in] spip pointer to the @p SPIDriver object
*/ */
static void spi_lld_enable(SPIDriver *spip) { static void spi_lld_enable(SPIDriver *spip) {
const hal_spi_config_t *config = __spi_getconf(spip);
uint32_t cr1, cr2; uint32_t cr1, cr2;
/* SPI setup.*/ /* SPI setup.*/
if (spip->config->slave) { if (config->slave) {
cr1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE); cr1 = config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE);
cr2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; cr2 = config->cr2 | SPI_CR2_FRXTH | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
} }
else { else {
cr1 = (spip->config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE; cr1 = (config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE;
cr2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; cr2 = config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
} }
spip->spi->CR1 = cr1; spip->spi->CR1 = cr1;
@ -154,7 +155,7 @@ static void spi_lld_enable(SPIDriver *spip) {
*/ */
static void spi_lld_disable(SPIDriver *spip) { static void spi_lld_disable(SPIDriver *spip) {
if (!spip->config->slave) { if (!__spi_getfield(spip, slave)) {
/* Master mode, stopping gracefully.*/ /* Master mode, stopping gracefully.*/
/* Stopping TX DMA channel.*/ /* Stopping TX DMA channel.*/
@ -246,7 +247,7 @@ static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags) {
/* Reporting the failure.*/ /* Reporting the failure.*/
__spi_isr_error_code(spip, HAL_RET_HW_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) { if ((flags & STM32_DMA_ISR_HTIF) != 0U) {
/* Half buffer interrupt.*/ /* Half buffer interrupt.*/
__spi_isr_half_code(spip); __spi_isr_half_code(spip);
@ -460,7 +461,7 @@ msg_t spi_lld_start(SPIDriver *spip) {
spip->txsource = (uint32_t)STM32_SPI_FILLER_PATTERN; spip->txsource = (uint32_t)STM32_SPI_FILLER_PATTERN;
/* If in stopped state then enables the SPI and DMA clocks.*/ /* If in stopped state then enables the SPI and DMA clocks.*/
if (spip->state == SPI_STOP) { if (spip->state == DRV_STATE_STOP) {
if (false) { if (false) {
} }
@ -586,7 +587,7 @@ msg_t spi_lld_start(SPIDriver *spip) {
} }
/* Configuration-specific DMA setup.*/ /* 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))) { if (!ds || (ds <= (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0))) {
/* Frame width is 8 bits or smaller.*/ /* Frame width is 8 bits or smaller.*/
spip->rxdmamode = (spip->rxdmamode & ~STM32_DMA_CR_SIZE_MASK) | 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; 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->rxdmamode |= (STM32_DMA_CR_CIRC | STM32_DMA_CR_HTIE);
spip->txdmamode |= (STM32_DMA_CR_CIRC | STM32_DMA_CR_HTIE); spip->txdmamode |= (STM32_DMA_CR_CIRC | STM32_DMA_CR_HTIE);
} }
@ -895,7 +896,7 @@ uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
* Byte size access (uint8_t *) for transactions that are <= 8-bit. * Byte size access (uint8_t *) for transactions that are <= 8-bit.
* Halfword size access (uint16_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 | if ((__spi_getfield(spip, cr2) & SPI_CR2_DS) <= (SPI_CR2_DS_2 |
SPI_CR2_DS_1 | SPI_CR2_DS_1 |
SPI_CR2_DS_0)) { SPI_CR2_DS_0)) {
volatile uint8_t *dr8p = (volatile uint8_t *)&spip->spi->DR; volatile uint8_t *dr8p = (volatile uint8_t *)&spip->spi->DR;

View File

@ -210,7 +210,7 @@ msg_t spiStartIgnoreI(void *ip, size_t n) {
osalDbgCheck((self != NULL) && (n > 0U)); osalDbgCheck((self != NULL) && (n > 0U));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); 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) && osalDbgCheck((self != NULL) && (n > 0U) &&
(rxbuf != NULL) && (txbuf != NULL)); (rxbuf != NULL) && (txbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); 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)); osalDbgCheck((self != NULL) && (n > 0U) && (txbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); 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)); osalDbgCheck((self != NULL) && (n > 0U) && (rxbuf != NULL));
#if SPI_SUPPORTS_CIRCULAR #if SPI_SUPPORTS_CIRCULAR
osalDbgCheck((__spi_getconf(self, circular) == false) || ((n & 1U) == 0U)); osalDbgCheck((__spi_getfield(self, circular) == false) || ((n & 1U) == 0U));
#endif #endif
osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready"); osalDbgAssert(self->state == HAL_DRV_STATE_READY, "not ready");