Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
4fee8034
Commit
4fee8034
authored
Jun 03, 2013
by
Jeroen Vreeken
Browse files
Changes needed for FreeBSD clock usage in sample
parent
8450f2f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
controller/controller/controller_sample.c
View file @
4fee8034
...
...
@@ -136,6 +136,12 @@ static void *sample_thread(void *arg)
struct
timespec
t_io
;
struct
timespec
t_end
;
param
.
sched_priority
=
99
;
clockid_t
clock
;
#ifdef __FreeBSD__
pthread_condattr_t
attr
;
pthread_mutex_t
lock
;
pthread_cond_t
cv
;
#endif
log_send
(
LOG_T_DEBUG
,
"Starting sample thread"
);
controller_sample_thread_running
=
true
;
...
...
@@ -150,7 +156,21 @@ static void *sample_thread(void *arg)
strerror
(
errno
));
}
clock_gettime
(
0
,
&
t
);
#ifndef __FreeBSD__
clock
=
0
;
#else
clock
=
CLOCK_MONOTONIC_PRECISE
;
pthread_condattr_init
(
&
attr
);
pthread_condattr_setclock
(
&
attr
,
clock
);
pthread_cond_init
(
&
cv
,
&
attr
);
pthread_condattr_destroy
(
&
attr
);
pthread_mutex_init
(
&
lock
,
NULL
);
pthread_mutex_lock
(
&
lock
);
#endif
clock_gettime
(
clock
,
&
t
);
t
.
tv_nsec
=
0
;
t
.
tv_sec
++
;
...
...
@@ -168,19 +188,23 @@ static void *sample_thread(void *arg)
/* Wait for the right moment...
(Internal timer or external interrupt) */
#ifndef __FreeBSD__
clock_nanosleep
(
0
,
TIMER_ABSTIME
,
&
t
,
NULL
);
#else
pthread_cond_timedwait
(
&
cv
,
&
lock
,
&
t
);
#endif
clock_gettime
(
0
,
&
t_start
);
clock_gettime
(
clock
,
&
t_start
);
/* Do sample stuff */
controller_block_calculate
();
clock_gettime
(
0
,
&
t_io
);
clock_gettime
(
clock
,
&
t_io
);
controller_block_trace
();
controller_block_param_handle
();
clock_gettime
(
0
,
&
t_end
);
clock_gettime
(
clock
,
&
t_end
);
sample_timing_add
(
&
st_start
,
&
t
,
&
t_start
);
sample_timing_add
(
&
st_io
,
&
t_start
,
&
t_io
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment