operator control of sync state machine
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 30 Apr 2018 22:53:48 +0000 (22:53 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 30 Apr 2018 22:53:48 +0000 (22:53 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@3541 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/codec2_ofdm.h
codec2-dev/src/freedv_api.c
codec2-dev/src/freedv_api.h
codec2-dev/src/ofdm.c
codec2-dev/src/ofdm_internal.h

index 47c80051d5f1e9372e08b573a39120a19ca2674c..0d96aaff435ccadfa8bcfab3153ffd15025d9332 100644 (file)
@@ -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
 }
index 15798f734045f66c34647aa8e5b40ce7097a7f83..882e032a60e409322d735547419b286016ef9327 100644 (file)
@@ -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;
 }
index e08f88cf9ce9f66fb00b4f781b8a1cc40c8b315a..b3e7526768ddf9a340c8763e16497d578d9ae2c8 100644 (file)
 #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 -------------------------------------------------------------------------
 
index c13ea1dbad29a94325dadef91ac81213db7c2428..7877aace636ea8947ad60dc7fa4d5c0857cd0153 100644 (file)
@@ -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);
+    }            
+}
+
index 5916e0845bff876e7e7841370b29fb3f0a037b92..32cb240e731317876bc70b681ad6075d23e0214c 100644 (file)
@@ -138,6 +138,7 @@ struct OFDM {
     int frame_count;
     int sync_start;
     int sync_end;
+    int sync_mode;
     
     /* interleaver sync state machine */