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

  • 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.

  • Hi, any Nordic employee

    I noticed another flaw in bsp implementation inherited from SDK11 and still present in SDK12. There is only one button and no LEDs in my project. In this configuration i got a compiler error, since m_app_ticks_per_100ms not defined but actually used. The macro check:

    #if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
    

    should be as follow:

    #if ((LEDS_NUMBER > 0) || (BUTTONS_NUMBER > 0)) && !(defined BSP_SIMPLE)
    

    examples\bsp\bsp.c lines 53, 515

  • Hi, I am facing the same situation and I agree with your suggestion. Did you get an answer? How did you finally managed it?

Related