Files
uv-k5-v3-emulator/tools/delay_rate.sh
mckero 542515d5ad Finish the portability sweep: one firmware resolver, no author paths
The probe scripts, run.sh, trace_run.sh, webui.py and two emulator tests each named the same hardcoded firmware from a source tree that is not in this repository. They now resolve QEMU and the firmware the way tools/uvk5_testenv.py does -- environment, then PATH, then whatever the checkout has -- and skip with a reason when there is nothing.

webui.py's --qemu and --elf lost their author defaults too: a bare qemu-system-arm through PATH, and no firmware until one is uploaded, which the page already reports.
2026-10-01 15:15:31 +08:00

45 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Measure how fast a SYSTICK_DelayUs loop is converging.
#
# r0 holds the target tick count, r1 the accumulated elapsed count, so sampling
# both twice gives the rate and an estimate of how long the delay will take.
set -uo pipefail
# shellcheck source=tools/uvk5_elf.sh
. "$(dirname "$0")/uvk5_elf.sh"
ELF=$(uvk5_find_elf) || { echo "SKIP no firmware found; set ELF or put one in assets/firmware" >&2; exit 0; }
GAP="${1:-4}"
SCRIPT=$(mktemp --suffix=.gdb)
trap 'rm -f "$SCRIPT"' EXIT
cat >"$SCRIPT" <<'EOF'
set confirm off
set pagination off
target remote :1234
info registers r0 r1
detach
quit
EOF
read_regs() {
gdb-multiarch -batch -x "$SCRIPT" "$ELF" 2>/dev/null \
| awk '/^r0 /{t=strtonum($2)} /^r1 /{e=strtonum($2)} END{print t, e}'
}
first=$(read_regs)
sleep "$GAP"
second=$(read_regs)
awk -v a="$first" -v b="$second" -v gap="$GAP" 'BEGIN {
split(a, x, " "); split(b, y, " ")
target = y[1]; from = x[2]; to = y[2]
rate = (to - from) / gap
printf "target=%d elapsed %d -> %d (%.0f ticks/s)\n", target, from, to, rate
if (rate > 0 && target > to)
printf "remaining: %.1f s\n", (target - to) / rate
else if (target <= to)
print "delay already satisfied"
else
print "not advancing"
}'