drivers: bluetooth: hci: spi: add small read delay
Add a small delay between reading the transport header and reading the HCI data. Failing to do so on a nRF9160<->nRF52832 link was reliably resulting in the nRF9160 trying to read data before the nRF52832 had set up the SPI transaction, resulting in the host reading a buffer full of 0x00 and having to run the entire read result again. Transceiving a 10 byte packet takes at least 31uS, while 100 byte packets are around 150uS (duration of `spi_transceive` call). Waiting 1 tick to eliminate the need for most retransmissions is a valid tradeoff. Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
21ed808ba1
commit
b3f12b430f
|
@ -56,6 +56,8 @@ LOG_MODULE_REGISTER(bt_driver);
|
|||
*/
|
||||
#define SPI_MAX_MSG_LEN 255 /* As defined by X-NUCLEO-IDB04A1 BSP */
|
||||
|
||||
#define DATA_DELAY_US DT_INST_PROP(0, controller_data_delay_us)
|
||||
|
||||
static uint8_t rxmsg[SPI_MAX_MSG_LEN];
|
||||
static uint8_t txmsg[SPI_MAX_MSG_LEN];
|
||||
|
||||
|
@ -326,11 +328,20 @@ static void bt_spi_rx_thread(void)
|
|||
header_slave[STATUS_HEADER_TOREAD] == 0xFF) &&
|
||||
!ret)) && exit_irq_high_loop());
|
||||
|
||||
/* Delay here is rounded up to next tick */
|
||||
k_sleep(K_USEC(DATA_DELAY_US));
|
||||
size = header_slave[STATUS_HEADER_TOREAD];
|
||||
if (ret == 0 && size != 0) {
|
||||
do {
|
||||
ret = bt_spi_transceive(&txmsg, size,
|
||||
&rxmsg, size);
|
||||
if (rxmsg[0] == 0U) {
|
||||
/* Consider increasing controller-data-delay-us
|
||||
* if this message is extremely common.
|
||||
*/
|
||||
LOG_DBG("Controller not ready for SPI transaction "
|
||||
"of %d bytes", size);
|
||||
}
|
||||
} while (rxmsg[0] == 0U && ret == 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,3 +23,15 @@ properties:
|
|||
description:
|
||||
Minimum duration to hold the reset-gpios pin low for.
|
||||
If not specified no delay beyond the code path execution time is guaranteed.
|
||||
|
||||
controller-data-delay-us:
|
||||
type: int
|
||||
default: 20
|
||||
description:
|
||||
Duration to delay between reading a valid header and reading the data associated
|
||||
with that header. This delay gives the controller time to configure the SPI data
|
||||
transaction after finishing the header transaction. Without this delay the host
|
||||
can attempt to read before the controller is ready, resulting in empty data that
|
||||
then needs to be read a second time. The default of 20uS was chosen as the lowest
|
||||
delay that reliably eliminated double transmits between a nRF9160 host and a
|
||||
nRF52832 controller.
|
||||
|
|
Loading…
Reference in a new issue