You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.4 KiB

Copyright Jeroen Vreeken (, 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
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 <>.
#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_trigger_time t_trig = timestamp();
static int 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;
log_send(LOG_T_DEBUG, "Setting systick to %dHZ", hz);
if(sysclk_tick_set_hz(hz)) {
log_send(LOG_T_ERROR, "Could not set tick frequency");
return -1;
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 = 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 },