jlaitine commented on issue #8346: URL: https://github.com/apache/nuttx/issues/8346#issuecomment-1408119188
I think the best way is just to always just round up, not round to nearest as what is currently done. The problem now happens always; e.g. if tick is 10ms and user wants to sleep 19ms, the code only sleeps 10ms. Previously it did 20ms. As this is mostly used as a timeout, it is very large error. If user wants to sleep 9ms, the code doesn't sleep at all, which breaks more or less all the i2c drivers at least. So if we want to change the *SEC2TICK macros, it would be something like: ``` #define NSEC2TICK(nsec) (((nsec)+(NSEC_PER_TICK/2))/NSEC_PER_TICK) /* Rounds */ #define USEC2TICK(usec) (((usec)+(USEC_PER_TICK/2))/USEC_PER_TICK) /* Rounds */ #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK # define MSEC2TICK(msec) (((msec)+(MSEC_PER_TICK/2))/MSEC_PER_TICK) /* Rounds */ #else # define MSEC2TICK(msec) USEC2TICK((msec) * USEC_PER_MSEC) /* Rounds */ #endif ``` into ``` #define NSEC2TICK(nsec) (((nsec)+(NSEC_PER_TICK - 1))/NSEC_PER_TICK) /* Rounds */ #define USEC2TICK(usec) (((usec)+(USEC_PER_TICK - 1))/USEC_PER_TICK) /* Rounds */ #if (MSEC_PER_TICK * USEC_PER_MSEC) == USEC_PER_TICK # define MSEC2TICK(msec) (((msec)+(MSEC_PER_TICK - 1))/MSEC_PER_TICK) /* Rounds */ #else # define MSEC2TICK(msec) USEC2TICK((msec) * USEC_PER_MSEC) /* Rounds */ #endif ``` But I would like to see that before decision like this is done, there are more eyes looking into it -- 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-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org