From afaae645ab716bb1bb6f4836e7ce32db4662052e Mon Sep 17 00:00:00 2001 From: Eve Date: Mon, 15 Jan 2024 11:35:15 +0100 Subject: [PATCH] wip: add write timeout in kconfig --- README.md | 24 ++++++++++++++++++++++++ drivers/nrf24l01/Kconfig | 7 +++++++ drivers/nrf24l01/nrf24l01.c | 2 +- include/app/drivers/nrf24.h | 6 ++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6142eb9..5f1304c 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,30 @@ To execute Twister integration tests, run the following command: west twister -T tests --integration ``` +# API reference + +This driver uses a minimalist custom API. + +## Read +``` +int nrf24_read(const struct device *dev, uint8_t *buffer, uint8_t data_len) +``` + +This methods reads data\_len bytes from the device dev, and places it in buffer. +In trigger mode, if NRF24L01\_READ\_TIMEOUT is exceeded, the function times out. + +In polling mode, it will loop forever. + +# Write +``` +int nrf24_write(const struct device *dev, uint8_t *buffer, uint8_t data_len) +``` + +This methods writes data\_len bytes from buffer, and sends it through device dev. +In trigger mode, if NRF24L01\_WRITE\_TIMEOUT is exceeded, the function times out. + +In polling mode, it will loop forever. + # Troubleshooting ## No RX received diff --git a/drivers/nrf24l01/Kconfig b/drivers/nrf24l01/Kconfig index 77e2111..e8bacab 100644 --- a/drivers/nrf24l01/Kconfig +++ b/drivers/nrf24l01/Kconfig @@ -27,4 +27,11 @@ config NRF24L01_READ_TIMEOUT help nRF24 timeout for reading, in ms. +config NRF24L01_WRITE_TIMEOUT + int "Timout for write operation" + depends on NRF24L01_TRIGGER + default 100 + help + nRF24 timeout for writing, in ms. + endif # NRF24L01 diff --git a/drivers/nrf24l01/nrf24l01.c b/drivers/nrf24l01/nrf24l01.c index c7a86cf..67e3d16 100644 --- a/drivers/nrf24l01/nrf24l01.c +++ b/drivers/nrf24l01/nrf24l01.c @@ -710,7 +710,7 @@ static int nrf24l01_write(const struct device *dev, uint8_t *buffer, uint8_t dat k_usleep(10); nrf24l01_toggle_ce(dev, LOW); #ifdef CONFIG_NRF24L01_TRIGGER - if (k_sem_take(&data->sem, K_MSEC(100)) != 0) { + if (k_sem_take(&data->sem, K_MSEC(CONFIG_NRF24L01_WRITE_TIMEOUT)) != 0) { LOG_ERR("TX sending timed out"); nrf24l01_toggle_ce(dev, LOW); return -ETIME; diff --git a/include/app/drivers/nrf24.h b/include/app/drivers/nrf24.h index e437653..0fdcf84 100644 --- a/include/app/drivers/nrf24.h +++ b/include/app/drivers/nrf24.h @@ -22,8 +22,10 @@ __subsystem struct nrf24_api { * * @param dev nrf24 instance. * @param buf Read buffer. + * @param data_len Number of bytes to read * * @retval 0 On success. + * @retval -EIO Nothing in RX queue (trigger mode) * @retval -errno Other negative errno in case of failure. */ __syscall int nrf24_read(const struct device *dev, uint8_t *buffer, uint8_t data_len); @@ -41,8 +43,12 @@ static inline int z_impl_nrf24_read(const struct device *dev, uint8_t *buffer, u * * @param dev nrf24 instance. * @param buf Write buffer. + * @param data_len Number of bytes to write * * @retval 0 On success. + * @retval -ETIME TX sending timed out (trigger mode) + * @retval -EIO Max retries exceeded (polling mode) + * @retval MAX_RT Message not acknowledged (trigger mode) * @retval -errno Other negative errno in case of failure. */ __syscall int nrf24_write(const struct device *dev, uint8_t *buffer, uint8_t data_len);