From 5a007851ff79fa81962b114f92c0fc923a4b73f4 Mon Sep 17 00:00:00 2001 From: gnxlxnxx Date: Thu, 18 Jun 2026 11:45:04 +0200 Subject: [PATCH] Fix Wrong Priorization (higher prio -> higher number) --- src/main.rs | 17 ++++++++--------- src/uart_parser.rs | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5f2ffb4..facc7c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -170,7 +170,7 @@ mod app { info!("----------Setup TIM----------"); - let freq = 10.kHz(); + let freq = 1.kHz(); info!("TIM3:"); info!("\tfreq: {} kHz", freq.to_kHz()); @@ -272,7 +272,7 @@ mod app { }, } - #[task(binds = USART1, local = [parser], shared = [serial, target], priority = 2)] + #[task(binds = USART1, local = [parser], shared = [serial, target], priority = 1)] fn uart_target(mut ctx: uart_target::Context) { let parser = ctx.local.parser; @@ -292,7 +292,7 @@ mod app { }); } - #[task(binds = TIM3, local = [timer3, adc1, adc_i, adc_q, adc_te21, avgbuffer_i, avgbuffer_q, avgbuffer_te21], shared = [target, serial])] + #[task(binds = TIM3, local = [timer3, adc1, adc_i, adc_q, adc_te21, avgbuffer_i, avgbuffer_q, avgbuffer_te21], shared = [target, serial], priority = 2)] fn adc_print(mut ctx: adc_print::Context) { // Clear interrupt flag ctx.local.timer3.clear_irq(); @@ -309,17 +309,16 @@ mod app { ctx.shared.serial.lock(|serial| { let _ = writeln!( serial, - "I: {},\tQ: {},\tTE11: {},\tTE21: {}\r", + "I: {:.3},\tQ: {:.3},\tTE11: {:.3},\tTE21: {:.3}\r", ctx.local.avgbuffer_i.average() as f32 * VDDA / u16::MAX as f32, ctx.local.avgbuffer_q.average() as f32 * VDDA / u16::MAX as f32, - TE11_AVG.load(Ordering::SeqCst) as f32 * VDDA / u16::MAX as f32, + TE11_AVG.load(Ordering::Relaxed) as f32 * VDDA / u16::MAX as f32, ctx.local.avgbuffer_te21.average() as f32 * VDDA / u16::MAX as f32, ); }); } - // #[task(binds = TIM2, local = [timer2, p, i, d, input, adc2, dac, freq], shared = [target, serial], priority = 1)] - #[task(binds = TIM2, local = [timer2, p, i, d, input, adc2, dac, freq, avgbuffer_te11], shared = [target, config], priority = 1)] + #[task(binds = TIM2, local = [timer2, p, i, d, input, adc2, dac, freq, avgbuffer_te11], shared = [target, config], priority = 3)] fn pid(mut ctx: pid::Context) { // Clear interrupt flag ctx.local.timer2.clear_irq(); @@ -330,9 +329,9 @@ mod app { let input: u32 = ctx.local.adc2.read(ctx.local.input).unwrap(); avgbuffer.push(input); - // let input: f32 = input as f32; + let input: u32 = avgbuffer.average(); - TE11_AVG.store(input, Ordering::SeqCst); + TE11_AVG.store(input, Ordering::Relaxed); let input: f32 = (input >> 4) as f32; diff --git a/src/uart_parser.rs b/src/uart_parser.rs index 3985058..344ac86 100644 --- a/src/uart_parser.rs +++ b/src/uart_parser.rs @@ -3,14 +3,14 @@ use core::str::{self, FromStr}; pub struct Parser { pub curr: u32, - pub buffer: [u8; 100], + pub buffer: [u8; 1000], } impl Parser { pub fn new() -> Self { Self { curr: 0, - buffer: [0_u8; 100], + buffer: [0_u8; 1000], } }