From 95f094c58489f4810e08f663e7fee490c9f9e56a Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 15 Aug 2014 01:47:06 +0000 Subject: [PATCH] freedv tx and rx unittests both running on SM1000 with file I/O. rx speed borderline git-svn-id: https://svn.code.sf.net/p/freetel/code@1803 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/stm32/Makefile | 27 +++++-- codec2-dev/stm32/src/freedv_rx_profile.c | 91 ++++++++++++++++++++++++ codec2-dev/stm32/src/freedv_tx_profile.c | 89 +++++++++++++++++++++++ codec2-dev/stm32/src/sm1000_main.c | 1 + 4 files changed, 201 insertions(+), 7 deletions(-) create mode 100644 codec2-dev/stm32/src/freedv_rx_profile.c create mode 100644 codec2-dev/stm32/src/freedv_tx_profile.c diff --git a/codec2-dev/stm32/Makefile b/codec2-dev/stm32/Makefile index d8c69c32..e33b8b9e 100644 --- a/codec2-dev/stm32/Makefile +++ b/codec2-dev/stm32/Makefile @@ -13,7 +13,7 @@ SIZE=$(BINPATH)/arm-none-eabi-size ################################################### -CFLAGS = -std=gnu99 -g -Wall -Tstm32_flash.ld -DSTM32F4XX -DCORTEX_M4 +CFLAGS = -std=gnu99 -O3 -g -Wall -Tstm32_flash.ld -DSTM32F4XX -DCORTEX_M4 CFLAGS += -mlittle-endian -mthumb -mthumb-interwork -nostartfiles -mcpu=cortex-m4 ifeq ($(FLOAT_TYPE), hard) @@ -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_profile.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 dl/$(PERIPHLIBZIP): mkdir -p dl @@ -263,18 +263,31 @@ src/stm32f4_adc.o: src/stm32f4_adc.c sm1000.elf: $(SM1000_SRCS) src/stm32f4_dac.o src/stm32f4_adc.o $(CC) $(CFLAGS) -O3 $^ -o $@ $(LIBPATHS) $(LIBS) -FREEDV_PROFILE_SRCS=\ -src/freedv_profile.c \ +FREEDV_TX_PROFILE_SRCS=\ +src/freedv_tx_profile.c \ src/stm32f4_machdep.c \ gdb_stdio.c \ src/system_stm32f4xx.c \ src/startup_stm32f4xx.s \ src/init.c -FREEDV_PROFILE_SRCS += $(CODEC2_SRCS) +FREEDV_TX_PROFILE_SRCS += $(CODEC2_SRCS) -freedv_profile.elf: $(FREEDV_PROFILE_SRCS) - $(CC) $(CFLAGS) $^ -o $@ $(LIBPATHS) $(LIBS) +freedv_tx_profile.elf: $(FREEDV_TX_PROFILE_SRCS) + $(CC) $(CFLAGS) -DPROFILE $^ -o $@ $(LIBPATHS) $(LIBS) + +FREEDV_RX_PROFILE_SRCS=\ +src/freedv_rx_profile.c \ +src/stm32f4_machdep.c \ +gdb_stdio.c \ +src/system_stm32f4xx.c \ +src/startup_stm32f4xx.s \ +src/init.c + +FREEDV_RX_PROFILE_SRCS += $(CODEC2_SRCS) + +freedv_rx_profile.elf: $(FREEDV_RX_PROFILE_SRCS) + $(CC) $(CFLAGS) -DPROFILE $^ -o $@ $(LIBPATHS) $(LIBS) clean: rm -f *.o diff --git a/codec2-dev/stm32/src/freedv_rx_profile.c b/codec2-dev/stm32/src/freedv_rx_profile.c new file mode 100644 index 00000000..c116c7ff --- /dev/null +++ b/codec2-dev/stm32/src/freedv_rx_profile.c @@ -0,0 +1,91 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: freedv_rx_profile.c + AUTHOR......: David Rowe + DATE CREATED: 13 August 2014 + + Profiling freedv_rx() 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 "freedv_api.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 + +int main(int argc, char *argv[]) { + struct freedv *f; + short inbuf[FREEDV_NSAMPLES], outbuf[FREEDV_NSAMPLES]; + FILE *fin, *fout; + int frame, nin, nout = 0; + PROFILE_VAR(freedv_start); + + machdep_profile_init(); + + f = freedv_open(FREEDV_MODE_1600); + + // Transmit --------------------------------------------------------------------- + + frame = 0; + + fin = fopen("mod.raw", "rb"); + if (fin == NULL) { + printf("Error opening input file\n"); + exit(1); + } + + fout = fopen("stm_out.raw", "wb"); + if (fout == NULL) { + printf("Error opening output file\n"); + exit(1); + } + + nin = freedv_nin(f); + while (fread(inbuf, sizeof(short), nin, fin) == nin) { + PROFILE_SAMPLE(freedv_start); + nout = freedv_rx(f, outbuf, inbuf); + nin = freedv_nin(f); + PROFILE_SAMPLE_AND_LOG2(freedv_start, " demod"); + + machdep_profile_print_logged_samples(); + fwrite(outbuf, sizeof(short), nout, fout); + printf("frame: %d\n", ++frame); + } + + fclose(fin); + fclose(fout); + + return 0; +} + diff --git a/codec2-dev/stm32/src/freedv_tx_profile.c b/codec2-dev/stm32/src/freedv_tx_profile.c new file mode 100644 index 00000000..7391c521 --- /dev/null +++ b/codec2-dev/stm32/src/freedv_tx_profile.c @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + + FILE........: freedv_tx_profile.c + AUTHOR......: David Rowe + DATE CREATED: 13 August 2014 + + Profiling freedv_tx() 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 "freedv_api.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 + +int main(int argc, char *argv[]) { + struct freedv *f; + short inbuf[FREEDV_NSAMPLES], outbuf[FREEDV_NSAMPLES]; + FILE *fin, *fout; + int frame; + PROFILE_VAR(freedv_start); + + machdep_profile_init(); + + f = freedv_open(FREEDV_MODE_1600); + + // Transmit --------------------------------------------------------------------- + + fin = fopen("stm_in.raw", "rb"); + if (fin == NULL) { + printf("Error opening input file\n"); + exit(1); + } + + fout = fopen("mod.raw", "wb"); + if (fout == NULL) { + printf("Error opening output file\n"); + exit(1); + } + + frame = 0; + + while (fread(inbuf, sizeof(short), FREEDV_NSAMPLES, fin) == FREEDV_NSAMPLES) { + PROFILE_SAMPLE(freedv_start); + freedv_tx(f, outbuf, inbuf); + PROFILE_SAMPLE_AND_LOG2(freedv_start, " freedv_tx"); + + fwrite(outbuf, sizeof(short), FREEDV_NSAMPLES, fout); + printf("frame: %d\n", ++frame); + machdep_profile_print_logged_samples(); + } + + fclose(fin); + fclose(fout); + + return 0; +} + diff --git a/codec2-dev/stm32/src/sm1000_main.c b/codec2-dev/stm32/src/sm1000_main.c index 9b6cbbdd..5aaabe9b 100644 --- a/codec2-dev/stm32/src/sm1000_main.c +++ b/codec2-dev/stm32/src/sm1000_main.c @@ -122,6 +122,7 @@ int main(void) { nout = freedv_rx(f, buf, buf); dac2_write(buf, nout); led_ptt(0); led_rt(f->fdmdv_stats.sync); led_err(f->total_bit_errors); + nin = freedv_nin(f); } } -- 2.25.1