From: Nathael Pajani Date: Tue, 10 Nov 2015 20:36:09 +0000 (+0100) Subject: Commit of the simple ADC Rx test, used for audio sampling. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=aa1c0339b4bd2a7cc347fc9f483cca35d74355d9;p=soft%2Flpc122x%2Fexamples Commit of the simple ADC Rx test, used for audio sampling. --- diff --git a/adc/adc_rx/Makefile b/adc/adc_rx/Makefile new file mode 100644 index 0000000..42a7b1d --- /dev/null +++ b/adc/adc_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/adc/adc_rx/main.c b/adc/adc_rx/main.c new file mode 100644 index 0000000..43a3c2c --- /dev/null +++ b/adc/adc_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; +} + +