You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/05/15 10:56:08 UTC
[incubator-nuttx] 03/06: Replace nxsem_timedwait_uninterruptible with nxsem_tickwait_uninterruptible
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 1fb8c13e5e80ee4cd5758e76821378162451c2fa
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue May 10 09:32:31 2022 +0800
Replace nxsem_timedwait_uninterruptible with nxsem_tickwait_uninterruptible
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
arch/arm/src/efm32/efm32_i2c.c | 42 ++++++-------------------
arch/arm/src/imxrt/imxrt_lpi2c.c | 43 ++++++-------------------
arch/arm/src/lc823450/lc823450_i2c.c | 27 +++-------------
arch/arm/src/s32k1xx/s32k1xx_lpi2c.c | 45 ++++++---------------------
arch/arm/src/stm32/stm32_i2c.c | 43 ++++++-------------------
arch/arm/src/stm32/stm32_i2c_alt.c | 43 ++++++-------------------
arch/arm/src/stm32/stm32_i2c_v2.c | 41 ++++++------------------
arch/arm/src/stm32/stm32f40xxx_i2c.c | 43 ++++++-------------------
arch/arm/src/stm32f0l0g0/stm32_i2c.c | 41 ++++++------------------
arch/arm/src/stm32f7/stm32_i2c.c | 41 ++++++------------------
arch/arm/src/stm32h7/stm32_i2c.c | 41 ++++++------------------
arch/arm/src/stm32l4/stm32l4_i2c.c | 41 ++++++------------------
arch/arm/src/tiva/common/tiva_i2c.c | 43 ++++++-------------------
arch/mips/src/pic32mz/pic32mz_i2c.c | 39 ++++++-----------------
arch/risc-v/src/esp32c3/esp32c3_i2c.c | 26 +++-------------
arch/risc-v/src/esp32c3/esp32c3_spi.c | 12 +------
arch/risc-v/src/mpfs/mpfs_i2c.c | 12 +------
arch/risc-v/src/mpfs/mpfs_spi.c | 12 +------
arch/xtensa/src/esp32/esp32_i2c.c | 27 +++-------------
arch/xtensa/src/esp32/esp32_spi.c | 12 +------
drivers/modem/altair/altmdm_sys.c | 33 ++------------------
drivers/sensors/lps25h.c | 13 ++------
drivers/wireless/bluetooth/bt_uart_bcm4343x.c | 18 +----------
include/nuttx/semaphore.h | 2 +-
mm/iob/iob_alloc.c | 14 +--------
net/utils/net_lock.c | 18 ++---------
sched/semaphore/sem_clockwait.c | 2 +-
wireless/bluetooth/bt_hcicore.c | 37 ++--------------------
28 files changed, 156 insertions(+), 655 deletions(-)
diff --git a/arch/arm/src/efm32/efm32_i2c.c b/arch/arm/src/efm32/efm32_i2c.c
index 59a8a3d866..eb0ede3f43 100644
--- a/arch/arm/src/efm32/efm32_i2c.c
+++ b/arch/arm/src/efm32/efm32_i2c.c
@@ -528,40 +528,10 @@ static useconds_t efm32_i2c_tousecs(int msgc, struct i2c_msg_s *msgs)
#ifndef CONFIG_I2C_POLLED
static inline int efm32_i2c_sem_waitdone(struct efm32_i2c_priv_s *priv)
{
- struct timespec abstime;
int ret;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_EFM32_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_EFM32_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
-
-#ifdef CONFIG_EFM32_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * efm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_EFM32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_EFM32_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-#endif
-
/* Enable I2C interrupts */
efm32_i2c_putreg(priv, EFM32_I2C_IEN_OFFSET, I2C_IF_NACK | I2C_IF_ACK |
@@ -569,7 +539,13 @@ static inline int efm32_i2c_sem_waitdone(struct efm32_i2c_priv_s *priv)
/* Wait until either the transfer is complete or the timeout expires */
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
+#ifdef CONFIG_EFM32_I2C_DYNTIMEO
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(efm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_EFM32_I2CTIMEOTICKS);
+#endif
/* Disable I2C interrupts */
@@ -579,7 +555,7 @@ static inline int efm32_i2c_sem_waitdone(struct efm32_i2c_priv_s *priv)
{
/* Break out of the loop on irrecoverable errors. This would
* include timeouts and mystery errors reported by
- * nxsem_timedwait.
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -615,7 +591,7 @@ static inline int efm32_i2c_sem_waitdone(struct efm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts are
* currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
start = clock_systime_ticks();
diff --git a/arch/arm/src/imxrt/imxrt_lpi2c.c b/arch/arm/src/imxrt/imxrt_lpi2c.c
index b230e37715..6f4750bc6d 100644
--- a/arch/arm/src/imxrt/imxrt_lpi2c.c
+++ b/arch/arm/src/imxrt/imxrt_lpi2c.c
@@ -581,7 +581,6 @@ static useconds_t imxrt_lpi2c_tousecs(int msgc, struct i2c_msg_s *msgs)
static inline int
imxrt_lpi2c_sem_waitdone(struct imxrt_lpi2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
uint32_t regval;
int ret;
@@ -615,48 +614,26 @@ static inline int
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_IMXRT_LPI2C_TIMEOSEC > 0
- abstime.tv_sec += CONFIG_IMXRT_LPI2C_TIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_IMXRT_LPI2C_DYNTIMEO
- abstime.tv_nsec += 1000 * imxrt_lpi2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_IMXRT_LPI2C_TIMEOMS > 0
- abstime.tv_nsec += CONFIG_IMXRT_LPI2C_TIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(imxrt_lpi2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_IMXRT_LPI2C_TIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -709,7 +686,7 @@ static inline int
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/lc823450/lc823450_i2c.c b/arch/arm/src/lc823450/lc823450_i2c.c
index c308ed905a..280396fe59 100644
--- a/arch/arm/src/lc823450/lc823450_i2c.c
+++ b/arch/arm/src/lc823450/lc823450_i2c.c
@@ -290,37 +290,20 @@ static inline void
static inline int
lc823450_i2c_sem_waitdone(struct lc823450_i2c_priv_s *priv)
{
- struct timespec abstime;
int ret;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_LC823450_I2C_TIMEOSEC > 0
- abstime.tv_sec += CONFIG_LC823450_I2C_TIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
-
- abstime.tv_nsec += priv->timeoms * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
/* Wait until either the transfer is complete or the timeout expires */
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ SEC2TICK(CONFIG_LC823450_I2C_TIMEOSEC) +
+ MSEC2TICK(priv->timeoms));
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
diff --git a/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c b/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c
index 5bd7eb0665..daadde4928 100644
--- a/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c
+++ b/arch/arm/src/s32k1xx/s32k1xx_lpi2c.c
@@ -471,7 +471,6 @@ static useconds_t s32k1xx_lpi2c_tousecs(int msgc, struct i2c_msg_s *msgs)
static inline int
s32k1xx_lpi2c_sem_waitdone(struct s32k1xx_lpi2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
uint32_t regval;
int ret;
@@ -505,50 +504,26 @@ static inline int
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_S32K1XX_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_S32K1XX_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_S32K1XX_I2C_DYNTIMEO
- abstime.tv_nsec +=
- 1000 * s32k1xx_lpi2c_tousecs(priv->msgc, priv->msgv);
-
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_S32K1XX_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_S32K1XX_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(s32k1xx_lpi2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_S32K1XX_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -603,7 +578,7 @@ static inline int
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32/stm32_i2c.c b/arch/arm/src/stm32/stm32_i2c.c
index 3b13cbe61e..877b6a91c3 100644
--- a/arch/arm/src/stm32/stm32_i2c.c
+++ b/arch/arm/src/stm32/stm32_i2c.c
@@ -528,7 +528,6 @@ static useconds_t stm32_i2c_tousecs(int msgc, struct i2c_msg_s *msgs)
#ifndef CONFIG_I2C_POLLED
static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
uint32_t regval;
int ret;
@@ -543,48 +542,26 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -626,7 +603,7 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32/stm32_i2c_alt.c b/arch/arm/src/stm32/stm32_i2c_alt.c
index 7c4f8e8e34..4f1ac39161 100644
--- a/arch/arm/src/stm32/stm32_i2c_alt.c
+++ b/arch/arm/src/stm32/stm32_i2c_alt.c
@@ -558,7 +558,6 @@ static useconds_t stm32_i2c_tousecs(int msgc, struct i2c_msg_s *msgs)
#ifndef CONFIG_I2C_POLLED
static int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
uint32_t regval;
int ret;
@@ -573,48 +572,26 @@ static int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -656,7 +633,7 @@ static int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32/stm32_i2c_v2.c b/arch/arm/src/stm32/stm32_i2c_v2.c
index 737a6bf07c..2714cd16c5 100644
--- a/arch/arm/src/stm32/stm32_i2c_v2.c
+++ b/arch/arm/src/stm32/stm32_i2c_v2.c
@@ -771,7 +771,6 @@ static inline void stm32_i2c_enableinterrupts(struct stm32_i2c_priv_s *priv)
#ifndef CONFIG_I2C_POLLED
static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -792,42 +791,20 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -867,7 +844,7 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32/stm32f40xxx_i2c.c b/arch/arm/src/stm32/stm32f40xxx_i2c.c
index 422697a6a9..bd367ce3c6 100644
--- a/arch/arm/src/stm32/stm32f40xxx_i2c.c
+++ b/arch/arm/src/stm32/stm32f40xxx_i2c.c
@@ -581,7 +581,6 @@ static useconds_t stm32_i2c_tousecs(int msgc, struct i2c_msg_s *msgs)
#ifndef CONFIG_I2C_POLLED
static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
uint32_t regval;
int ret;
@@ -596,48 +595,26 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -679,7 +656,7 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32f0l0g0/stm32_i2c.c b/arch/arm/src/stm32f0l0g0/stm32_i2c.c
index 58d61bc44d..550dd10f07 100644
--- a/arch/arm/src/stm32f0l0g0/stm32_i2c.c
+++ b/arch/arm/src/stm32f0l0g0/stm32_i2c.c
@@ -785,7 +785,6 @@ static inline void stm32_i2c_enableinterrupts(struct stm32_i2c_priv_s *priv)
#ifndef CONFIG_I2C_POLLED
static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -806,42 +805,20 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32F0L0G0_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32F0L0G0_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32F0L0G0_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32F0L0G0_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32F0L0G0_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32F0L0G0_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -881,7 +858,7 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32f7/stm32_i2c.c b/arch/arm/src/stm32f7/stm32_i2c.c
index 402c2d0b1e..35f7ecafcb 100644
--- a/arch/arm/src/stm32f7/stm32_i2c.c
+++ b/arch/arm/src/stm32f7/stm32_i2c.c
@@ -808,7 +808,6 @@ static inline void stm32_i2c_enableinterrupts(struct stm32_i2c_priv_s *priv)
#ifndef CONFIG_I2C_POLLED
static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -829,42 +828,20 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32F7_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32F7_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32F7_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32F7_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32F7_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32F7_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -904,7 +881,7 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32h7/stm32_i2c.c b/arch/arm/src/stm32h7/stm32_i2c.c
index 469b89a9bb..b19d722aee 100644
--- a/arch/arm/src/stm32h7/stm32_i2c.c
+++ b/arch/arm/src/stm32h7/stm32_i2c.c
@@ -767,7 +767,6 @@ static inline void stm32_i2c_enableinterrupts(struct stm32_i2c_priv_s *priv)
#ifndef CONFIG_I2C_POLLED
static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -788,42 +787,20 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32H7_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32H7_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32H7_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32H7_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32H7_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32H7_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -863,7 +840,7 @@ static inline int stm32_i2c_sem_waitdone(struct stm32_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/stm32l4/stm32l4_i2c.c b/arch/arm/src/stm32l4/stm32l4_i2c.c
index 11113f0d98..ecf1703a9f 100644
--- a/arch/arm/src/stm32l4/stm32l4_i2c.c
+++ b/arch/arm/src/stm32l4/stm32l4_i2c.c
@@ -815,7 +815,6 @@ void stm32l4_i2c_enableinterrupts(struct stm32l4_i2c_priv_s *priv)
static inline
int stm32l4_i2c_sem_waitdone(struct stm32l4_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -836,42 +835,20 @@ int stm32l4_i2c_sem_waitdone(struct stm32l4_i2c_priv_s *priv)
priv->intstate = INTSTATE_WAITING;
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_STM32L4_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_STM32L4_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_STM32L4_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * stm32l4_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_STM32L4_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_STM32L4_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(stm32l4_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_STM32L4_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -912,7 +889,7 @@ int stm32l4_i2c_sem_waitdone(struct stm32l4_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/arm/src/tiva/common/tiva_i2c.c b/arch/arm/src/tiva/common/tiva_i2c.c
index 5f47633ef0..95fceb1390 100644
--- a/arch/arm/src/tiva/common/tiva_i2c.c
+++ b/arch/arm/src/tiva/common/tiva_i2c.c
@@ -671,7 +671,6 @@ static useconds_t tiva_i2c_tousecs(int msgc, struct i2c_msg_s *msgv)
#ifndef CONFIG_I2C_POLLED
static inline int tiva_i2c_sem_waitdone(struct tiva_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -686,47 +685,25 @@ static inline int tiva_i2c_sem_waitdone(struct tiva_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting.
* NOTE: Interrupts are currently disabled but will be temporarily
- * re-enabled below when nxsem_timedwait() sleeps.
+ * re-enabled below when nxsem_tickwait_uninterruptible() sleeps.
*/
do
{
- /* Get the current time */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_TIVA_I2C_TIMEOSEC > 0
- abstime.tv_sec += CONFIG_TIVA_I2C_TIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_TIVA_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * tiva_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_TIVA_I2C_TIMEOMS > 0
- abstime.tv_nsec += CONFIG_TIVA_I2C_TIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->waitsem,
+ USEC2TICK(tiva_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->waitsem,
+ CONFIG_TIVA_I2C_TIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->waitsem, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
tiva_i2c_traceevent(priv, I2CEVENT_TIMEOUT,
@@ -769,7 +746,7 @@ static inline int tiva_i2c_sem_waitdone(struct tiva_i2c_priv_s *priv)
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
start = clock_systime_ticks();
diff --git a/arch/mips/src/pic32mz/pic32mz_i2c.c b/arch/mips/src/pic32mz/pic32mz_i2c.c
index 01530ed9a4..4020004d10 100644
--- a/arch/mips/src/pic32mz/pic32mz_i2c.c
+++ b/arch/mips/src/pic32mz/pic32mz_i2c.c
@@ -660,7 +660,6 @@ static useconds_t pic32mz_i2c_tousecs(int msgc, struct i2c_msg_s *msgs)
static inline int
pic32mz_i2c_sem_waitdone(struct pic32mz_i2c_priv_s *priv)
{
- struct timespec abstime;
irqstate_t flags;
int ret;
@@ -672,40 +671,20 @@ static inline int
do
{
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- /* Calculate a time in the future */
-
-#if CONFIG_PIC32MZ_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_PIC32MZ_I2CTIMEOSEC;
-#endif
-
- /* Add a value proportional to the number of bytes in the transfer */
+ /* Wait until either the transfer is complete or the timeout expires */
#ifdef CONFIG_PIC32MZ_I2C_DYNTIMEO
- abstime.tv_nsec += 1000 * pic32mz_i2c_tousecs(priv->msgc, priv->msgv);
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
-#elif CONFIG_PIC32MZ_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_PIC32MZ_I2CTIMEOMS * 1000 * 1000;
- if (abstime.tv_nsec >= 1000 * 1000 * 1000)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ USEC2TICK(pic32mz_i2c_tousecs(priv->msgc, priv->msgv)));
+#else
+ ret = nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ CONFIG_PIC32MZ_I2CTIMEOTICKS);
#endif
-
- /* Wait until either the transfer is complete or the timeout expires */
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
if (ret < 0)
{
/* Break out of the loop on irrecoverable errors. This would
- * include timeouts and mystery errors reported by nxsem_timedwait.
+ * include timeouts and mystery errors reported by
+ * nxsem_tickwait_uninterruptible.
*/
break;
@@ -748,7 +727,7 @@ static inline int
/* Signal the interrupt handler that we are waiting. NOTE: Interrupts
* are currently disabled but will be temporarily re-enabled below when
- * nxsem_timedwait() sleeps.
+ * nxsem_tickwait_uninterruptible() sleeps.
*/
priv->intstate = INTSTATE_WAITING;
diff --git a/arch/risc-v/src/esp32c3/esp32c3_i2c.c b/arch/risc-v/src/esp32c3/esp32c3_i2c.c
index 8b7865dc3b..e762567f34 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_i2c.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_i2c.c
@@ -84,6 +84,9 @@
#define TIMESPEC_TO_US(sec, nano) ((sec * USEC_PER_SEC) + (nano / NSEC_PER_USEC))
#endif
+#define ESP32C3_I2CTIMEOTICKS \
+ (SEC2TICK(CONFIG_ESP32C3_I2CTIMEOSEC) + MSEC2TICK(CONFIG_ESP32C3_I2CTIMEOMS))
+
/* I2C hardware FIFO depth */
#define I2C_FIFO_SIZE (32)
@@ -793,27 +796,8 @@ static void esp32c3_i2c_reset_fsmc(struct esp32c3_i2c_priv_s *priv)
#ifndef CONFIG_I2C_POLLED
static int esp32c3_i2c_sem_waitdone(struct esp32c3_i2c_priv_s *priv)
{
- int ret;
- struct timespec abstime;
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
-#if CONFIG_ESP32C3_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_ESP32C3_I2CTIMEOSEC;
-#endif
-
-#if CONFIG_ESP32C3_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_ESP32C3_I2CTIMEOMS * NSEC_PER_MSEC;
- if (abstime.tv_nsec >= 1000 * NSEC_PER_MSEC)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * NSEC_PER_MSEC;
- }
-#endif
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
-
- return ret;
+ return nxsem_tickwait_uninterruptible(&priv->sem_isr,
+ ESP32C3_I2CTIMEOTICKS);
}
#endif
diff --git a/arch/risc-v/src/esp32c3/esp32c3_spi.c b/arch/risc-v/src/esp32c3/esp32c3_spi.c
index 209589db70..3b78b8cfd9 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_spi.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_spi.c
@@ -425,17 +425,7 @@ static int esp32c3_spi_lock(struct spi_dev_s *dev, bool lock)
#ifdef CONFIG_ESP32C3_SPI2_DMA
static int esp32c3_spi_sem_waitdone(struct esp32c3_spi_priv_s *priv)
{
- int ret;
- struct timespec abstime;
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- abstime.tv_sec += 10;
- abstime.tv_nsec += 0;
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
-
- return ret;
+ return nxsem_tickwait_uninterruptible(&priv->sem_isr, SEC2TICK(10));
}
#endif
diff --git a/arch/risc-v/src/mpfs/mpfs_i2c.c b/arch/risc-v/src/mpfs/mpfs_i2c.c
index e9a7f2ce64..8f04a33dee 100755
--- a/arch/risc-v/src/mpfs/mpfs_i2c.c
+++ b/arch/risc-v/src/mpfs/mpfs_i2c.c
@@ -340,17 +340,7 @@ static void mpfs_i2c_deinit(struct mpfs_i2c_priv_s *priv)
static int mpfs_i2c_sem_waitdone(struct mpfs_i2c_priv_s *priv)
{
- struct timespec abstime;
- int ret;
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- abstime.tv_sec += 10;
- abstime.tv_nsec += 0;
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
-
- return ret;
+ return nxsem_tickwait_uninterruptible(&priv->sem_isr, SEC2TICK(10));
}
/****************************************************************************
diff --git a/arch/risc-v/src/mpfs/mpfs_spi.c b/arch/risc-v/src/mpfs/mpfs_spi.c
index 66ba550d82..4c3fa75fc0 100644
--- a/arch/risc-v/src/mpfs/mpfs_spi.c
+++ b/arch/risc-v/src/mpfs/mpfs_spi.c
@@ -681,17 +681,7 @@ static int mpfs_spi_hwfeatures(struct spi_dev_s *dev,
static int mpfs_spi_sem_waitdone(struct mpfs_spi_priv_s *priv)
{
- struct timespec abstime;
- int ret;
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- abstime.tv_sec += 10;
- abstime.tv_nsec += 0;
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
-
- return ret;
+ return nxsem_tickwait_uninterruptible(&priv->sem_isr, SEC2TICK(10));
}
/****************************************************************************
diff --git a/arch/xtensa/src/esp32/esp32_i2c.c b/arch/xtensa/src/esp32/esp32_i2c.c
index c665c8d3de..6dea1b053c 100644
--- a/arch/xtensa/src/esp32/esp32_i2c.c
+++ b/arch/xtensa/src/esp32/esp32_i2c.c
@@ -79,6 +79,9 @@
#define TIMESPEC_TO_US(sec, nano) ((sec * USEC_PER_SEC) + (nano / NSEC_PER_USEC))
#endif
+#define ESP32_I2CTIMEOTICKS \
+ (SEC2TICK(CONFIG_ESP32_I2CTIMEOSEC) + MSEC2TICK(CONFIG_ESP32_I2CTIMEOMS))
+
/* Default option */
#define I2C_FIFO_SIZE (255)
@@ -723,31 +726,9 @@ static void esp32_i2c_reset_fsmc(struct esp32_i2c_priv_s *priv)
#ifndef CONFIG_I2C_POLLED
static int esp32_i2c_sem_waitdone(struct esp32_i2c_priv_s *priv)
{
- int ret;
- struct timespec abstime;
-
- /* Get the current absolute time and adds a offset as timeout */
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
-#if CONFIG_ESP32_I2CTIMEOSEC > 0
- abstime.tv_sec += CONFIG_ESP32_I2CTIMEOSEC;
-#endif
-
-#if CONFIG_ESP32_I2CTIMEOMS > 0
- abstime.tv_nsec += CONFIG_ESP32_I2CTIMEOMS * NSEC_PER_MSEC;
- if (abstime.tv_nsec >= 1000 * NSEC_PER_MSEC)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * NSEC_PER_MSEC;
- }
-#endif
-
/* Wait on ISR semaphore */
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
-
- return ret;
+ return nxsem_tickwait_uninterruptible(&priv->sem_isr, ESP32_I2CTIMEOTICKS);
}
#endif
diff --git a/arch/xtensa/src/esp32/esp32_spi.c b/arch/xtensa/src/esp32/esp32_spi.c
index 593c996670..d5518b9913 100644
--- a/arch/xtensa/src/esp32/esp32_spi.c
+++ b/arch/xtensa/src/esp32/esp32_spi.c
@@ -497,17 +497,7 @@ static int esp32_spi_lock(struct spi_dev_s *dev, bool lock)
static int esp32_spi_sem_waitdone(struct esp32_spi_priv_s *priv)
{
- int ret;
- struct timespec abstime;
-
- clock_gettime(CLOCK_REALTIME, &abstime);
-
- abstime.tv_sec += 10;
- abstime.tv_nsec += 0;
-
- ret = nxsem_timedwait_uninterruptible(&priv->sem_isr, &abstime);
-
- return ret;
+ return nxsem_tickwait_uninterruptible(&priv->sem_isr, SEC2TICK(10));
}
/****************************************************************************
diff --git a/drivers/modem/altair/altmdm_sys.c b/drivers/modem/altair/altmdm_sys.c
index 33cb2b3630..47c0eb73a6 100644
--- a/drivers/modem/altair/altmdm_sys.c
+++ b/drivers/modem/altair/altmdm_sys.c
@@ -394,8 +394,6 @@ int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle,
FAR uint32_t * pattern, uint32_t timeout_ms)
{
int ret = OK;
- struct timespec abs_time;
- struct timespec curr_time;
irqstate_t flags;
uint32_t ptn;
@@ -419,32 +417,6 @@ int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle,
return ERROR;
}
- if (timeout_ms != ALTMDM_SYS_FLAG_TMOFEVR)
- {
- /* Get current time. */
-
- ret = clock_gettime(CLOCK_REALTIME, &curr_time);
- if (ret != OK)
- {
- return ret;
- }
-
- abs_time.tv_sec = timeout_ms / 1000;
- abs_time.tv_nsec = (timeout_ms - (abs_time.tv_sec * 1000)) *
- 1000 * 1000;
-
- abs_time.tv_sec += curr_time.tv_sec;
- abs_time.tv_nsec += curr_time.tv_nsec;
-
- /* Check more than 1 sec. */
-
- if (abs_time.tv_nsec >= (1000 * 1000 * 1000))
- {
- abs_time.tv_sec += 1;
- abs_time.tv_nsec -= (1000 * 1000 * 1000);
- }
- }
-
*pattern = 0;
while (1)
@@ -514,10 +486,11 @@ int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle,
{
/* Wait for the semaphore to be posted until timeout occurs. */
- ret = nxsem_timedwait_uninterruptible(&handle->sem, &abs_time);
+ ret = nxsem_tickwait_uninterruptible(&handle->sem,
+ MSEC2TICK(timeout_ms));
if (ret < 0)
{
- m_err("nxsem_timedwait_uninterruptible() failed:%d\n", ret);
+ m_err("nxsem_tickwait_uninterruptible() failed:%d\n", ret);
break;
}
}
diff --git a/drivers/sensors/lps25h.c b/drivers/sensors/lps25h.c
index 4f9d9f6a83..15919ee1a4 100644
--- a/drivers/sensors/lps25h.c
+++ b/drivers/sensors/lps25h.c
@@ -494,7 +494,6 @@ static int lps25h_one_shot(FAR struct lps25h_dev_s *dev)
{
int ret = ERROR;
int retries;
- struct timespec abstime;
irqstate_t flags;
if (!dev->irqenabled)
@@ -530,16 +529,8 @@ static int lps25h_one_shot(FAR struct lps25h_dev_s *dev)
return ret;
}
- clock_gettime(CLOCK_REALTIME, &abstime);
- abstime.tv_sec += (LPS25H_RETRY_TIMEOUT_MSECS / 1000);
- abstime.tv_nsec += (LPS25H_RETRY_TIMEOUT_MSECS % 1000) * 1000 * 1000;
- while (abstime.tv_nsec >= (1000 * 1000 * 1000))
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= 1000 * 1000 * 1000;
- }
-
- ret = nxsem_timedwait_uninterruptible(&dev->waitsem, &abstime);
+ ret = nxsem_tickwait_uninterruptible(&dev->waitsem,
+ MSEC2TICK(LPS25H_RETRY_TIMEOUT_MSECS));
if (ret == OK)
{
break;
diff --git a/drivers/wireless/bluetooth/bt_uart_bcm4343x.c b/drivers/wireless/bluetooth/bt_uart_bcm4343x.c
index facd7ed1b9..70eae69a18 100644
--- a/drivers/wireless/bluetooth/bt_uart_bcm4343x.c
+++ b/drivers/wireless/bluetooth/bt_uart_bcm4343x.c
@@ -125,7 +125,6 @@ static int uartwriteconf(FAR const struct btuart_lowerhalf_s *lower,
int ret;
int gotlen = 0;
FAR uint8_t *din;
- struct timespec abstime;
DEBUGASSERT(lower != NULL);
@@ -149,22 +148,7 @@ static int uartwriteconf(FAR const struct btuart_lowerhalf_s *lower,
din = kmm_malloc(maxl);
while (gotlen < maxl)
{
- ret = clock_gettime(CLOCK_REALTIME, &abstime);
- if (ret < 0)
- {
- goto exit_uartwriteconf;
- }
-
- /* Add the offset to the time in the future */
-
- abstime.tv_nsec += NSEC_PER_SEC / 10;
- if (abstime.tv_nsec >= NSEC_PER_SEC)
- {
- abstime.tv_nsec -= NSEC_PER_SEC;
- abstime.tv_sec++;
- }
-
- ret = nxsem_timedwait_uninterruptible(rxsem, &abstime);
+ ret = nxsem_tickwait_uninterruptible(rxsem, MSEC2TICK(100));
if (ret < 0)
{
/* We didn't receive enough message, so fall out */
diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h
index dcea5ee863..736113c96e 100644
--- a/include/nuttx/semaphore.h
+++ b/include/nuttx/semaphore.h
@@ -566,7 +566,7 @@ int nxsem_timedwait_uninterruptible(FAR sem_t *sem,
* Name: nxsem_clockwait_uninterruptible
*
* Description:
- * This function is wrapped version of nxsem_timedwait(), which is
+ * This function is wrapped version of nxsem_clockwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
diff --git a/mm/iob/iob_alloc.c b/mm/iob/iob_alloc.c
index 7df00e8227..0f5d24567b 100644
--- a/mm/iob/iob_alloc.c
+++ b/mm/iob/iob_alloc.c
@@ -136,19 +136,7 @@ static FAR struct iob_s *iob_allocwait(bool throttled, unsigned int timeout,
}
else
{
- struct timespec abstime;
-
- DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
-
- abstime.tv_sec += timeout / MSEC_PER_SEC;
- abstime.tv_nsec += timeout % MSEC_PER_SEC * NSEC_PER_MSEC;
- if (abstime.tv_nsec >= NSEC_PER_SEC)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= NSEC_PER_SEC;
- }
-
- ret = nxsem_timedwait_uninterruptible(sem, &abstime);
+ ret = nxsem_tickwait_uninterruptible(sem, MSEC2TICK(timeout));
}
if (ret >= 0)
diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c
index 8d634cbaa4..5dc6967c4c 100644
--- a/net/utils/net_lock.c
+++ b/net/utils/net_lock.c
@@ -97,27 +97,15 @@ _net_timedwait(sem_t *sem, bool interruptible, unsigned int timeout)
if (timeout != UINT_MAX)
{
- struct timespec abstime;
-
- DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
-
- abstime.tv_sec += timeout / MSEC_PER_SEC;
- abstime.tv_nsec += timeout % MSEC_PER_SEC * NSEC_PER_MSEC;
- if (abstime.tv_nsec >= NSEC_PER_SEC)
- {
- abstime.tv_sec++;
- abstime.tv_nsec -= NSEC_PER_SEC;
- }
-
/* Wait until we get the lock or until the timeout expires */
if (interruptible)
{
- ret = nxsem_timedwait(sem, &abstime);
+ ret = nxsem_tickwait(sem, MSEC2TICK(timeout));
}
else
{
- ret = nxsem_timedwait_uninterruptible(sem, &abstime);
+ ret = nxsem_tickwait_uninterruptible(sem, MSEC2TICK(timeout));
}
}
else
@@ -447,7 +435,7 @@ int net_lockedwait_uninterruptible(sem_t *sem)
* Description:
* Allocate an IOB. If no IOBs are available, then atomically wait for
* for the IOB while temporarily releasing the lock on the network.
- * This function is wrapped version of nxsem_timedwait(), this wait will
+ * This function is wrapped version of nxsem_tickwait(), this wait will
* be terminated when the specified timeout expires.
*
* Caution should be utilized. Because the network lock is relinquished
diff --git a/sched/semaphore/sem_clockwait.c b/sched/semaphore/sem_clockwait.c
index d203ee676a..1ea1d4fc86 100644
--- a/sched/semaphore/sem_clockwait.c
+++ b/sched/semaphore/sem_clockwait.c
@@ -190,7 +190,7 @@ out:
* Name: nxsem_clockwait_uninterruptible
*
* Description:
- * This function is wrapped version of nxsem_timedwait(), which is
+ * This function is wrapped version of nxsem_clockwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c
index 1914835b53..8268f0943b 100644
--- a/wireless/bluetooth/bt_hcicore.c
+++ b/wireless/bluetooth/bt_hcicore.c
@@ -76,8 +76,7 @@
* to be adjusted.
*/
-#define TIMEOUT_SEC 2
-#define TIMEOUT_NSEC 500 * 1024 * 1024
+#define TIMEOUT_MSEC 2500
/****************************************************************************
* Public Data
@@ -1816,8 +1815,6 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
}
else
{
- struct timespec abstime;
-
/* Wait for the response to the command. An I/O error will be
* declared if the response does not occur within the timeout
* interval.
@@ -1825,38 +1822,10 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
* REVISIT: The cause of the timeout could be a failure to receive a
* response to a sent frame or, perhaps, a failure to send the frame.
* Should there also be logic to flush any unsent Tx packets?
- *
- * Get the current time. Not that we lock the scheduler here so that
- * we can be assured that there will be no context switches will occur
- * between the time that we calculate the delay time and until we get
- * to the wait.
*/
- sched_lock();
- ret = clock_gettime(CLOCK_REALTIME, &abstime);
- if (ret >= 0)
- {
- /* Add the offset to the time in the future */
-
- abstime.tv_sec += TIMEOUT_SEC;
- abstime.tv_nsec += TIMEOUT_NSEC;
-
- /* Handle carry from nanoseconds to seconds */
-
- if (abstime.tv_nsec >= NSEC_PER_SEC)
- {
- abstime.tv_nsec -= NSEC_PER_SEC;
- abstime.tv_sec++;
- }
-
- /* Now wait for the response. The scheduler lock will be
- * released while we are waiting.
- */
-
- ret = nxsem_timedwait_uninterruptible(&sync_sem, &abstime);
- }
-
- sched_unlock();
+ ret = nxsem_tickwait_uninterruptible(&sync_sem,
+ MSEC2TICK(TIMEOUT_MSEC));
}
/* Indicate failure if we failed to get the response */