drivers: spi: nrfx: Restore recently changed spi_context function
Function spi_context_longest_current_buf() has been introduced in commitddef35c1da
for the purpose of getting the longest possible (potentially partial) SPI transfer for which all currently active directions have a continuous buffer. Such transfer can be done with taking advantage of a DMA that cannot use scattered buffers (and this is the case for nRF SPI drivers with which this function has been introduced). Unfortunately, because of its inadequate name, later on this function has been incorrectly used in other SPI drivers for getting the longer of TX/RX buffers. And commitafc480f12b
recently "fixed" the implementation of this function, assumably to adjust it to those incorrect uses, but this way it has also broken the nRF SPI drivers. Instead of restoring the original implementation of the function in question, this commit adds a new one with functionality equivalent to that original but with a hopefully less misleading name, and this function is used in the nRF SPI drivers. Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
This commit is contained in:
parent
c5a7e15fd8
commit
a3430c2caf
4 changed files with 19 additions and 3 deletions
|
@ -343,6 +343,22 @@ bool spi_context_rx_buf_on(struct spi_context *ctx)
|
||||||
return !!(ctx->rx_buf && ctx->rx_len);
|
return !!(ctx->rx_buf && ctx->rx_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the maximum length of a transfer for which all currently active
|
||||||
|
* directions have a continuous buffer, i.e. the maximum SPI transfer that
|
||||||
|
* can be done with DMA that handles only non-scattered buffers.
|
||||||
|
*/
|
||||||
|
static inline size_t spi_context_max_continuous_chunk(struct spi_context *ctx)
|
||||||
|
{
|
||||||
|
if (!ctx->tx_len) {
|
||||||
|
return ctx->rx_len;
|
||||||
|
} else if (!ctx->rx_len) {
|
||||||
|
return ctx->tx_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MIN(ctx->tx_len, ctx->rx_len);
|
||||||
|
}
|
||||||
|
|
||||||
static inline size_t spi_context_longest_current_buf(struct spi_context *ctx)
|
static inline size_t spi_context_longest_current_buf(struct spi_context *ctx)
|
||||||
{
|
{
|
||||||
return ctx->tx_len > ctx->rx_len ? ctx->tx_len : ctx->rx_len;
|
return ctx->tx_len > ctx->rx_len ? ctx->tx_len : ctx->rx_len;
|
||||||
|
|
|
@ -142,7 +142,7 @@ static void transfer_next_chunk(const struct device *dev)
|
||||||
struct spi_context *ctx = &dev_data->ctx;
|
struct spi_context *ctx = &dev_data->ctx;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
size_t chunk_len = spi_context_longest_current_buf(ctx);
|
size_t chunk_len = spi_context_max_continuous_chunk(ctx);
|
||||||
|
|
||||||
if (chunk_len > 0) {
|
if (chunk_len > 0) {
|
||||||
nrfx_spi_xfer_desc_t xfer;
|
nrfx_spi_xfer_desc_t xfer;
|
||||||
|
|
|
@ -160,7 +160,7 @@ static void transfer_next_chunk(const struct device *dev)
|
||||||
struct spi_context *ctx = &dev_data->ctx;
|
struct spi_context *ctx = &dev_data->ctx;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
size_t chunk_len = spi_context_longest_current_buf(ctx);
|
size_t chunk_len = spi_context_max_continuous_chunk(ctx);
|
||||||
|
|
||||||
if (chunk_len > 0) {
|
if (chunk_len > 0) {
|
||||||
nrfx_spim_xfer_desc_t xfer;
|
nrfx_spim_xfer_desc_t xfer;
|
||||||
|
|
|
@ -112,7 +112,7 @@ static void prepare_for_transfer(const struct device *dev)
|
||||||
struct spi_context *ctx = &dev_data->ctx;
|
struct spi_context *ctx = &dev_data->ctx;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
size_t buf_len = spi_context_longest_current_buf(ctx);
|
size_t buf_len = spi_context_max_continuous_chunk(ctx);
|
||||||
|
|
||||||
if (buf_len > 0) {
|
if (buf_len > 0) {
|
||||||
nrfx_err_t result;
|
nrfx_err_t result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue