From 4e2620709551604121fe860742266de5890937fe Mon Sep 17 00:00:00 2001 From: drowe67 Date: Mon, 30 Apr 2018 22:53:48 +0000 Subject: [PATCH] operator control of sync state machine git-svn-id: https://svn.code.sf.net/p/freetel/code@3541 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/src/codec2_ofdm.h | 4 +++ codec2-dev/src/freedv_api.c | 27 ++++++++++++++++++++ codec2-dev/src/freedv_api.h | 7 ++++++ codec2-dev/src/ofdm.c | 46 +++++++++++++++++++++++++++++++++- codec2-dev/src/ofdm_internal.h | 1 + 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/codec2-dev/src/codec2_ofdm.h b/codec2-dev/src/codec2_ofdm.h index 47c80051..0d96aaff 100644 --- a/codec2-dev/src/codec2_ofdm.h +++ b/codec2-dev/src/codec2_ofdm.h @@ -43,6 +43,9 @@ extern "C" { #define OFDM_AMP_SCALE (2E5*1.1491/1.06) /* use to scale to 16 bit short */ #define OFDM_CLIP (32767*0.35) /* experimentally derived constant to reduce PAPR to about 8dB */ +#define OFDM_SYNC_UNSYNC 0 /* force sync state machine to lose sync, and search for new sync */ +#define OFDM_SYNC_AUTO 1 /* falls out of sync automatically */ +#define OFDM_SYNC_MANUAL 2 /* fall out of sync only under operator control */ struct OFDM; @@ -75,6 +78,7 @@ void ofdm_set_timing_enable(struct OFDM *, bool); void ofdm_set_foff_est_enable(struct OFDM *, bool); void ofdm_set_phase_est_enable(struct OFDM *, bool); void ofdm_set_off_est_hz(struct OFDM *, float); +void ofdm_set_sync(struct OFDM *ofdm, int sync_cmd); #ifdef __cplusplus } diff --git a/codec2-dev/src/freedv_api.c b/codec2-dev/src/freedv_api.c index 15798f73..882e032a 100644 --- a/codec2-dev/src/freedv_api.c +++ b/codec2-dev/src/freedv_api.c @@ -2159,6 +2159,33 @@ int freedv_set_alt_modem_samp_rate(struct freedv *f, int samp_rate){ return -1; } + +/*---------------------------------------------------------------------------* \ + + FUNCTIONS...: freedv_set_sync + AUTHOR......: David Rowe + DATE CREATED: May 2018 + + Extended control of sync state machines, especially for FreeDV 700D. + This mode is required to acquire sync up at very low SNRS. This is + difficult to implement, for example we may get a false sync, or the + state machine may fall out of sync by mistake during a long fade. + + So with this API call we allow some operator assistance. + + Ensure this is called inthe same thread as freedv_rx(). + +\*---------------------------------------------------------------------------*/ + +void freedv_set_sync(struct freedv *freedv, int sync_cmd) { + assert (freedv != NULL); + + if (freedv->mode != FREEDV_MODE_700D) { + ofdm_set_sync(freedv->ofdm, sync_cmd); + } + +} + struct FSK * freedv_get_fsk(struct freedv *f){ return f->fsk; } diff --git a/codec2-dev/src/freedv_api.h b/codec2-dev/src/freedv_api.h index e08f88cf..b3e75267 100644 --- a/codec2-dev/src/freedv_api.h +++ b/codec2-dev/src/freedv_api.h @@ -47,6 +47,12 @@ #define FREEDV_MODE_700C 6 #define FREEDV_MODE_700D 7 +/* operator control of 700D state machine */ + +#define FREEDV_SYNC_UNSYNC 0 /* force sync state machine to lose sync, and search for new sync */ +#define FREEDV_SYNC_AUTO 1 /* falls out of sync automatically */ +#define FREEDV_SYNC_MANUAL 2 /* fall out of sync only under operator control */ + struct freedv; /* advanced freedv open options rqd by some modes */ @@ -121,6 +127,7 @@ void freedv_set_varicode_code_num (struct freedv *freedv, int val); void freedv_set_data_header (struct freedv *freedv, unsigned char *header); int freedv_set_alt_modem_samp_rate (struct freedv *freedv, int samp_rate); void freedv_set_carrier_ampl (struct freedv *freedv, int c, float ampl); +void freedv_set_sync (struct freedv *freedv, int sync_cmd); // Get parameters ------------------------------------------------------------------------- diff --git a/codec2-dev/src/ofdm.c b/codec2-dev/src/ofdm.c index c13ea1db..7877aace 100644 --- a/codec2-dev/src/ofdm.c +++ b/codec2-dev/src/ofdm.c @@ -397,6 +397,7 @@ struct OFDM *ofdm_create(const struct OFDM_CONFIG *config) { ofdm->frame_count = 0; ofdm->sync_start = 0; ofdm->sync_end = 0; + ofdm->sync_mode = OFDM_SYNC_AUTO; strcpy(ofdm->sync_state_interleaver,"search"); strcpy(ofdm->last_sync_state_interleaver,"search"); @@ -1079,7 +1080,7 @@ void ofdm_sync_state_machine(struct OFDM *ofdm, int *rx_uw) { ofdm->sync_counter = 0; } - if (ofdm->sync_counter == 6) { + if ((ofdm->sync_mode == OFDM_SYNC_AUTO) && (ofdm->sync_counter == 6)) { /* run of consective bad frames ... drop sync */ strcpy(next_state, "search"); strcpy(ofdm->sync_state_interleaver, "search"); @@ -1092,3 +1093,46 @@ void ofdm_sync_state_machine(struct OFDM *ofdm, int *rx_uw) { strcpy(ofdm->sync_state, next_state); } + +/*---------------------------------------------------------------------------* \ + + FUNCTIONS...: ofdm_set_sync + AUTHOR......: David Rowe + DATE CREATED: May 2018 + + Operator control of sync state machine. This mode is required to + acquire sync up at very low SNRS. This is difficult to implement, + for example we may get a false sync, or the state machine may fall + out of sync by mistake during a long fade. + + So with this API call we allow some operator assistance. + + Ensure this is called in the same thread as ofdm_sync_state_machine(). + +\*---------------------------------------------------------------------------*/ + +void ofdm_set_sync(struct OFDM *ofdm, int sync_cmd) { + assert (ofdm != NULL); + + switch(sync_cmd) { + case OFDM_SYNC_UNSYNC: + /* force manual unsync, in case operator detects false sync, + which will cuase sync state machine to have another go at + sync */ + strcpy(ofdm->sync_state, "search"); + strcpy(ofdm->sync_state_interleaver, "search"); + break; + case OFDM_SYNC_AUTO: + /* normal operating mode - sync state machine decides when to unsync */ + ofdm->sync_mode = OFDM_SYNC_AUTO; + break; + case OFDM_SYNC_MANUAL: + /* allow sync state machine to sync, but not to unsync, the + operator will decide that manually */ + ofdm->sync_mode = OFDM_SYNC_MANUAL; + break; + default: + assert(0); + } +} + diff --git a/codec2-dev/src/ofdm_internal.h b/codec2-dev/src/ofdm_internal.h index 5916e084..32cb240e 100644 --- a/codec2-dev/src/ofdm_internal.h +++ b/codec2-dev/src/ofdm_internal.h @@ -138,6 +138,7 @@ struct OFDM { int frame_count; int sync_start; int sync_end; + int sync_mode; /* interleaver sync state machine */ -- 2.25.1