api/spi: Slave transactions will return received frames on success
Unlike master mode which will always return 0 on success. Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
3f4cffc302
commit
f1ae94027a
2 changed files with 31 additions and 3 deletions
|
@ -44,6 +44,10 @@ struct spi_context {
|
|||
size_t tx_len;
|
||||
u8_t *rx_buf;
|
||||
size_t rx_len;
|
||||
|
||||
#ifdef CONFIG_SPI_SLAVE
|
||||
int recv_frames;
|
||||
#endif /* CONFIG_SPI_SLAVE */
|
||||
};
|
||||
|
||||
#define SPI_CONTEXT_INIT_LOCK(_data, _ctx_name) \
|
||||
|
@ -77,10 +81,12 @@ static inline void spi_context_lock(struct spi_context *ctx,
|
|||
|
||||
static inline void spi_context_release(struct spi_context *ctx, int status)
|
||||
{
|
||||
if (!status &&
|
||||
#ifdef CONFIG_SPI_SLAVE
|
||||
if (status >= 0 &&
|
||||
(ctx->config->operation & (SPI_LOCK_ON | SPI_OP_MODE_SLAVE))) {
|
||||
return;
|
||||
}
|
||||
#endif /* CONFIG_SPI_SLAVE */
|
||||
|
||||
#ifdef CONFIG_SPI_ASYNC
|
||||
if (!ctx->asynchronous || status) {
|
||||
|
@ -110,6 +116,13 @@ static inline int spi_context_wait_for_completion(struct spi_context *ctx)
|
|||
k_sem_take(&ctx->sync, K_FOREVER);
|
||||
status = ctx->sync_status;
|
||||
#endif /* CONFIG_SPI_ASYNC */
|
||||
|
||||
#ifdef CONFIG_SPI_SLAVE
|
||||
if (spi_context_is_slave(ctx) && !status) {
|
||||
return ctx->recv_frames;
|
||||
}
|
||||
#endif /* CONFIG_SPI_SLAVE */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
@ -221,6 +234,10 @@ void spi_context_buffers_setup(struct spi_context *ctx,
|
|||
|
||||
ctx->sync_status = 0;
|
||||
|
||||
#ifdef CONFIG_SPI_SLAVE
|
||||
ctx->recv_frames = 0;
|
||||
#endif /* CONFIG_SPI_SLAVE */
|
||||
|
||||
SYS_LOG_DBG("current_tx %p (%zu), current_rx %p (%zu),"
|
||||
" tx buf/len %p/%zu, rx buf/len %p/%zu",
|
||||
ctx->current_tx, ctx->tx_count,
|
||||
|
@ -272,6 +289,13 @@ bool spi_context_tx_buf_on(struct spi_context *ctx)
|
|||
static ALWAYS_INLINE
|
||||
void spi_context_update_rx(struct spi_context *ctx, u8_t dfs, u32_t len)
|
||||
{
|
||||
#ifdef CONFIG_SPI_SLAVE
|
||||
if (spi_context_is_slave(ctx)) {
|
||||
ctx->recv_frames += len;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_SPI_SLAVE */
|
||||
|
||||
if (!ctx->rx_len) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -244,7 +244,9 @@ struct spi_driver_api {
|
|||
* @param rx_bufs Buffer array where data to be read will be written to,
|
||||
* or NULL if none.
|
||||
*
|
||||
* @retval 0 If successful, negative errno code otherwise.
|
||||
* @retval 0 If successful, negative errno code otherwise. In case of slave
|
||||
* transaction: if successful it will return the amount of frames
|
||||
* received, negative errno code otherwise.
|
||||
*/
|
||||
__syscall int spi_transceive(struct device *dev,
|
||||
const struct spi_config *config,
|
||||
|
@ -318,7 +320,9 @@ static inline int spi_write(struct device *dev,
|
|||
* notify the end of the transaction, and whether it went
|
||||
* successfully or not).
|
||||
*
|
||||
* @retval 0 If successful, negative errno code otherwise.
|
||||
* @retval 0 If successful, negative errno code otherwise. In case of slave
|
||||
* transaction: if successful it will return the amount of frames
|
||||
* received, negative errno code otherwise.
|
||||
*/
|
||||
static inline int spi_transceive_async(struct device *dev,
|
||||
const struct spi_config *config,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue