aboutsummaryrefslogtreecommitdiffstats
path: root/src/tone-test-sim
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-06-17 18:56:15 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-06-17 18:56:15 +0200
commit76f58c6eb4991d3f8c9648d0dc8a57e496f01d5a (patch)
treec100d1acf0511367111fbcf9b7d465500474afff /src/tone-test-sim
parent7b25d27d064b561cd8f3b72e25f61102241991f8 (diff)
downloadglutte-o-matic-76f58c6eb4991d3f8c9648d0dc8a57e496f01d5a.tar.gz
glutte-o-matic-76f58c6eb4991d3f8c9648d0dc8a57e496f01d5a.tar.bz2
glutte-o-matic-76f58c6eb4991d3f8c9648d0dc8a57e496f01d5a.zip
Add tone-test-sim
Diffstat (limited to 'src/tone-test-sim')
-rw-r--r--src/tone-test-sim/Makefile149
l---------src/tone-test-sim/Source1
-rwxr-xr-xsrc/tone-test-sim/analyse.py24
-rw-r--r--src/tone-test-sim/src/Core/FreeRTOSConfig.h4
-rw-r--r--src/tone-test-sim/src/Core/vc.c30
-rw-r--r--src/tone-test-sim/src/test.c38
6 files changed, 246 insertions, 0 deletions
diff --git a/src/tone-test-sim/Makefile b/src/tone-test-sim/Makefile
new file mode 100644
index 0000000..9e48dbc
--- /dev/null
+++ b/src/tone-test-sim/Makefile
@@ -0,0 +1,149 @@
+
+######## Build options ########
+
+verbose = 1
+
+######## Build setup ########
+
+# SRCROOT should always be the current directory
+SRCROOT = $(CURDIR)
+
+# .o directory
+ODIR = obj
+
+# Source VPATHS
+VPATH += $(SRCROOT)/Source
+VPATH += $(SRCROOT)/Source/portable/MemMang
+VPATH += $(SRCROOT)/Source/portable/GCC/POSIX
+VPATH += $(SRCROOT)/src/Core
+VPATH += $(SRCROOT)/src/GPIO
+VPATH += $(SRCROOT)/src/GPS
+
+# FreeRTOS Objects
+C_FILES += croutine.c
+C_FILES += event_groups.c
+C_FILES += list.c
+C_FILES += queue.c
+C_FILES += tasks.c
+C_FILES += timers.c
+
+# portable Objects
+C_FILES += heap_3.c
+C_FILES += port.c
+
+# common Objects
+#COMMON_SOURCE_LIST=$(shell cat ../common/sourcelist.txt)
+#C_FILES+=$(COMMON_SOURCE_LIST:%.c=../common/%.c)
+
+C_FILES+=../common/src/Audio/tone.c
+
+# Main Object
+SRC_SOURCES+=$(shell find -L src/ -name '*.c' -not -name 'vc.c')
+C_FILES += $(SRC_SOURCES)
+
+# Include Paths
+INCLUDES += -I$(SRCROOT)/Source/include
+INCLUDES += -I$(SRCROOT)/Source/portable/GCC/POSIX/
+INCLUDES += -I$(SRCROOT)/src/Core
+INCLUDES += -I$(SRCROOT)/../common/includes/
+INCLUDES += -I$(SRCROOT)
+
+# Generate OBJS names
+OBJS = $(patsubst %.c,%.o,$(C_FILES))
+OBJS += src/Core/vc.o
+
+######## C Flags ########
+
+# Warnings
+CWARNS += -W
+CWARNS += -Wall
+# CWARNS += -Werror
+CWARNS += -Wextra
+CWARNS += -Wformat
+CWARNS += -Wmissing-braces
+CWARNS += -Wno-cast-align
+CWARNS += -Wparentheses
+CWARNS += -Wshadow
+CWARNS += -Wno-sign-compare
+CWARNS += -Wswitch
+CWARNS += -Wuninitialized
+CWARNS += -Wunknown-pragmas
+CWARNS += -Wunused-function
+CWARNS += -Wunused-label
+CWARNS += -Wunused-parameter
+CWARNS += -Wunused-value
+CWARNS += -Wunused-variable
+CWARNS += -Wmissing-prototypes
+
+CFLAGS += -DDEBUG=1
+CFLAGS += -g -DUSE_STDIO=1 -D__GCC_POSIX__=1 -lm -lm
+ifneq ($(shell uname), Darwin)
+CFLAGS += -pthread
+endif
+
+# MAX_NUMBER_OF_TASKS = max pthreads used in the POSIX port.
+# Default value is 64 (_POSIX_THREAD_THREADS_MAX), the minimum number required by POSIX.
+CFLAGS += -DMAX_NUMBER_OF_TASKS=300 -DSIMULATOR
+
+CFLAGS += $(INCLUDES) $(CWARNS) -O2
+
+######## Makefile targets ########
+
+# Rules
+.PHONY : all
+all: vc.h setup tone-test-sim
+
+.PHONY : setup
+setup:
+# Make obj directory
+ @mkdir -p $(ODIR)
+
+# Fix to place .o files in ODIR
+_OBJS = $(patsubst %,$(ODIR)/%,$(OBJS))
+
+dir_guard=@mkdir -p $(@D)
+
+$(ODIR)/src/Core/vc.o: src/Core/vc.c vc.h
+ $(dir_guard)
+ @echo "[CC] version information vc.c"
+ifeq ($(verbose),1)
+ $(CC) $(CFLAGS) src/Core/vc.c -c -o $(ODIR)/src/Core/vc.o
+else
+ @$(CC) $(CFLAGS) src/Core/vc.c -c -o $(ODIR)/src/Core/vc.o
+endif
+
+$(ODIR)/%.o: %.c
+ $(dir_guard)
+# If verbose, print gcc execution, else hide
+ifeq ($(verbose),1)
+ @echo "[CC] $<"
+ $(CC) $(CFLAGS) -c -o $@ $<
+else
+ @echo "[CC] $(notdir $<)"
+ @$(CC) $(CFLAGS) -c -o $@ $<
+endif
+
+.PHONY: vc.h
+vc.h: ../../.git/logs/HEAD
+ @echo "// This file is generated by Makefile." > vc.h
+ @echo "// Do not edit this file!" >> vc.h
+ @echo "const char* vc_get_version(void);" >> vc.h
+ @echo >> vc.h
+ @git log -1 --format="format:#define GIT_VERSION \"%h\"" >> vc.h
+ @echo >> vc.h
+ @echo >> vc.h
+ @echo [GEN] vc.h
+
+tone-test-sim: $(_OBJS)
+ @echo "[LK] $@"
+ifeq ($(verbose),1)
+ $(CC) $(CFLAGS) $^ $(LINKFLAGS) $(LIBS) -o $@
+else
+ @$(CC) $(CFLAGS) $^ $(LINKFLAGS) $(LIBS) -o $@
+endif
+ @echo "[:)] Happiness :)"
+
+.PHONY : clean
+clean:
+ @-rm -rf $(ODIR) tone-test-sim common/
+ @echo "[RM] Cleanuped °o°"
diff --git a/src/tone-test-sim/Source b/src/tone-test-sim/Source
new file mode 120000
index 0000000..5f455fb
--- /dev/null
+++ b/src/tone-test-sim/Source
@@ -0,0 +1 @@
+../FreeRTOS-Sim-master/Source \ No newline at end of file
diff --git a/src/tone-test-sim/analyse.py b/src/tone-test-sim/analyse.py
new file mode 100755
index 0000000..a67644c
--- /dev/null
+++ b/src/tone-test-sim/analyse.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+dat = np.loadtxt("tone.csv", dtype=np.int32, delimiter=",")
+# columns :"freq, threshold, num_samples, detector_output"
+
+fig, ax = plt.subplots()
+plt.scatter(dat[...,0], dat[...,1], c=dat[...,3].astype(np.float32))
+plt.show()
+
+if 0:
+ thresholds = [800, 2000, 4000, 8000]
+
+ fig, ax = plt.subplots()
+
+ for th in thresholds:
+ dat_th = dat[dat[...,1] == th]
+ dat_th[...,1]
+ ax.plot(dat_th[...,0], dat_th[...,3], label="{}".format(th))
+
+ legend = ax.legend(loc='upper left', shadow=True)
+ plt.show()
diff --git a/src/tone-test-sim/src/Core/FreeRTOSConfig.h b/src/tone-test-sim/src/Core/FreeRTOSConfig.h
new file mode 100644
index 0000000..19086b7
--- /dev/null
+++ b/src/tone-test-sim/src/Core/FreeRTOSConfig.h
@@ -0,0 +1,4 @@
+#include "../../../common/src/Core/FreeRTOSConfig.h"
+
+
+#define configCHECK_FOR_STACK_OVERFLOW 0 /* Do not use this option on the PC port. */
diff --git a/src/tone-test-sim/src/Core/vc.c b/src/tone-test-sim/src/Core/vc.c
new file mode 100644
index 0000000..253ab2d
--- /dev/null
+++ b/src/tone-test-sim/src/Core/vc.c
@@ -0,0 +1,30 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+*/
+
+#include "vc.h"
+
+const char* vc_get_version()
+{
+ return GIT_VERSION;
+}
diff --git a/src/tone-test-sim/src/test.c b/src/tone-test-sim/src/test.c
new file mode 100644
index 0000000..ca35c1c
--- /dev/null
+++ b/src/tone-test-sim/src/test.c
@@ -0,0 +1,38 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include "vc.h"
+#include "Audio/tone.h"
+
+#define FLOAT_PI 3.1415926535897932384f
+
+int main(int argc, char **argv)
+{
+ printf("Hello, ver %s\n", vc_get_version());
+ printf("Saving results to tone.csv\n");
+ printf("freq, threshold, num_samples, detector_output\n");
+
+ FILE *fd = fopen("tone.csv", "w");
+ if (!fd) {
+ printf("Cannot create file\n");
+ return 1;
+ }
+
+ const int freq_start = 1750 - 175;
+ const int freq_stop = 1750 + 175;
+
+ for (int freq = freq_start; freq < freq_stop; freq += 20) {
+ for (int threshold = 800; threshold < 8000; threshold += 80) {
+ tone_init(threshold);
+
+ for (size_t j = 0; j < 200; j++) {
+ float samplef = cosf(2.0f * FLOAT_PI * freq / AUDIO_IN_RATE);
+ int16_t sample = samplef * 32767.0f;
+ int r = tone_detect_1750(sample);
+ if (r != -1) {
+ fprintf(fd, "%d,%d,%zu,%d\n",freq, threshold, j, r);
+ }
+ }
+ }
+ }
+}