Commit 49bf1255 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add profile block (timing can now be traced per sample with standard tracing).

Add some build flags to make more stuff switchable.
Fix delay setting for rs485 in block_vesp_tty. (prevent hanging serial port).
parent 0a48e37f
HOSTSYS=@HOSTSYS@
BUILDSYS=@BUILDSYS@
BUILD_CONSOLE=@BUILD_CONSOLE@
BUILD_CONSOLE_HTTPD=@BUILD_CONSOLE_HTTPD@
BUILD_CONSOLE_J2000_INDI=@BUILD_CONSOLE_J2000_INDI@
BUILD_ETHERCAT=@BUILD_ETHERCAT@
BUILD_VESP=@BUILD_VESP@
BUILD_AM335X=@BUILD_AM335X@
AC_INIT(dt_ctrl, git)
AC_SUBST(HOSTSYS,["$ac_cv_env_host_alias_value"])
AC_SUBST(BUILDSYS,["$ac_cv_env_build_alias_value"])
AS_IF([echo "$HOSTSYS" | grep "arm"],[HAVE_ARM=1],[HAVE_ARM=0])
#######################################################################
#
# Enable/disable controller
#
AC_ARG_ENABLE([ethercat],
[AS_HELP_STRING([--disable-ethercat], [Enable/Disable Ethercat @<:@yes@:>@])],
[:],
[enable_ethercat=yes])
AC_ARG_ENABLE([vesp],
[AS_HELP_STRING([--disable-vesp], [Enable/Disable vesp @<:@yes@:>@])],
[:],
[enable_vesp=yes])
AC_ARG_ENABLE([am335x],
[AS_HELP_STRING([--disable-am335x], [Enable/Disable am335x @<:@yes@:>@])],
[:],
[enable_am335x=yes])
#######################################################################
#
# Enable/disable console
#
AC_ARG_ENABLE([console],
[AS_HELP_STRING([--disable-console], [Enable console @<:@yes@:>@])],
[AS_HELP_STRING([--disable-console], [Enable/Disable console @<:@yes@:>@])],
[:],
[enable_console=yes])
......@@ -60,8 +84,6 @@ AS_CASE(["$with_libindi"],
# Some conclusions based on test results
#
AC_SUBST(HOSTSYS,["$ac_cv_env_host_alias_value"])
AC_SUBST(BUILDSYS,["$ac_cv_env_build_alias_value"])
AS_IF([test "$enable_console" = "yes"],
[AC_SUBST(BUILD_CONSOLE,["yes"])],
......@@ -76,6 +98,20 @@ AS_IF([test "$BUILD_CONSOLE" = "yes" && test "$HAVE_LIBINDI" = "1"],
[AC_SUBST(BUILD_CONSOLE_J2000_INDI,[""])])
AS_IF([test "$enable_ethercat" = "yes"],
[AC_SUBST(BUILD_ETHERCAT,["yes"])],
[AC_SUBST(BUILD_ETHERCAT,[""])])
AS_IF([test "$enable_vesp" = "yes"],
[AC_SUBST(BUILD_VESP,["yes"])],
[AC_SUBST(BUILD_VESP,[""])])
AS_IF([test "$enable_am335x" = "yes" && test "$HAVE_ARM" = "1"],
[AC_SUBST(BUILD_AM335X,["yes"])],
[AC_SUBST(BUILD_AM335X,[""])])
#######################################################################
#
# Output
......@@ -103,3 +139,16 @@ AS_IF([test "$BUILD_CONSOLE_HTTPD" != ""],
AS_IF([test "$BUILD_CONSOLE_J2000_INDI" != ""],
AC_MSG_NOTICE([ console_j2000_indi: yes]),
AC_MSG_NOTICE([ console_j2000_indi: no]))
AS_IF([test "$BUILD_ETHERCAT" != ""],
AC_MSG_NOTICE([ ethercat: yes]),
AC_MSG_NOTICE([ ethercat: no]))
AS_IF([test "$BUILD_VESP" != ""],
AC_MSG_NOTICE([ vesp: yes]),
AC_MSG_NOTICE([ vesp: no]))
AS_IF([test "$BUILD_AM335X" != ""],
AC_MSG_NOTICE([ am335x: yes]),
AC_MSG_NOTICE([ am335x: no]))
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2015
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <controller/controller_block.h>
#include <controller/controller_sample.h>
#include <log/log.h>
struct controller_block_private {
float latency;
float blocks;
float sample;
};
static void prof_calculate(struct controller_block *prof)
{
struct controller_block_private *priv = prof->private;
struct timespec ts;
controller_sample_trigger->timestamp2timespec(&ts, controller_sample_latency);
priv->latency = ts.tv_sec + (double)ts.tv_nsec * 0.000000001;
controller_sample_trigger->timestamp2timespec(&ts, controller_sample_duration_blocks);
priv->blocks = ts.tv_sec + (double)ts.tv_nsec * 0.000000001;
controller_sample_trigger->timestamp2timespec(&ts, controller_sample_duration_sample);
priv->sample = ts.tv_sec + (double)ts.tv_nsec * 0.000000001;
}
static struct controller_block_outterm_list outterms[] = {
{ "latency", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, latency) },
{ "blocks", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, blocks) },
{ "sample", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, sample) },
{ NULL }
};
static struct controller_block * block_controller_profile_create(char *name, int argc, va_list val)
{
struct controller_block *prof;
if (!(prof = controller_block_alloc("controller_profile", name, sizeof(struct controller_block_private))))
return NULL;
if (controller_block_outterm_list_init(prof, outterms))
goto err_block;
prof->calculate = prof_calculate;
if (controller_block_add(prof))
goto err_block;
return prof;
err_block:
controller_block_free(prof);
return NULL;
}
BLOCK_CREATE(controller_profile) = {
.create = block_controller_profile_create,
.args = { NULL },
};
......@@ -9,6 +9,7 @@ BLOCKS := \
bridge_pwm \
command_bool \
command_float \
controller_profile \
counter \
debug \
decoder_uint32_bool \
......
......@@ -12,11 +12,14 @@ $(eval $(call SUBDIR,controller))
$(eval $(call SUBDIR,shell))
$(eval $(call SUBDIR,block))
$(eval $(call SUBDIR,trigger))
ifdef BUILD_ETHERCAT
$(eval $(call SUBDIR,ec))
endif
$(eval $(call SUBDIR,test))
ifdef BUILD_VESP
$(eval $(call SUBDIR,vesp))
ifneq (,$(findstring arm,$(HW)))
endif
ifdef BUILD_AM335X
$(eval $(call SUBDIR,am335x))
endif
......
......@@ -64,7 +64,7 @@ struct sample_timing {
char *name;
};
static struct sample_timing st_start, st_io, st_end, st_sample;
static struct sample_timing st_start, st_block, st_end, st_sample;
struct controller_sample_start_hook {
void (*func)(void *arg);
......@@ -83,11 +83,9 @@ static void sample_timing_init(struct sample_timing *st, char *name)
}
static void sample_timing_add(struct sample_timing *st,
controller_trigger_time t1, controller_trigger_time t2)
controller_trigger_time tt)
{
int64_t t;
t = t2 - t1;
int64_t t = tt;
if (t > st->max)
st->max = t;
......@@ -198,6 +196,9 @@ 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....
*/
......@@ -207,7 +208,7 @@ static void *sample_thread(void *arg)
struct sched_param param;
controller_trigger_time t_trig;
controller_trigger_time t_start;
controller_trigger_time t_io;
controller_trigger_time t_block;
controller_trigger_time t_end;
param.sched_priority = 90;
sigset_t sigset;
......@@ -260,17 +261,20 @@ static void *sample_thread(void *arg)
/* Do sample stuff */
controller_block_calculate();
t_io = timestamp();
t_block = timestamp();
controller_block_trace();
controller_sample_task_exec();
t_end = timestamp();
sample_timing_add(&st_start, t_trig, t_start);
sample_timing_add(&st_io, t_start, t_io);
sample_timing_add(&st_end, t_trig, t_end);
sample_timing_add(&st_sample, t_start, t_end);
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);
}
......@@ -301,7 +305,7 @@ static void *sample_monitor(void *arg)
log_send(LOG_T_DEBUG, "%s", linebuf);
sample_timing_snprintf(&st_end, linebuf, 200);
log_send(LOG_T_DEBUG, "%s", linebuf);
sample_timing_snprintf(&st_io, linebuf, 200);
sample_timing_snprintf(&st_block, linebuf, 200);
log_send(LOG_T_DEBUG, "%s", linebuf);
sample_timing_snprintf(&st_sample, linebuf, 200);
log_send(LOG_T_DEBUG, "%s", linebuf);
......@@ -318,7 +322,7 @@ static void controller_sample_timing_reset(void)
{
sample_timing_init(&st_start, "start");
sample_timing_init(&st_end, "end");
sample_timing_init(&st_io, "io");
sample_timing_init(&st_block, "blocks");
sample_timing_init(&st_sample, "sample");
}
......@@ -330,7 +334,7 @@ static ssize_t controller_sample_timing_snprintf(char *dest, size_t n)
used += sprintf(dest + used, "\n");
used += sample_timing_snprintf(&st_end, dest + used, n - used);
used += sprintf(dest + used, "\n");
used += sample_timing_snprintf(&st_io, dest + used, n - used);
used += sample_timing_snprintf(&st_block, dest + used, n - used);
used += sprintf(dest + used, "\n");
used += sample_timing_snprintf(&st_sample, dest + used, n - used);
used += sprintf(dest + used, "\n");
......@@ -394,7 +398,7 @@ int controller_sample_start(void)
sample_timing_init(&st_start, "start");
sample_timing_init(&st_end, "end");
sample_timing_init(&st_io, "io");
sample_timing_init(&st_block, "blocks");
sample_timing_init(&st_sample, "sample");
for (i = 0; i < controller_sample_start_hooks_nr; i++)
......
......@@ -40,5 +40,8 @@ int controller_sample_trigger_create(char *name, int argc, va_list ap,
extern controller_trigger_time controller_sample_timestamp;
extern struct controller_trigger *controller_sample_trigger;
extern controller_trigger_time controller_sample_latency;
extern controller_trigger_time controller_sample_duration_blocks;
extern controller_trigger_time controller_sample_duration_sample;
#endif /* _INCLUDE_CONTROLLER_SAMPLE_ */
......@@ -32,7 +32,12 @@ import "dt_ctrl_az_sim.ctrl"
import "dt_ctrl_ec_sim.ctrl"
blocks ($(frequency), $(delay)) {
# Profiling block, may be commented out.
{ "controller_profile", "profile" }
{ "setpoint_generator_3d", "azimuth_spg", "Azimuth_Setpoint", "rad" }
{ "servo_state", "azimuth_servo_state" }
{ "and4", "azimuth_safe_and" }
......
......@@ -235,7 +235,7 @@ static int vesp_dev_open(struct controller_block *block)
}
struct serial_rs485 rs485conf;
struct serial_rs485 rs485conf = { 0 };
/* Enable RS485 mode: */
rs485conf.flags |= SER_RS485_ENABLED;
......@@ -255,10 +255,10 @@ static int vesp_dev_open(struct controller_block *block)
}
/* Set rts delay before send, if needed: */
//rs485conf.delay_rts_before_send = ...;
rs485conf.delay_rts_before_send = 0;
/* Set rts delay after send, if needed: */
//rs485conf.delay_rts_after_send = ...;
rs485conf.delay_rts_after_send = 0;
/* Set this flag if you want to receive data even whilst sending data */
//rs485conf.flags |= SER_RS485_RX_DURING_TX;
......
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