How to calculate max value for chThdSleepSeconds() ?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

How to calculate max value for chThdSleepSeconds() ?

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

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

Post by Giovanni »

hi,

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

Giovanni
gallegojm
Posts: 42
Joined: Mon Apr 06, 2015 2:02 am

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

Post 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
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

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

Post by Giovanni »

Are debug options enabled? assertions, checks, state checker.

Giovanni
Post Reply