feilipu / Arduino_FreeRTOS_Library

A FreeRTOS Library for all Arduino ATmega Devices (Uno R3, Leonardo, Mega, etc).
MIT License
841 stars 204 forks source link

pdMS_TO_TICKS() overflows #61

Closed manuelferreira65 closed 4 years ago

manuelferreira65 commented 4 years ago

define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) )

If TickType_t defined as uint16_t xTimeInMs * configTICK_RATE_HZ overflows with xTimeInMs = 1058.

feilipu commented 4 years ago

I don't think it was expected that TickType_t would be a 16 bit type, hence top line, before divide, overflows.

Try removing the casts from the top line. Richard may already have fixed this. I'll check.

feilipu commented 4 years ago

Resolved with 10.3.0-1, here.

feilipu commented 4 years ago

Resolved finally with this code.

#if configUSE_16_BIT_TICKS == 1
    #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( uint32_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) )
#else
    #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000 ) )
#endif