Browse Source

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)
jeroen
Jeroen Vreeken 3 years ago
parent
commit
ade7079324
38 changed files with 541 additions and 159 deletions
  1. +2
    -2
      Makefile
  2. +1
    -1
      build.mk
  3. +7
    -0
      buildflags.mk.in
  4. +5
    -1
      common/command/build.mk
  5. +3
    -0
      common/command/command_joystick.c
  6. +7
    -0
      common/log/build.mk
  7. +2
    -0
      common/log/log.h
  8. +103
    -0
      common/log/log_std.c
  9. +4
    -0
      common/trace/build.mk
  10. +8
    -4
      common/utils/build.mk
  11. +64
    -1
      configure.ac
  12. +1
    -1
      controller/block/block_joystick.c
  13. +1
    -1
      controller/block/block_quadrature_decoder.c
  14. +3
    -3
      controller/block/block_state_machine.c
  15. +1
    -1
      controller/block/block_trajectplayer.c
  16. +12
    -7
      controller/block/build.mk
  17. +1
    -0
      controller/block/il2c/build.mk
  18. +8
    -2
      controller/build.mk
  19. +32
    -8
      controller/controller/build.mk
  20. +4
    -17
      controller/controller/controller_block.c
  21. +0
    -2
      controller/controller/controller_block.h
  22. +2
    -0
      controller/controller/controller_block_trace.c
  23. +42
    -0
      controller/controller/controller_lib.c
  24. +23
    -0
      controller/controller/controller_lib.h
  25. +26
    -0
      controller/controller/controller_lib_static.c
  26. +10
    -0
      controller/controller/controller_load.c
  27. +4
    -0
      controller/controller/controller_load_parser.y
  28. +108
    -89
      controller/controller/controller_sample.c
  29. +2
    -0
      controller/controller/controller_sample.h
  30. +18
    -1
      controller/controller/controller_sample_task.c
  31. +3
    -3
      controller/controller/controller_trace.c
  32. +12
    -7
      controller/dt_ctrl.c
  33. +2
    -2
      controller/ec/build.mk
  34. +1
    -1
      controller/ec/eth_linux.c
  35. +6
    -2
      controller/shell/build.mk
  36. +5
    -2
      controller/test/build.mk
  37. +5
    -1
      controller/trigger/build.mk
  38. +3
    -0
      controller/vesp/vesp.h

+ 2
- 2
Makefile View File

@ -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


+ 1
- 1
build.mk View File

@ -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 $<"


+ 7
- 0
buildflags.mk.in View File

@ -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@

+ 5
- 1
common/command/build.mk View File

@ -1,9 +1,11 @@
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

+ 3
- 0
common/command/command_joystick.c View File

@ -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>


+ 7
- 0
common/log/build.mk View File

@ -1,5 +1,10 @@
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)


+ 2
- 0
common/log/log.h View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <inttypes.h>
enum log_type {
LOG_T_ERROR,


+ 103
- 0
common/log/log_std.c View File

@ -0,0 +1,103 @@
/*
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;
}

+ 4
- 0
common/trace/build.mk View File

@ -1,4 +1,6 @@
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

+ 8
- 4
common/utils/build.mk View File

@ -1,4 +1,5 @@
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

+ 64
- 1
configure.ac View File

@ -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]))


+ 1
- 1
controller/block/block_joystick.c View File

@ -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);
}


+ 1
- 1
controller/block/block_quadrature_decoder.c View File

@ -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;
}


+ 3
- 3
controller/block/block_state_machine.c View File

@ -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);
}


+ 1
- 1
controller/block/block_trajectplayer.c View File

@ -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 {


+ 12
- 7
controller/block/build.mk View File

@ -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


+ 1
- 0
controller/block/il2c/build.mk View File

@ -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)


+ 8
- 2
controller/build.mk View File

@ -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)


+ 32
- 8
controller/controller/build.mk View File

@ -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)


+ 4
- 17
controller/controller/controller_block.c View File

@ -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) {
@ -102,9 +91,7 @@ int controller_block_create(char *type, char *name, int argc, va_list ap,
ret = -1;
}
err:
dlclose(handle);
err:
return ret;
}


+ 0
- 2
controller/controller/controller_block.h View File

@ -23,8 +23,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdarg.h>
// Keep this enum in sync with the list in controller_block_term_type2str() in


+ 2
- 0
controller/controller/controller_block_trace.c View File

@ -24,6 +24,8 @@
#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <pthread.h>
#include <controller/controller_block.h>
#include <controller/controller_time.h>


+ 42
- 0
controller/controller/controller_lib.c View File

@ -0,0 +1,42 @@
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2018
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 <dlfcn.h>
#include <stdlib.h>
#include <log/log.h>
#include <controller/controller_lib.h>
void *controller_lib_sym(char *symbol_name)
{
void *sym;
void *handle;
handle = dlopen(NULL, RTLD_NOW);
if (!handle) {
log_send(LOG_T_ERROR,
"Could not get handle from dlopen(): %s", dlerror());
return NULL;
}
sym = dlsym(handle, symbol_name);
if (!sym) {
dlclose(handle);
}
return sym;
}

+ 23
- 0
controller/controller/controller_lib.h View File

@ -0,0 +1,23 @@
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2018
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/>.
*/
#ifndef _INCLUDE_CONTROLLER_LIB_H_
#define _INCLUDE_CONTROLLER_LIB_H_
void *controller_lib_sym(char *symbol_name);
#endif /*_INCLUDE_CONTROLLER_LIB_H_*/

+ 26
- 0
controller/controller/controller_lib_static.c View File

@ -0,0 +1,26 @@
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2018
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 <controller/controller_lib.h>
#include <stdlib.h>
void *controller_lib_sym(char *symbol_name)
{
//TODO stub for now
return NULL;
}

+ 10
- 0
controller/controller/controller_load.c View File

@ -551,7 +551,11 @@ int controller_load_import(yyscan_t scanner, char *rel_name)
return -1;
}
#ifdef HAVE_FILEIO
char *realname = realpath(file_name, NULL);
#else
char *realname = file_name;
#endif
if (!realname) {
log_send(LOG_T_ERROR, "Could not find realpath");
@ -631,6 +635,8 @@ int controller_load_yy_input(char *buf, size_t *readbytes, size_t sizebytes, yys
}
#ifdef BUILD_TCP
static int controller_load_shell(char *args, char *out, int *outlen)
{
int ret;
@ -679,6 +685,7 @@ static int controller_load_shell(char *args, char *out, int *outlen)
return *outlen;
}
static int controller_load_file_shell(char *args, char *out, int *outlen)
{
int ret;
@ -704,6 +711,7 @@ static int controller_load_file_shell(char *args, char *out, int *outlen)
return *outlen;
}
static struct shell_cmd controller_cmd[] = {
{ "controller",
"parse arguments as controller commands",
@ -726,6 +734,8 @@ int controller_load_shell_add(void)
return ret;
}
#endif
// This routine is called (possibly recursively) to load a single file.
// Linking all inputs/outputs is allowed to fail here, since there might be
// links that go to/come from blocks that will be instantiated in other files


+ 4
- 0
controller/controller/controller_load_parser.y View File

@ -520,6 +520,7 @@ trace : BRACEOPENSYM
stringvar
BRACECLOSESYM
{
#ifdef HAVE_TCP
struct controller_trace_name trace;
trace.name = $2;
@ -528,6 +529,7 @@ trace : BRACEOPENSYM
trace.termname = $8;
controller_trace_list_add(&trace);
#endif
}
| BRACEOPENSYM
stringvar COMMASYM
@ -535,6 +537,7 @@ trace : BRACEOPENSYM
ALIASVARIABLESYM
BRACECLOSESYM
{
#ifdef HAVE_TCP
struct controller_trace_name trace;
trace.name = $2;
@ -543,5 +546,6 @@ trace : BRACEOPENSYM
trace.termname = controller_load_variable_alias_get_term($6);
controller_trace_list_add(&trace);
#endif
}
;

+ 108
- 89
controller/controller/controller_sample.c View File

@ -24,18 +24,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <limits.h>
#include <time.h>
#include <string.h>
#include <sys/mman.h>
#include <errno.h>
#include <signal.h>
#include <sched.h>
#include <dirent.h>
#include <ctype.h>
#include <inttypes.h>
#include <dlfcn.h>
#ifdef HAVE_PTHREAD
#include <sys/mman.h>
#include <sched.h>
#include <dirent.h>
#include <pthread.h>
#endif
#include <controller/controller_block.h>
#include <controller/controller_sample.h>
@ -43,6 +45,7 @@
#include <controller/controller_time.h>
#include <controller/controller_trigger.h>
#include <controller/controller_load.h>
#include <controller/controller_lib.h>
#include <log/log.h>
#include <shell/shell.h>
@ -53,8 +56,7 @@ static uint32_t controller_samplenr = 0;
controller_trigger_time controller_sample_timestamp;
static pthread_t controller_sample_thread;
static bool controller_sample_thread_running = false;
static bool controller_sample_running_flag = false;
struct sample_timing {
controller_trigger_time min;
@ -97,7 +99,7 @@ static void sample_timing_add(struct sample_timing *st,
return;
}
#if defined(HAVE_TCP) || defined(HAVE_PTHREAD)
static ssize_t sample_timing_snprintf(struct sample_timing *st,
char *dest, size_t n)
{
@ -107,7 +109,20 @@ static ssize_t sample_timing_snprintf(struct sample_timing *st,
((double)st->sum / 1000.0) / (double)st->n,
(double)st->max/1000.0);
}
#endif
struct controller_trigger *controller_sample_trigger = NULL;
static controller_trigger_time (*wait_next)(struct controller_trigger *) = NULL;
static controller_trigger_time (*timestamp)(void) = NULL;
controller_trigger_time controller_sample_latency;
controller_trigger_time controller_sample_duration_blocks;
controller_trigger_time controller_sample_duration_sample;
#ifdef HAVE_PTHREAD
static pthread_t controller_sample_thread;
static void alarm_handler(int d)
{
@ -117,7 +132,7 @@ static void alarm_handler(int d)
static void cpu_bind(void)
{
#ifndef __FreeBSD__
#ifdef __linux__
unsigned int cpus = 2;
cpu_set_t set_sample, set_others;
int r, n;
@ -192,24 +207,12 @@ static void cpu_bind(void)
}
struct controller_trigger *controller_sample_trigger = NULL;
static controller_trigger_time (*wait_next)(struct controller_trigger *) = NULL;
static controller_trigger_time (*timestamp)(void) = NULL;
controller_trigger_time controller_sample_latency;
controller_trigger_time controller_sample_duration_blocks;
controller_trigger_time controller_sample_duration_sample;
/*
This thread should be realtime....
*/
static void *sample_thread(void *arg)
{
struct timespec t;
struct sched_param param;
controller_trigger_time t_trig;
controller_trigger_time t_start;
controller_trigger_time t_block;
controller_trigger_time t_end;
param.sched_priority = 90;
sigset_t sigset;
struct sigaction sigact;
@ -223,7 +226,6 @@ static void *sample_thread(void *arg)
sigaction(SIGALRM, &sigact, NULL);
log_send(LOG_T_DEBUG, "Starting sample thread");
controller_sample_thread_running = true;
cpu_bind();
@ -237,45 +239,11 @@ static void *sample_thread(void *arg)
strerror(errno));
}
t.tv_sec = 0;
t.tv_nsec = nsec_interval;
controller_sample_trigger->init(controller_sample_trigger, &t);
log_time_source_set(controller_sample_trigger->timestamp,
controller_sample_trigger->timestamp2timespec);
while (1) {
/* Pre sample stuff: */
controller_samplenr++;
/* Wait for the right moment...
(Internal timer or external interrupt) */
t_trig = wait_next(controller_sample_trigger);
controller_sample_trigger->timestamp2timespec(&t, t_trig);
controller_sample_timestamp = t_trig;
controller_time_seconds = t.tv_sec;
controller_time_nsec = t.tv_nsec;
t_start = timestamp();
/* Do sample stuff */
controller_block_calculate();
t_block = timestamp();
controller_sample_iteration(wait_next(controller_sample_trigger));
controller_block_trace();
controller_sample_task_exec();
t_end = timestamp();
controller_sample_latency = t_start - t_trig;
controller_sample_duration_blocks = t_block - t_start;
controller_sample_duration_sample = t_end - t_start;
sample_timing_add(&st_start, controller_sample_latency);
sample_timing_add(&st_block, controller_sample_duration_blocks);
sample_timing_add(&st_end, t_end - t_trig);
sample_timing_add(&st_sample, controller_sample_duration_sample);
// alarm(1);
}
return NULL;
@ -286,11 +254,6 @@ bool controller_sample_context(void)
return pthread_equal(controller_sample_thread, pthread_self());
}
bool controller_sample_running(void)
{
return controller_sample_thread_running;
}
static void *sample_monitor(void *arg)
{
@ -298,7 +261,7 @@ static void *sample_monitor(void *arg)
linebuf[200] = 0;
while(1) {
log_send(LOG_T_DEBUG, "Samplenr: %d\tOverruns: %d",
log_send(LOG_T_DEBUG, "Samplenr: %"PRId32"\tOverruns: %d",
controller_samplenr,
controller_sample_trigger->overruns(controller_sample_trigger));
sample_timing_snprintf(&st_start, linebuf, 200);
@ -314,10 +277,74 @@ static void *sample_monitor(void *arg)
return NULL;
}
#else
bool controller_sample_context(void)
{
//TODO stub for now!!!
return false;
}
#endif
bool controller_sample_running(void)
{
return controller_sample_running_flag;
}
void controller_sample_iteration(controller_trigger_time t_trig)
{
struct timespec t;
controller_trigger_time t_start;
controller_trigger_time t_block;
controller_trigger_time t_end;
controller_samplenr++;
controller_sample_trigger->timestamp2timespec(&t, t_trig);
controller_sample_timestamp = t_trig;
controller_time_seconds = t.tv_sec;
controller_time_nsec = t.tv_nsec;
t_start = timestamp();
/* Do sample stuff */
controller_block_calculate();
t_block = timestamp();
#ifdef HAVE_TCP
controller_block_trace();
#endif
controller_sample_task_exec();
t_end = timestamp();
controller_sample_latency = t_start - t_trig;
controller_sample_duration_blocks = t_block - t_start;
controller_sample_duration_sample = t_end - t_start;
sample_timing_add(&st_start, controller_sample_latency);
sample_timing_add(&st_block, controller_sample_duration_blocks);
sample_timing_add(&st_end, t_end - t_trig);
sample_timing_add(&st_sample, controller_sample_duration_sample);
}
#ifdef HAVE_TCP
/********************************************
* Shell interface:
*/
static struct shell_cmd sample_shell_cmd = {
"timing", "reset/print sample timing", controller_sample_timing
};
int controller_sample_shell_add(void)
{
return shell_cmd_add(&sample_shell_cmd);
}
static void controller_sample_timing_reset(void)
{
sample_timing_init(&st_start, "start");
@ -357,17 +384,7 @@ static int controller_sample_timing(char *args, char *out, int *outlen)
return *outlen;
}
static struct shell_cmd sample_shell_cmd = {
"timing", "reset/print sample timing", controller_sample_timing
};
int controller_sample_shell_add(void)
{
return shell_cmd_add(&sample_shell_cmd);
}
#endif
void controller_sample_start_hook(void (*func)(void *arg), void *arg)
{
@ -382,9 +399,8 @@ void controller_sample_start_hook(void (*func)(void *arg), void *arg)
int controller_sample_start(void)
{
pthread_t thread_id;
pthread_attr_t attr;
int i;
struct timespec t;
if (!controller_sample_trigger) {
log_send(LOG_T_DEBUG, "No trigger defined");
@ -401,17 +417,30 @@ int controller_sample_start(void)
sample_timing_init(&st_block, "blocks");
sample_timing_init(&st_sample, "sample");
t.tv_sec = 0;
t.tv_nsec = nsec_interval;
controller_sample_trigger->init(controller_sample_trigger, &t);
log_time_source_set(controller_sample_trigger->timestamp,
controller_sample_trigger->timestamp2timespec);
for (i = 0; i < controller_sample_start_hooks_nr; i++)
controller_sample_start_hooks[i].func(
controller_sample_start_hooks[i].arg);
controller_sample_running_flag = true;
#ifdef HAVE_PTHREAD
pthread_t thread_id;
pthread_attr_t attr;
pthread_attr_init(&attr);
#ifndef __FreeBSD__
#ifdef __linux__
pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN * 2);
#endif
pthread_create(&thread_id, &attr, sample_monitor, NULL);
sched_yield();
pthread_create(&controller_sample_thread, &attr, sample_thread, NULL);
#endif
return 0;
}
@ -422,21 +451,12 @@ int controller_sample_start(void)
int controller_sample_trigger_create(char *name, int argc, va_list ap,
char **arg_types)
{
void *handle;
struct controller_trigger_create *create;
struct controller_trigger_create *create = NULL;
int ret = 0;
char *symbol;
// Try to load the trigger's module.
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, name, POSTFIX);
create = dlsym(handle, symbol);
create = controller_lib_sym(symbol);
free(symbol);
if (!create) {
@ -464,6 +484,5 @@ int controller_sample_trigger_create(char *name, int argc, va_list ap,
timestamp = controller_sample_trigger->timestamp;
errout:
dlclose(handle);
return ret;
}

+ 2
- 0
controller/controller/controller_sample.h View File

@ -29,6 +29,8 @@ int controller_sample_start(void);
void controller_sample_start_hook(void (*func)(void *arg), void *arg);
void controller_sample_iteration(controller_trigger_time t_trig);
bool controller_sample_context(void);
bool controller_sample_running(void);


+ 18
- 1
controller/controller/controller_sample_task.c View File

@ -19,7 +19,9 @@
#include <controller/controller_sample.h>
#include <stdlib.h>
#ifdef HAVE_SEMAPHORE
#include <semaphore.h>
#endif
struct task_data {
struct task_data *next;
@ -28,7 +30,11 @@ struct task_data {
void *arg;
int ret;
#ifdef HAVE_SEMAPHORE
sem_t sem;
#else
volatile bool done;
#endif
};
static struct task_data *tasklist = NULL;
@ -43,14 +49,21 @@ int controller_sample_task(int (*task)(void *), void *arg)
data.task = task;
data.arg = arg;
#ifdef HAVE_SEMAPHORE
sem_init(&data.sem, 0, 0);
#else
data.done = false;
#endif
do {
data.next = tasklist;
} while (!__sync_bool_compare_and_swap(&tasklist, data.next, &data));
#ifdef HAVE_SEMAPHORE
sem_wait(&data.sem);
#else
while (!data.done);
#endif
return data.ret;
}
@ -65,6 +78,10 @@ void controller_sample_task_exec(void)
data->ret = data->task(data->arg);
#ifdef HAVE_SEMAPHORE
sem_post(&data->sem);
#else
data->done = true;
#endif
}
}

+ 3
- 3
controller/controller/controller_trace.c View File

@ -326,9 +326,9 @@ static void handler_name(struct trace *trace, int channel, char *name)
termname = hdl->tracename;
while (termname[0] && termname[0] != '.')
termname++;
if (termname[0] == '.') {
termname[0] = 0;
termname++;
if (termname[0] == '.') {
termname[0] = 0;
termname++;
}
}


+ 12
- 7
controller/dt_ctrl.c View File

@ -44,7 +44,6 @@
#include <controller/controller_time.h>
#include <controller/controller_mem.h>
#include <shell/shell.h>
#include <ec/ec.h>
#include <log/log.h>
#include <dt_port_numbers.h>
@ -61,25 +60,23 @@ int main(int argc, char **argv)
int i;
size_t usage_0, usage_r, usage_w, usage_rw;
#ifdef HAVE_FILEIO
sigemptyset (&sigset);
sigaddset(&sigset, SIGALRM);
sigprocmask(SIG_BLOCK, &sigset, NULL);
log_server_start(CTRL_LOG_PORT, LOG_T_DEBUG, LOG_T_INFO);
if (argc < 2) {
printf("Usage: %s <controllerfile>\n", argv[0]);
printf("\n");
printf("E.g.: %s dt_ctrl.ctrl\n", argv[0]);
goto err_init;
}
#endif
log_server_start(CTRL_LOG_PORT, LOG_T_DEBUG, LOG_T_INFO);
ctrl_filename = argv[1];
controller_load_variable_int_set("shell", 0);
controller_load_variable_string_set("shell_intro", shell_intro);
controller_load_variable_string_set("shell_prompt", shell_prompt);
controller_load_variable_int_set("trace_server", 1);
/* Create and link blocks */
@ -100,9 +97,14 @@ int main(int argc, char **argv)
outputs += controller_block_get(i)->outputs;
}
#ifdef HAVE_TCP
if (controller_load_variable_int_get("trace_server"))
controller_trace_server_start(CTRL_TRACE_PORT, outputs);
controller_load_variable_int_set("shell", 0);
controller_load_variable_string_set("shell_intro", shell_intro);
controller_load_variable_string_set("shell_prompt", shell_prompt);
/* Start command shell */
if (controller_load_variable_int_get("shell")) {
controller_sample_shell_add();
@ -113,10 +115,13 @@ int main(int argc, char **argv)
shell_server_start(CTRL_SHELL_PORT, 10);
}
#endif
#ifdef HAVE_FILEIO
asprintf(&dot_filename, "%s.dot", ctrl_filename);
controller_dumpdot(dot_filename);
free(dot_filename);
#endif
/* Start 'sample' */


+ 2
- 2
controller/ec/build.mk View File

@ -44,8 +44,8 @@ EC_OBJS := $(EC_SRCS:.c=.lo)
$(EC_OBJS): CFLAGS += -O3 -Wall
$(LIBDIR)/libethercat.la: libcontroller.la liblog.la
$(LIBDIR)/libethercat.la_CFLAGS += -pthread
$(LIBDIR)/libethercat.la_LDFLAGS += -lm -pthread -lcontroller -llog
$(LIBDIR)/libethercat.la_CFLAGS +=
$(LIBDIR)/libethercat.la_LDFLAGS += -lm -lpthread -lcontroller -llog
$(LIBDIR)/libethercat.la: $(EC_OBJS)
$(LIB_LINK)


+ 1
- 1
controller/ec/eth_linux.c View File

@ -63,7 +63,7 @@ struct eth *eth_open(char *ifname)
if (ec_sock < 0)
goto err;
strncpy(ifreq.ifr_name, ifname, IFNAMSIZ);
strncpy(ifreq.ifr_name, ifname, IFNAMSIZ-1);
ret = ioctl(ec_sock, SIOCGIFINDEX, &ifreq);
if (ret < 0) {
log_send(LOG_T_ERROR, "ioctl SIOCGIFINDEX: %s", strerror(errno));


+ 6
- 2
controller/shell/build.mk View File

@ -1,4 +1,6 @@
ifdef BUILD_TCP
SHELL_TARGETS += $(LIBDIR)/libshell.la
SHELL_SRCS= $(DIR)/shell.c
@ -7,8 +9,8 @@ SHELL_OBJS := $(SHELL_SRCS:.c=.lo)
$(SHELL_OBJS): CFLAGS += -O3 -Wall
$(LIBDIR)/libshell.la: liblog.la
$(LIBDIR)/libshell.la_CFLAGS += -pthread
$(LIBDIR)/libshell.la_LDFLAGS += -llog
$(LIBDIR)/libshell.la_CFLAGS +=
$(LIBDIR)/libshell.la_LDFLAGS += -llog -lpthread
$(LIBDIR)/libshell.la: $(SHELL_OBJS)
$(LIB_LINK)
@ -16,3 +18,5 @@ $(LIBDIR)/libshell.la: $(SHELL_OBJS)
TARGETS += $(SHELL_TARGETS)
CLEAN += $(SHELL_TARGETS) $(SHELL_OBJS)
SRCS += $(SHELL_SRCS)
endif

+ 5
- 2
controller/test/build.mk View File

@ -7,9 +7,12 @@ TEST_BLOCKS := \
test_output_bool \
test_output_float \
test_output_sint32 \
test_output_uint32 \
test_command
test_output_uint32
ifdef BUILD_TCP
TEST_BLOCKS += \
test_command
endif
TEST_BLOCK_SRCS := $(addsuffix .c,$(addprefix $(DIR)/block_,$(TEST_BLOCKS))) \
$(DIR)/test_block.c


+ 5
- 1
controller/trigger/build.mk View File

@ -2,10 +2,14 @@
TRIGGER_TARGETS := $(LIBDIR)/libtrigger.la
TRIGGERS := \
immediate
ifdef BUILD_PTHREAD
TRIGGERS += \
default \
immediate \
prestart \
busyloop
endif
TRIGGER_SRCS := $(addsuffix .c,$(addprefix $(DIR)/trigger_,$(TRIGGERS)))
TRIGGER_OBJS := $(TRIGGER_SRCS:.c=.lo)


+ 3
- 0
controller/vesp/vesp.h View File

@ -21,6 +21,9 @@
#include <controller/controller_bus.h>
#include <time.h>
#include <unistd.h>
#ifndef __packed
#define __packed __attribute__((packed))
#endif


Loading…
Cancel
Save