This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Wrong computation in BSP_MS_TO_TICK macro

Hi,

I noticed a possible issue in BSP_MS_TO_TICK macro computation. In bsp.c, the macro is defined as:

#define BSP_MS_TO_TICK(MS) (m_app_ticks_per_100ms * (MS / 100))

This macro is used many places in BSP to start timers. But due to the places of parenthesis, it forbid the usage of timers shorter than 100ms. It does a division of MS by 100, leading to 0 if MS < 100.

Rather than:

#define BSP_MS_TO_TICK(MS) ((m_app_ticks_per_100ms * MS) / 100)

It shall be (mind the place of the parenthesis):

#define BSP_MS_TO_TICK(MS) (m_app_ticks_per_100ms * (MS / 100))

Multiply before divide is probably better to avoid 0 tick computation when MS < 100ms.

Is it on-purpose ? Can you confirm there is no issue setting timers shorter than 100ms ? (I think/hope not).

Regards. Djamil

Parents
  • If this was in a header file, then I would have agreed with you. I am not happy with the paranthesis either, but we cannot call this a bug. This is because this macro is defined in bsp.c file. and all the values used within this module are multiples of 100. So I think it is what the developer intended.

    If you want changing anything in this file, then you can change the parenthesis to suit your needs. I can confirm that anything less than 100ms would not work as you said, and i also confirm that the module as it is should work fine with all intervals being multiples of 100.

Reply
  • If this was in a header file, then I would have agreed with you. I am not happy with the paranthesis either, but we cannot call this a bug. This is because this macro is defined in bsp.c file. and all the values used within this module are multiples of 100. So I think it is what the developer intended.

    If you want changing anything in this file, then you can change the parenthesis to suit your needs. I can confirm that anything less than 100ms would not work as you said, and i also confirm that the module as it is should work fine with all intervals being multiples of 100.

Children
No Data
Related