Mercurial > hg > beaglert
changeset 64:b89dd0c97a04 newapi
added Makefile, added default_main, added error checking in scripts
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 15 Jul 2015 19:59:29 +0100 |
parents | 3ada83df91a5 |
children | 22dd19d0cdd3 |
files | Makefile core/default_main.cpp scripts/build_project.sh scripts/setup_board.sh |
diffstat | 4 files changed, 266 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Wed Jul 15 19:59:29 2015 +0100 @@ -0,0 +1,139 @@ +# BeagleRT +# Low-latency, real-time audio and sensor processing on BeagleBone Black +# (c) 2015 Andrew McPherson, Victor Zappi, Giulio Moro +# Centre for Digital Music, Queen Mary University of London + +# This Makefile is intended for use on the BeagleBone Black itself +# and not for cross-compiling + +RM := rm -rf +STATIC_LIBS := ./libprussdrv.a ./libNE10.a +LIBS := -lrt -lnative -lxenomai + +ASM_SRCS := $(wildcard source/*.S) +ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o))) +ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d))) + +C_SRCS := $(wildcard source/*.c) +C_OBJS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.o))) +C_DEPS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.d))) + +CPP_SRCS := $(wildcard source/*.cpp) +CPP_OBJS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.o))) +CPP_DEPS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.d))) + +# Core BeagleRT sources +CORE_CPP_SRCS := \ +./core/GPIOcontrol.cpp \ +./core/I2c_Codec.cpp \ +./core/PRU.cpp \ +./core/RTAudio.cpp \ +./core/RTAudioCommandLine.cpp \ +./core/Utilities.cpp \ +./core/client.cpp + +CORE_OBJS := \ +./build/core/GPIOcontrol.o \ +./build/core/I2c_Codec.o \ +./build/core/PRU.o \ +./build/core/RTAudio.o \ +./build/core/RTAudioCommandLine.o \ +./build/core/Utilities.o \ +./build/core/client.o + +CORE_CPP_DEPS := \ +./build/core/GPIOcontrol.d \ +./build/core/I2c_Codec.d \ +./build/core/PRU.d \ +./build/core/RTAudio.d \ +./build/core/RTAudioCommandLine.d \ +./build/core/Utilities.d \ +./build/core/client.d + +# Objects for a system-supplied default main() file, if the user +# only wants to provide the render functions. +DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp +DEFAULT_MAIN_OBJS := ./build/core/default_main.o +DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d + +# All = build BeagleRT +all: BeagleRT + +# Rule for BeagleRT core C++ files +build/core/%.o: ./core/%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 -O2 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + +# Rule for user-supplied C++ files +build/source/%.o: ./source/%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I./include -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 -O2 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + +# Rule for user-supplied C files +build/source/%.o: ./source/%.c + @echo 'Building file: $<' + @echo 'Invoking: GCC C Compiler' + gcc -I./include -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 -O2 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + +# Rule for user-supplied assembly files +build/source/%.o: ./source/%.S + @echo 'Building file: $<' + @echo 'Invoking: GCC Assembler' + as -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + +# This is a nasty kludge: we want to be able to optionally link in a default +# main file if the user hasn't supplied one. We check for the presence of the main() +# function, and conditionally call one of two recursive make targets depending on whether +# we want to link in the default main file or not. The kludge is the mess of a shell script +# line below. Surely there's a better way to do this? +BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) + $(eval NEXT_TARGET := $(shell bash -c 'if [ `nm build/source/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "BeagleRT_with_main"; else echo "BeagleRT_without_main"; fi')) + $(MAKE) $(NEXT_TARGET) + @echo 'Finished building target: $@' + @echo ' ' +# $(MAKE) --no-print-directory post-build + +# Rule for building BeagleRT including the default main file (no user-supplied main()) +BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) + @echo 'Building target: $@' + @echo 'Invoking: GCC C++ Linker' + g++ -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "BeagleRT" $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) + +# Rule for building BeagleRT without the default main file (user-supplied main()) +BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) + @echo 'Building target: $@' + @echo 'Invoking: GCC C++ Linker' + g++ -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "BeagleRT" $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) + +# Other Targets: + +# Remove the temporary user-supplied source, plus the objects built from them +sourceclean: + -$(RM) source/* build/source/* BeagleRT + -@echo ' ' + +# Remove all the built objects, including the core BeagleRT objects +distclean: + -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT + -@echo ' ' + +# Remove only the user-generated objects +clean: + -$(RM) build/source/* BeagleRT + -@echo ' ' + +post-build: +# Nothing to do here (for now) + +.PHONY: all clean distclean sourceclean dependents +.SECONDARY: post-build
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/default_main.cpp Wed Jul 15 19:59:29 2015 +0100 @@ -0,0 +1,91 @@ +/* + * default_main.cpp + * + * Created on: Oct 24, 2014 + * Author: parallels + */ +#include <unistd.h> +#include <iostream> +#include <cstdlib> +#include <libgen.h> +#include <signal.h> +#include <getopt.h> +#include "../include/BeagleRT.h" + +using namespace std; + +// Handle Ctrl-C by requesting that the audio rendering stop +void interrupt_handler(int var) +{ + gShouldStop = true; +} + +// Print usage information +void usage(const char * processName) +{ + cerr << "Usage: " << processName << " [options]" << endl; + + BeagleRT_usage(); + + cerr << " --help [-h]: Print this menu\n"; +} + +int main(int argc, char *argv[]) +{ + BeagleRTInitSettings settings; // Standard audio settings + + struct option customOptions[] = + { + {"help", 0, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + // Set default settings + BeagleRT_defaultSettings(&settings); + + // Parse command-line arguments + while (1) { + int c; + if ((c = BeagleRT_getopt_long(argc, argv, "h", customOptions, &settings)) < 0) + break; + switch (c) { + case 'h': + usage(basename(argv[0])); + exit(0); + case '?': + default: + usage(basename(argv[0])); + exit(1); + } + } + + // Initialise the PRU audio device + if(BeagleRT_initAudio(&settings, 0) != 0) { + cout << "Error: unable to initialise audio" << endl; + return -1; + } + + // Start the audio device running + if(BeagleRT_startAudio()) { + cout << "Error: unable to start real-time audio" << endl; + return -1; + } + + // Set up interrupt handler to catch Control-C and SIGTERM + signal(SIGINT, interrupt_handler); + signal(SIGTERM, interrupt_handler); + + // Run until told to stop + while(!gShouldStop) { + usleep(100000); + } + + // Stop the audio device + BeagleRT_stopAudio(); + + // Clean up any resources allocated for audio + BeagleRT_cleanupAudio(); + + // All done! + return 0; +}
--- a/scripts/build_project.sh Wed Jul 15 19:46:51 2015 +0100 +++ b/scripts/build_project.sh Wed Jul 15 19:59:29 2015 +0100 @@ -44,15 +44,18 @@ # Check that we have a directory containing at least one source file # as an argument + if [ -z "$1" ] then usage exit fi -C_FILES=$(find "$1" -maxdepth 1 -type f -name "*.c") -CPP_FILES=$(find "$1" -maxdepth 1 -type f -name "*.cpp") -ASM_FILES=$(find "$1" -maxdepth 1 -type f -name "*.S") +FIND_STRING="find $* -maxdepth 10000 -type f " + +C_FILES=$($FIND_STRING -name "*.c") +CPP_FILES=$($FIND_STRING -name "*.cpp") +ASM_FILES=$($FIND_STRING -name "*.S") if [[ -z $C_FILES ]] && [[ -z $CPP_FILES ]] && [[ -z $ASM_FILES ]] then @@ -64,11 +67,31 @@ # Stop BeagleRT and clean out old source files echo "Stopping BeagleRT and removing old source files..." -ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT ; sleep 0.5; make sourceclean -C $BBB_PATH" +ssh -t -t $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT ; make sourceclean -C $BBB_PATH" + +#concatenate arguments to form path. +BBB_SOURCE_PATH= #initially empty, will be filled with input arguments +for i in "$@" #parse input arguments +do + if [ -d "$1" ] #check if the path is a folder + then #if it is, include all of its files + BBB_SOURCE_PATH+=" ${1}/* " + else + BBB_SOURCE_PATH+=" $1 " + fi + shift + # Copy new souce files to the board +done # Copy new source files to the board echo "Copying new source files to BeagleBone..." -scp "$1"/* "$BBB_ADDRESS:$BBB_PATH/source/" +scp $BBB_SOURCE_PATH "$BBB_ADDRESS:$BBB_PATH/source/" + +if [ $? -ne 0 ] +then + echo "Error while copying files" + exit +fi # Make new BeagleRT executable and run if [ $RUN_PROJECT -eq 0 ] @@ -77,5 +100,5 @@ ssh $BBB_ADDRESS "make all -C $BBB_PATH" else echo "Building and running project..." - ssh $BBB_ADDRESS "make all -C $BBB_PATH ; screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" + ssh $BBB_ADDRESS "make all -C $BBB_PATH && screen -S BeagleRT -d -m $BBB_PATH/BeagleRT $COMMAND_ARGS" fi \ No newline at end of file
--- a/scripts/setup_board.sh Wed Jul 15 19:46:51 2015 +0100 +++ b/scripts/setup_board.sh Wed Jul 15 19:59:29 2015 +0100 @@ -44,16 +44,20 @@ then # Stop BeagleRT if running and remove all files echo "Stopping BeagleRT and removing old files." - ssh $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT ; sleep 0.5 ; rm -rf $BBB_PATH ; mkdir $BBB_PATH" + ssh $BBB_ADDRESS "screen -X -S BeagleRT quit ; pkill BeagleRT; sleep 0.5 ; rm -rf $BBB_PATH ; mkdir $BBB_PATH" # Copy relevant files to BeagleBone Black echo "Copying new files to BeagleBone..." scp -r $SCRIPTDIR/../core $SCRIPTDIR/../include $SCRIPTDIR/../Makefile $SCRIPTDIR/../libNE10.a $SCRIPTDIR/../libprussdrv.a $BBB_ADDRESS:$BBB_PATH + if [ $? -ne 0 ] + then + echo "Error while copying files" + exit + fi # Make remaining directories needed for building echo "Creating directory structure on BeagleBone..." - ssh $BBB_ADDRESS "mkdir $BBB_PATH/source ; mkdir $BBB_PATH/build ; mkdir $BBB_PATH/build/core ; mkdir $BBB_PATH/build/source" - + ssh $BBB_ADDRESS "mkdir -p $BBB_PATH/source ; mkdir -p $BBB_PATH/build ; mkdir -p $BBB_PATH/build/core ; mkdir -p $BBB_PATH/build/source" &&\ echo "Done." fi