tuner ISR running in about 13% of CPU
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 20 Feb 2015 21:34:54 +0000 (21:34 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 20 Feb 2015 21:34:54 +0000 (21:34 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2042 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/stm32/Makefile
codec2-dev/stm32/inc/stm32f4_adc_tuner.h
codec2-dev/stm32/src/adcdac_ut.c
codec2-dev/stm32/src/iir_tuner.c
codec2-dev/stm32/src/sm1000_main.c
codec2-dev/stm32/src/stm32f4_adc_tuner.c
codec2-dev/stm32/src/tuner_ut.c

index 70caba0d5c43a23720622ecd388c5a572117b9d7..8e5d822f691210f82712cbb124c6ed88e18a3813 100644 (file)
@@ -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
index d2ed444adcbe5c2d947009c7ec789dcc270240b9..2db99fef71a583da96db6398a2d707c3c946cca6 100644 (file)
@@ -1,6 +1,6 @@
 /*---------------------------------------------------------------------------*\
 
-  FILE........: stm32f4_adc.h
+  FILE........: stm32f4_adc_tuner.h
   AUTHOR......: David Rowe
   DATE CREATED: 19 Feb 2015
 
index 39719da761079750be8ae7f2cbf49be195d4a283..423f45aacdc20120f9fac4aa3a979790b2e7d9a6 100644 (file)
@@ -58,12 +58,12 @@ int main(void) {
 \r
         while(adc2_read(buf, SINE_SAMPLES) == -1);\r
         \r
-        if (switch_select()) {\r
+        if (!switch_select()) {\r
             for(i=0; i<SINE_SAMPLES; i++)\r
-                buf[i] = 0;\r
+                buf[i] = aSine[i];\r
         }\r
             \r
-        dac1_write(buf, SINE_SAMPLES);\r
+        dac2_write(buf, SINE_SAMPLES);\r
     }\r
    \r
 }\r
index 5e13bc535a223ea5b936294103bc50fad7a59650..05e6c209b7875c0261dfadcd55f6f0938dd3e637 100644 (file)
@@ -40,6 +40,7 @@
 #endif
 
 #include "stm32f4_adc_tuner.h"
+#include "iir_tuner.h"
 
 /* Filter coefficients of IIR tuner (BETA1) and FIR equaliser (BETA2).
    Note neat trick to relate BETA2 to BETA1 by the decimation rate */
@@ -55,7 +56,7 @@ float y_2, y_1, z_2, z_1;
    ADC -> 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;
 
index 1f719f26fde1db3847a15fbcaa72487e0a3d4d26..b40fa516b767c3bab6cb16b8a398a9eeded211e3 100644 (file)
@@ -6,6 +6,10 @@
 \r
   Main program for SM1000.\r
 \r
+  TODO\r
+\r
+  [ ] make led blink 1-2-3 times for "mode"\r
+\r
 \*---------------------------------------------------------------------------*/\r
 \r
 /*\r
@@ -31,6 +35,7 @@
 #include "codec2_fdmdv.h"\r
 #include "sm1000_leds_switches.h"\r
 #include <stm32f4xx_gpio.h>\r
+#include <stdlib.h>\r
 \r
 #define FREEDV_NSAMPLES_16K (2*FREEDV_NSAMPLES)\r
 \r
@@ -112,6 +117,14 @@ int main(void) {
             if (adc2_read(&adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES_16K) == 0) {\r
                 GPIOE->ODR = (1 << 3);\r
 \r
+                /* clipping indicator */\r
+\r
+                led_err(0);\r
+                for (i=0; i<FREEDV_NSAMPLES_16K; i++) {\r
+                    if (abs(adc16k[FDMDV_OS_TAPS_16K+i]) > 28000)\r
+                        led_err(1);\r
+                }\r
+\r
                 fdmdv_16_to_8_short(adc8k, &adc16k[FDMDV_OS_TAPS_16K], FREEDV_NSAMPLES);\r
 \r
                 if (ss.mode == ANALOG) {\r
@@ -122,11 +135,16 @@ int main(void) {
                 }\r
                 if (ss.mode == DV) {\r
                     freedv_tx(f, &dac8k[FDMDV_OS_TAPS_8K], adc8k);\r
+                    for(i=0; i<FREEDV_NSAMPLES; i++)\r
+                        dac8k[FDMDV_OS_TAPS_8K+i] *= 0.398; /* 8dB back off from peak */\r
                     fdmdv_8_to_16_short(dac16k, &dac8k[FDMDV_OS_TAPS_8K], FREEDV_NSAMPLES);              \r
                     dac1_write(dac16k, FREEDV_NSAMPLES_16K);\r
                 }\r
                 if (ss.mode == TONE) {\r
-                    while(dac1_write((short*)aSine, SINE_SAMPLES) == 0);\r
+                    short buf[SINE_SAMPLES];\r
+                    for(i=0; i<FREEDV_NSAMPLES; i++)\r
+                        buf[i] = aSine[i]*0.398; /* 8dB back off from peak */                   \r
+                    while(dac1_write(buf, SINE_SAMPLES) == 0);\r
                 }\r
 \r
                 led_ptt(1); led_rt(0); led_err(0); not_cptt(0);\r
@@ -198,7 +216,7 @@ void iterate_select_state_machine(SWITCH_STATE *ss) {
     next_state = ss->state;\r
     switch(ss->state) {\r
         case SS_IDLE:\r
-            if (switch_select()) {\r
+            if (switch_select() == 0) {\r
                 downTicker = FIFTY_MS;\r
                 next_state = SS_DEBOUNCE_DOWN;\r
             }\r
@@ -212,7 +230,7 @@ void iterate_select_state_machine(SWITCH_STATE *ss) {
             }\r
             break;\r
         case SS_WAIT_BUTTON_UP:\r
-            if (switch_select() == 0) {\r
+            if (switch_select() == 1) {\r
                 downTicker = FIFTY_MS;\r
                 next_state = SS_DEBOUNCE_UP;\r
             }\r
index ff5b71db8bf47d5247d71a11ea958bbab38c820b..e9b15f843af0666517bc09d23e894f8f7b65c1e0 100644 (file)
@@ -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++;
         }
 
index 07818da99a9c82a7c6f477dde74179f4c8db35ca..308b08e7966e94aefcebf7f72d68aa8efb007d37 100644 (file)
 #include "sm1000_leds_switches.h"\r
 \r
 int main(void) {\r
-    short buf[SINE_SAMPLES];\r
-    int   i;\r
+    float tuner_out[ADC_TUNER_N];\r
 \r
     dac_open(4*DAC_BUF_SZ);\r
-    adc_open(4*ADC_TUNER_N;\r
+    adc_open(4*ADC_TUNER_N);\r
     sm1000_leds_switches_init();\r
 \r
     while (1) {\r
 \r
-        while(adc1_read(buf, ADC_TUNER_N) == -1);\r
+        while(adc1_read((short *)tuner_out, ADC_TUNER_N) == -1);\r
         \r
-        /*\r
-        if (switch_select()) {\r
-            for(i=0; i<SINE_SAMPLES; i++)\r
-                buf[i] = 0;\r
-        }\r
-            \r
-        dac1_write(buf, SINE_SAMPLES);\r
-        */\r
     }\r
    \r
 }\r