Started work on sm2000 freedv rx demo
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 30 Jun 2016 04:57:25 +0000 (04:57 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 30 Jun 2016 04:57:25 +0000 (04:57 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2835 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/Makefile
codec2-dev/stm32/src/sm2000_adc_dump.c
codec2-dev/stm32/src/sm2000_rxdemo.c [new file with mode: 0644]
codec2-dev/stm32/src/sm2000_stw.c

index 1514914ebbd56b86eb14614b917736e72c8d3e5f..a611a48f12ca4e3d6cd8f4657407c834e5d0df54 100644 (file)
@@ -441,7 +441,7 @@ SRCS += src/startup_stm32f4xx.s src/init.c
 
 OBJS = $(SRCS:.c=.o)
 
-all: libstm32f4.a codec2_profile.bin fft_test.bin dac_ut.bin dac_play.bin adc_rec.bin pwm_ut.bin fdmdv_profile.bin sm1000_leds_switches_ut.bin sm1000.bin adcdac_ut.bin freedv_tx_profile.bin freedv_rx_profile.bin adc_sd.bin usb_vcp_ut.bin tuner_ut.bin fast_dac_ut.bin adc_sfdr_ut.bin adc_rec_usb.bin si5351_ut.bin mco_ut.bin sm2000_stw.bin
+all: libstm32f4.a codec2_profile.bin fft_test.bin dac_ut.bin dac_play.bin adc_rec.bin pwm_ut.bin fdmdv_profile.bin sm1000_leds_switches_ut.bin sm1000.bin adcdac_ut.bin freedv_tx_profile.bin freedv_rx_profile.bin adc_sd.bin usb_vcp_ut.bin tuner_ut.bin fast_dac_ut.bin adc_sfdr_ut.bin adc_rec_usb.bin si5351_ut.bin mco_ut.bin sm2000_stw.bin sm2000_adcdump.bin
 
 # Rule for making directories automatically.
 # Note we don't use -p as it's a GNU extension.
@@ -841,6 +841,26 @@ mco_ut.elf: $(MCO_UT_SRCS:.c=.o) libstm32f4.a
 
 # ---------------------------------------------------------------------------------
 
+SM2000_RXDEMO_SRCS=\
+src/sm2000_rxdemo.c \
+src/sm1000_leds_switches.c \
+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_RXDEMO_SRCS+=$(CODEC2_SRCS)
+
+sm2000_rxdemo.elf: $(SM2000_RXDEMO_SRCS:.c=.O3.o) libstm32f4.a
+       $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
+
+# ---------------------------------------------------------------------------------
+
 SM2000_STW_SRCS=\
 src/sm2000_stw.c \
 src/sm1000_leds_switches.c \
index f08fb9ca6eb54103c490fb6eb71f2beb2bde9bfb..87472f70ca539a4a1e09663e6cf92dcfa8623041 100644 (file)
@@ -67,8 +67,9 @@ 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);
-
+    //dac_open(DAC_FS_96KHZ, 4*DAC_BUF_SZ);
+    adc_open(ADC_FS_96KHZ, 10*ADC_BUF_SZ);
+    
     usb_vcp_init();
 
     while(1) {
@@ -88,18 +89,23 @@ int main(void) {
         /* and assumes enough bytes are available, need to test that
            host is throttled appropriately */
 
-        int n = dac1_free();
+        int n = adc1_samps();
         if (n) {
             uint16_t  s, buf[n];
             uint8_t   b;
+            adc1_read(buf,n);
             for(i=0; i<n; i++) {
+                               b = (uint8_t)(buf[i]&0xFF);
+                               VCP_put_char(b);
+                               b = (uint8_t)((buf[i]>>8)&0xFF);
+                               VCP_put_char(b);
                 //VCP_get_char(&b);
-                s = b << 8;
+                //s = b << 8;
                 //VCP_get_char(&b);
-                s += b;
-                buf[i] = s;
+                //s += b;
+                //buf[i] = s;
             }
-            dac1_write((short*)buf, n);
+            //dac1_write((short*)buf, n);
         }
                 
     }
diff --git a/codec2-dev/stm32/src/sm2000_rxdemo.c b/codec2-dev/stm32/src/sm2000_rxdemo.c
new file mode 100644 (file)
index 0000000..868a513
--- /dev/null
@@ -0,0 +1,170 @@
+/*---------------------------------------------------------------------------*\
+
+  FILE........: sm2000_stw.c
+  AUTHOR......: David Rowe
+  DATE CREATED: June 2016
+
+  Test program to support SM2000 "set to work" - tetsing and bring up.
+
+\*---------------------------------------------------------------------------*/
+
+/*
+  Copyright (C) 2016 David Rowe
+
+  All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License version 2.1, as
+  published by the Free Software Foundation.  This program is
+  distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#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_adc.h"
+//#include "stm32f4_usb_vcp.h"
+#include "fsk.h"
+#include "freedv_vhf_framing.h"
+#include "golay23.h"
+#include "string.h"
+#define SINE_SAMPLES   24
+
+/* 32 sample sine wave which at Fs=16kHz will be 500Hz.  Note samples
+   are 16 bit 2's complement, the DAC driver convertsto 12 bit
+   unsigned. */
+
+short aSine[] = {
+     5000,  -2500,  -2500, 5000,  -2500,  -2500, 
+     5000,  -2500,  -2500, 5000,  -2500,  -2500, 
+     5000,  -2500,  -2500, 5000,  -2500,  -2500, 
+     5000,  -2500,  -2500, 5000,  -2500,  -2500
+};
+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;
+    struct FSK * fsk;
+    struct freedv_vhf_deframer * deframer;
+    char chbuf[100];
+    float * mod_buf;
+    
+    sm1000_leds_switches_init();
+    led_pwr(1);
+    
+    fsk = fsk_create_hbr(96000,1200,10,4,32000-1800,1200);
+    fsk_set_est_limits(fsk,29000,35000);
+    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);
+
+    I2C_Setup();
+    si5351_init(0, SI5351_CRYSTAL_LOAD_6PF, 0);
+    freq_in_Hz_times_100 = 1070000000ULL - 3200000ULL;
+    ret = si5351_set_freq(freq_in_Hz_times_100, 0, SI5351_CLK0);
+
+    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) {
+               if(switch_ptt() && (!spstate)){
+                       ptt = ptt ? 0 : 1;
+                       mbptr = 0;
+               }
+               spstate = switch_ptt();
+               
+        led_ptt(ptt);
+        txrx_12V(ptt);
+        
+        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 8a39dc3fd465e93f8e1f386077df6f38bdc80b42..868a513e5bcfd028fa911f3320ac358fde2b98ae 100644 (file)
@@ -37,7 +37,7 @@
 #include "fsk.h"
 #include "freedv_vhf_framing.h"
 #include "golay23.h"
-
+#include "string.h"
 #define SINE_SAMPLES   24
 
 /* 32 sample sine wave which at Fs=16kHz will be 500Hz.  Note samples
@@ -64,18 +64,20 @@ uint8_t bit_buf[] = { 1,0,1,1,0,0,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;
     struct FSK * fsk;
     struct freedv_vhf_deframer * deframer;
-    
+    char chbuf[100];
     float * mod_buf;
     
     sm1000_leds_switches_init();
     led_pwr(1);
     
     fsk = fsk_create_hbr(96000,1200,10,4,32000-1800,1200);
+    fsk_set_est_limits(fsk,29000,35000);
     deframer = fvhff_create_deframer(FREEDV_VHF_FRAME_A,1);
     if(fsk==NULL){
                led_err(1);
@@ -160,6 +162,7 @@ int main(void) {
                                                led_ptt(0);
                                        }
                                        nin = fsk_nin(fsk);
+                                       
                                }
                        }
                }