Page 1 of 1

How to calculate max value for chThdSleepSeconds() ?

Posted: Mon Jul 20, 2015 6:13 pm
by gallegojm
The function chThdSleepSeconds() is defined as a macro in chthreads.h and there is this comment:

Code: Select all

 * @note    The maximum specifiable value is implementation dependent.
....
#define chThdSleepSeconds(sec) chThdSleep(S2ST(sec))


and in chvt.h:

Code: Select all

#define S2ST(sec)                                                           \
  ((systime_t)((uint32_t)(sec) * (uint32_t)NIL_CFG_ST_FREQUENCY))


So, if NIL_CFG_ST_FREQUENCY = 10000 ( case of STM32F407 ), the maximum number of seconds will be:
2^32 / 10000 = 429496,7296
or 4 days 23 hours 18 minutes 16 seconds

Is it correct?
But I try chThdSleepSeconds( 24*60*60 ) (one day) and it seems like the thread will not wake up

Re: How to calculate max value for chThdSleepSeconds() ?

Posted: Mon Jul 20, 2015 6:53 pm
by Giovanni
hi,

Are you sure the frequency is 10000? I don't see why it shouldn't work.

Giovanni

Re: How to calculate max value for chThdSleepSeconds() ?

Posted: Mon Jul 20, 2015 7:18 pm
by gallegojm
Hi Giovanni

Yes, in chconf.h:

Code: Select all

#define CH_CFG_ST_RESOLUTION                32
....
#define CH_CFG_ST_FREQUENCY                 10000


Note I made an error copying the definition of S2ST. It is:

Code: Select all

#define S2ST(sec)                                                           \
  ((systime_t)((uint32_t)(sec) * (uint32_t)CH_CFG_ST_FREQUENCY))
but that do not change any thing to my problem

Jean-Michel

Re: How to calculate max value for chThdSleepSeconds() ?

Posted: Mon Jul 20, 2015 7:55 pm
by Giovanni
Are debug options enabled? assertions, checks, state checker.

Giovanni