From: drowe67 Date: Fri, 18 Jul 2014 05:24:55 +0000 (+0000) Subject: first pass at stm modem profiling UT, untested X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=c814df567156a59dc0070872df85809c38bea65f;p=freetel-svn-tracking.git first pass at stm modem profiling UT, untested git-svn-id: https://svn.code.sf.net/p/freetel/code@1765 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index 917e1ae2..661b21aa 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -2,7 +2,6 @@ ################################################### -PROJ_NAME=stm32f4_codec2 FLOAT_TYPE=hard ################################################### @@ -45,14 +44,10 @@ CFLAGS += -DARM_MATH_CM4 ################################################### -# Sources - -SRCS = main.c gdb_stdio.c stm32f4_timer.c system_stm32f4xx.c - # Codec 2 CODEC2_SRC=../src -SRCS += \ +CODEC2_SRCS=\ $(CODEC2_SRC)/lpc.c \ $(CODEC2_SRC)/nlp.c \ $(CODEC2_SRC)/postfilter.c \ @@ -68,7 +63,8 @@ $(CODEC2_SRC)/codebook.c \ $(CODEC2_SRC)/codebookd.c \ $(CODEC2_SRC)/codebookjvm.c \ $(CODEC2_SRC)/codebookge.c \ -$(CODEC2_SRC)/dump.c +$(CODEC2_SRC)/dump.c \ +$(CODEC2_SRC)/fdmdv.c CFLAGS += -D__EMBEDDED__ -DTIMER @@ -110,7 +106,7 @@ OBJS = $(SRCS:.c=.o) ################################################### -all: libstm32f4.a $(PROJ_NAME).elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf power_ut.elf +all: libstm32f4.a codec2_profile.elf fft_test.elf dac_ut.elf dac_play.elf adc_rec.elf pwm_ut.elf power_ut.elf fdmdv_profile.elf dl/$(PERIPHLIBZIP): mkdir -p dl @@ -126,7 +122,18 @@ libstm32f4.a: $(PERIPHLIBDIR) for F in $(CMSIS)/DSP_Lib/Source/*/*.c ; do $(MAKE) $${F%.c}.o ; done find $(PERIPHLIBDIR) -type f -name '*.o' -exec $(AR) crs libstm32f4.a {} ";" -$(PROJ_NAME).elf: $(SRCS) +#################################################### + +CODEC2_PROFILE_SRCS=\ +src/codec2_profile.c \ +src/gdb_stdio.c \ +src/stm32f4_timer.c \ +src/startup_stm32f4xx.s \ +src/init.c \ +src/system_stm32f4xx.c +CODEC2_PROFILE_SRCS += $(CODEC2_SRCS) + +codec2_profile.elf: $(CODEC2_PROFILE_SRCS) $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) fft_test.elf: $(FFT_TEST_SRCS) @@ -188,27 +195,24 @@ src/startup_stm32f4xx.s \ src/init.c \ src/stm32f4_timer.c \ -POWER_UT_SRCS += \ -$(CODEC2_SRC)/lpc.c \ -$(CODEC2_SRC)/nlp.c \ -$(CODEC2_SRC)/postfilter.c \ -$(CODEC2_SRC)/sine.c \ -$(CODEC2_SRC)/codec2.c \ -$(CODEC2_SRC)/kiss_fft.c \ -$(CODEC2_SRC)/interp.c \ -$(CODEC2_SRC)/lsp.c \ -$(CODEC2_SRC)/phase.c \ -$(CODEC2_SRC)/quantise.c \ -$(CODEC2_SRC)/pack.c \ -$(CODEC2_SRC)/codebook.c \ -$(CODEC2_SRC)/codebookd.c \ -$(CODEC2_SRC)/codebookjvm.c \ -$(CODEC2_SRC)/codebookge.c \ -$(CODEC2_SRC)/dump.c +POWER_UT_SRCS += $(CODEC2_SRCS) power_ut.elf: $(POWER_UT_SRCS) $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) +FDMDV_PROFILE_SRCS=\ +src/fdmdv_profile.c \ +gdb_stdio.c \ +src/system_stm32f4xx.c \ +src/startup_stm32f4xx.s \ +src/init.c \ +src/stm32f4_timer.c + +FDMDV_PROFILE_SRCS += $(CODEC2_SRCS) + +fdmdv_profile.elf: $(FDMDV_PROFILE_SRCS) + $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) + clean: rm -f *.o rm -f *.elf diff --git a/codec2-dev/stm32/src/codec2_profile.c b/codec2-dev/stm32/src/codec2_profile.c new file mode 100644 index 00000000..7a6a28c0 --- /dev/null +++ b/codec2-dev/stm32/src/codec2_profile.c @@ -0,0 +1,182 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: codec2_profile.c + AUTHOR......: David Rowe + DATE CREATED: 30 May 2013 + + Profiling Codec 2 operation on the STM32F4. + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2014 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 +#include +#include + +#include "stm32f4xx_conf.h" +#include "stm32f4xx.h" +#include "gdb_stdio.h" +#include "codec2.h" +#include "dump.h" +#include "sine.h" +#include "machdep.h" + +#ifdef __EMBEDDED__ +#define printf gdb_stdio_printf +#define fopen gdb_stdio_fopen +#define fclose gdb_stdio_fclose +#define fread gdb_stdio_fread +#define fwrite gdb_stdio_fwrite +#endif + +static void c2demo(int mode, char inputfile[], char outputfile[]) +{ + struct CODEC2 *codec2; + short *inbuf, *outbuf; + unsigned char *bits; + int nsam, nbit; + FILE *fin, *fout; + int frame; + TIMER_VAR(enc_start, dec_start); + + codec2 = codec2_create(mode); + nsam = codec2_samples_per_frame(codec2); + outbuf = (short*)malloc(nsam*sizeof(short)); + inbuf = (short*)malloc(nsam*sizeof(short)); + nbit = codec2_bits_per_frame(codec2); + bits = (unsigned char*)malloc(nbit*sizeof(char)); + + fin = fopen(inputfile, "rb"); + if (fin == NULL) { + printf("Error opening input file: %s\n\nTerminating....\n",inputfile); + exit(1); + } + + fout = fopen(outputfile, "wb"); + if (fout == NULL) { + printf("Error opening output file: %s\n\nTerminating....\n",outputfile); + exit(1); + } + + #ifdef DUMP + dump_on("stm32f4"); + #endif + frame = 0; + + while (fread(inbuf, sizeof(short), nsam, fin) == nsam) { + TIMER_SAMPLE(enc_start); + codec2_encode(codec2, bits, inbuf); + TIMER_SAMPLE_AND_LOG(dec_start, enc_start, " enc"); + codec2_decode(codec2, outbuf, bits); + TIMER_SAMPLE_AND_LOG2(dec_start, " dec"); + TIMER_SAMPLE_AND_LOG2(enc_start, " enc & dec"); + fwrite((char*)outbuf, sizeof(short), nsam, fout); + printf("frame: %d\n", ++frame); + machdep_timer_print_logged_samples(); + } + + #ifdef DUMP + dump_off("sm32f4"); + #endif + + fclose(fin); + fclose(fout); + free(inbuf); + free(outbuf); + free(bits); + codec2_destroy(codec2); +} + +#define SPEED_TEST_SAMPLES 24000 + +static void c2speedtest(int mode, char inputfile[]) +{ + struct CODEC2 *codec2; + short *inbuf, *outbuf, *pinbuf; + unsigned char *bits; + int nsam, nbit, nframes; + FILE *fin; + int f, nread; + + codec2 = codec2_create(mode); + nsam = codec2_samples_per_frame(codec2); + nframes = SPEED_TEST_SAMPLES/nsam; + outbuf = (short*)malloc(nsam*sizeof(short)); + inbuf = (short*)malloc(SPEED_TEST_SAMPLES*sizeof(short)); + nbit = codec2_bits_per_frame(codec2); + bits = (unsigned char*)malloc(nbit*sizeof(char)); + + fin = fopen(inputfile, "rb"); + if (fin == NULL) { + printf("Error opening input file: %s\nTerminating....\n",inputfile); + exit(1); + } + + nread = fread(inbuf, sizeof(short), SPEED_TEST_SAMPLES, fin); + if (nread != SPEED_TEST_SAMPLES) { + printf("error reading %s, %d samples reqd, %d read\n", + inputfile, SPEED_TEST_SAMPLES, nread); + } + fclose(fin); + + pinbuf = inbuf; + for(f=0; fODR = (1 << 13); + codec2_encode(codec2, bits, pinbuf); + pinbuf += nsam; + GPIOD->ODR &= ~(1 << 13); + codec2_decode(codec2, outbuf, bits); + } + + free(inbuf); + free(outbuf); + free(bits); + codec2_destroy(codec2); +} + +void gpio_init() { + RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD + GPIOD->MODER = (1 << 26); // set pin 13 to be general + // purpose output +} + +int main(int argc, char *argv[]) { + gpio_init(); + machdep_timer_init (); + + printf("Starting c2demo\n"); + + /* File I/O test for profiling or (with #define DUMP) + dumping states for optimisation and tiuning */ + + c2demo(CODEC2_MODE_1600, "stm_in.raw", "stm_out.raw"); + + printf("Starting c2 speed test\n"); + + /* Another test of execution speed. Look at PD13 with a + oscilliscope. On time is enc, off is dec */ + + c2speedtest(CODEC2_MODE_1600, "stm_in.raw"); + + printf("Finished\n"); + + return 0; +} + diff --git a/codec2-dev/stm32/src/fdmdv_profile.c b/codec2-dev/stm32/src/fdmdv_profile.c new file mode 100644 index 00000000..0e4e765f --- /dev/null +++ b/codec2-dev/stm32/src/fdmdv_profile.c @@ -0,0 +1,98 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: fdmdv_profile.c + AUTHOR......: David Rowe + DATE CREATED: 18 July 2014 + + Profiling Codec 2 operation on the STM32F4. + +\*---------------------------------------------------------------------------*/ + +/* + Copyright (C) 2014 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 +#include +#include +#include + +#include "stm32f4xx_conf.h" +#include "stm32f4xx.h" +#include "gdb_stdio.h" +#include "codec2_fdmdv.h" +#include "dump.h" +#include "sine.h" +#include "machdep.h" + +#ifdef __EMBEDDED__ +#define printf gdb_stdio_printf +#define fopen gdb_stdio_fopen +#define fclose gdb_stdio_fclose +#define fread gdb_stdio_fread +#define fwrite gdb_stdio_fwrite +#endif + +#define TEST_FRAMES 25 + +int main(int argc, char *argv[]) { + struct FDMDV *fdmdv; + int bits_per_fdmdv_frame, bits_per_codec_frame; + int *tx_bits; + int *rx_bits; + COMP tx_fdm[2*FDMDV_NOM_SAMPLES_PER_FRAME]; + int i, nin, reliable_sync_bit, sync_bit; + struct FDMDV_STATS stats; + TIMER_VAR(mod_start, demod_start); + + fdmdv = fdmdv_create(FDMDV_NC); + + bits_per_fdmdv_frame = fdmdv_bits_per_frame(fdmdv); + bits_per_codec_frame = 2*fdmdv_bits_per_frame(fdmdv); + tx_bits = (int*)malloc(sizeof(int)*bits_per_codec_frame); assert(tx_bits != NULL); + rx_bits = (int*)malloc(sizeof(int)*bits_per_codec_frame); assert(rx_bits != NULL); + + nin = FDMDV_NOM_SAMPLES_PER_FRAME; + + for(i=0; i -#include -#include -#include - -#include "stm32f4xx_conf.h" -#include "stm32f4xx.h" -#include "gdb_stdio.h" -#include "codec2.h" -#include "dump.h" -#include "sine.h" -#include "machdep.h" - -#ifdef __EMBEDDED__ -#define printf gdb_stdio_printf -#define fopen gdb_stdio_fopen -#define fclose gdb_stdio_fclose -#define fread gdb_stdio_fread -#define fwrite gdb_stdio_fwrite -#endif - -static void c2demo(int mode, char inputfile[], char outputfile[]) -{ - struct CODEC2 *codec2; - short *inbuf, *outbuf; - unsigned char *bits; - int nsam, nbit; - FILE *fin, *fout; - int frame; - TIMER_VAR(enc_start, dec_start); - - codec2 = codec2_create(mode); - nsam = codec2_samples_per_frame(codec2); - outbuf = (short*)malloc(nsam*sizeof(short)); - inbuf = (short*)malloc(nsam*sizeof(short)); - nbit = codec2_bits_per_frame(codec2); - bits = (unsigned char*)malloc(nbit*sizeof(char)); - - fin = fopen(inputfile, "rb"); - if (fin == NULL) { - printf("Error opening input file: %s\n\nTerminating....\n",inputfile); - exit(1); - } - - fout = fopen(outputfile, "wb"); - if (fout == NULL) { - printf("Error opening output file: %s\n\nTerminating....\n",outputfile); - exit(1); - } - - #ifdef DUMP - dump_on("stm32f4"); - #endif - frame = 0; - - while (fread(inbuf, sizeof(short), nsam, fin) == nsam) { - TIMER_SAMPLE(enc_start); - codec2_encode(codec2, bits, inbuf); - TIMER_SAMPLE_AND_LOG(dec_start, enc_start, " enc"); - codec2_decode(codec2, outbuf, bits); - TIMER_SAMPLE_AND_LOG2(dec_start, " dec"); - TIMER_SAMPLE_AND_LOG2(enc_start, " enc & dec"); - fwrite((char*)outbuf, sizeof(short), nsam, fout); - printf("frame: %d\n", ++frame); - machdep_timer_print_logged_samples(); - } - - #ifdef DUMP - dump_off("sm32f4"); - #endif - - fclose(fin); - fclose(fout); - free(inbuf); - free(outbuf); - free(bits); - codec2_destroy(codec2); -} - -#define SPEED_TEST_SAMPLES 24000 - -static void c2speedtest(int mode, char inputfile[]) -{ - struct CODEC2 *codec2; - short *inbuf, *outbuf, *pinbuf; - unsigned char *bits; - int nsam, nbit, nframes; - FILE *fin; - int f, nread; - - codec2 = codec2_create(mode); - nsam = codec2_samples_per_frame(codec2); - nframes = SPEED_TEST_SAMPLES/nsam; - outbuf = (short*)malloc(nsam*sizeof(short)); - inbuf = (short*)malloc(SPEED_TEST_SAMPLES*sizeof(short)); - nbit = codec2_bits_per_frame(codec2); - bits = (unsigned char*)malloc(nbit*sizeof(char)); - - fin = fopen(inputfile, "rb"); - if (fin == NULL) { - printf("Error opening input file: %s\nTerminating....\n",inputfile); - exit(1); - } - - nread = fread(inbuf, sizeof(short), SPEED_TEST_SAMPLES, fin); - if (nread != SPEED_TEST_SAMPLES) { - printf("error reading %s, %d samples reqd, %d read\n", - inputfile, SPEED_TEST_SAMPLES, nread); - } - fclose(fin); - - pinbuf = inbuf; - for(f=0; fODR = (1 << 13); - codec2_encode(codec2, bits, pinbuf); - pinbuf += nsam; - GPIOD->ODR &= ~(1 << 13); - codec2_decode(codec2, outbuf, bits); - } - - free(inbuf); - free(outbuf); - free(bits); - codec2_destroy(codec2); -} - -void gpio_init() { - RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN; // enable the clock to GPIOD - GPIOD->MODER = (1 << 26); // set pin 13 to be general - // purpose output -} - -int main(int argc, char *argv[]) { - SystemInit(); - gpio_init(); - machdep_timer_init (); - - printf("Starting c2demo\n"); - - /* File I/O test for profiling or (with #define DUMP) - dumping states for optimisation and tiuning */ - - c2demo(CODEC2_MODE_1600, "stm_in.raw", "stm_out.raw"); - - printf("Starting c2 speed test\n"); - - /* Another test of execution speed. Look at PD13 with a - oscilliscope. On time is enc, off is dec */ - - c2speedtest(CODEC2_MODE_1600, "stm_in.raw"); - - printf("Finished\n"); - - return 0; -} - diff --git a/codec2-dev/stm32/src/stm32f4_timer.c b/codec2-dev/stm32/src/stm32f4_timer.c index 609f9fbc..a2dc1461 100644 --- a/codec2-dev/stm32/src/stm32f4_timer.c +++ b/codec2-dev/stm32/src/stm32f4_timer.c @@ -66,10 +66,12 @@ unsigned int machdep_timer_sample(void) { unsigned int machdep_timer_sample_and_log(unsigned int start, char s[]) { - char tmp[80]; + char tmp[80]; + float msec; unsigned int dwt = *DWT_CYCCNT - start; - sprintf(tmp, "%s %5.2f msecs\n",s,1000.0*(float)dwt/CORE_CLOCK); + msec = 1000.0*(float)dwt/CORE_CLOCK; + sprintf(tmp, "%s %5.2f msecs\n",s,(double)msec); if ((strlen(buf) + strlen(tmp)) < BUF_SZ) strcat(buf, tmp); return *DWT_CYCCNT; @@ -80,3 +82,4 @@ void machdep_timer_print_logged_samples(void) gdb_stdio_printf("%s", buf); *buf = 0; } +