From 91facbf6999542d0cbe7c06337d77d2194a5e90a Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Tue, 28 May 2024 19:55:21 +0200 Subject: [PATCH] rx: reset internal state when restarting after a transmission --- impl/src/layer1/correlator.c | 9 +++++++++ impl/src/layer1/correlator.h | 10 ++++++++++ impl/src/layer1/rx.c | 18 ++++++++++++++++++ impl/src/layer1/rx.h | 18 +++++++++++++++++- impl/src/main.c | 1 + 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/impl/src/layer1/correlator.c b/impl/src/layer1/correlator.c index f1c5426..1340313 100644 --- a/impl/src/layer1/correlator.c +++ b/impl/src/layer1/correlator.c @@ -76,6 +76,15 @@ void correlator_free(correlator_ctx_t *ctx) ctx->search_sequence_len = 0; } +void correlator_reset(correlator_ctx_t *ctx) +{ + // Clear the history buffer + memset(ctx->input_history, 0, ctx->buffer_size * sizeof(ctx->input_history[0])); + + // start writing from the beginning + ctx->history_ptr = 0; +} + float complex correlator_step(correlator_ctx_t *ctx, float complex sample) { diff --git a/impl/src/layer1/correlator.h b/impl/src/layer1/correlator.h index ef38293..65144d1 100644 --- a/impl/src/layer1/correlator.h +++ b/impl/src/layer1/correlator.h @@ -67,6 +67,16 @@ bool correlator_init(correlator_ctx_t *ctx, const float complex *search_seq, siz */ void correlator_free(correlator_ctx_t *ctx); +/*! + * \brief Reset a correlator. + * + * \details + * Erases all data in the history buffer and starts writing from the beginning. + * + * \param ctx The correlator context to reset. + */ +void correlator_reset(correlator_ctx_t *ctx); + /*! * \brief Process one sample in the correlator. * diff --git a/impl/src/layer1/rx.c b/impl/src/layer1/rx.c index 43e09db..1b0e843 100644 --- a/impl/src/layer1/rx.c +++ b/impl/src/layer1/rx.c @@ -600,6 +600,24 @@ result_t layer1_rx_shutdown(layer1_rx_t *rx) } +result_t layer1_rx_reset(layer1_rx_t *rx) +{ + // reset the state machine + rx->state = RX_STATE_ACQUISITION; + + // reset the correlator (to avoid spurious preamble detection) + correlator_reset(&rx->preamble_correlator); + + // reset symbol synchronizer + symsync_crcf_reset(rx->symsync); + + // drop partial debug info + reset_packet_debug_info(rx); + + return OK; +} + + bool layer1_rx_is_busy(const layer1_rx_t *rx) { return is_squelch_open(rx); diff --git a/impl/src/layer1/rx.h b/impl/src/layer1/rx.h index 6564592..7b315b6 100644 --- a/impl/src/layer1/rx.h +++ b/impl/src/layer1/rx.h @@ -114,7 +114,7 @@ result_t layer1_rx_shutdown(layer1_rx_t *rx); * \param rx Pointer to the receiver context. * \param samples Pointer to the samples to process. * \param sample_count Number of samples to process. - * \returns The result of the shutdown. + * \returns The result of the sample processing. */ result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t sample_count); @@ -142,4 +142,20 @@ bool layer1_rx_is_busy(const layer1_rx_t *rx); */ float layer1_rx_get_coarse_carrier_frequency(const layer1_rx_t *rx); + +/*! + * \brief Reset the receiver. + * + * This ensures that the receiver can lock on to newly received packets in a + * defined way. The following submodules are reset: + * + * - Correlator + * - RX state machine + * - Symbol synchronization + * + * \param rx Pointer to the receiver context. + * \returns The result of the reset. + */ +result_t layer1_rx_reset(layer1_rx_t *rx); + #endif // LAYER1_RX_H diff --git a/impl/src/main.c b/impl/src/main.c index 0eb265f..4a86f71 100644 --- a/impl/src/main.c +++ b/impl/src/main.c @@ -317,6 +317,7 @@ int main(int argc, char **argv) } else if(on_air) { // ret == 0 fprintf(stderr, "TX -> RX\n"); RESULT_CHECK(sdr_flush_tx_buffer(&sdr)); + RESULT_CHECK(layer1_rx_reset(&rx)); RESULT_CHECK(sdr_stop_tx(&sdr)); RESULT_CHECK(sdr_start_rx(&sdr));