sm2000 set to work test program, in teh middle of modifiying for DAC play
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 18 Jun 2016 00:18:13 +0000 (00:18 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Sat, 18 Jun 2016 00:18:13 +0000 (00:18 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2828 01035d8c-6547-0410-b346-abe4f91aad63

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

index 5a8dd7ed122ef90a46f2f3b095e15af63c9aba7a..90bd63b2b5cb7aa0409b10935f21b8ecfd1d5551 100644 (file)
@@ -436,7 +436,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
+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
 
 # Rule for making directories automatically.
 # Note we don't use -p as it's a GNU extension.
@@ -821,6 +821,41 @@ si5351_ut.elf: $(SI5351_UT_SRCS:.c=.o) libstm32f4.a
 
 # ---------------------------------------------------------------------------------
 
+MCO_UT_SRCS=\
+src/mco_ut.c \
+src/tm_stm32f4_mco_output.c \
+src/tm_stm32f4_gpio.c \
+src/system_stm32f4xx.c \
+src/startup_stm32f4xx.s \
+src/init.c \
+
+mco_ut.elf: $(MCO_UT_SRCS:.c=.o) libstm32f4.a
+       $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
+
+# ---------------------------------------------------------------------------------
+
+# ---------------------------------------------------------------------------------
+
+SM2000_STW_SRCS=\
+src/sm2000_stw.c \
+src/sm1000_leds_switches.c \
+src/debugblinky.c \
+src/new_i2c.c \
+src/si53xx.c \
+src/stm32f4_dac.c \
+../src/fifo.c \
+src/stm32f4_usb_vcp.c \
+src/system_stm32f4xx.c \
+src/startup_stm32f4xx.s \
+src/init.c \
+
+SM2000_STW_SRCS+=$(USB_VCP)
+
+sm2000_stw.elf: $(SM2000_STW_SRCS:.c=.o) libstm32f4.a
+       $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS)
+
+# ---------------------------------------------------------------------------------
+
 # Objects that require the peripheral library
 src/sm1000_main.o: $(PERIPHLIBDIR)/.unpack
 src/codec2_profile.o: $(PERIPHLIBDIR)/.unpack
diff --git a/codec2-dev/stm32/src/sm2000_stw.c b/codec2-dev/stm32/src/sm2000_stw.c
new file mode 100644 (file)
index 0000000..df74e80
--- /dev/null
@@ -0,0 +1,105 @@
+/*---------------------------------------------------------------------------*\
+
+  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 "new_i2c.h"
+#include "si53xx.h"
+#include "debugblinky.h"
+#include "sm1000_leds_switches.h"
+#include "stm32f4_dac.h"
+#include "stm32f4_usb_vcp.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];
+
+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;
+
+    sm1000_leds_switches_init();
+    led_pwr(1);
+    led_ptt(0);
+
+    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, 4*DAC_BUF_SZ);
+
+    usb_vcp_init();
+
+    while(1) {
+        ptt = 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);
+        }
+                
+    }
+}