Closed Dazza0 closed 11 months ago
I just tested my proposed macro on a 32-bit platform. It works as expected, although for a complete test, you'd have to adapt pdMS_TO_TICKS()
as well:
- #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 ) )
I tested with a tick rate of 500 Hz.
@htibosch Thanks for the quick review. I've update both pdTICKS_TO_MS()
and pdMS_TO_TICKS()
to use a uint64_t
cast.
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
0640b2e
) 93.51% compared to head (acc71c7
) 93.51%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Given that we now have a way to make TickType_t 64-bit, do we need this to be explicitly uint64_t
?
I think that we do not and TickType_t
should be good. Those who need wider TickType_t
can do so in their FreeRTOSConfig.h
. What do you think @Dazza0, @htibosch ?
The problem is that it may take a lot of time before one discovers that mentioned macro is overflowing. I am one of them: I couldn't understand why the timestamps in my logging were erroneous.
And I can imagine that someone choses TICK_TYPE_WIDTH_32_BITS
and conversion macro's that do not overflow in 1.5 day.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
Description
This PR adds a simple
pdTICKS_TO_MS()
convenience macro to convert time in ticks to time in milliseconds.Test Steps
Checklist:
Related Issue
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.