#!/bin/sh
set -eu
A99_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
for profile in baseline tuned; do
 A99_GAIN=80000.0f
 if [ "$profile" = tuned ]; then A99_GAIN=400000.0f; fi
 cc -std=c11 -O1 -g -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -DA98_PLL_KI="$A99_GAIN" "$A99_ROOT/drill_smo.c" "$A99_ROOT/dynamic_probe.c" -lm -o "$A99_ROOT/dynamic_probe_$profile"
 "$A99_ROOT/dynamic_probe_$profile" > "$A99_ROOT/dynamic-$profile-A99.csv"
done
for test_name in timing_probe sweep test_discrete_residual test_phase_response; do
 cc -std=c11 -O1 -g -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined "$A99_ROOT/drill_smo.c" "$A99_ROOT/$test_name.c" -lm -o "$A99_ROOT/$test_name"
 "$A99_ROOT/$test_name" > "$A99_ROOT/$test_name.log"
done
arm-none-eabi-gcc -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mthumb -mfloat-abi=hard -std=c11 -Os -g -ffreestanding -fno-builtin -fno-common -Wall -Wextra -Werror -c "$A99_ROOT/drill_smo.c" -o "$A99_ROOT/drill_smo_m4f.o"
arm-none-eabi-size "$A99_ROOT/drill_smo_m4f.o" > "$A99_ROOT/arm-size.log"
