From b0a523248766c1e001ea0f5d2e40c23b3178e629 Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 9 Mar 2020 14:18:09 +0100 Subject: Fix a bunch of compiler warnings --- controller/fw/src/dsss_demod.c | 30 +++++++++++++++++------------- controller/fw/src/dsss_demod.h | 4 ---- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'controller/fw/src') diff --git a/controller/fw/src/dsss_demod.c b/controller/fw/src/dsss_demod.c index a561436..97cc039 100644 --- a/controller/fw/src/dsss_demod.c +++ b/controller/fw/src/dsss_demod.c @@ -28,7 +28,7 @@ static float run_biquad(float x, const struct iir_biquad *const q, struct iir_bi static void matcher_init(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE]); static void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], uint64_t ts, int peak_ch, float peak_ampl); -static void group_received(struct dsss_demod_state *st, uint64_t ts); +static void group_received(struct dsss_demod_state *st); #ifdef SIMULATION void debug_print_vector(const char *name, size_t len, const float *data, size_t stride, bool index, bool debug) { @@ -38,7 +38,7 @@ void debug_print_vector(const char *name, size_t len, const float *data, size_t if (index) { DEBUG_PRINTN(" %16s [", ""); for (size_t i=0; imatcher_cache); } -#ifdef SIMULATION -void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts, int record_channel) { -#else -void dsss_demod_step(struct dsss_demod_state *st, float new_value) { -#endif - +void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts) { //const float hole_patching_threshold = 0.01 * DSSS_CORRELATION_LENGTH; st->signal[st->signal_wpos] = new_value; @@ -77,7 +72,7 @@ void dsss_demod_step(struct dsss_demod_state *st, float new_value) { for (size_t i=0; icorrelation[i], st->correlation_wpos); - float avg; + float avg = 0.0f; for (size_t i=0; igroup.len = 0; @@ -151,7 +146,7 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u /* TODO make these constants configurable from Makefile */ const float skip_sampling_depreciation = 0.2f; /* 0.0 -> no depreciation, 1.0 -> complete disregard */ const float score_depreciation = 0.1f; /* 0.0 -> no depreciation, 1.0 -> complete disregard */ - const uint64_t current_phase = ts % DSSS_CORRELATION_LENGTH; + const int current_phase = ts % DSSS_CORRELATION_LENGTH; const int max_skips = TRANSMISSION_SYMBOLS/4*3; for (size_t i=0; i states[i].candidate_score) { /* We win, update candidate */ + assert(i < DSSS_MATCHER_CACHE_SIZE); states[i].candidate_score = score; states[i].candidate_phase = current_phase; states[i].candidate_data = decode_peak(peak_ch, peak_ampl); @@ -177,6 +173,8 @@ void matcher_tick(struct matcher_state states[static DSSS_MATCHER_CACHE_SIZE], u */ if (abs(states[i].last_phase - current_phase) == group_phase_tolerance + DSSS_DECIMATION) { /* Process window results */ + assert(i < DSSS_MATCHER_CACHE_SIZE); + assert(0 <= states[i].data_pos && states[i].data_pos < TRANSMISSION_SYMBOLS); states[i].data[ states[i].data_pos ] = states[i].candidate_data; states[i].data_pos = states[i].data_pos + 1; states[i].last_score = score_depreciation * states[i].last_score + @@ -208,7 +206,7 @@ static float score_group(const struct group *g, int phase_delta) { return fabsf(g->max) * gaussian(1.0f, 0.0f, distance_func_phase_tolerance, phase_delta); } -void group_received(struct dsss_demod_state *st, uint64_t ts) { +void group_received(struct dsss_demod_state *st) { const int group_phase = st->group.max_ts % DSSS_CORRELATION_LENGTH; /* This is the score of a decoding starting at this group (with no context) */ float base_score = score_group(&st->group, 0); @@ -231,6 +229,8 @@ void group_received(struct dsss_demod_state *st, uint64_t ts) { float group_score = score_group(&st->group, phase_delta); if (st->matcher_cache[i].candidate_score < group_score) { + assert(i < DSSS_MATCHER_CACHE_SIZE); + /* Append to entry */ st->matcher_cache[i].candidate_score = group_score; st->matcher_cache[i].candidate_phase = group_phase; st->matcher_cache[i].candidate_data = decode_peak(st->group.max_ch, st->group.max); @@ -248,6 +248,8 @@ void group_received(struct dsss_demod_state *st, uint64_t ts) { /* If we found empty entries, replace one by a new decoding starting at this group */ if (empty_idx >= 0) { + DEBUG_PRINT("Writing to %zd", empty_idx); + assert(0 <= empty_idx && empty_idx < DSSS_MATCHER_CACHE_SIZE); st->matcher_cache[empty_idx].last_phase = group_phase; st->matcher_cache[empty_idx].candidate_score = base_score; st->matcher_cache[empty_idx].last_score = base_score; @@ -259,6 +261,8 @@ void group_received(struct dsss_demod_state *st, uint64_t ts) { /* If the weakest decoding in cache is weaker than a new decoding starting here, replace it */ } else if (min_score < base_score && min_idx >= 0) { + DEBUG_PRINT("Writing to %zd", min_idx); + assert(0 <= min_idx && min_idx < DSSS_MATCHER_CACHE_SIZE); st->matcher_cache[min_idx].last_phase = group_phase; st->matcher_cache[min_idx].candidate_score = base_score; st->matcher_cache[min_idx].last_score = base_score; @@ -309,7 +313,7 @@ float gold_correlate_step(const size_t ncode, const float a[DSSS_CORRELATION_LEN float acc_outer = 0.0f; uint8_t table_byte = 0; - if (debug) DEBUG_PRINTN("Correlate n=%d: ", ncode); + if (debug) DEBUG_PRINTN("Correlate n=%zd: ", ncode); for (size_t i=0; i