Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working OS/X build #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PLATFORM := $(shell uname -s)
LIBSOURCES = fft_fftw.c libcsdr_wrapper.c
#SOURCES = csdr.c $(LIBSOURCES)
cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
ifeq ($(PLATFORM),Darwin)
CPUFEATURES = $(shell sysctl -a | grep machdep.cpu.features | tr [A-Z] [a-z])
cpufeature = $(if $(findstring $(1),$(CPUFEATURES)),$(2))
endif
PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) $(call cpufeature,sse4a,-msse4a) $(call cpufeature,sse4_1,-msse4.1) $(call cpufeature,sse4_2,-msse4.2 -msse4) -mfpmath=sse
PARAMS_NEON = -mfloat-abi=hard -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS
#tnx Jan Szumiec for the Raspberry Pi support
Expand All @@ -37,6 +42,10 @@ PARAMS_ARM = $(if $(call cpufeature,BCM2708,dummy-text),$(PARAMS_RASPI),$(PARAMS
PARAMS_SIMD = $(if $(call cpufeature,sse,dummy-text),$(PARAMS_SSE),$(PARAMS_ARM))
PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
ifeq ($(PLATFORM),Darwin)
PARAMS_LOOPVECT = -O3 -ffast-math
PARAMS_LIBS = -g -lm -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
endif
PARAMS_SO = -fpic
PARAMS_MISC = -Wno-unused-result
#DEBUG_ON = 0 #debug is always on by now (anyway it could be compiled with `make DEBUG_ON=1`)
Expand All @@ -45,6 +54,10 @@ FFTW_PACKAGE = fftw-3.3.3
PREFIX ?= /usr
SOVERSION = 0.15
PARSEVECT ?= yes
SONAME = -soname
ifeq ($(PLATFORM),Darwin)
SONAME = -install_name
endif

.PHONY: clean-vect clean codequality checkdocs v
all: codequality csdr nmux
Expand All @@ -53,7 +66,7 @@ libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastd
@echo Auto-detected optimization parameters: $(PARAMS_SIMD)
@echo
rm -f dumpvect*.vect
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -Wl,-soname,libcsdr.so.$(SOVERSION) -o libcsdr.so.$(SOVERSION)
gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -Wl,$(SONAME),libcsdr.so.$(SOVERSION) -o libcsdr.so.$(SOVERSION)
@ln -fs libcsdr.so.$(SOVERSION) libcsdr.so
ifeq ($(PARSEVECT),yes)
-./parsevect dumpvect*.vect
Expand All @@ -77,10 +90,14 @@ install: all
install -m 0755 csdr-fm $(PREFIX)/bin
install -m 0755 nmux $(PREFIX)/bin
#-install -m 0755 ddcd $(PREFIX)/bin
ifneq ($(PLATFORM),Darwin)
@ldconfig || echo please run ldconfig
endif
uninstall:
rm $(PREFIX)/lib/libcsdr.so.$(SOVERSION) $(PREFIX)/bin/csdr $(PREFIX)/bin/csdr-fm
ifneq ($(PLATFORM),Darwin)
ldconfig
endif
disasm:
objdump -S libcsdr.so.$(SOVERSION) > libcsdr.disasm
emcc-clean:
Expand Down
44 changes: 35 additions & 9 deletions csdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "fastddc.h"
#include <assert.h>

#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif

// Use clock_gettime in linux, clock_get_time in OS X.
void get_monotonic_time(struct timespec *ts){
#ifdef __MACH__
clock_serv_t cclock;
mach_timespec_t mts;
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
clock_get_time(cclock, &mts);
mach_port_deallocate(mach_task_self(), cclock);
ts->tv_sec = mts.tv_sec;
ts->tv_nsec = mts.tv_nsec;
#else
clock_gettime(CLOCK_MONOTONIC_RAW, ts);
#endif
}

char usage[]=
"csdr - a simple commandline tool for Software Defined Radio receiver DSP.\n\n"
"usage: \n\n"
Expand Down Expand Up @@ -366,20 +386,24 @@ int initialize_buffers()
buffer_u8 = (unsigned char*)malloc(the_bufsize*sizeof(unsigned char));
buffer_i16 = (short*) malloc(the_bufsize*sizeof(short));
temp_f = (float*) malloc(the_bufsize*sizeof(float) * 4);
#ifndef __APPLE__
if(the_bufsize<=4096) //this is hacky, should be done correctly
{
fcntl(STDIN_FILENO, F_SETPIPE_SZ, 4096);
fcntl(STDOUT_FILENO, F_SETPIPE_SZ, 4096);
}
#endif
return the_bufsize;
}

int sendbufsize(int size)
{
#ifndef __APPLE__
if(size<=4096)
{
fcntl(STDOUT_FILENO, F_SETPIPE_SZ, 4096);
}
#endif
//The first word is a preamble, "csdr".
//If the next csdr process detects it, sets the buffer size according to the second word
if(!env_csdr_dynamic_bufsize_on) return env_csdr_fixed_bufsize;
Expand Down Expand Up @@ -424,8 +448,10 @@ int main(int argc, char *argv[])
if(argc<=1) return badsyntax(0);
if(!strcmp(argv[1],"--help")) return badsyntax(0);

#ifndef __APPLE__
fcntl(STDIN_FILENO, F_SETPIPE_SZ, 65536*32);
fcntl(STDOUT_FILENO, F_SETPIPE_SZ, 65536*32);
#endif
//fprintf(stderr, "csdr: F_SETPIPE_SZ\n");

if(!strcmp(argv[1],"setbuf"))
Expand Down Expand Up @@ -1793,15 +1819,15 @@ int main(int argc, char *argv[])
//initialize FFT library, and measure time
errhead(); fprintf(stderr,"initializing... ");
struct timespec start_time, end_time;
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
get_monotonic_time(&start_time);
FFT_PLAN_T* plan=make_fft_c2c(fft_size,input,output,1,benchmark);
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
get_monotonic_time(&end_time);
fprintf(stderr,"done in %g seconds.\n",TIME_TAKEN(start_time,end_time));

//do the actual measurement about the FFT
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
get_monotonic_time(&start_time);
for(int i=0;i<fft_cycles;i++) fft_execute(plan);
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
get_monotonic_time(&end_time);
float time_taken_fft = TIME_TAKEN(start_time,end_time);
errhead(); fprintf(stderr,"%d transforms of %d processed in %g seconds, %g seconds each.\n",fft_cycles,fft_size,time_taken_fft,time_taken_fft/fft_cycles);
return 0;
Expand Down Expand Up @@ -2004,11 +2030,11 @@ int main(int argc, char *argv[])
if(flowcontrol_is_buffering)
{
fprintf(stderr, "flowcontrol: buffering, flowcontrol_bufindex = %d\n", flowcontrol_bufindex);
if(flowcontrol_bufindex==flowcontrol_bufsize) { flowcontrol_is_buffering = 0; clock_gettime(CLOCK_MONOTONIC_RAW, &start_time); }
if(flowcontrol_bufindex==flowcontrol_bufsize) { flowcontrol_is_buffering = 0; get_monotonic_time(&start_time); }
else if(read_return<=0) continue;
}
else {
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
get_monotonic_time(&end_time);
int thrust_added=0;
while( (all_bytes_written+thrust*flowcontrol_readsize) / TIME_TAKEN(start_time,end_time) < data_rate )
{
Expand All @@ -2017,7 +2043,7 @@ int main(int argc, char *argv[])
//if(!(test++%10)) fprintf(stderr, "abw=%g\n", all_bytes_written / TIME_TAKEN(start_time,end_time));
/*if(!thrust_added && TIME_TAKEN(start_time,end_time)>50)
{
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
get_monotonic_time(&start_time);
all_bytes_written=0;
}*/
while(all_bytes_written>data_rate && TIME_TAKEN(start_time,end_time)>1)
Expand Down Expand Up @@ -2063,11 +2089,11 @@ int main(int argc, char *argv[])
if(!time_now_sec)
{
time_now_sec=1;
clock_gettime(CLOCK_MONOTONIC_RAW, &start_time);
get_monotonic_time(&start_time);
}
else
{
clock_gettime(CLOCK_MONOTONIC_RAW, &end_time);
get_monotonic_time(&end_time);
float timetaken;
if(time_now_sec<(timetaken=TIME_TAKEN(start_time,end_time)))
{
Expand Down
7 changes: 7 additions & 0 deletions nmux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,13 @@ void* client_thread (void* param)
if(set_nonblocking(this_client->socket))
error_exit(MSG_START "cannot set_nonblocking() on this_client->socket");

#ifdef __APPLE__
int sockopt = 1;
if( setsockopt(this_client->socket, SOL_SOCKET, SO_NOSIGPIPE, (char *)&sockopt, sizeof(sockopt)) == -1 )
error_exit(MSG_START "cannot set SO_NOSIGPIPE");
#define MSG_NOSIGNAL 0
#endif

int client_buffer_index = 0;
int client_goto_source = 0;
char* pool_read_buffer = NULL;
Expand Down