From bcb0abc05df358204a6e3b5d463e393f42d77353 Mon Sep 17 00:00:00 2001 From: W-Mai <1341398182@qq.com> Date: Wed, 11 Jan 2023 16:19:47 +0800 Subject: [PATCH] sim/posix/sim_linuxspi.c: fix select not work and incorrect behaviour Fixed missing `SPI_SELECT` method and incorrect sending behavior in sim_linuxspi Signed-off-by: xinbingnan --- arch/sim/src/sim/posix/sim_linuxspi.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/sim/src/sim/posix/sim_linuxspi.c b/arch/sim/src/sim/posix/sim_linuxspi.c index 79c3de53d2..466ab40ce2 100644 --- a/arch/sim/src/sim/posix/sim_linuxspi.c +++ b/arch/sim/src/sim/posix/sim_linuxspi.c @@ -191,6 +191,26 @@ static int linux_spi_lock(struct spi_dev_s *dev, bool lock) static void linux_spi_select(struct spi_dev_s *dev, uint32_t devid, bool selected) { + if (!selected) + { + struct linux_spi_dev_s *priv = (struct linux_spi_dev_s *)dev; + + /* Some members of struct spi_ioc_transfer transfer_data is default 0: + * @speed_hz = 0, thus it's ignored, MAX_SEPPD_HZ will be used. + * @bits_per_word = 0, thus it's ignored, BITS_PER_WORD will be used. + * @delay_usecs = 0, thus thers's no delay before next transfer. + */ + + struct spi_ioc_transfer transfer_data = + { + .tx_buf = (unsigned long)NULL, + .rx_buf = (unsigned long)NULL, + .len = 0, + .cs_change = false, + }; + + ioctl(priv->file, SPI_IOC_MESSAGE(1), &transfer_data); + } } /**************************************************************************** @@ -641,7 +661,7 @@ static int linux_spi_transfer(struct spi_dev_s *dev, const void *txbuffer, .tx_buf = (unsigned long)txbuffer, /* Transmit buffer. */ .rx_buf = (unsigned long)rxbuffer, /* Receive buffer. */ .len = (uint32_t)nwords, /* Number of words. */ - .cs_change = false, /* In normal, CS remains selected. */ + .cs_change = true, /* In normal, CS remains selected. */ }; #ifdef CONFIG_SPI_HWFEATURES