From 555b0a6019d1acf1c4f3991159bc3e744a584513 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 20 Feb 2015 06:35:11 +0000 Subject: [PATCH] first pass at tuner UT, some building issues git-svn-id: https://svn.code.sf.net/p/freetel/code@2041 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/Makefile | 19 +++++++- codec2-dev/stm32/src/iir_tuner.c | 4 +- codec2-dev/stm32/src/stm32f4_adc_tuner.c | 10 ++--- codec2-dev/stm32/src/tuner_ut.c | 56 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 codec2-dev/stm32/src/tuner_ut.c diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index dd677e9c..70caba0d 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -30,7 +30,7 @@ endif 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.1.0 +PERIPHLIBVER = V1.4.0 PERIPHLIBNAME = STM32F4xx_DSP_StdPeriph_Lib PERIPHLIBDIR = $(PERIPHLIBNAME)_$(PERIPHLIBVER) CMSIS = $(PERIPHLIBDIR)/Libraries/CMSIS @@ -109,7 +109,7 @@ OBJS = $(SRCS:.c=.o) ################################################### -all: libstm32f4.a codec2_profile.elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf fdmdv_profile.elf sm1000_leds_switches_ut.elf sm1000.elf adcdac_ut.elf freedv_tx_profile.elf freedv_rx_profile.elf adc_sd.elf usb_vcp_ut.elf fdmdv_dump_rt.elf +all: libstm32f4.a codec2_profile.elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf fdmdv_profile.elf sm1000_leds_switches_ut.elf sm1000.elf adcdac_ut.elf freedv_tx_profile.elf freedv_rx_profile.elf adc_sd.elf usb_vcp_ut.elf fdmdv_dump_rt.elf tuner_ut.elf dl/$(PERIPHLIBZIP): mkdir -p dl @@ -350,6 +350,21 @@ FDMDV_DUMP_RT_SRCS += $(CODEC2_SRCS) fdmdv_dump_rt.elf: $(FDMDV_DUMP_RT_SRCS) src/stm32f4_dac.o src/stm32f4_adc.o $(CC) $(CFLAGS) -O3 $^ -o $@ $(LIBPATHS) $(LIBS) +TUNER_UT_SRCS=\ +src/tuner_ut.c \ +../src/fifo.c \ +src/stm32f4_dac.c \ +src/stm32f4_adc_tuner.c \ +src/sm1000_leds_switches.c \ +src/debugblinky.c \ +src/system_stm32f4xx.c \ +src/startup_stm32f4xx.s \ +src/init.c + +tuner_ut.elf: $(ADCDAC_UT_SRCS) + $(CC) $(CFLAGS) -O0 $^ -o $@ $(LIBPATHS) $(LIBS) + $(OBJCOPY) -O binary tuner_ut.elf tuner_ut.bin + clean: rm -f *.o rm -f *.elf diff --git a/codec2-dev/stm32/src/iir_tuner.c b/codec2-dev/stm32/src/iir_tuner.c index 7e6fe109..5e13bc53 100644 --- a/codec2-dev/stm32/src/iir_tuner.c +++ b/codec2-dev/stm32/src/iir_tuner.c @@ -4,7 +4,7 @@ AUTHOR......: David Rowe DATE CREATED: 20 Feb 2015 - Filter/decimator function, broken out to this filer so we can unit + Filter/decimator function, broken out to this file so we can unit test easily. Unit testing: @@ -72,7 +72,7 @@ void inline iir_tuner(float dec_buf[], unsigned short adc_buf[]) { } /* Equaliser FIR filter, notch at Fs/(4*ADC_TUNER_M) to smooth out - IIR BF passband response */ + IIR BPF passband response */ z = y + BETA2*z_2; dec_buf[j] = z; diff --git a/codec2-dev/stm32/src/stm32f4_adc_tuner.c b/codec2-dev/stm32/src/stm32f4_adc_tuner.c index ef7a46c0..ff5b71db 100644 --- a/codec2-dev/stm32/src/stm32f4_adc_tuner.c +++ b/codec2-dev/stm32/src/stm32f4_adc_tuner.c @@ -43,7 +43,6 @@ struct FIFO *adc1_fifo; unsigned short adc_buf[ADC_TUNER_BUF_SZ]; -float y_2, y_1; int adc_overflow1; int half,full; @@ -52,9 +51,6 @@ int half,full; #define DMA_STREAMx DMA2_Stream0 #define ADCx ADC1 -#define BETA1 0.999 -#define BETA2 0.955 - void adc_configure(); static void tim2_config(void); @@ -204,7 +200,7 @@ void adc_configure(){ */ void DMA2_Stream0_IRQHandler(void) { - short dec_buf[ADC_TUNER_N/2]; + float dec_buf[ADC_TUNER_N/2]; GPIOE->ODR = (1 << 0); @@ -217,7 +213,7 @@ void DMA2_Stream0_IRQHandler(void) { /* write first half to fifo */ - if (fifo_write(adc1_fifo, dec_buf, ADC_TUNER_N/2) == -1) { + if (fifo_write(adc1_fifo, (short)dec_buf, ADC_TUNER_N) == -1) { adc_overflow1++; } @@ -235,7 +231,7 @@ void DMA2_Stream0_IRQHandler(void) { /* write second half to fifo */ - if (fifo_write(adc1_fifo, dec_buf, ADC_TUNER_N/2) == -1) { + if (fifo_write(adc1_fifo, (short)dec_buf, ADC_TUNER_N) == -1) { adc_overflow1++; } diff --git a/codec2-dev/stm32/src/tuner_ut.c b/codec2-dev/stm32/src/tuner_ut.c new file mode 100644 index 00000000..07818da9 --- /dev/null +++ b/codec2-dev/stm32/src/tuner_ut.c @@ -0,0 +1,56 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: tuner_ut.c + AUTHOR......: David Rowe + DATE CREATED: 20 Feb 2015 + + Unit test for high speed ADC radio tuner. + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2015 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 . +*/ + +#include +#include "stm32f4_dac.h" +#include "stm32f4_adc_tuner.h" +#include "sm1000_leds_switches.h" + +int main(void) { + short buf[SINE_SAMPLES]; + int i; + + dac_open(4*DAC_BUF_SZ); + adc_open(4*ADC_TUNER_N; + sm1000_leds_switches_init(); + + while (1) { + + while(adc1_read(buf, ADC_TUNER_N) == -1); + + /* + if (switch_select()) { + for(i=0; i