Environment: RM57 + IAR 7.40.5 For ARM + JTAG emulator
in our project, we're using PMU cycle counter API to determine some function duration. Reading PMU cycle counter API is like this:
_pmuGetCycleCount_
mrc p15, #0, r0, c9, c13, #0
bx lr
Test Codes: ( they are actually same codes only in different function names)
uint32 DelayMs(void)
{
volatile uint32 i = 0u;
uint32 u32T0 = 0u;
uint32 u32T1 = 0u;
u32T0 = _pmuGetCycleCount_();
for(i = 0u; i<30400u; i++);
u32T1 = _pmuGetCycleCount_();
return u32T1 - u32T0; /* test the duration of for loop */
}
uint32 DelayMs1(void)
{
volatile uint32 i = 0u;
uint32 u32T0 = 0u;
uint32 u32T1 = 0u;
u32T0 = _pmuGetCycleCount_();
for(i = 0u; i<30400u; i++);
u32T1 = _pmuGetCycleCount_();
return u32T1 - u32T0; /* test the duration of for loop */
}
uint32 DelayMs2(void)
{
volatile uint32 i = 0u;
uint32 u32T0 = 0u;
uint32 u32T1 = 0u;
u32T0 = _pmuGetCycleCount_();
for(i = 0u; i<30400u; i++);
u32T1 = _pmuGetCycleCount_();
return u32T1 - u32T0; /* test the duration of for loop */
}
void main()
{
...DelayMs(); DelayMs1(); DelayMs(); DelayMs2();....
}
These codes are running in single-task environment, and we've been disabled IRQ.
What's really confusing is that we get different output from DelayMs(), DelayMs1() and DelayMs2(). Sometimes there can be up to 10% bias. Like DelayMs() returns 1500000, DelayMs1() returns 1600000.
Plus, we can invoke these funtions multiple times in any order, for instance:
DelayMs();
DelayMs2();
DelayMs2();
DelayMs1();
DelayMs()......
all DelayMs() returns same result, and so do all DelayMs1(). So I infer this has nothing to do with IRQ...
Any thoughts what might cause this bias?