浏览代码

Make sure micros() is monotonic

main
PaulStoffregen 5 年前
父节点
当前提交
bd4a9e2cfb
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. +6
    -4
      teensy4/delay.c

+ 6
- 4
teensy4/delay.c 查看文件

@@ -67,13 +67,15 @@ void delay(uint32_t msec)
uint32_t micros(void)
{
uint32_t ccdelta, usec, smc, scc;
do {
__LDREXW(&systick_safe_read);
do {
__LDREXW(&systick_safe_read);
smc = systick_millis_count;
scc = systick_cycle_count;
} while ( __STREXW(1, &systick_safe_read));
} while ( __STREXW(1, &systick_safe_read));
ccdelta = ARM_DWT_CYCCNT - scc;
usec = 1000*smc + (ccdelta/(F_CPU_ACTUAL/1000000));
uint32_t frac = ccdelta/(F_CPU_ACTUAL/1000000);
if (frac > 999) frac = 999;
usec = 1000*smc + frac;
return usec;
}


正在加载...
取消
保存