From 799598714b6dcea52de10c3fce62dec007f7e5b4 Mon Sep 17 00:00:00 2001
From: Adam Wujek <adam.wujek@cern.ch>
Date: Thu, 21 Jul 2016 14:57:36 +0200
Subject: [PATCH] userspace/libwr: move softpll header to libwr

--move softpll_export.h to the libwr
--create libwr/softpll.h with:
  FPGA_SPLL_STAT
  SPLL_MAGIC
--move strncpy_e from snmpd to libwr

Signed-off-by: Adam Wujek <adam.wujek@cern.ch>
---
 userspace/libwr/include/libwr/softpll.h       |  8 ++++++++
 .../include/libwr}/softpll_export.h           |  0
 userspace/libwr/include/libwr/util.h          |  4 ++++
 userspace/libwr/util.c                        | 16 +++++++++++++++
 userspace/snmpd/wrsSpllStatusGroup.c          |  5 +----
 userspace/snmpd/wrsSpllStatusGroup.h          |  2 +-
 userspace/snmpd/wrsSpllVersionGroup.c         | 20 ++-----------------
 7 files changed, 32 insertions(+), 23 deletions(-)
 create mode 100644 userspace/libwr/include/libwr/softpll.h
 rename userspace/{snmpd => libwr/include/libwr}/softpll_export.h (100%)

diff --git a/userspace/libwr/include/libwr/softpll.h b/userspace/libwr/include/libwr/softpll.h
new file mode 100644
index 000000000..856a7de3b
--- /dev/null
+++ b/userspace/libwr/include/libwr/softpll.h
@@ -0,0 +1,8 @@
+#ifndef __SOFTPLL_H
+#define __SOFTPLL_H
+
+#include "softpll_export.h"
+#define FPGA_SPLL_STAT 0x10006800
+#define SPLL_MAGIC 0x5b1157a7
+
+#endif  /* __SOFTPLL_H */
diff --git a/userspace/snmpd/softpll_export.h b/userspace/libwr/include/libwr/softpll_export.h
similarity index 100%
rename from userspace/snmpd/softpll_export.h
rename to userspace/libwr/include/libwr/softpll_export.h
diff --git a/userspace/libwr/include/libwr/util.h b/userspace/libwr/include/libwr/util.h
index 3351148d8..f247726b9 100644
--- a/userspace/libwr/include/libwr/util.h
+++ b/userspace/libwr/include/libwr/util.h
@@ -14,4 +14,8 @@ uint64_t get_monotonic_tics(void);
 /* get monotonic number of seconds */
 time_t get_monotonic_sec(void);
 
+/* Change endianess of the string, for example when accessing strings in
+ * the SoftPLL */
+void strncpy_e(char *d, char *s, int len);
+
 #endif /* __LIBWR_HW_UTIL_H */
diff --git a/userspace/libwr/util.c b/userspace/libwr/util.c
index 57763ab53..877dbbe59 100644
--- a/userspace/libwr/util.c
+++ b/userspace/libwr/util.c
@@ -4,6 +4,7 @@
 
 #include <libwr/wrs-msg.h>
 #include <libwr/util.h>
+#include <arpa/inet.h> /* for ntohl */
 
 static int loops_per_msec = -1;
 
@@ -69,3 +70,18 @@ time_t get_monotonic_sec(void)
 	clock_gettime(CLOCK_MONOTONIC, &tv);
 	return tv.tv_sec;
 }
+
+/* change endianess of the string, for example when accessing strings in
+ * the SoftPLL */
+void strncpy_e(char *d, char *s, int len)
+{
+	int i;
+	int len_4;
+	uint32_t *s_i, *d_i;
+
+	s_i = (uint32_t *)s;
+	d_i = (uint32_t *)d;
+	len_4 = (len+3)/4; /* ceil len to word lenth (4) */
+	for (i = 0; i < len_4; i++)
+		d_i[i] = ntohl(s_i[i]);
+}
diff --git a/userspace/snmpd/wrsSpllStatusGroup.c b/userspace/snmpd/wrsSpllStatusGroup.c
index 53ac9160d..8d3b90caa 100644
--- a/userspace/snmpd/wrsSpllStatusGroup.c
+++ b/userspace/snmpd/wrsSpllStatusGroup.c
@@ -1,11 +1,8 @@
 #include "wrsSnmp.h"
-#include "softpll_export.h"
+#include <libwr/softpll.h>
 #include "wrsSpllStatusGroup.h"
 #include "snmp_mmap.h"
 
-#define FPGA_SPLL_STAT 0x10006800
-#define SPLL_MAGIC 0x5b1157a7
-
 static struct spll_stats *spll_stats_p;
 
 static struct pickinfo wrsSpllStatus_pickinfo[] = {
diff --git a/userspace/snmpd/wrsSpllStatusGroup.h b/userspace/snmpd/wrsSpllStatusGroup.h
index 7e12999ae..49a529d28 100644
--- a/userspace/snmpd/wrsSpllStatusGroup.h
+++ b/userspace/snmpd/wrsSpllStatusGroup.h
@@ -1,7 +1,7 @@
 #ifndef WRS_SPLL_STATUS_GROUP_H
 #define WRS_SPLL_STATUS_GROUP_H
 
-#include "softpll_export.h"
+#include <libwr/softpll.h>
 
 #define WRSSPLLSTATUS_CACHE_TIMEOUT 5
 #define WRSSPLLSTATUS_OID WRS_OID, 7, 3, 2
diff --git a/userspace/snmpd/wrsSpllVersionGroup.c b/userspace/snmpd/wrsSpllVersionGroup.c
index b62334a6c..eae112fb9 100644
--- a/userspace/snmpd/wrsSpllVersionGroup.c
+++ b/userspace/snmpd/wrsSpllVersionGroup.c
@@ -1,11 +1,9 @@
 #include "wrsSnmp.h"
 #include "wrsSpllVersionGroup.h"
-#include "softpll_export.h"
+#include <libwr/softpll.h>
+#include <libwr/util.h>
 #include "snmp_mmap.h"
 
-#define FPGA_SPLL_STAT 0x10006800
-#define SPLL_MAGIC 0x5b1157a7
-
 static struct spll_stats *spll_stats_p;
 
 static struct pickinfo wrsSpllVersion_pickinfo[] = {
@@ -16,20 +14,6 @@ static struct pickinfo wrsSpllVersion_pickinfo[] = {
 
 struct wrsSpllVersion_s wrsSpllVersion_s;
 
-/* change endianess of the string */
-static void strncpy_e(char *d, char *s, int len)
-{
-	int i;
-	int len_4;
-	uint32_t *s_i, *d_i;
-
-	s_i = (uint32_t *)s;
-	d_i = (uint32_t *)d;
-	len_4 = (len+3)/4; /* ceil len to word lenth (4) */
-	for (i = 0; i < len_4; i++)
-		d_i[i] = ntohl(s_i[i]);
-}
-
 time_t wrsSpllVersion_data_fill(void)
 {
 	static time_t time_update;
-- 
GitLab