From 9c649ea7d1dd0206092697d73c894fd2c4fe29b3 Mon Sep 17 00:00:00 2001 From: Darian <32921628+Dazza0@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:34:53 +0800 Subject: [PATCH] Add time conversion macros (#866) This commit updates the following time conversion macros: - pdMS_TO_TICKS: Added cast to "uint64_t" to prevent overflow - pdTICKS_TO_MS: Added macro to convert ticks to milliseconds Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> --- include/projdefs.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/projdefs.h b/include/projdefs.h index c81ad5684..26f6e4f0c 100644 --- a/include/projdefs.h +++ b/include/projdefs.h @@ -39,7 +39,14 @@ typedef void (* TaskFunction_t)( void * ); * overridden by a macro of the same name defined in FreeRTOSConfig.h in case the * definition here is not suitable for your application. */ #ifndef pdMS_TO_TICKS - #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( TickType_t ) ( xTimeInMs ) * ( TickType_t ) configTICK_RATE_HZ ) / ( TickType_t ) 1000U ) ) + #define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInMs ) * ( uint64_t ) configTICK_RATE_HZ ) / ( uint64_t ) 1000U ) ) +#endif + +/* Converts a time in ticks to a time in milliseconds. This macro can be + * overridden by a macro of the same name defined in FreeRTOSConfig.h in case the + * definition here is not suitable for your application. */ +#ifndef pdTICKS_TO_MS + #define pdTICKS_TO_MS( xTimeInTicks ) ( ( TickType_t ) ( ( ( uint64_t ) ( xTimeInTicks ) * ( uint64_t ) 1000U ) / ( uint64_t ) configTICK_RATE_HZ ) ) #endif #define pdFALSE ( ( BaseType_t ) 0 )