我正在尝试测量功能期间经过的时间,但我不确定我是否正确执行此操作。当我停止systick时,它返回的值是24,这是不可能的。
#define SYSTICKS 0xFFFFFFu
static volatile uint32_t Count = 0;
void SysTick_Handler(void)
{
Count++;
}
int doSomething()
{
int a = 0;
int b = 8;
return a + b;
}
int main(int argc, char *argv[])
SysTick_Config(SYSTICKS);
volatile uint64_t a = (uint64_t)SYSTICKS - SysTick->VAL;
a += ((uint64_t)SYSTICKS * Count);
/* some code here */
doSomething();
volatile uint64_t b = (uint64_t)SYSTICKS - SysTick->VAL;
b += ((uint64_t)SYSTICKS * Count);
volatile uint64_t timeElapsed = a - b;
printf("a = %lld\r\n", a);
printf("b = %lld\r\n", b);
printf("timeElapsed = %lld\n", timeElapsed);
这是输出
a = 16777215
b = 24
timeElapsed = 16777191