Skip to content

Commit f36c15e

Browse files
ananglstephanosio
authored andcommitted
drivers: spi_context: Use total transfer length in timeout calculation
When estimating the time that a given SPI transfer will take, whole buffer sets for TX and RX need to be taken into account, not only their first parts. Correct `spi_context_wait_for_completion()` accordingly. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 0267612 commit f36c15e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/spi/spi_context.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ static inline void spi_context_release(struct spi_context *ctx, int status)
129129
#endif /* CONFIG_SPI_ASYNC */
130130
}
131131

132+
static inline size_t spi_context_total_tx_len(struct spi_context *ctx);
133+
static inline size_t spi_context_total_rx_len(struct spi_context *ctx);
134+
132135
static inline int spi_context_wait_for_completion(struct spi_context *ctx)
133136
{
134137
int status = 0;
@@ -141,9 +144,11 @@ static inline int spi_context_wait_for_completion(struct spi_context *ctx)
141144
if (IS_ENABLED(CONFIG_SPI_SLAVE) && spi_context_is_slave(ctx)) {
142145
timeout = K_FOREVER;
143146
} else {
147+
uint32_t tx_len = spi_context_total_tx_len(ctx);
148+
uint32_t rx_len = spi_context_total_rx_len(ctx);
144149
uint32_t timeout_ms;
145150

146-
timeout_ms = MAX(ctx->tx_len, ctx->rx_len) * 8 * 1000 /
151+
timeout_ms = MAX(tx_len, rx_len) * 8 * 1000 /
147152
ctx->config->frequency;
148153
timeout_ms += CONFIG_SPI_COMPLETION_TIMEOUT_TOLERANCE;
149154

0 commit comments

Comments
 (0)