Replace busy-wait with time-based sleep in sweden.c

This commit is contained in:
Chris
2026-02-08 14:52:19 +01:00
parent e2cf01bb4a
commit b245dc5f00
5 changed files with 20 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
#include "cli_utils.h"
#include "wm.h"
// Forward declarations - these will be provided by cmd.c
extern void cmd_putchar(char c);
@@ -78,3 +79,14 @@ void cli_delay(int iterations) {
__asm__ __volatile__("nop");
}
}
void cli_sleep(int ms) {
// Timer is ~60Hz, so 1 tick = 16.66ms
uint32_t ticks = ms / 16;
if (ticks == 0 && ms > 0) ticks = 1;
uint32_t target = wm_get_ticks() + ticks;
while (wm_get_ticks() < target) {
__asm__ __volatile__("hlt");
}
}