This is an automated email from the ASF dual-hosted git repository. xiaoxiang 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 b6fbcb6 nrf52: Add a static copy buffer for i2c b6fbcb6 is described below commit b6fbcb649c29d6e1f7052756f2099a1f3424a30f Author: Brennan Ashton <bash...@brennanashton.com> AuthorDate: Sun Jan 17 14:18:12 2021 -0800 nrf52: Add a static copy buffer for i2c Signed-off-by: Brennan Ashton <bash...@brennanashton.com> --- arch/arm/src/nrf52/Kconfig | 19 +++++++++++++++++++ arch/arm/src/nrf52/nrf52_i2c.c | 24 +++++++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/arm/src/nrf52/Kconfig b/arch/arm/src/nrf52/Kconfig index 6a4fc9a..89a8742 100644 --- a/arch/arm/src/nrf52/Kconfig +++ b/arch/arm/src/nrf52/Kconfig @@ -632,5 +632,24 @@ menu "I2C Master Configuration" config NRF52_I2C_MASTER_DISABLE_NOSTART bool "Disable the I2C Master NOSTART flag support" default n + ---help--- + To combine two i2c messages that are part of a + single transaction (NO_STOP-NO_START) the nrf52 + hardware requires these be joined into a single + transfer. This can be expensive and some devices + can get away with multi-part transfers as separate + transfers. Enable this at your own risk! + +config NRF52_I2C_MASTER_COPY_BUF_SIZE + int "Static buffer size for NOSTART flag support" + depends on !NRF52_I2C_MASTER_DISABLE_NOSTART + default 4 + ---help--- + To combine two i2c messages that are part of a + single transaction (NO_STOP-NO_START) the nrf52 + hardware requires these be joined into a single + transfer. This static buffer will be used if the + transaction will fit otherwise it will fall back + on malloc. endmenu diff --git a/arch/arm/src/nrf52/nrf52_i2c.c b/arch/arm/src/nrf52/nrf52_i2c.c index 2a4233f..c189a53 100644 --- a/arch/arm/src/nrf52/nrf52_i2c.c +++ b/arch/arm/src/nrf52/nrf52_i2c.c @@ -68,6 +68,11 @@ struct nrf52_i2c_priv_s uint8_t msgc; /* Message count */ struct i2c_msg_s *msgv; /* Message list */ uint8_t *ptr; /* Current message buffer */ +#ifdef CONFIG_NRF52_I2C_MASTER_COPY_BUF_SIZE + /* Static buffer used for continued messages */ + + uint8_t copy_buf[CONFIG_NRF52_I2C_MASTER_COPY_BUF_SIZE]; +#endif uint32_t freq; /* Current I2C frequency */ int dcnt; /* Current message length */ uint16_t flags; /* Current message flags */ @@ -308,11 +313,20 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev, /* Combine buffers */ - pack_buf = kmm_malloc(priv->msgv[0].length + - priv->msgv[1].length); - if (pack_buf == NULL) + if ((priv->msgv[0].length + + priv->msgv[1].length) <= + CONFIG_NRF52_I2C_MASTER_COPY_BUF_SIZE) + { + pack_buf = priv->copy_buf; + } + else { - return -1; + pack_buf = kmm_malloc(priv->msgv[0].length + + priv->msgv[1].length); + if (pack_buf == NULL) + { + return -ENOMEM; + } } /* Combine messages */ @@ -496,7 +510,7 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev, errout: #ifndef CONFIG_NRF52_I2C_MASTER_DISABLE_NOSTART - if (pack_buf != NULL) + if (pack_buf != NULL && pack_buf != priv->copy_buf) { kmm_free(pack_buf); }