xTimerCreate() and configASSERT( )

Hello! In timers.c in function xTimerCreate() the term “xTimerPeriodInTicks > 0”
always evaluates to ZERO/FALSE:
xTimerHandle xTimerCreate(...)
{
xTIMER *pxNewTimer;
    /* Allocate the timer structure. */
    if( xTimerPeriodInTicks == ( portTickType ) 0U )
    {
        pxNewTimer = NULL;
        configASSERT( ( xTimerPeriodInTicks > 0 ) );
    }
Therefore one will always see a compiler warning similar to:
["..FreeRTOS_Sourcetimers.c" 236/3] condition is always true
What is the sense of this assert when timers.h documents:
If the timer cannot be created (because , or the
timer period was set to 0
) then 0 is returned.
In my view this assert should be removed as this code does not do
what is documented. I suggest:
xTimerHandle xTimerCreate(...)
{
xTIMER *pxNewTimer = NULL;
    /* Allocate the timer structure. */
    if( xTimerPeriodInTicks > ( portTickType ) 0U )
    {
Regards
Friedl

xTimerCreate() and configASSERT( )

Therefore one will always see a compiler warning similar to:
I’m not sure I have ever seen that warning, which is curious, although software timers are a new(ish) features and most of the demos don’t include them because they are too old.  Still, I have used timers with IAR, Keil, GCC, etc… The assertion is valid, but will be moved to outside of the ‘if’ statement to remove the possibility of a warning.
If the timer cannot be created (because , or the
timer period was set to 0) then 0 is returned. In my view this assert should be removed as this code does not do
what is documented
Well, the code returns NULL, which is 0 cast to a pointer, so it does behave as documented, although the documentation is somewhat imprecise.  I have change the documentation to instead say “then NULL is returned”. Regards.

xTimerCreate() and configASSERT( )

richardbarry
Still, I have used timers with IAR, Keil, GCC, etc…
This is a TASKING compiler and it sees that “xTimerPeriodInTicks > 0” is always false and therefore the assert always true inside “xTimerPeriodInTicks == ( portTickType ) 0U”.
richardbarry
The assertion is valid, but will be moved to outside of the ‘if’ statement to remove the possibility of a warning.
You can’t have a
configASSERT( ( xTimerPeriodInTicks > 0 ) )
there as well or the function will NEVER return 0 nor NULL in case of xTimerPeriodInTicks == 0.

xTimerCreate() and configASSERT( )

I can see that the original position of the assert can only be reached when ( xTimerPeriodInTicks == 0 ), and therefore the assert will always be evaluated to false, because if ( xTimerPeriodInTicks == 0 ) it cannot simultaneously be > 0.  The assert is useful to keep, but should not be placed in a position where it could cause a compiler warning to be generated, so I have moved it outside of the if() statement….but you say:
You can’t have a
configASSERT( ( xTimerPeriodInTicks > 0 ) ) there as well or the function will NEVER return 0 nor NULL in case of xTimerPeriodInTicks == 0. The assert is a debugging statement only, it can be defined however the user wants and in production code (where it will presumably not be defined) its position will not change the logic of a function as it won’t generate any code.  Setting the timer period to 0 is an error.  The C code protects against that eventuality by trapping the error and exiting the function returning NULL.  The assert() gives people an opportunity to catch that happening while they are developing their application.  I think I disagree with your statement that the function will never return NULL – it will if xTimerPeriodInTicks == 0 if configASSERT is not defined, or configASSERT() is defined to something that does not prevent the application from continuing executing.  The assert is not a logic statement that effects the flow of the code, just provided for the convenience of users while they are creating their applications. Regards.