mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python/port] Use msleep (not millis) in micropython_port_interruptible_msleep
This commit is contained in:
committed by
EmilieNumworks
parent
069319a7ae
commit
577e7db8dd
@@ -23,13 +23,20 @@ bool micropython_port_vm_hook_loop() {
|
||||
}
|
||||
|
||||
bool micropython_port_interruptible_msleep(uint32_t delay) {
|
||||
uint32_t start = Ion::Timing::millis();
|
||||
while (Ion::Timing::millis() - start < delay) {
|
||||
/* We don't use millis because the systick drifts when changing the HCLK
|
||||
* frequency. */
|
||||
constexpr uint32_t interruptionCheckDelay = 100;
|
||||
const uint32_t numberOfInterruptionChecks = delay / interruptionCheckDelay;
|
||||
uint32_t remainingInterruptionChecks = numberOfInterruptionChecks;
|
||||
while (remainingInterruptionChecks > 0) {
|
||||
// We assume the time taken by the interruption check is insignificant
|
||||
if (micropython_port_interrupt_if_needed()) {
|
||||
return true;
|
||||
}
|
||||
Ion::Timing::msleep(1);
|
||||
remainingInterruptionChecks--;
|
||||
Ion::Timing::msleep(interruptionCheckDelay);
|
||||
}
|
||||
Ion::Timing::msleep(delay - numberOfInterruptionChecks * interruptionCheckDelay);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user