Skip to content

Commit

Permalink
wip: add write timeout in kconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
everedero committed Jan 15, 2024
1 parent 30f507d commit afaae64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions drivers/nrf24l01/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion drivers/nrf24l01/nrf24l01.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions include/app/drivers/nrf24.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit afaae64

Please sign in to comment.