[PATCH 06/12] kern_tc.c: Replace FREEBSD event mechanism by adding pointers to function

Gabriel Moyano gabriel.moyano at dlr.de
Thu Apr 7 08:36:01 UTC 2022


---
 cpukit/include/sys/timepps.h | 11 +++++++++++
 cpukit/score/src/kern_tc.c   | 20 +++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/cpukit/include/sys/timepps.h b/cpukit/include/sys/timepps.h
index 5703381ffa..a72579d5d7 100644
--- a/cpukit/include/sys/timepps.h
+++ b/cpukit/include/sys/timepps.h
@@ -149,6 +149,12 @@ struct mtx;
 
 #define	PPSFLAG_MTX_SPIN	0x01	/* Driver mtx is MTX_SPIN type. */
 
+#ifdef __rtems__
+struct pps_state;
+typedef int (*wait_event_func)(struct pps_state *pps, struct timespec timeout);
+typedef void (*wakeup_func)(struct pps_state *pps);
+#endif /* __rtems__ */
+
 struct pps_state {
 	/* Capture information. */
 	struct timehands *capth;
@@ -164,6 +170,11 @@ struct pps_state {
 	int		ppscap;
 	struct timecounter *ppstc;
 	unsigned	ppscount[3];
+#ifdef __rtems__
+    wait_event_func wait_event;
+    wakeup_func wakeup;
+#endif /* __rtems__ */
+
 	/*
 	 * The following fields are valid if the driver calls pps_init_abi().
 	 */
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index 77f7a9212c..a5c7b4b841 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -1910,9 +1910,15 @@ abi_aware(struct pps_state *pps, int vers)
 static int
 pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
 {
+#ifndef __rtems__
 	int err, timo;
+#else /* __rtems__ */
+	int err;
+#endif /* __rtems__ */
 	pps_seq_t aseq, cseq;
+#ifndef __rtems__
 	struct timeval tv;
+#endif /* __rtems__ */
 
 	if (fapi->tsformat && fapi->tsformat != PPS_TSFMT_TSPEC)
 		return (EINVAL);
@@ -1925,6 +1931,7 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
 	 * sleep a long time.
 	 */
 	if (fapi->timeout.tv_sec || fapi->timeout.tv_nsec) {
+#ifndef __rtems__
 		if (fapi->timeout.tv_sec == -1)
 			timo = 0x7fffffff;
 		else {
@@ -1932,7 +1939,6 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
 			tv.tv_usec = fapi->timeout.tv_nsec / 1000;
 			timo = tvtohz(&tv);
 		}
-#ifndef __rtems__
 		aseq = atomic_load_int(&pps->ppsinfo.assert_sequence);
 		cseq = atomic_load_int(&pps->ppsinfo.clear_sequence);
 		while (aseq == atomic_load_int(&pps->ppsinfo.assert_sequence) &&
@@ -1943,6 +1949,7 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
 		while (aseq == atomic_load_acq_int(&pps->ppsinfo.assert_sequence) &&
 		    cseq == atomic_load_acq_int(&pps->ppsinfo.clear_sequence)) {
 #endif /* __rtems__ */
+#ifndef __rtems__
 			if (abi_aware(pps, 1) && pps->driver_mtx != NULL) {
 				if (pps->flags & PPSFLAG_MTX_SPIN) {
 					err = msleep_spin(pps, pps->driver_mtx,
@@ -1954,6 +1961,12 @@ pps_fetch(struct pps_fetch_args *fapi, struct pps_state *pps)
 			} else {
 				err = tsleep(pps, PCATCH, "ppsfch", timo);
 			}
+#else /* __rtems__ */
+            if (pps->wait_event != NULL)
+                err = (*pps->wait_event)(pps, fapi->timeout);
+            else
+                err = EAGAIN;
+#endif /* __rtems__ */
 			if (err == EWOULDBLOCK) {
 				if (fapi->timeout.tv_sec == -1) {
 					continue;
@@ -2227,7 +2240,12 @@ pps_event(struct pps_state *pps, int event)
 #endif
 
 	/* Wakeup anyone sleeping in pps_fetch().  */
+#ifndef __rtems__
 	wakeup(pps);
+#else /* __rtems__ */
+    if (pps->wakeup != NULL)
+        (*pps->wakeup)(pps);
+#endif /* __rtems__ */
 }
 #else /* __rtems__ */
 /* FIXME: https://devel.rtems.org/ticket/2349 */
-- 
2.25.1



More information about the devel mailing list