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

Add systick based trigger.

parent ade70793
......@@ -26,6 +26,7 @@ endif
ifdef HOSTSYS
CC=${HOSTSYS}-gcc
LD=${HOSTSYS}-ld
LIBTOOL=${HOSTSYS}-libtool
CONF_HOST=--host=${HOSTSYS}
HW=$(HOSTSYS)
......@@ -41,9 +42,13 @@ endif
@${LIBTOOL} --quiet --mode=compile --tag=CC $(CC) -MMD $(CFLAGS) -c $< -o $@
@sed -e "s:\.il2c.c:\.il:" -i -i $*.il2c.d
%.o : %.ctrl
@echo "BLOB LD $@"
@$(LD) -r -b binary $< -o $@
%: %.o
@echo " LD $@"
${LIBTOOL} --quiet --mode=link --tag=CC $(LINK.o) $(filter %.o,$^) $(LOADLIBS) $(LDLIBS) $($@_LDFLAGS) $(CFLAGS) -o $@
@${LIBTOOL} --quiet --mode=link --tag=CC $(LINK.o) $(filter %.o,$^) $(LOADLIBS) $(LDLIBS) $($@_LDFLAGS) $(CFLAGS) -o $@
%.lo: %.c
@echo "LT CC $<"
......
......@@ -16,6 +16,9 @@ BUILD_TEST=@BUILD_TEST@
BUILD_PTHREAD=@BUILD_PTHREAD@
BUILD_TCP=@BUILD_TCP@
BUILD_DYNAMICLINKING=@BUILD_DYNAMICLINKING@
BUILD_FILEIO=@BUILD_FILEIO@
BUILD_EMBEDDED=@BUILD_EMBEDDED@
BUILD_SYSTICK=@BUILD_SYSTICK@
BUILD_CFLAGS=@CFLAGS@ @CFLAGS_PTHREAD@ @CFLAGS_TCP@ @CFLAGS_FILEIO@
BUILD_CFLAGS=@CFLAGS@ @CFLAGS_PTHREAD@ @CFLAGS_TCP@ @CFLAGS_FILEIO@ @CFLAGS_EMBEDDED@ @CFLAGS_SYSTICK@
......@@ -31,6 +31,10 @@ AC_ARG_ENABLE([test],
[:],
[enable_test=yes])
AC_ARG_ENABLE([embedded],
[AS_HELP_STRING([--enable-embedded], [Enable/Disable embedde controller @<:@no@:>@])],
[enable_embedded=yes],
[:])
#######################################################################
#
......@@ -126,6 +130,7 @@ AC_CHECK_HEADER(semaphore.h,[HAVE_SEMAPHORE=1],[HAVE_SEMAPHORE=0])
AC_CHECK_HEADER(dlfcn.h,[HAVE_DYNAMICLINKING=1],[HAVE_DYNAMICLINKING=0])
AC_CHECK_HEADER(sysclk.h,[HAVE_SYSTICK=1],[HAVE_SYSTICK=0])
#######################################################################
#
......@@ -206,6 +211,21 @@ AS_IF([test "$HAVE_FILEIO" = "1"],
[AC_SUBST(CFLAGS_FILEIO,["-DHAVE_FILEIO"])],
[AC_SUBST(CFLAGS_FILEIO,[""])])
AS_IF([test "$enable_embedded" = "yes"],
[AC_SUBST(BUILD_EMBEDDED,["yes"])],
[AC_SUBST(BUILD_EMBEDDED,[""])])
AS_IF([test "$enable_embedded" = "yes"],
[AC_SUBST(CFLAGS_EMBEDDED,["-DHAVE_EMBEDDED"])],
[AC_SUBST(CFLAGS_EMBEDDED,[""])])
AS_IF([test "$HAVE_SYSTICK" = "1"],
[AC_SUBST(BUILD_SYSTICK,["yes"])],
[AC_SUBST(BUILD_SYSTICK,[""])])
AS_IF([test "$HAVE_SYSTICK" = "1"],
[AC_SUBST(CFLAGS_SYSTICK,["-DHAVE_SYSTICK -D_POSIX_TIMERS"])],
[AC_SUBST(CFLAGS_SYSTICK,[""])])
#######################################################################
#
......
......@@ -30,6 +30,12 @@ DT_CTRL_TARGETS += $(DIR)/dt_ctrl
DT_CTRL_SRCS := $(DIR)/dt_ctrl.c
DT_CTRL_OBJS := $(DT_CTRL_SRCS:.c=.o)
ifdef BUILD_EMBEDDED
DT_CTRL_OBJS += $(DIR)/ctrl_embedded.o
endif
, := ,
BLOCKS := $(addprefix -Wl$(,)-u -Wl$(,)block_,$(addsuffix _create_struct,$(CTRL_BLOCKS)))
BLOCKS += $(addprefix -Wl$(,)-u -Wl$(,)block_,$(addsuffix _create,$(CTRL_BLOCKS)))
......
......@@ -635,22 +635,14 @@ 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 controller_load_mem(char *name, char *ctrl, size_t ctrl_size)
{
int ret;
struct controller_load_extra extra;
char *safe_context;
yyscan_t scanner;
if (!args) {
*outlen = sprintf(out,
"no arguments\n");
return *outlen;
}
extra.filename = "shell";
extra.filename = name;
extra.ret = 0;
extra.va_entries = NULL;
extra.va_list_start = false;
......@@ -658,10 +650,10 @@ static int controller_load_shell(char *args, char *out, int *outlen)
extra.va_type_list = NULL;
extra.array = NULL;
extra.use_string = true;
extra.stringlen = strlen(args);
extra.string = args;
extra.stringlen = ctrl_size;
extra.string = ctrl;
log_send(LOG_T_DEBUG, "parsing: %s", args);
log_send(LOG_T_DEBUG, "parsing: %s", name);
yylex_init_extra(&extra, &scanner);
......@@ -674,6 +666,23 @@ static int controller_load_shell(char *args, char *out, int *outlen)
yylex_destroy(scanner);
return ret;
}
#ifdef BUILD_TCP
static int controller_load_shell(char *args, char *out, int *outlen)
{
int ret;
if (!args) {
*outlen = sprintf(out,
"no arguments\n");
return *outlen;
}
ret = controller_load_mem("shell", args, strlen(args));
if (ret) {
*outlen = sprintf(out,
"failed to parse arguments\n");
......
......@@ -36,5 +36,6 @@ void controller_load_variable_string_set(char *varname, char *val);
int controller_load_variable_int_get(char *varname);
void controller_load_variable_int_set(char *varname, int i);
int controller_load_mem(char *name, char *ctrl, size_t ctrl_size);
#endif /* _INCLUDE_CONTROLLER_LOAD_H_ */
......@@ -118,7 +118,7 @@ void *controller_mem_calloc(int flags, size_t nmemb, size_t size)
if (block)
chunk = &(block->chunks);
}
if (chunk && *chunk) {
if (block && chunk && *chunk) {
struct controller_mem_chunk *a_chunk, *e_chunk, *r_chunk;
r_chunk = *chunk;
......
......@@ -419,7 +419,6 @@ int controller_sample_start(void)
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);
......@@ -429,6 +428,8 @@ int controller_sample_start(void)
controller_sample_running_flag = true;
controller_sample_trigger->init(controller_sample_trigger, &t);
#ifdef HAVE_PTHREAD
pthread_t thread_id;
pthread_attr_t attr;
......
......@@ -48,6 +48,10 @@
#include <dt_port_numbers.h>
#ifdef HAVE_EMBEDDED
extern char _binary_controller_ctrl_embedded_ctrl_start;
extern char _binary_controller_ctrl_embedded_ctrl_end;
#endif
int main(int argc, char **argv)
......@@ -75,6 +79,7 @@ int main(int argc, char **argv)
log_server_start(CTRL_LOG_PORT, LOG_T_DEBUG, LOG_T_INFO);
#ifndef HAVE_EMBEDDED
ctrl_filename = argv[1];
controller_load_variable_int_set("trace_server", 1);
......@@ -86,6 +91,11 @@ int main(int argc, char **argv)
log_send(LOG_T_ERROR, "Could not load controller file");
goto err_init;
}
#else
controller_load_mem("ctrl_embedded",
&_binary_controller_ctrl_embedded_ctrl_start,
&_binary_controller_ctrl_embedded_ctrl_end - &_binary_controller_ctrl_embedded_ctrl_start);
#endif
if (controller_time_process() != 0) {
goto err_init;
......
......@@ -2,7 +2,8 @@
TRIGGER_TARGETS := $(LIBDIR)/libtrigger.la
TRIGGERS := \
immediate
immediate \
systick
ifdef BUILD_PTHREAD
TRIGGERS += \
......
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 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_trigger.h>
#include <controller/controller_time.h>
#include <controller/controller_sample.h>
#include <log/log.h>
#include <time.h>
#include <sysclk.h>
static controller_trigger_time ts2timestamp(struct timespec *ts)
{
return (uint64_t)ts->tv_nsec + (uint64_t)ts->tv_sec * 1000000000;
}
static controller_trigger_time timestamp(void)
{
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
return ts2timestamp(&t);
}
static void sample_systick(void)
{
controller_sample_iteration(timestamp());
}
static int wait_init_systick(struct controller_trigger *trigger, struct timespec *ts_interval)
{
double interval = (double)ts_interval->tv_sec * 1000000000.0 + (double)ts_interval->tv_nsec;
int hz = 1000000000.0 / interval;
sysclk_tick_set_hz(hz);
sysclk_tick_set_hook(sample_systick);
return 0;
}
static int overrun_cnt;
static int overruns(struct controller_trigger *trigger)
{
return overrun_cnt;
}
static void timestamp2timespec(struct timespec *ts, controller_trigger_time ct)
{
ts->tv_sec = ct / 1000000000;
ts->tv_nsec = ct % 1000000000;
}
static struct controller_trigger trigger_systick = {
.init = wait_init_systick,
.next = NULL,
.timestamp = timestamp,
.timestamp2timespec = timestamp2timespec,
.timespec2timestamp = ts2timestamp,
.overruns = overruns,
};
struct controller_trigger *trigger_systick_create(int argc, va_list ap)
{
log_send(LOG_T_DEBUG, "systick trigger");
return &trigger_systick;
}
TRIGGER_CREATE(systick) = {
.create = trigger_systick_create,
.args = { NULL },
};
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