US2ST with ULL

Discussions and support about ChibiOS/RT, the free embedded RTOS.
pito
Posts: 199
Joined: Sun Nov 06, 2011 3:54 pm

US2ST with ULL

Postby pito » Sun Mar 20, 2016 1:51 pm

While playing with VLdisco demo (cpu @40MHz) I've tried to use

Code: Select all

chThdSleepMicroseconds(2000100);  //2.0001sec


The macro flows over with CH_CFG_ST_FREQUENCY=10000 so I've modified it

Code: Select all

#define US2ST(usec)                                                         \
  ((systime_t)(((((uint64_t)(usec)) *                                       \
                 ((uint64_t)CH_CFG_ST_FREQUENCY)) + 999999ULL) / 1000000ULL))


and it blinks as expected now :) .

PS: I would do it with MS2ST too, as t>429secs with CH_CFG_ST_FREQUENCY=10000 will overflow as well (and those values are quite realistic).
PPS: and finally a check of the resulting macro value against the tick timer size (16 or 32bit) may help too..

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: US2ST with ULL

Postby Giovanni » Tue Mar 22, 2016 3:07 pm

The problem is that if you pass to the macro a variable then it would do 64 bits arithmetic at runtime.

It is a real problem, both solution are not perfect.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 15 guests