drivers: spi_context: Fix spi_context_xx_len_left

These two functions were using the value of ctx->xx_len wrong, the unit
is in words, not bytes, but spi_context_count_xx_buf_lens was iterating
over the length of bytes, not words.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2025-06-04 12:51:56 -05:00 committed by Anas Nashif
commit fd6b05c81b
2 changed files with 8 additions and 6 deletions

View file

@ -661,17 +661,17 @@ static inline size_t spi_context_total_rx_len(struct spi_context *ctx)
/* Similar to spi_context_total_tx_len, except does not count words that have been finished
* in the current buffer, ie only including what is remaining in the current buffer in the sum.
*/
static inline size_t spi_context_tx_len_left(struct spi_context *ctx)
static inline size_t spi_context_tx_len_left(struct spi_context *ctx, uint8_t dfs)
{
return ctx->tx_len + spi_context_count_tx_buf_lens(ctx, 1);
return (ctx->tx_len * dfs) + spi_context_count_tx_buf_lens(ctx, 1);
}
/* Similar to spi_context_total_rx_len, except does not count words that have been finished
* in the current buffer, ie only including what is remaining in the current buffer in the sum.
*/
static inline size_t spi_context_rx_len_left(struct spi_context *ctx)
static inline size_t spi_context_rx_len_left(struct spi_context *ctx, uint8_t dfs)
{
return ctx->rx_len + spi_context_count_rx_buf_lens(ctx, 1);
return (ctx->rx_len * dfs) + spi_context_count_rx_buf_lens(ctx, 1);
}
#ifdef __cplusplus

View file

@ -241,6 +241,7 @@ static void lpspi_isr(const struct device *dev)
const struct lpspi_config *config = dev->config;
struct lpspi_data *data = dev->data;
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
uint8_t word_size_bytes = lpspi_data->word_size_bytes;
struct spi_context *ctx = &data->ctx;
uint32_t status_flags = base->SR;
@ -252,7 +253,7 @@ static void lpspi_isr(const struct device *dev)
lpspi_handle_tx_irq(dev);
}
if (spi_context_rx_len_left(ctx) == 0) {
if (spi_context_rx_len_left(ctx, word_size_bytes) == 0) {
base->IER &= ~LPSPI_IER_RDIE_MASK;
base->CR |= LPSPI_CR_RRF_MASK; /* flush rx fifo */
}
@ -274,7 +275,8 @@ static void lpspi_isr(const struct device *dev)
lpspi_data->fill_len = fill_len;
}
if (spi_context_rx_len_left(ctx) == 1 && (LPSPI_VERID_MAJOR(base->VERID) < 2)) {
if ((DIV_ROUND_UP(spi_context_rx_len_left(ctx, word_size_bytes), word_size_bytes) == 1) &&
(LPSPI_VERID_MAJOR(base->VERID) < 2)) {
/* Due to stalling behavior on older LPSPI,
* need to end xfer in order to get last bit clocked out on bus.
*/