Added fsk mod/demod to sm2000_stw tests;
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 23 Jun 2016 01:22:41 +0000 (01:22 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 23 Jun 2016 01:22:41 +0000 (01:22 +0000)
added fifo peek functionality to stm32f4_adc

git-svn-id: https://svn.code.sf.net/p/freetel/code@2829 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/Makefile
codec2-dev/stm32/inc/stm32f4_adc.h
codec2-dev/stm32/src/adcdac_ut.c
codec2-dev/stm32/src/sm2000_stw.c
codec2-dev/stm32/src/stm32f4_adc.c

index 90bd63b2b5cb7aa0409b10935f21b8ecfd1d5551..1514914ebbd56b86eb14614b917736e72c8d3e5f 100644 (file)
@@ -32,9 +32,9 @@ endif
 
 # Definitions for the STM32F4 Standard Peripheral Library
 
-PERIPHLIBURL    = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/
+PERIPHLIBURL    = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware
 PERIPHLIBZIP    = stm32f4_dsp_stdperiph_lib.zip
-PERIPHLIBVER   = V1.6.1
+PERIPHLIBVER   = V1.7.1
 PERIPHLIBNAME  = STM32F4xx_DSP_StdPeriph_Lib
 PERIPHLIBDIR   = $(PERIPHLIBNAME)
 CMSIS          = $(PERIPHLIBDIR)/Libraries/CMSIS
@@ -382,6 +382,7 @@ $(CODEC2_SRC)/postfilter.c \
 $(CODEC2_SRC)/sine.c \
 $(CODEC2_SRC)/codec2.c \
 $(CODEC2_SRC)/kiss_fft.c \
+$(CODEC2_SRC)/kiss_fftr.c \
 $(CODEC2_SRC)/interp.c \
 $(CODEC2_SRC)/lsp.c \
 $(CODEC2_SRC)/phase.c \
@@ -395,7 +396,11 @@ $(CODEC2_SRC)/dump.c \
 $(CODEC2_SRC)/fdmdv.c \
 $(CODEC2_SRC)/freedv_api.c \
 $(CODEC2_SRC)/varicode.c \
-$(CODEC2_SRC)/golay23.c
+$(CODEC2_SRC)/golay23.c \
+$(CODEC2_SRC)/fsk.c \
+$(CODEC2_SRC)/fmfsk.c \
+$(CODEC2_SRC)/freedv_vhf_framing.c \
+$(CODEC2_SRC)/freedv_data_channel.c
 
 CFLAGS += -D__EMBEDDED__
 
@@ -843,15 +848,40 @@ src/debugblinky.c \
 src/new_i2c.c \
 src/si53xx.c \
 src/stm32f4_dac.c \
+src/stm32f4_adc.c \
 ../src/fifo.c \
+src/system_stm32f4xx.c \
+src/startup_stm32f4xx.s \
+src/init.c 
+
+SM2000_STW_SRCS+=$(CODEC2_SRCS)
+
+#SM2000_STW_SRCS+=$(USB_VCP)
+
+sm2000_stw.elf: $(SM2000_STW_SRCS:.c=.O3.o) libstm32f4.a
+       $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
+
+# ---------------------------------------------------------------------------------
+
+SM2000_ADCDUMP_SRCS=\
+src/sm2000_adc_dump.c \
+src/sm1000_leds_switches.c \
+src/debugblinky.c \
+src/new_i2c.c \
+src/si53xx.c \
+src/stm32f4_dac.c \
 src/stm32f4_usb_vcp.c \
+src/stm32f4_adc.c \
+../src/fifo.c \
 src/system_stm32f4xx.c \
 src/startup_stm32f4xx.s \
-src/init.c \
+src/init.c 
+
+SM2000_ADCDUMP_SRCS_SRCS+=$(CODEC2_SRCS)
 
-SM2000_STW_SRCS+=$(USB_VCP)
+SM2000_ADCDUMP_SRCS+=$(USB_VCP)
 
-sm2000_stw.elf: $(SM2000_STW_SRCS:.c=.o) libstm32f4.a
+sm2000_adcdump.elf: $(SM2000_ADCDUMP_SRCS:.c=.O3.o) libstm32f4.a
        $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
 
 # ---------------------------------------------------------------------------------
index c04d22a072e3d27090b8c01ffafa68dbe546cfc3..f1e403e42c6847ff460adc611c768c9eda9a4475 100644 (file)
@@ -38,5 +38,7 @@
 void adc_open(int fs_divisor, int fifo_sz);
 int adc1_read(short buf[], int n); /* ADC1 Pin PA1 */
 int adc2_read(short buf[], int n); /* ADC2 Pin PA2 */
+int adc1_samps();
+int adc2_samps();
 
 #endif
index 3aeaf0282622c99684051d78df356dc507710463..d83087de12781d0fbb1b828b951d72912b28c959 100644 (file)
@@ -48,7 +48,7 @@ int main(void) {
     short buf[SINE_SAMPLES];
     int   i;
 
-    dac_open(4*DAC_BUF_SZ);
+    dac_open(ADC_FS_16KHZ,4*DAC_BUF_SZ);
     adc_open(ADC_FS_16KHZ, 4*ADC_BUF_SZ);
     sm1000_leds_switches_init();
 
index df74e8078189bd8ae0c92fb4d5117af17d71d7a4..8a39dc3fd465e93f8e1f386077df6f38bdc80b42 100644 (file)
 */
 
 #include <assert.h>
+#include <stdint.h>
 #include "new_i2c.h"
 #include "si53xx.h"
 #include "debugblinky.h"
 #include "sm1000_leds_switches.h"
 #include "stm32f4_dac.h"
-#include "stm32f4_usb_vcp.h"
+#include "stm32f4_adc.h"
+//#include "stm32f4_usb_vcp.h"
+#include "fsk.h"
+#include "freedv_vhf_framing.h"
+#include "golay23.h"
 
 #define SINE_SAMPLES   24
 
@@ -47,17 +52,36 @@ short aSine[] = {
 };
 short zeros[SINE_SAMPLES];
 
+uint8_t bit_buf[] = { 1,0,1,1,0,0,0,1,
+                  1,0,1,1,0,1,0,1,
+                  0,1,0,0,1,0,1,1,
+                  1,0,0,0,0,0,0,1,
+                  1,1,0,0,0,0,0,1,
+                  1,0,1,0,0,0,0,1,
+                  1,0,0,1,0,0,0,1,
+                  1,0,0,0,1,0,0,1,
+                  1,0,0,0,0,1,0,1,
+                  1,0,0,0,0,0,1,1,
+                  1,0,0,0,0,0,1,1,
+                  1,0,0,0,0,0,1,1, };
 int main(void) {
     int ret, ptt, i;
     uint64_t freq_in_Hz_times_100;
-
-    for(i=0; i<SINE_SAMPLES; i++)
-        aSine[i] *= 1.5;
-
+    struct FSK * fsk;
+    struct freedv_vhf_deframer * deframer;
+    
+    float * mod_buf;
+    
     sm1000_leds_switches_init();
     led_pwr(1);
-    led_ptt(0);
-
+    
+    fsk = fsk_create_hbr(96000,1200,10,4,32000-1800,1200);
+    deframer = fvhff_create_deframer(FREEDV_VHF_FRAME_A,1);
+    if(fsk==NULL){
+               led_err(1);
+               while(1);
+       }
+    mod_buf = malloc(sizeof(float)*fsk->Nmem);
     init_debug_blinky();
     txrx_12V(0);
 
@@ -66,40 +90,78 @@ int main(void) {
     freq_in_Hz_times_100 = 1070000000ULL - 3200000ULL;
     ret = si5351_set_freq(freq_in_Hz_times_100, 0, SI5351_CLK0);
 
-    dac_open(DAC_FS_96KHZ, 4*DAC_BUF_SZ);
-
-    usb_vcp_init();
-
+    dac_open(DAC_FS_96KHZ, 2000);
+    adc_open(ADC_FS_96KHZ, 2000);
+
+    //usb_vcp_init();
+    int mbptr = 0;
+       int golay_ctr = 0;
+       uint8_t c2_buffer[8];
+       int k;
+       int spstate;
+       ptt = 1;
+       int nin = fsk_nin(fsk);
+       spstate = 0;
     while(1) {
-        ptt = switch_ptt();
+               if(switch_ptt() && (!spstate)){
+                       ptt = ptt ? 0 : 1;
+                       mbptr = 0;
+               }
+               spstate = switch_ptt();
+               
         led_ptt(ptt);
         txrx_12V(ptt);
-
-        /*
-        if (ptt)
-            dac1_write((short*)aSine, SINE_SAMPLES);
-        else
-            dac1_write((short*)zeros, SINE_SAMPLES);
-        */
-
-        /* read another buffer from USB when DAC empties */
-        /* note assumes USB host write two bytes at a time */
-        /* and assumes enough bytes are available, need to test that
-           host is throttled appropriately */
-
-        int n = dac1_free();
-        if (n) {
-            uint16_t  s, buf[n];
-            uint8_t   b;
-            for(i=0; i<n; i++) {
-                //VCP_get_char(&b);
-                s = b << 8;
-                //VCP_get_char(&b);
-                s += b;
-                buf[i] = s;
-            }
-            dac1_write((short*)buf, n);
-        }
-                
+        
+        if(ptt){
+                       int n = dac1_free();
+                       if (n) {
+                               int16_t  buf[n];
+                               for(i=0; i<n && mbptr<fsk->N; i++,mbptr++) {
+                                       buf[i] = (short)(mod_buf[mbptr]*700);
+                               }
+                               dac1_write((short*)buf, i);
+                       }
+                       if(mbptr>=fsk->N){
+                               /* Encode frame index into golay codeword to protect from test BER*/
+                               k = golay23_encode((golay_ctr)&0x0FFF);
+                               c2_buffer[5] = (k    )&0xFF;
+                               c2_buffer[1] = (k>>8 )&0xFF;
+                               c2_buffer[0] = (k>>16)&0x7F;
+                               /* Frame the bits */
+                               fvhff_frame_bits(FREEDV_VHF_FRAME_A, bit_buf, c2_buffer,NULL,NULL);
+                               /* Mod the FSK */
+                               fsk_mod(fsk,mod_buf,bit_buf);
+                               mbptr = 0;
+                               golay_ctr++;
+                       }
+               }else{
+                       
+                       int n = adc1_samps();
+                       if (n) {
+                               int16_t buf[n];
+                               adc1_read(buf,n);
+                               for(i=0; i<n && mbptr<nin; i++,mbptr++){
+                                       mod_buf[mbptr] = ((float)buf[i]);
+                               }
+                               if(mbptr>=nin){
+                                       led_rt(1);
+                                       fsk_demod(fsk,bit_buf,mod_buf);
+                                       led_rt(0);
+                                       if(fvhff_deframe_bits(deframer,c2_buffer,NULL,NULL,bit_buf)){
+                                               led_err(1);             
+                                       }else{
+                                               //led_err(0);
+                                               led_err(0);
+                                       }
+                                       mbptr = 0;
+                                       if(fsk_nin(fsk)!=nin){
+                                               led_ptt(1);
+                                       }else{
+                                               led_ptt(0);
+                                       }
+                                       nin = fsk_nin(fsk);
+                               }
+                       }
+               }
     }
 }
index 7ebd114007f9018a154504b84371473647101115..d1da87b78e5b45bcf0c0c40a1db349105068c019 100644 (file)
@@ -76,6 +76,15 @@ int adc2_read(short buf[], int n) {
     return fifo_read(adc2_fifo, buf, n);
 }
 
+/* Returns number of signed 16 bit samples in the FIFO currently */
+int adc1_samps(){
+       return fifo_used(adc1_fifo);
+}
+
+/* Returns number of signed 16 bit samples in the FIFO currently */
+int adc2_samps(){
+       return fifo_used(adc2_fifo);
+}
 
 static void tim2_config(int fs_divisor)
 {