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

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

Children
Related