static void completed(struct device *dev, int error) { const struct spi_dw_config *info = dev->config->config_info; struct spi_dw_data *spi = dev->driver_data; if (error) { goto out; } if (spi_context_tx_on(&spi->ctx) || spi_context_rx_on(&spi->ctx)) { return; } out: /* need to give time for FIFOs to drain before issuing more commands */ while (test_bit_sr_busy(info->regs)) { } /* Disabling interrupts */ write_imr(DW_SPI_IMR_MASK, info->regs); /* Disabling the controller */ clear_bit_ssienr(info->regs); spi_context_cs_control(&spi->ctx, false); LOG_DBG("SPI transaction completed %s error", error ? "with" : "without"); spi_context_complete(&spi->ctx, error); }
/* Shift a SPI frame as slave. */ static void spi_stm32_shift_s(SPI_TypeDef *spi, struct spi_stm32_data *data) { u8_t tx_frame; u8_t rx_frame; tx_frame = spi_stm32_next_tx(data); if (LL_SPI_IsActiveFlag_TXE(spi)) { LL_SPI_TransmitData8(spi, tx_frame); /* The update is ignored if TX is off. */ spi_context_update_tx(&data->ctx, 1); } if (LL_SPI_IsActiveFlag_RXNE(spi)) { rx_frame = LL_SPI_ReceiveData8(spi); if (spi_context_rx_on(&data->ctx)) { *data->ctx.rx_buf = rx_frame; spi_context_update_rx(&data->ctx, 1); } } }
static void push_data(struct device *dev) { const struct spi_dw_config *info = dev->config->config_info; struct spi_dw_data *spi = dev->driver_data; u32_t data = 0U; u32_t f_tx; DBG_COUNTER_INIT(); if (spi_context_rx_on(&spi->ctx)) { f_tx = DW_SPI_FIFO_DEPTH - read_txflr(info->regs) - read_rxflr(info->regs); if ((int)f_tx < 0) { f_tx = 0U; /* if rx-fifo is full, hold off tx */ } } else { f_tx = DW_SPI_FIFO_DEPTH - read_txflr(info->regs); } while (f_tx) { if (spi_context_tx_buf_on(&spi->ctx)) { switch (spi->dfs) { case 1: data = UNALIGNED_GET((u8_t *) (spi->ctx.tx_buf)); break; case 2: data = UNALIGNED_GET((u16_t *) (spi->ctx.tx_buf)); break; #ifndef CONFIG_ARC case 4: data = UNALIGNED_GET((u32_t *) (spi->ctx.tx_buf)); break; #endif } } else if (spi_context_rx_on(&spi->ctx)) { /* No need to push more than necessary */ if ((int)(spi->ctx.rx_len - spi->fifo_diff) <= 0) { break; } data = 0U; } else if (spi_context_tx_on(&spi->ctx)) { data = 0U; } else { /* Nothing to push anymore */ break; } write_dr(data, info->regs); spi_context_update_tx(&spi->ctx, spi->dfs, 1); spi->fifo_diff++; f_tx--; DBG_COUNTER_INC(); } if (!spi_context_tx_on(&spi->ctx)) { /* prevents any further interrupts demanding TX fifo fill */ write_txftlr(0, info->regs); } LOG_DBG("Pushed: %d", DBG_COUNTER_RESULT()); }
static bool spi_stm32_transfer_ongoing(struct spi_stm32_data *data) { return spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx); }