FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [February 2013 Threads] xTimerCreate() and configASSERT( )Posted by Friedrich Lobenstock on February 3, 2013 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_Source\timers.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
RE: xTimerCreate() and configASSERT( )Posted by Richard on February 3, 2013 “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.
RE: xTimerCreate() and configASSERT( )Posted by Friedrich Lobenstock on February 3, 2013 “ 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". “ 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.
RE: xTimerCreate() and configASSERT( )Posted by Richard on February 4, 2013 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|