4.27. MCU
4.27.2. Description
The MCU
module supplies an API that helps using certain functions of the MCU.
As an example, it can be used to access the current value of the free running
counter of the real time interrupt module.
This can be used as a quick and reliable method for measuring code execution time. The following example Measuring execution time with the RTI can help finding states in a line of code that takes longer than expected for execution.
1 const uint32_t entry = MCU_GetFreeRunningCount();
2 /* code under test here */
3 const uint32_t exit = MCU_GetFreeRunningCount();
4 const uint32_t time_us = MCU_ConvertFrcDifferenceToTimespan_us(exit - entry);
5 if (time_us > 250u) {
6 /* do something that the compiler won't optimize away */
7 volatile uint8_t test = 0u;
8 /* set breakpoint for example here */
9 test++;
10 }
The MCU
module also supplies the function MCU_Delay_us()
.
It waits blocking for the time in microseconds given as parameter.
As this function uses the free running counter, it can be interrupted by the
operating system.
After its execution resumes, it will exit if the time given as parameter has
elapsed.
A timeout has also been implemented to avoid blocking the system with the
function.
If the time given as parameter is higher than the time resulting from the
timeout, the function will exit after the timeout and will not wait for the
time given as parameter.
This means that the timeout value should be checked.