You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/05/10 10:30:04 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6226: Replace nxsem_timedwait_uninterruptible with nxsem_tickwait_uninterruptible

xiaoxiang781216 commented on code in PR #6226:
URL: https://github.com/apache/incubator-nuttx/pull/6226#discussion_r869077568


##########
arch/arm/src/am335x/am335x_i2c.c:
##########
@@ -546,48 +545,25 @@ static inline int am335x_i2c_sem_waitdone(struct am335x_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() sleeps.
    */
 
   priv->intstate = INTSTATE_WAITING;
   do
     {
-      /* Get the current time */
-
-      clock_gettime(CLOCK_REALTIME, &abstime);
-
-      /* Calculate a time in the future */
-
-#if CONFIG_AM335X_I2CTIMEOSEC > 0
-      abstime.tv_sec += CONFIG_AM335X_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_AM335X_I2C_DYNTIMEO
-      abstime.tv_nsec += 1000 * am335x_i2c_tousecs(priv->msgc, priv->msgv);
-      if (abstime.tv_nsec >= 1000 * 1000 * 1000)
-        {
-          abstime.tv_sec++;
-          abstime.tv_nsec -= 1000 * 1000 * 1000;
-        }
-
-#elif CONFIG_AM335X_I2CTIMEOMS > 0
-      abstime.tv_nsec += CONFIG_AM335X_I2CTIMEOMS * 1000 * 1000;
-      if (abstime.tv_nsec >= 1000 * 1000 * 1000)
-        {
-          abstime.tv_sec++;
-          abstime.tv_nsec -= 1000 * 1000 * 1000;
-        }
+      ret = nxsem_tickwait(&priv->sem_isr,
+                       USEC2TICK(am335x_i2c_tousecs(priv->msgc, priv->msgv));
+#else
+      ret = nxsem_tickwait(&priv->sem_isr,
+                       CONFIG_AM335X_I2CTIMEOTICKS);

Review Comment:
   Done.



##########
arch/arm/src/efm32/efm32_i2c.c:
##########
@@ -528,48 +528,24 @@ 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 |
                        I2C_IF_MSTOP | I2C_IF_RXDATAV | I2C_IF_ERRORS);
 
       /* 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);

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org