freeRTOS Time Measurement
Time Measurement
time slicing : In the examples, both tasks were created at the same priority, and both tasks were always able to run. Therefore, each task executed for a ‘time slice’, entering the Running state at the start of a time slice, and exiting the Running state at the end of a time slice.The length of the time slice is effectively set by the tick interrupt frequency, which is configured by the application-defined configTICK_RATE_HZ
For example, if configTICK_RATE_HZ is set to 100 (Hz), then the time slice will be 10 milliseconds. The time between two tick interrupts is called the ‘tick period’. One time slice equals one tick period.
FreeRTOS API calls always specify time in multiples of tick periods, which are often referred to
simply as ‘ticks’.
The pdMS_TO_TICKS() macro converts a time specified in milliseconds into
a time specified in ticks.
pdMS_TO_TICKS() cannot be used if the tick frequency is above 1KHz (if
configTICK_RATE_HZ is greater than 1000).
/* pdMS_TO_TICKS() takes a time in milliseconds as its only parameter, and evaluates
to the equivalent time in tick periods. This example shows xTimeInTicks being set to
the number of tick periods that are equivalent to 200 milliseconds. */
TickType_t xTimeInTicks = pdMS_TO_TICKS( 200 );
use pdMS_TO_TICKS() to convert a time specified as 200 milliseconds into an equivalent time specified in ticks.
Note: It is not recommended to specify times in ticks directly within the application, but instead
to use the pdMS_TO_TICKS() macro to specify times in milliseconds, and in so doing,
ensuring times specified within the application do not change if the tick frequency is changed.
留言
張貼留言