Module: xenomai-3
Branch: master
Commit: 1c8a4e81df26498e2408828ada7b6139ccc19790
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1c8a4e81df26498e2408828ada7b6139ccc19790

Author: Philippe Gerum <r...@xenomai.org>
Date:   Fri Sep 25 17:57:46 2015 +0200

cobalt/rtdm: update API dealing with periodic tasks

rtdm_task_set_period() is updated to accept an initial date for
delimiting the time line.

rtdm_task_wait_period() now accepts a parameter to retrieve the count
of overruns upon -ETIMEDOUT error.

In addition, using the periodic task API from a Cobalt thread is
now allowed.

This enables more sophisticated periodic task processing, and closely
matches the inner xnthread* interface those calls are based on.

---

 include/cobalt/kernel/rtdm/driver.h          |    9 +++++---
 kernel/cobalt/rtdm/drvlib.c                  |   29 +++++++++++++++++++++-----
 kernel/cobalt/thread.c                       |    8 +++----
 kernel/drivers/autotune/autotune.c           |    2 +-
 kernel/drivers/net/stack/rtcfg/rtcfg_timer.c |    2 +-
 5 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/driver.h 
b/include/cobalt/kernel/rtdm/driver.h
index 80308ca..541fb04 100644
--- a/include/cobalt/kernel/rtdm/driver.h
+++ b/include/cobalt/kernel/rtdm/driver.h
@@ -1033,12 +1033,15 @@ static inline void rtdm_task_set_priority(rtdm_task_t 
*task, int priority)
 }
 
 static inline int rtdm_task_set_period(rtdm_task_t *task,
+                                      nanosecs_abs_t start_date,
                                       nanosecs_rel_t period)
 {
        if (period < 0)
                period = 0;
+       if (start_date == 0)
+               start_date = XN_INFINITE;
 
-       return xnthread_set_periodic(task, XN_INFINITE, XN_RELATIVE, period);
+       return xnthread_set_periodic(task, start_date, XN_ABSOLUTE, period);
 }
 
 static inline int rtdm_task_unblock(rtdm_task_t *task)
@@ -1054,11 +1057,11 @@ static inline rtdm_task_t *rtdm_task_current(void)
        return xnthread_current();
 }
 
-static inline int rtdm_task_wait_period(void)
+static inline int rtdm_task_wait_period(unsigned long *overruns_r)
 {
        if (!XENO_ASSERT(COBALT, !xnsched_unblockable_p()))
                return -EPERM;
-       return xnthread_wait_period(NULL);
+       return xnthread_wait_period(overruns_r);
 }
 
 static inline int rtdm_task_sleep(nanosecs_rel_t delay)
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index ca46531..7b3ab1a 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -200,17 +200,36 @@ void rtdm_task_set_priority(rtdm_task_t *task, int 
priority);
 /**
  * @brief Adjust real-time task period
  *
- * @param[in,out] task Task handle as returned by rtdm_task_init()
- * @param[in] period New period in nanoseconds of a cyclic task, 0 for
- * non-cyclic mode
+ * @param[in,out] task Task handle as returned by rtdm_task_init(), or
+ * NULL for referring to the current RTDM task or Cobalt thread (see
+ * note).
+ *
+ * @param[in] start_date The initial (absolute) date of the first
+ * release point, expressed in nanoseconds.  @a task will be delayed
+ * by the first call to rtdm_task_wait_period() until this point is
+ * reached. If @a start_date is zero, the first release point is set
+ * to @a period nanoseconds after the current date.
+
+ * @param[in] period New period in nanoseconds of a cyclic task, zero
+ * for non-cyclic mode.
  *
  * @coretags{task-unrestricted}
+ *
+ * @note Both RTDM tasks in kernel space and Cobalt threads in
+ * user-space are based on Xenomai core threads, which implement this
+ * service. For this reason, enabling periodic timing for a Cobalt
+ * thread via the RTDM interface is possible.
  */
-int rtdm_task_set_period(rtdm_task_t *task, nanosecs_rel_t period);
+int rtdm_task_set_period(rtdm_task_t *task, nanosecs_abs_t start_date,
+                        nanosecs_rel_t period);
 
 /**
  * @brief Wait on next real-time task period
  *
+ * @param[in] overrun_r Address of a long word receiving the count of
+ * overruns if -ETIMEDOUT is returned, or NULL if the caller don't
+ * need that information.
+ *
  * @return 0 on success, otherwise:
  *
  * - -EINVAL is returned if calling task is not in periodic mode.
@@ -220,7 +239,7 @@ int rtdm_task_set_period(rtdm_task_t *task, nanosecs_rel_t 
period);
  *
  * @coretags{primary-only, might-switch}
  */
-int rtdm_task_wait_period(void);
+int rtdm_task_wait_period(unsigned long *overruns_r);
 
 /**
  * @brief Activate a blocked real-time task
diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index 6a571af..508ed69 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1236,10 +1236,10 @@ EXPORT_SYMBOL_GPL(xnthread_unblock);
  * @param idate The initial (absolute) date of the first release
  * point, expressed in nanoseconds. The affected thread will be
  * delayed by the first call to xnthread_wait_period() until this
- * point is reached. If @a idate is equal to XN_INFINITE, the current
- * system date is used, and no initial delay takes place. In the
- * latter case, @a timeout_mode is not considered and can have any
- * valid value.
+ * point is reached. If @a idate is equal to XN_INFINITE, the first
+ * release point is set to @a period nanoseconds after the current
+ * date. In the latter case, @a timeout_mode is not considered and can
+ * have any valid value.
  *
  * @param timeout_mode The mode of the @a idate parameter. It can
  * either be set to XN_ABSOLUTE or XN_REALTIME with @a idate different
diff --git a/kernel/drivers/autotune/autotune.c 
b/kernel/drivers/autotune/autotune.c
index a20ee38..8060c3c 100644
--- a/kernel/drivers/autotune/autotune.c
+++ b/kernel/drivers/autotune/autotune.c
@@ -250,7 +250,7 @@ void task_handler(void *arg)
                        break;
 
                for (;;) {
-                       ret = rtdm_task_wait_period();
+                       ret = rtdm_task_wait_period(NULL);
                        if (ret && ret != -ETIMEDOUT)
                                goto out;
 
diff --git a/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c 
b/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c
index 012893a..5b9ab5d 100644
--- a/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c
+++ b/kernel/drivers/net/stack/rtcfg/rtcfg_timer.c
@@ -81,7 +81,7 @@ void rtcfg_timer(int ifindex)
 
         rtdm_mutex_unlock(&rtcfg_dev->dev_mutex);
 
-        rtdm_task_wait_period();
+        rtdm_task_wait_period(NULL);
     }
 
     rtcfg_dev->flags &= ~FLAG_TIMER_STARTED;


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

Reply via email to