cleanup math test Fp refernce

This commit is contained in:
bunnie 2026-02-22 03:20:11 +08:00
parent c80877d064
commit 8ee6d86748
2 changed files with 3 additions and 29 deletions

View file

@ -1,14 +1,12 @@
#include <stdint.h>
#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);
}
}

View file

@ -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,