Skip to content

Fix systime_now_us() occasional fault#189

Merged
JcZou merged 1 commit intoFirmament-Autopilot:masterfrom
Pan-Chenliang:systime_fix
Mar 9, 2026
Merged

Fix systime_now_us() occasional fault#189
JcZou merged 1 commit intoFirmament-Autopilot:masterfrom
Pan-Chenliang:systime_fix

Conversation

@Pan-Chenliang
Copy link
Copy Markdown
Contributor

在 i2c timeout 故障中,捕捉两次调用systime_now_us的时间差,出现故障的时候时间差总是1000us。分析发现systime_now_us()有极小概率出现 毫秒+微妙 刚好多跳了一毫秒的情况。类似秒针跳到60,分针+1,但是秒针还没回0。此时的读取会多1000us,导致i2c超时函数直接判定超时。

经过在6c上测试,修改后50次启动中没有出现i2c启动失败的情况。

now_us = time_now_ms * 1000ULL + systick_us;

/* Fix the race condition where the SysTick hardware timer has wrapped around */
if (now_us < monotonic_us) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可能用while会更好?

@JcZou JcZou merged commit 9285599 into Firmament-Autopilot:master Mar 9, 2026
4 checks passed
@Pan-Chenliang Pan-Chenliang deleted the systime_fix branch March 9, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants