spi context: Add function for getting single transfer buffers length.

Added function helps setting the longest possible rx and tx buffers for
single SPI transfer. Each of these buffers is a continuous memory
region. It is useful for example when peripheral supports easyDMA.

Signed-off-by: Michał Kruszewski <michal.kruszewski@nordicsemi.no>
This commit is contained in:
Michał Kruszewski 2017-07-26 17:19:38 +02:00 committed by Anas Nashif
parent ce80c9e42d
commit ddef35c1da

View file

@ -254,6 +254,19 @@ bool spi_context_rx_on(struct spi_context *ctx)
return !!(ctx->rx_buf || ctx->rx_len);
}
static inline size_t spi_context_longest_current_buf(struct spi_context *ctx)
{
if (!ctx->tx_len) {
return ctx->rx_len;
} else if (!ctx->rx_len) {
return ctx->tx_len;
} else if (ctx->tx_len < ctx->rx_len) {
return ctx->tx_len;
}
return ctx->rx_len;
}
#ifdef __cplusplus
}
#endif