From 8ee6d86748a5c52d65c2631751a315166dcf1967 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 22 Feb 2026 03:20:11 +0800 Subject: [PATCH] cleanup math test Fp refernce --- libs/bio-lib/src/c/math_test/main.c | 13 ++----------- libs/bio-lib/src/c/math_test/mod.rs | 19 +------------------ 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/libs/bio-lib/src/c/math_test/main.c b/libs/bio-lib/src/c/math_test/main.c index bb7e4512d..bd38637b8 100644 --- a/libs/bio-lib/src/c/math_test/main.c +++ b/libs/bio-lib/src/c/math_test/main.c @@ -1,14 +1,12 @@ #include -#include "fp.h" +#include "fp_q12.h" #include "bio.h" void main(void) { int32_t in; fp_t arg; - // fp_t state = FP_FROM_INT(1); - // fp_t a; - // computes fifo1 <- cosine(fifo0), where the value presented is in degrees + // computes fifo1 <- cosine(fifo0) + 1.0, where the value presented is in degrees as an FP value while (1) { in = pop_fifo0(); @@ -17,13 +15,6 @@ void main(void) { arg = fp_div(arg, FP_FROM_INT(180)); arg = fp_add(fp_cos(arg), FP_FROM_INT(1)); - /* - arg = FP_FROM_INT(in); - a = fp_mul(arg, FP_FROM_INT(2)); - a = fp_add(state, a); - result = fp_div(a, state); - state = arg; - */ push_fifo1(arg); } } diff --git a/libs/bio-lib/src/c/math_test/mod.rs b/libs/bio-lib/src/c/math_test/mod.rs index 88ae8b740..96ff368c6 100644 --- a/libs/bio-lib/src/c/math_test/mod.rs +++ b/libs/bio-lib/src/c/math_test/mod.rs @@ -5,24 +5,7 @@ use bao1x_hal::bio::{Bio, CoreCsr}; use math_test::*; use utralib::utra::bio_bdma; -/// Number of fractional bits in the Q20.12 fixed-point format. -const FRAC_BITS: u32 = 12; -const FRAC_SCALE: i32 = 1 << FRAC_BITS; // 4096 -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub struct Fp(pub i32); - -impl Fp { - pub fn from_int(x: i32) -> Self { Self(x << FRAC_BITS) } - - pub fn from_float(x: f32) -> Self { Self((x * FRAC_SCALE as f32 + 0.5) as i32) } - - pub fn to_int(self) -> i32 { self.0 >> FRAC_BITS } - - pub fn to_float(self) -> f32 { self.0 as f32 / FRAC_SCALE as f32 } - - /// Wrap a raw i32 coming directly off the hardware register. - pub fn from_raw(raw: i32) -> Self { Self(raw) } -} +use super::Fp; pub struct MathTest { bio_ss: Bio,