You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/09/28 12:34:19 UTC
[incubator-nuttx] branch master updated: nRF52: Add basic error
handling for i2c in polling mode
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new bbf16b2 nRF52: Add basic error handling for i2c in polling mode
bbf16b2 is described below
commit bbf16b27d9b5d185837140102f355a2fa00c71d8
Author: Brennan Ashton <ba...@brennanashton.com>
AuthorDate: Tue Sep 15 22:57:45 2020 -0700
nRF52: Add basic error handling for i2c in polling mode
There was no error handling before and it would block on common
cases like NACK which meant that you could not use the i2ctool
to perform a scan of the bus.
This does not handle the interrupt flow which also has incomplete
error handling.
---
arch/arm/src/nrf52/nrf52_i2c.c | 61 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 57 insertions(+), 4 deletions(-)
diff --git a/arch/arm/src/nrf52/nrf52_i2c.c b/arch/arm/src/nrf52/nrf52_i2c.c
index 29ee5d6..6cf954e 100644
--- a/arch/arm/src/nrf52/nrf52_i2c.c
+++ b/arch/arm/src/nrf52/nrf52_i2c.c
@@ -325,6 +325,25 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
#ifdef CONFIG_I2C_POLLED
while (nrf52_i2c_getreg(priv,
NRF52_TWIM_EVENTS_LASTTX_OFFSET) != 1);
+ while (1)
+ {
+ regval = nrf52_i2c_getreg(priv,
+ NRF52_TWIM_ERRORSRC_OFFSET) & 0x7;
+ if (regval != 0)
+ {
+ i2cerr("Error SRC: %x\n", regval);
+ ret = -1;
+ nrf52_i2c_putreg(priv,
+ NRF52_TWIM_ERRORSRC_OFFSET, 0x7);
+ goto errout;
+ }
+
+ if (nrf52_i2c_getreg(priv,
+ NRF52_TWIM_EVENTS_LASTTX_OFFSET) == 1)
+ {
+ break;
+ }
+ }
/* Clear event */
@@ -357,8 +376,25 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
/* Wait for last RX done */
#ifdef CONFIG_I2C_POLLED
- while (nrf52_i2c_getreg(priv,
- NRF52_TWIM_EVENTS_LASTRX_OFFSET) != 1);
+ while (1)
+ {
+ regval = nrf52_i2c_getreg(priv,
+ NRF52_TWIM_ERRORSRC_OFFSET) & 0x7;
+ if (regval != 0)
+ {
+ i2cerr("Error SRC: %x\n", regval);
+ ret = -1;
+ nrf52_i2c_putreg(priv,
+ NRF52_TWIM_ERRORSRC_OFFSET, 0x7);
+ goto errout;
+ }
+
+ if (nrf52_i2c_getreg(priv,
+ NRF52_TWIM_EVENTS_LASTRX_OFFSET) == 1)
+ {
+ break;
+ }
+ }
/* Clear event */
@@ -387,8 +423,25 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
/* Wait for stop event */
#ifdef CONFIG_I2C_POLLED
- while (nrf52_i2c_getreg(priv,
- NRF52_TWIM_EVENTS_STOPPED_OFFSET) != 1);
+ while (1)
+ {
+ regval = nrf52_i2c_getreg(priv,
+ NRF52_TWIM_ERRORSRC_OFFSET) & 0x7;
+ if (regval != 0)
+ {
+ i2cerr("Error SRC: %x\n", regval);
+ ret = -1;
+ nrf52_i2c_putreg(priv,
+ NRF52_TWIM_ERRORSRC_OFFSET, 0x7);
+ goto errout;
+ }
+
+ if (nrf52_i2c_getreg(priv,
+ NRF52_TWIM_EVENTS_STOPPED_OFFSET) == 1)
+ {
+ break;
+ }
+ }
/* Clear event */