From f949ae529541afa03853566352d70a56ab45fd10 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 20 Feb 2015 21:34:54 +0000 Subject: [PATCH] tuner ISR running in about 13% of CPU git-svn-id: https://svn.code.sf.net/p/freetel/code@2042 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/Makefile | 18 ++++++++++++++---- codec2-dev/stm32/inc/stm32f4_adc_tuner.h | 2 +- codec2-dev/stm32/src/adcdac_ut.c | 6 +++--- codec2-dev/stm32/src/iir_tuner.c | 3 ++- codec2-dev/stm32/src/sm1000_main.c | 24 +++++++++++++++++++++--- codec2-dev/stm32/src/stm32f4_adc_tuner.c | 8 +++++--- codec2-dev/stm32/src/tuner_ut.c | 15 +++------------ 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 70caba0d..8e5d822f 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.4.0 +PERIPHLIBVER = V1.1.0 PERIPHLIBNAME = STM32F4xx_DSP_StdPeriph_Lib PERIPHLIBDIR = $(PERIPHLIBNAME)_$(PERIPHLIBVER) CMSIS = $(PERIPHLIBDIR)/Libraries/CMSIS @@ -350,21 +350,31 @@ 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/iir_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) +# this needs to be compiled without the optimiser or ugly things happen +# would be nice to work out why as ISRs need to run fast + +src/stm32f4_adc_tuner.o: src/stm32f4_adc_tuner.c + $(CC) $(CFLAGS) $^ -c -o $@ + +tuner_ut.elf: $(TUNER_UT_SRCS) src/stm32f4_adc_tuner.o + $(CC) $(CFLAGS) -O3 $^ -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/inc/stm32f4_adc_tuner.h b/codec2-dev/stm32/inc/stm32f4_adc_tuner.h index d2ed444a..2db99fef 100644 --- a/codec2-dev/stm32/inc/stm32f4_adc_tuner.h +++ b/codec2-dev/stm32/inc/stm32f4_adc_tuner.h @@ -1,6 +1,6 @@ /*---------------------------------------------------------------------------*\ - FILE........: stm32f4_adc.h + FILE........: stm32f4_adc_tuner.h AUTHOR......: David Rowe DATE CREATED: 19 Feb 2015 diff --git a/codec2-dev/stm32/src/adcdac_ut.c b/codec2-dev/stm32/src/adcdac_ut.c index 39719da7..423f45aa 100644 --- a/codec2-dev/stm32/src/adcdac_ut.c +++ b/codec2-dev/stm32/src/adcdac_ut.c @@ -58,12 +58,12 @@ int main(void) { while(adc2_read(buf, SINE_SAMPLES) == -1); - if (switch_select()) { + if (!switch_select()) { for(i=0; i signed conversion - IIR BPF - Decimate - FIR Equaliser -> FIFO */ -void inline iir_tuner(float dec_buf[], unsigned short adc_buf[]) { +void iir_tuner(float dec_buf[], unsigned short adc_buf[]) { int i, j, k; float x, y, z; diff --git a/codec2-dev/stm32/src/sm1000_main.c b/codec2-dev/stm32/src/sm1000_main.c index 1f719f26..b40fa516 100644 --- a/codec2-dev/stm32/src/sm1000_main.c +++ b/codec2-dev/stm32/src/sm1000_main.c @@ -6,6 +6,10 @@ Main program for SM1000. + TODO + + [ ] make led blink 1-2-3 times for "mode" + \*---------------------------------------------------------------------------*/ /* @@ -31,6 +35,7 @@ #include "codec2_fdmdv.h" #include "sm1000_leds_switches.h" #include +#include #define FREEDV_NSAMPLES_16K (2*FREEDV_NSAMPLES) @@ -112,6 +117,14 @@ int main(void) { if (adc2_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) { GPIOE->ODR = (1 << 3); + /* clipping indicator */ + + led_err(0); + for (i=0; i 28000) + led_err(1); + } + fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES); if (ss.mode == ANALOG) { @@ -122,11 +135,16 @@ int main(void) { } if (ss.mode == DV) { freedv_tx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k); + for(i=0; istate; switch(ss->state) { case SS_IDLE: - if (switch_select()) { + if (switch_select() == 0) { downTicker = FIFTY_MS; next_state = SS_DEBOUNCE_DOWN; } @@ -212,7 +230,7 @@ void iterate_select_state_machine(SWITCH_STATE *ss) { } break; case SS_WAIT_BUTTON_UP: - if (switch_select() == 0) { + if (switch_select() == 1) { downTicker = FIFTY_MS; next_state = SS_DEBOUNCE_UP; } diff --git a/codec2-dev/stm32/src/stm32f4_adc_tuner.c b/codec2-dev/stm32/src/stm32f4_adc_tuner.c index ff5b71db..e9b15f84 100644 --- a/codec2-dev/stm32/src/stm32f4_adc_tuner.c +++ b/codec2-dev/stm32/src/stm32f4_adc_tuner.c @@ -39,7 +39,7 @@ #include "codec2_fifo.h" #include "stm32f4_adc_tuner.h" #include "debugblinky.h" -#include "iir_tuner.c" +#include "iir_tuner.h" struct FIFO *adc1_fifo; unsigned short adc_buf[ADC_TUNER_BUF_SZ]; @@ -202,6 +202,8 @@ void adc_configure(){ void DMA2_Stream0_IRQHandler(void) { float dec_buf[ADC_TUNER_N/2]; + /* PE0 is asserted high for the duration of this ISR + GPIOE->ODR = (1 << 0); /* Half transfer interrupt */ @@ -213,7 +215,7 @@ void DMA2_Stream0_IRQHandler(void) { /* write first half to fifo */ - if (fifo_write(adc1_fifo, (short)dec_buf, ADC_TUNER_N) == -1) { + if (fifo_write(adc1_fifo, (short*)dec_buf, ADC_TUNER_N) == -1) { adc_overflow1++; } @@ -231,7 +233,7 @@ void DMA2_Stream0_IRQHandler(void) { /* write second half to fifo */ - if (fifo_write(adc1_fifo, (short)dec_buf, ADC_TUNER_N) == -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 index 07818da9..308b08e7 100644 --- a/codec2-dev/stm32/src/tuner_ut.c +++ b/codec2-dev/stm32/src/tuner_ut.c @@ -31,25 +31,16 @@ #include "sm1000_leds_switches.h" int main(void) { - short buf[SINE_SAMPLES]; - int i; + float tuner_out[ADC_TUNER_N]; dac_open(4*DAC_BUF_SZ); - adc_open(4*ADC_TUNER_N; + adc_open(4*ADC_TUNER_N); sm1000_leds_switches_init(); while (1) { - while(adc1_read(buf, ADC_TUNER_N) == -1); + while(adc1_read((short *)tuner_out, ADC_TUNER_N) == -1); - /* - if (switch_select()) { - for(i=0; i