Skip to content

Commit 7aa0778

Browse files
decsnynashif
authored andcommitted
spi_nxp_lpspi: Simplify tx ctx update
There is no need to update the tx context in interrupt instead of directly after the fill, this just makes the code more complex. Also, the spi context header already handled iterating over buffers so we can remove that code too. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent 877fa97 commit 7aa0778

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ LOG_MODULE_DECLARE(spi_lpspi, CONFIG_SPI_LOG_LEVEL);
1212
#include "spi_nxp_lpspi_priv.h"
1313

1414
struct lpspi_driver_data {
15-
size_t fill_len;
1615
uint8_t word_size_bytes;
1716
};
1817

@@ -126,7 +125,7 @@ static inline void lpspi_fill_tx_fifo(const struct device *dev, const uint8_t *b
126125
buf_remaining_bytes -= word_size;
127126
}
128127

129-
LOG_DBG("Filled TX FIFO to %d words (%d bytes)", lpspi_data->fill_len, offset);
128+
LOG_DBG("Filled TX FIFO to %d words (%d bytes)", fill_len, offset);
130129
}
131130

132131
/* just fills TX fifo with the specified amount of NOPS */
@@ -187,34 +186,26 @@ static void lpspi_next_tx_fill(const struct device *dev)
187186
actual_filled += next_buf_fill;
188187
}
189188

190-
lpspi_data->fill_len = actual_filled;
189+
spi_context_update_tx(ctx, lpspi_data->word_size_bytes, actual_filled);
191190
}
192191

193192
static inline void lpspi_handle_tx_irq(const struct device *dev)
194193
{
195194
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
196195
struct lpspi_data *data = dev->data;
197-
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
198196
struct spi_context *ctx = &data->ctx;
199197

200198
base->SR = LPSPI_SR_TDF_MASK;
201199

202200
/* If we receive a TX interrupt but no more data is available,
203-
* we can be sure that all data has been written to the bus.
201+
* we can be sure that all data has been written to the fifo.
204202
* Disable the interrupt to signal that we are done.
205203
*/
206204
if (!spi_context_tx_on(ctx)) {
207205
base->IER &= ~LPSPI_IER_TDIE_MASK;
208206
return;
209207
}
210208

211-
while (spi_context_tx_on(ctx) && lpspi_data->fill_len > 0) {
212-
size_t this_buf_words_sent = MIN(lpspi_data->fill_len, ctx->tx_len);
213-
214-
spi_context_update_tx(ctx, lpspi_data->word_size_bytes, this_buf_words_sent);
215-
lpspi_data->fill_len -= this_buf_words_sent;
216-
}
217-
218209
lpspi_next_tx_fill(dev);
219210
}
220211

@@ -272,7 +263,6 @@ static void lpspi_isr(const struct device *dev)
272263
max_fill - tx_current_fifo_len : 0;
273264

274265
lpspi_fill_tx_fifo_nop(dev, fill_len);
275-
lpspi_data->fill_len = fill_len;
276266
}
277267

278268
if ((DIV_ROUND_UP(spi_context_rx_len_left(ctx, word_size_bytes), word_size_bytes) == 1) &&

0 commit comments

Comments
 (0)