瀏覽代碼

Make sure micros() is monotonic

teensy4-core
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;
}


Loading…
取消
儲存