From 95f9750a4f443c663d251eb1bd04d3f996947914 Mon Sep 17 00:00:00 2001 From: nathael Pajani Date: Thu, 19 Nov 2015 15:09:02 +0100 Subject: [PATCH] Move the host app for microphone to the right app directory ... --- microphone/host_rx/Makefile | 32 ++++++++++++ microphone/host_rx/main.c | 99 +++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 microphone/host_rx/Makefile create mode 100644 microphone/host_rx/main.c diff --git a/microphone/host_rx/Makefile b/microphone/host_rx/Makefile new file mode 100644 index 0000000..42a7b1d --- /dev/null +++ b/microphone/host_rx/Makefile @@ -0,0 +1,32 @@ +#CROSS_COMPILE ?= arm-linux-gnueabihf- +CC = $(CROSS_COMPILE)gcc + +CFLAGS = -Wall -O2 -Wextra + +EXEC = adc_rx + +all: $(EXEC) + + +OBJDIR = objs +SRC = $(shell find . -name \*.c) +OBJS = ${SRC:%.c=${OBJDIR}/%.o} +INCLUDES = includes/ + +${OBJDIR}/%.o: %.c + @mkdir -p $(dir $@) + @echo "-- compiling" $< + @$(CC) -MMD -MP -MF ${OBJDIR}/$*.d $(CFLAGS) $< -c -o $@ -I$(INCLUDES) + +$(EXEC): $(OBJS) + @echo "Linking $@ ..." + @$(CC) $(LDFLAGS) -o $@ $(OBJS) + @echo Done. + + +clean: + find ${OBJDIR} -name "*.o" -exec rm {} \; + find ${OBJDIR} -name "*.d" -exec rm {} \; + +mrproper: clean + rm -f $(EXEC) diff --git a/microphone/host_rx/main.c b/microphone/host_rx/main.c new file mode 100644 index 0000000..43a3c2c --- /dev/null +++ b/microphone/host_rx/main.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * ADC Rx test + * main.c + * + * Copyright 2013-2014 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 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 General Public License + * along with this program. If not, see . + * + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#define SERIAL_BAUD B1152000 + +int serial_setup(char* name) +{ + struct termios tio; + int fd = -1; + + /* Open serial port */ + fd = open(name, O_RDWR | O_NONBLOCK); + if (fd < 0) { + perror("Unable to open communication with companion chip"); + return -1; + } + /* Setup serial port */ + memset(&tio, 0, sizeof(tio)); + tio.c_cflag = CS8 | CREAD | CLOCAL; /* 8n1, see termios.h for more information */ + tio.c_cc[VMIN] = 1; + tio.c_cc[VTIME] = 5; + cfsetospeed(&tio, SERIAL_BAUD); + cfsetispeed(&tio, SERIAL_BAUD); + tcsetattr(fd, TCSANOW, &tio); + + return fd; +} + + + +int main(int argc, char* argv[]) +{ + int tty_fd = -1; + int out_fd = 1; + + /* Need Serial port and destination file as parameter */ + if (argc != 3) { + printf("Need tty device number and destination file\n"); + printf("Please start with %s /dev/ttyUSB0 raw_audio (for example)\n", argv[0]); + return -1; + } + + /* Open tty */ + tty_fd = serial_setup(argv[1]); + if (tty_fd < 0) { + printf("Unable to open specified serial port %s\n", argv[1]); + return -4; + } + + /* And never stop getting data ! */ + while (1) { + char buf[BUF_SIZE]; + int ret = 0, len = 0; + + memset(buf, 0, BUF_SIZE); + len = read(tty_fd, buf, BUF_SIZE); + + } /* End of infinite loop */ + + close(tty_fd); + close(out_fd); + return 0; +} + + -- 2.43.0