Permalink
Browse files

Building core Bela library (libbela). It includes libprussdrv, which …

…has been recompiled with -fPIC. A small step for #266
  • Loading branch information...
giuliomoro committed Mar 26, 2017
1 parent 144558a commit a3097808fd5247cf85ce5bd6e3975e3b549ccfb9
Showing with 64 additions and 50 deletions.
  1. +19 −11 Makefile
  2. +41 −0 core/Gpio.cpp
  3. +4 −39 include/Gpio.h
  4. BIN lib/libprussdrv.a
View
@@ -20,7 +20,7 @@
.DEFAULT_GOAL := Bela
AT?=@
NO_PROJECT_TARGETS=help coreclean distclean stop nostartup connect idestart idestop idestartup idenostartup ideconnect scsynthstart scsynthstop scsynthconnect scsynthstartup scsynthnostartup update checkupdate updateunsafe lib
NO_PROJECT_TARGETS=help coreclean distclean stop nostartup connect idestart idestop idestartup idenostartup ideconnect scsynthstart scsynthstop scsynthconnect scsynthstartup scsynthnostartup update checkupdate updateunsafe lib libbela.so
NO_PROJECT_TARGETS_MESSAGE=PROJECT or EXAMPLE should be set for all targets except: $(NO_PROJECT_TARGETS)
# list of targets that automatically activate the QUIET=true flag
QUIET_TARGETS=runide
@@ -174,7 +174,8 @@ CORE_C_DEPS := $(addprefix build/core/,$(notdir $(CORE_C_SRCS:.c=.d)))
CORE_CPP_SRCS = $(filter-out core/default_main.cpp core/default_libpd_render.cpp, $(wildcard core/*.cpp))
CORE_OBJS := $(CORE_OBJS) $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
EXTRA_CORE_OBJS := $(filter-out build/core/RTAudio.o build/core/PRU.o build/core/RTAudioCommandLine.o, $(CORE_OBJS))
CORE_CORE_OBJS := build/core/RTAudio.o build/core/PRU.o build/core/RTAudioCommandLine.o build/core/I2c_Codec.o build/core/math_runfast.o build/core/GPIOcontrol.o
EXTRA_CORE_OBJS := $(filter-out $(CORE_CORE_OBJS), $(CORE_OBJS))
CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
CORE_ASM_SRCS := $(wildcard core/*.S)
@@ -492,19 +493,26 @@ update: stop
echo Update succesful $(LOG); \
' $(LOG)
LIB_SO ?= libbelaextra.so
LIB_A ?= libbelaextra.a
LIB_OBJS ?= $(EXTRA_CORE_OBJS)
lib: $(LIB_SO) $(LIB_A)
LIB_EXTRA_SO = libbelaextra.so
LIB_EXTRA_A = libbelaextra.a
LIB_EXTRA_OBJS = $(EXTRA_CORE_OBJS)
$(LIB_EXTRA_SO): $(LIB_EXTRA_OBJS)
gcc -shared -Wl,-soname,$(LIB_EXTRA_SO) $(LDLIBS) -o lib/$(LIB_EXTRA_SO) $(LIB_EXTRA_OBJS) $(LDFLAGS)
$(LIB_EXTRA_A): $(LIB_EXTRA_OBJS) $(PRU_OBJS) $(LIB_DEPS)
ar rcs lib/$(LIB_EXTRA_A) $(LIB_EXTRA_OBJS)
LIB_SO =libbela.so
LIB_A = libbela.a
LIB_OBJS = $(CORE_CORE_OBJS) build/core/AuxiliaryTasks.o lib/libprussdrv.a
$(LIB_SO): $(LIB_OBJS)
gcc -shared -Wl,-soname,$(LIB_SO) $(LDLIBS) \
-o build/$(LIB_SO) $(LIB_OBJS) $(LDFLAGS)
gcc -shared -Wl,-soname,$(LIB_SO) $(LDLIBS) -o lib/$(LIB_SO) $(LIB_OBJS) $(LDFLAGS)
$(LIB_A): $(LIB_OBJS) $(PRU_OBJS) $(LIB_DEPS)
ar rcs build/$(LIB_A) $(LIB_OBJS)
ar rcs lib/$(LIB_A) $(LIB_OBJS)
lib: lib/libbelaextra.so lib/libbelaextra.a lib/libbela.so lib/libbela.a
View
@@ -0,0 +1,41 @@
#include "../include/Gpio.h"
int Gpio::open(unsigned int pin, unsigned int direction){
if(pin >= 128){
return -1;
}
if(fd != -1){
close();
}
oldPin = pin;
// gpio_export can fail if the pin has already been exported.
// We don't care.
gpio_export(pin);
if(gpio_set_dir(pin, direction) < 0){
return -1;
}
fd = ::open("/dev/mem", O_RDWR);
int bank = pin / 32;
pin = pin - bank * 32;
pinMask = 1 << pin;
uint32_t gpioBase = GPIO_ADDRESSES[bank];
gpio = (uint32_t *)mmap(0, GPIO_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpioBase);
if(gpio == MAP_FAILED){
fprintf(stderr, "Unable to map GPIO pin %u\n", pin);
return -2;
}
// actually use the memmapped memory,
// to avoid mode switches later:
// read the current value
int value = read();
// and write it back
write(value);
return 0;
}
void Gpio::close(){
gpio_unexport(oldPin);
::close(fd);
oldPin = -1;
fd = -1;
}
View
@@ -48,48 +48,13 @@ class Gpio{
*
* @return 0 if success, -1 otherwise;
*/
int open(unsigned int pin, unsigned int direction){
if(pin >= 128){
return -1;
}
if(fd != -1){
close();
}
oldPin = pin;
// gpio_export can fail if the pin has already been exported.
// We don't care.
gpio_export(pin);
if(gpio_set_dir(pin, direction) < 0){
return -1;
}
fd = ::open("/dev/mem", O_RDWR);
int bank = pin / 32;
pin = pin - bank * 32;
pinMask = 1 << pin;
uint32_t gpioBase = GPIO_ADDRESSES[bank];
gpio = (uint32_t *)mmap(0, GPIO_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, gpioBase);
if(gpio == MAP_FAILED){
fprintf(stderr, "Unable to map GPIO pin %u\n", pin);
return -2;
}
// actually use the memmapped memory,
// to avoid mode switches later:
// read the current value
int value = read();
// and write it back
write(value);
return 0;
}
int open(unsigned int pin, unsigned int direction);
/**
* Closes a currently open GPIO
*/
void close(){
gpio_unexport(oldPin);
::close(fd);
oldPin = -1;
fd = -1;
}
void close();
/**
* Read the GPIO value.
* @return the GPIO value
View
Binary file not shown.

0 comments on commit a309780

Please sign in to comment.