Commit ade70793 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Builds for atsam

using:   $ ./configure --host arm-none-eabihf --disable-vesp --disable-am335x --disable-ethercat CFLAGS=-specs /usr/local/arm-none-eabihf/lib/atsamx70x21_flash.specs
(add quotes to spec argument)
parent 51502aac
......@@ -118,8 +118,8 @@ TARGETS:= $$($(DIR)_TMPTARGETS) $$(TARGETS)
DIR := $(DIR)
endef
CFLAGS := -pthread -D_GNU_SOURCE -Icommon -Icommon/include -Icontroller -Iconsole/console -Iinclude
LDFLAGS := -pthread -Lcommon/lib -Lcontroller/lib -Lconsole/console/lib -Llib -Wl,--as-needed
CFLAGS := $(BUILD_CFLAGS) -D_GNU_SOURCE -Icommon -Icommon/include -Icontroller -Iconsole/console -Iinclude
LDFLAGS := -Lcommon/lib -Lcontroller/lib -Lconsole/console/lib -Llib -Wl,--as-needed
VPATH += common/lib controller/lib console/console/lib lib
VPATH += include
......
......@@ -43,7 +43,7 @@ endif
%: %.o
@echo " LD $@"
@${LIBTOOL} --quiet --mode=link --tag=CC $(LINK.o) $(filter %.o,$^) $(LOADLIBS) $(LDLIBS) $($@_LDFLAGS) -o $@
${LIBTOOL} --quiet --mode=link --tag=CC $(LINK.o) $(filter %.o,$^) $(LOADLIBS) $(LDLIBS) $($@_LDFLAGS) $(CFLAGS) -o $@
%.lo: %.c
@echo "LT CC $<"
......
......@@ -10,5 +10,12 @@ BUILD_CONSOLE_J2000_INDI=@BUILD_CONSOLE_J2000_INDI@
BUILD_ETHERCAT=@BUILD_ETHERCAT@
BUILD_VESP=@BUILD_VESP@
BUILD_AM335X=@BUILD_AM335X@
BUILD_LINUX_JOYSTICK=@BUILD_LINUX_JOYSTICK@
BUILD_TEST=@BUILD_TEST@
BUILD_PTHREAD=@BUILD_PTHREAD@
BUILD_TCP=@BUILD_TCP@
BUILD_DYNAMICLINKING=@BUILD_DYNAMICLINKING@
BUILD_CFLAGS=@CFLAGS@ @CFLAGS_PTHREAD@ @CFLAGS_TCP@ @CFLAGS_FILEIO@
ifdef BUILD_TCP
COMMAND_TARGETS += $(LIBDIR)/libcommand.la
COMMAND_TARGETS += $(DIR)/command_list $(DIR)/command_send
ifneq ($(OS), FreeBSD)
ifdef BUILD_LINUX_JOYSTICK
COMMAND_TARGETS += $(DIR)/command_joystick
endif
......@@ -46,3 +48,5 @@ CLEAN += $(COMMAND_TARGETS) $(ARCHOBJS) \
$(COMMAND_SEND_OBJS) \
$(COMMAND_JOYSTICK_OBJS) \
$(LIBDIR)/libcommand.a
endif
......@@ -18,6 +18,9 @@
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/joystick.h>
#include <command/command.h>
#include <dt_port_numbers.h>
......
ifdef BUILD_TCP
ARCHSRCS = $(DIR)/log.c
else
ARCHSRCS = $(DIR)/log_std.c
endif
ARCHOBJS = $(ARCHSRCS:.c=.lo)
SRCS+=$(ARCHSRCS)
......@@ -7,8 +12,10 @@ SRCS+=$(ARCHSRCS)
TARGETS += $(LIBDIR)/liblog.la
$(ARCHOBJS): CFLAGS += -Wall -O3 -fPIC
ifdef BUILD_TCP
$(LIBDIR)/liblog.la: libutils.la
$(LIBDIR)/liblog.la_LDFLAGS += -lutils
endif
$(LIBDIR)/liblog.la: $(ARCHOBJS)
$(LIB_LINK)
......
......@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <inttypes.h>
enum log_type {
LOG_T_ERROR,
......
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2008, 2013, 2014, 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2013
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 3 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 <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <log/log.h>
static enum log_type log_level_console;
static enum log_type log_level_remote;
static uint64_t def_timestamp(void)
{
static uint64_t ctr = 0;
return ctr++;
}
uint64_t (*log_timestamp)(void) = def_timestamp;
static char *logtype(enum log_type type)
{
switch(type) {
case LOG_T_ERROR:
return " ERROR: ";
case LOG_T_WARNING:
return "WARNING: ";
case LOG_T_INFO:
return " INFO: ";
case LOG_T_DEBUG:
return " DEBUG: ";
default:
return "UNKNOWN: ";
}
}
void log_send(enum log_type type, char *fmt, ...)
{
va_list ap;
if (log_level_console < type && log_level_remote < type)
return;
printf("%s", logtype(type));
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
int log_server_start(int port, enum log_type console_level,
enum log_type remote_level)
{
log_level_console = console_level;
log_level_remote = remote_level;
return 0;
}
void log_server_flush(void)
{
}
void log_level_set(enum log_type console_level, enum log_type remote_level)
{
log_level_console = console_level;
log_level_remote = remote_level;
}
int log_time_source_set(
uint64_t (*timestamp)(void),
void (*stamp2spec)(struct timespec *, uint64_t))
{
log_timestamp = timestamp;
return 0;
}
ifdef BUILD_TCP
TRACE_TARGETS += $(LIBDIR)/libtrace.la
TRACE_TARGETS += $(DIR)/trace_dump
TRACE_TARGETS += $(DIR)/trace_dumpdiff
......@@ -79,3 +81,5 @@ CLEAN += $(TRACE_LIST_OBJS)
CLEAN += $(TRACE_VIEW_OBJS)
CLEAN += $(TRACE2FILE_OBJS)
CLEAN += $(TRACE2PORT_OBJS)
endif
ifdef BUILD_TCP
TARGETS += $(LIBDIR)/libutils.la
TARGETS += $(DIR)/weather_test
......@@ -6,8 +7,8 @@ TARGETS += $(DIR)/weather_test
WEATHER_SRCS := $(DIR)/weather_test.c $(DIR)/weather.c $(DIR)/tcp_connect.c
WEATHER_OBJS := $(WEATHER_SRCS:.c=.o)
$(DIR)/weather_test_CFLAGS += -pthread
$(DIR)/weather_test_LDFLAGS += -pthread
$(DIR)/weather_test_CFLAGS +=
$(DIR)/weather_test_LDFLAGS += -lpthread
$(DIR)/weather_test: $(WEATHER_OBJS)
ARCHSRCS := $(DIR)/tcp_connect.c \
......@@ -22,8 +23,8 @@ ARCHSRCS := $(DIR)/tcp_connect.c \
ARCHOBJS := $(ARCHSRCS:.c=.lo)
LU_CFLAGS := -Wall -O3 -fPIC -pthread
LU_LDFLAGS := -lrt -lm
LU_CFLAGS := -Wall -O3 -fPIC
LU_LDFLAGS := -lrt -lm -lpthread
LU_CFLAGS += `pkg-config --cflags glib-2.0`
LU_LDFLAGS += `pkg-config --libs glib-2.0`
......@@ -39,3 +40,6 @@ CLEAN += $(DIR)/weather_test
CLEAN += $(WEATHER_OBJS) $(ARCHOBJS) $(LIBDIR)/libutils.a
SRCS += $(ARCHSRCS) $(WEATHER_SRCS)
endif
......@@ -105,13 +105,35 @@ AS_CASE(["$with_libnova"],
[AC_CHECK_HEADERS([libnova/libnova.h])]
)
#######################################################################
#
# Support for linux joystick
AC_CHECK_HEADER(linux/joystick.h,[HAVE_HEADER_LINUX_JOYSTICK=1],[HAVE_HEADER_LINUX_JOYSTICK=0])
#######################################################################
#
# Real OS or embedded?
AC_CHECK_LIB(pthread,pthread_attr_init,[HAVE_LIBPTHREAD=1],[HAVE_LIBPTHREAD=0])
AC_CHECK_LIB(c,realpath,[HAVE_FILEIO=1],[HAVE_FILEIO=0])
AC_CHECK_HEADER(sys/socket.h,[HAVE_TCP=1],[HAVE_TCP=0])
AC_CHECK_HEADER(semaphore.h,[HAVE_SEMAPHORE=1],[HAVE_SEMAPHORE=0])
AC_CHECK_HEADER(dlfcn.h,[HAVE_DYNAMICLINKING=1],[HAVE_DYNAMICLINKING=0])
#######################################################################
#
# Some conclusions based on test results
#
AS_IF([test "$enable_console" = "yes"],
AS_IF([test "$enable_console" = "yes" && test "$HAVE_TCP" = "1"],
[AC_SUBST(BUILD_CONSOLE,["yes"])],
[AC_SUBST(BUILD_CONSOLE,[""])])
......@@ -148,6 +170,43 @@ AS_IF([test "$enable_test" = "yes"],
[AC_SUBST(BUILD_TEST,["yes"])],
[AC_SUBST(BUILD_TEST,[""])])
AS_IF([test "$HAVE_LIBPTHREAD" = "1"],
[AC_SUBST(CFLAGS_PTHREAD,["-DHAVE_PTHREAD"])],
[AC_SUBST(CFLAGS_PTHREAD,[""])])
AS_IF([test "$HAVE_LIBPTHREAD" = "1"],
[AC_SUBST(BUILD_PTHREAD,["yes"])],
[AC_SUBST(BUILD_PTHREAD,[""])])
AS_IF([test "$HAVE_TCP" = "1"],
[AC_SUBST(CFLAGS_TCP,["-DHAVE_TCP"])],
[AC_SUBST(CFLAGS_TCP,[""])])
AS_IF([test "$HAVE_TCP" = "1"],
[AC_SUBST(BUILD_TCP,["yes"])],
[AC_SUBST(BUILD_TCP,[""])])
AS_IF([test "$HAVE_SEMAPHORE" = "1"],
[AC_SUBST(CFLAGS_TCP,["-DHAVE_SEMAPHORE"])],
[AC_SUBST(CFLAGS_TCP,[""])])
AS_IF([test "$HAVE_HEADER_LINUX_JOYSTICK" = "1"],
[AC_SUBST(BUILD_LINUX_JOYSTICK,["yes"])],
[AC_SUBST(BUILD_LINUX_JOYSTICK,[""])])
AS_IF([test "$HAVE_DYNAMICLINKING" = "1"],
[AC_SUBST(BUILD_DYNAMICLINKING,["yes"])],
[AC_SUBST(BUILD_DYNAMICLINKING,[""])])
AS_IF([test "$HAVE_FILEIO" = "1"],
[AC_SUBST(BUILD_FILEIO,["yes"])],
[AC_SUBST(BUILD_FILEIO,[""])])
AS_IF([test "$HAVE_FILEIO" = "1"],
[AC_SUBST(CFLAGS_FILEIO,["-DHAVE_FILEIO"])],
[AC_SUBST(CFLAGS_FILEIO,[""])])
#######################################################################
#
# Output
......@@ -192,6 +251,10 @@ AS_IF([test "$BUILD_VESP" != ""],
AC_MSG_NOTICE([ vesp: yes]),
AC_MSG_NOTICE([ vesp: no]))
AS_IF([test "$BUILD_LINUX_JOYSTICK" != ""],
AC_MSG_NOTICE([ linux joystick: yes]),
AC_MSG_NOTICE([ linux joystick: no]))
AS_IF([test "$BUILD_AM335X" != ""],
AC_MSG_NOTICE([ am335x: yes]),
AC_MSG_NOTICE([ am335x: no]))
......
......@@ -170,7 +170,7 @@ static struct controller_block * block_joystick_create(char *name, int argc, va_
block->output[outnr].type = CONTROLLER_BLOCK_TERM_BOOL;
block->output[outnr].value.b = &block->private->buttons[i];
block->output[outnr].source = block;
block->output[outnr].name = malloc(16);
block->output[outnr].name = malloc(20);
sprintf(block->output[outnr].name, "button%d", i);
}
......
......@@ -117,7 +117,7 @@ static void calculate(struct controller_block *block)
if ((INPUT(home) == true) && (VAR(last_home) == false)) {
// rising edge on 'home' input
if (pos != 0) {
log_send(LOG_T_DEBUG, "homing @ %d", pos);
log_send(LOG_T_DEBUG, "homing @ %"PRId32, pos);
}
pos = 0;
}
......
......@@ -107,7 +107,7 @@ static void calculate(struct controller_block *sm)
for (i = 0; i < priv->no; i++) {
priv->out[i] = state->out[i];
}
log_send(LOG_T_DEBUG, "%s: %d -> %d", sm->name,
log_send(LOG_T_DEBUG, "%s: %"PRId32" -> %"PRId32"", sm->name,
priv->state_table[cur_state].state,
priv->state_table[new_state].state);
}
......@@ -159,7 +159,7 @@ static void add_state(struct controller_block *sm, uint32_t state, bool *out)
priv->state_table[statenr].out[i] = out[i];
}
log_send(LOG_T_DEBUG, "%s: new state %d (%d)", sm->name, state, statenr);
log_send(LOG_T_DEBUG, "%s: new state %"PRId32" (%d)", sm->name, state, statenr);
}
static void add_transition(struct controller_block *sm,
......@@ -194,7 +194,7 @@ static void add_transition(struct controller_block *sm,
priv->state_table[statenr].transition_nr = nr + 1;
log_send(LOG_T_DEBUG, "%s: transition %d: %d -> %d (%d -> %d)",
log_send(LOG_T_DEBUG, "%s: transition %d: %"PRId32" -> %"PRId32" (%d -> %d)",
sm->name, nr, from, to, statenr, to_statenr);
}
......
......@@ -126,7 +126,7 @@ static void calculate(struct controller_block *player)
if (cur >= priv->nr) {
if (!priv->err)
log_send(LOG_T_ERROR,
"%s: Illegal select, trajectory %d not available!",
"%s: Illegal select, trajectory %"PRId32" not available!",
player->name, *priv->select);
priv->err = true;
} else {
......
......@@ -7,9 +7,6 @@ BLOCKS := \
add \
and \
bridge_pwm \
command_bool \
command_float \
command_uint32 \
controller_profile \
counter \
debug \
......@@ -38,9 +35,6 @@ BLOCKS := \
quantize \
random \
rangecheck \
setpoint_generator_1d \
setpoint_generator_3d \
servo_state \
sine \
state_machine \
subtract \
......@@ -54,6 +48,17 @@ BLOCKS := \
schmitt_trigger \
oneshot
ifdef BUILD_TCP
BLOCKS += \
command_bool \
command_float \
command_uint32 \
setpoint_generator_1d \
setpoint_generator_3d \
servo_state
endif
BLOCKS_IL := \
not \
or2 \
......@@ -70,7 +75,7 @@ BLOCKS_NO_C := \
ex2 \
value_float
ifneq ($(OS), FreeBSD)
ifdef BUILD_LINUX_JOYSTICK
BLOCKS+= \
joystick
endif
......
......@@ -25,6 +25,7 @@ $(DIR)/il2c: $(IL2C_OBJS)
# il2c is used in the build, not runtime
$(IL2C_OBJS): CC = $(BUILDCC)
$(DIR)/il2c: CC = $(BUILDCC)
$(DIR)/il2c: CFLAGS = -Wall -O2
$(DIR)/il2c: LIBTOOL = $(BUILDLIBTOOL)
......
......@@ -41,7 +41,6 @@ TRIGGERS += $(subst .la,,$(subst lib,-l,$(CTRL_TRIGGER_LIBS)))
$(DIR)/dt_ctrl: \
libcontroller.la \
liblog.la \
libshell.la \
$(CTRL_BLOCK_LIBS) \
$(CTRL_TRIGGER_LIBS)
$(DIR)/dt_ctrl_CFLAGS += -Wall -O3
......@@ -49,11 +48,18 @@ $(DIR)/dt_ctrl_LDFLAGS += \
-Wl,-E \
-lcontroller \
-llog \
-lshell \
$(BLOCKS) \
$(TRIGGERS)
$(DIR)/dt_ctrl: $(DT_CTRL_OBJS)
ifdef BUILD_TCP
$(DIR)/dt_ctrl: \
libshell.la
$(DIR)/dt_ctrl_LDFLAGS += \
-lshell
endif
# Make test reports as part of the test target
DT_CTRL_TESTS := $(CTRL_TESTS)
......
......@@ -4,31 +4,55 @@ CONTROLLER_TARGETS += $(LIBDIR)/libcontroller.la
CONTROLLER_SRCS= \
$(DIR)/controller_block.c \
$(DIR)/controller_block_param.c \
$(DIR)/controller_block_trace.c \
$(DIR)/controller_bus.c \
$(DIR)/controller_command.c \
$(DIR)/controller_mem.c \
$(DIR)/controller_module.c \
$(DIR)/controller_time.c \
$(DIR)/controller_trace.c \
$(DIR)/controller_sample.c \
$(DIR)/controller_sample_task.c \
$(DIR)/controller_dumpdot.c \
$(DIR)/controller_load.c \
$(DIR)/controller_load_variable.c \
$(DIR)/controller_load_parser.tab.c \
$(DIR)/controller_load_parser.yy.c
CONTROLLER_OBJS := $(CONTROLLER_SRCS:.c=.lo)
$(CONTROLLER_OBJS): CFLAGS += -g -Wall -pthread
$(LIBDIR)/libcontroller.la: libshell.la libcommand.la libtrace.la
$(LIBDIR)/libcontroller.la_LDFLAGS += -lshell -pthread -lrt -lcommand -ltrace
$(LIBDIR)/libcontroller.la_LDFLAGS += -lm
ifdef BUILD_FILEIO
CONTROLLER_SRCS+= \
$(DIR)/controller_dumpdot.c
endif
ifdef BUILD_DYNAMICLINKING
CONTROLLER_SRCS+= \
$(DIR)/controller_lib.c
ifneq ($(OS), FreeBSD)
$(LIBDIR)/libcontroller.la_LDFLAGS += -ldl
endif
else
CONTROLLER_SRCS+= \
$(DIR)/controller_lib_static.c
endif
ifdef BUILD_TCP
CONTROLLER_SRCS+= \
$(DIR)/controller_block_trace.c \
$(DIR)/controller_command.c \
$(DIR)/controller_trace.c
endif
CONTROLLER_OBJS := $(CONTROLLER_SRCS:.c=.lo)
$(CONTROLLER_OBJS): CFLAGS += -g -Wall
ifdef BUILD_TCP
$(LIBDIR)/libcontroller.la: libshell.la libcommand.la libtrace.la
$(LIBDIR)/libcontroller.la_LDFLAGS += -lshell -lpthread -lrt -lcommand -ltrace
endif
$(LIBDIR)/libcontroller.la: $(CONTROLLER_OBJS)
$(LIB_LINK)
......
......@@ -19,13 +19,10 @@
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <pthread.h>
#include <dlfcn.h>
#include <controller/controller_mem.h>
#include <controller/controller_block.h>
......@@ -33,6 +30,7 @@
#include <controller/controller_bus.h>
#include <controller/controller_time.h>
#include <controller/controller_load.h>
#include <controller/controller_lib.h>
#include <log/log.h>
int nr_blocks = 0;
......@@ -56,24 +54,15 @@ static char *controller_block_context = "unknown";
int controller_block_create(char *type, char *name, int argc, va_list ap,
char **arg_types)
{
void *handle;
struct controller_block_create *create;
struct controller_block_create *create = NULL;
char *prefix = BLOCK_PREFIX;
char *postfix_create = BLOCK_CREATE_POSTFIX;
char *symbol;
int ret = 0;
handle = dlopen(NULL, RTLD_NOW);
if (!handle) {
log_send(LOG_T_ERROR,
"Could not get handle from dlopen(): %s", dlerror());
return -1;
}
asprintf(&symbol, "%s%s%s", prefix, type, postfix_create);
// Try to load the block's module
create = dlsym(handle, symbol);
create = controller_lib_sym(symbol);
free(symbol);
if (create && create->create) {
......@@ -103,8 +92,6 @@ int controller_block_create(char *type, char *name, int argc, va_list ap,
}
err:
dlclose(handle);
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment