Skip to content

Commit fd6b05c

Browse files
decsnynashif
authored andcommitted
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>
1 parent 2c75ad0 commit fd6b05c

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

drivers/spi/spi_context.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,17 @@ static inline size_t spi_context_total_rx_len(struct spi_context *ctx)
661661
/* Similar to spi_context_total_tx_len, except does not count words that have been finished
662662
* in the current buffer, ie only including what is remaining in the current buffer in the sum.
663663
*/
664-
static inline size_t spi_context_tx_len_left(struct spi_context *ctx)
664+
static inline size_t spi_context_tx_len_left(struct spi_context *ctx, uint8_t dfs)
665665
{
666-
return ctx->tx_len + spi_context_count_tx_buf_lens(ctx, 1);
666+
return (ctx->tx_len * dfs) + spi_context_count_tx_buf_lens(ctx, 1);
667667
}
668668

669669
/* Similar to spi_context_total_rx_len, except does not count words that have been finished
670670
* in the current buffer, ie only including what is remaining in the current buffer in the sum.
671671
*/
672-
static inline size_t spi_context_rx_len_left(struct spi_context *ctx)
672+
static inline size_t spi_context_rx_len_left(struct spi_context *ctx, uint8_t dfs)
673673
{
674-
return ctx->rx_len + spi_context_count_rx_buf_lens(ctx, 1);
674+
return (ctx->rx_len * dfs) + spi_context_count_rx_buf_lens(ctx, 1);
675675
}
676676

677677
#ifdef __cplusplus

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ static void lpspi_isr(const struct device *dev)
241241
const struct lpspi_config *config = dev->config;
242242
struct lpspi_data *data = dev->data;
243243
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
244+
uint8_t word_size_bytes = lpspi_data->word_size_bytes;
244245
struct spi_context *ctx = &data->ctx;
245246
uint32_t status_flags = base->SR;
246247

@@ -252,7 +253,7 @@ static void lpspi_isr(const struct device *dev)
252253
lpspi_handle_tx_irq(dev);
253254
}
254255

255-
if (spi_context_rx_len_left(ctx) == 0) {
256+
if (spi_context_rx_len_left(ctx, word_size_bytes) == 0) {
256257
base->IER &= ~LPSPI_IER_RDIE_MASK;
257258
base->CR |= LPSPI_CR_RRF_MASK; /* flush rx fifo */
258259
}
@@ -274,7 +275,8 @@ static void lpspi_isr(const struct device *dev)
274275
lpspi_data->fill_len = fill_len;
275276
}
276277

277-
if (spi_context_rx_len_left(ctx) == 1 && (LPSPI_VERID_MAJOR(base->VERID) < 2)) {
278+
if ((DIV_ROUND_UP(spi_context_rx_len_left(ctx, word_size_bytes), word_size_bytes) == 1) &&
279+
(LPSPI_VERID_MAJOR(base->VERID) < 2)) {
278280
/* Due to stalling behavior on older LPSPI,
279281
* need to end xfer in order to get last bit clocked out on bus.
280282
*/

0 commit comments

Comments
 (0)