From 918092cd9ff15831d2b30d17cf16ce5d65c41571 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Mon, 16 Feb 2026 14:09:18 +0100 Subject: [PATCH] sync during ir_recv dev --- firmware/libs/ir/recv/src/ir_recv.c | 41 +++++++++++++---------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/firmware/libs/ir/recv/src/ir_recv.c b/firmware/libs/ir/recv/src/ir_recv.c index e7f77e7..1abe8da 100644 --- a/firmware/libs/ir/recv/src/ir_recv.c +++ b/firmware/libs/ir/recv/src/ir_recv.c @@ -76,10 +76,10 @@ void ir_recv_sim_thread(void *p1, void *p2, void *p3) { } } } + K_THREAD_DEFINE(sim_tid, 1024, ir_recv_sim_thread, NULL, NULL, NULL, 5, 0, 0); #endif -/* --- Robust State Machine --- */ typedef enum { IR_STATE_IDLE, IR_STATE_HEADER_SYNC, @@ -99,7 +99,7 @@ typedef struct { static ir_ctx_t channels[3]; -static void process_sample(ir_ctx_t *ctx, int16_t raw) { +static void process_ir_sample(ir_ctx_t *ctx, int16_t raw) { bool active = (raw > 2048); if (IS_ENABLED(CONFIG_IR_RECV_INVERT_SIGNAL)) active = !active; @@ -164,27 +164,22 @@ static void process_sample(ir_ctx_t *ctx, int16_t raw) { */ void ir_recv_thread(void *arg1, void *arg2, void *arg3) { - while (1) - { - k_sem_take(&adc_sem, K_FOREVER); - - while (read_idx != write_idx) - { - int16_t *buf = adc_buffers[read_idx]; - - for (int i = 0; i < SAMPLES_PER_BUFFER; i++) - { - /* De-interleave and process IR channels */ - process_ir_sample(&channels[0], buf[i * ADC_CHANNELS + 0]); - process_ir_sample(&channels[1], buf[i * ADC_CHANNELS + 1]); - process_ir_sample(&channels[2], buf[i * ADC_CHANNELS + 2]); - - /* Optional: Handle battery sample at buf[i * ADC_CHANNELS + 3] */ - } - - read_idx = (read_idx + 1) % BUFFER_COUNT; - } - } + while (1) + { + k_sem_take(&adc_sem, K_FOREVER); + while (read_idx != write_idx) + { + int16_t *buf = adc_buffers[read_idx]; + for (int i = 0; i < SAMPLES_PER_BUFFER; i++) + { + /* Now this call matches the static function name above */ + process_ir_sample(&channels[0], buf[i * ADC_CHANNELS + 0]); + process_ir_sample(&channels[1], buf[i * ADC_CHANNELS + 1]); + process_ir_sample(&channels[2], buf[i * ADC_CHANNELS + 2]); + } + read_idx = (read_idx + 1) % BUFFER_COUNT; + } + } } K_THREAD_DEFINE(ir_recv_tid, 2048, ir_recv_thread, NULL, NULL, NULL, 2, 0, 0);