Module: xenomai-3
Branch: wip/drivers
Commit: 61f6da906cda308c9f9a9de84ebf6010e988ccb8
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=61f6da906cda308c9f9a9de84ebf6010e988ccb8

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Dec 13 14:56:10 2016 +0100

boilerplate/time: add helper to init a timespec from a scalar

---

 include/boilerplate/time.h |    3 +++
 lib/boilerplate/time.c     |   11 +++++++++++
 2 files changed, 14 insertions(+)

diff --git a/include/boilerplate/time.h b/include/boilerplate/time.h
index fff6075..8d317e7 100644
--- a/include/boilerplate/time.h
+++ b/include/boilerplate/time.h
@@ -44,6 +44,9 @@ void timespec_adds(struct timespec *__restrict r,
                   const struct timespec *__restrict t1,
                   sticks_t t2);
 
+void timespec_sets(struct timespec *__restrict r,
+                  ticks_t ns);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/boilerplate/time.c b/lib/boilerplate/time.c
index 547f899..d112593 100644
--- a/lib/boilerplate/time.c
+++ b/lib/boilerplate/time.c
@@ -72,3 +72,14 @@ void timespec_adds(struct timespec *__restrict r,
                r->tv_nsec -= 1000000000;
        }
 }
+
+void timespec_sets(struct timespec *__restrict r,
+                  ticks_t ns)
+{
+       r->tv_sec = ns / 1000000000UL;
+       r->tv_nsec = ns - r->tv_sec * 1000000000UL;
+       if (r->tv_nsec >= 1000000000) {
+               r->tv_sec++;
+               r->tv_nsec -= 1000000000;
+       }
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to