Re: [PATCH 04/13] staging: comedi: ni_routing: Add NI signal routing info

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/09/18 17:38, Spencer E. Olson wrote:
See README for a thorough discussion of this content.

Adds tables of all register values for routing various signals to various
terminals on National Instruments hardware.  This information is directly
compared to and taken from register-level programming documentation and/or
register-level programming examples as provided by National Instruments.

Furthermore, this information was mostly compared (favorably) to the
register values already used in the comedi drivers for NI hardware.

Adds tables of valid routes for many devices.  This information is not
consistent from device to device, nor entirely consistent within device
families.  One additional major challenge is that this information does not
seem to be obtainable in any programmatic fashion, neither through the
proprietary NIDAQmx(-base) c-libraries, nor with register level
programming, _nor_ through any documentation.  In fact, the only consistent
source of this information is through the proprietary NI-MAX software,
which currently only runs on Windows platforms.  A further challenge is
that this information cannot be exported from NI-MAX, except by screenshot.

The collection and maintenance of this information is somewhat tedious and
requires frequent re-examination and comparison of NI-MAX and/or the
NI-MHDDK documentation (register programming information) and NI-MHDDK
examples.  Tools are added with this patch to facilitate generating CSV
files from the data tables.  These CSV files can be used with a spreadsheet
program to provide better visual comparision with screenshots gathered from
NI-MAX.  Tools are also added to regenerate the data tables from CSV
content--this greatly enhances updating data tables with large changes
(such as when adding devices).

Signed-off-by: Spencer E. Olson <olsonse@xxxxxxxxx>
---
  .../staging/comedi/drivers/ni_routing/README  |  240 ++
  .../drivers/ni_routing/ni_device_routes.c     |   66 +
  .../ni_routing/ni_device_routes/pci-6070e.c   |  637 ++++
  .../ni_routing/ni_device_routes/pci-6220.c    | 1416 +++++++
  .../ni_routing/ni_device_routes/pci-6221.c    | 1600 ++++++++
  .../ni_routing/ni_device_routes/pci-6229.c    | 1600 ++++++++
  .../ni_routing/ni_device_routes/pci-6251.c    | 1650 ++++++++
  .../ni_routing/ni_device_routes/pci-6254.c    | 1462 +++++++
  .../ni_routing/ni_device_routes/pci-6259.c    | 1650 ++++++++
  .../ni_routing/ni_device_routes/pci-6534.c    |  288 ++
  .../ni_routing/ni_device_routes/pci-6602.c    | 3376 +++++++++++++++++
  .../ni_routing/ni_device_routes/pci-6713.c    |  398 ++
  .../ni_routing/ni_device_routes/pci-6723.c    |  398 ++
  .../ni_routing/ni_device_routes/pci-6733.c    |  426 +++
  .../ni_routing/ni_device_routes/pxi-6030e.c   |  606 +++
  .../ni_routing/ni_device_routes/pxi-6224.c    | 1430 +++++++
  .../ni_routing/ni_device_routes/pxi-6225.c    | 1611 ++++++++
  .../ni_routing/ni_device_routes/pxi-6251.c    | 1653 ++++++++
  .../ni_routing/ni_device_routes/pxi-6733.c    |  426 +++
  .../ni_routing/ni_device_routes/pxie-6251.c   | 1654 ++++++++
  .../drivers/ni_routing/ni_route_values.c      |   96 +
  .../ni_routing/ni_route_values/ni_660x.c      |  641 ++++
  .../ni_routing/ni_route_values/ni_eseries.c   |  593 +++
  .../ni_routing/ni_route_values/ni_mseries.c   | 1743 +++++++++
  .../drivers/ni_routing/tools/.gitignore       |    4 +
  .../comedi/drivers/ni_routing/tools/Makefile  |   67 +
  .../ni_routing/tools/convert_c_to_py.c        |  161 +
  .../ni_routing/tools/convert_csv_to_c.py      |  409 ++
  .../ni_routing/tools/convert_py_to_csv.py     |   67 +
  .../ni_routing/tools/csv_collection.py        |   40 +
  .../ni_routing/tools/make_blank_csv.py        |   32 +
  .../drivers/ni_routing/tools/ni_names.py      |   55 +
  32 files changed, 26495 insertions(+)
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/README
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6220.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6221.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6229.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6251.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6254.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6259.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6534.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6602.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6713.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6723.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6733.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6030e.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6224.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6225.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6251.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxi-6733.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pxie-6251.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_route_values.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_660x.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_eseries.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/ni_route_values/ni_mseries.c
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/tools/.gitignore
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/tools/Makefile
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c
  create mode 100755 drivers/staging/comedi/drivers/ni_routing/tools/convert_csv_to_c.py
  create mode 100755 drivers/staging/comedi/drivers/ni_routing/tools/convert_py_to_csv.py
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/tools/csv_collection.py
  create mode 100755 drivers/staging/comedi/drivers/ni_routing/tools/make_blank_csv.py
  create mode 100644 drivers/staging/comedi/drivers/ni_routing/tools/ni_names.py


[snipped README file]

diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c
new file mode 100644
index 000000000000..8af135aa5188
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
+/*
+ *  comedi/drivers/ni_routing/ni_device_routes.c
+ *  List of valid routes for specific NI boards.
+ *
+ *  COMEDI - Linux Control and Measurement Device Interface
+ *  Copyright (C) 2016 Spencer E. Olson <olsonse@xxxxxxxxx>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ */
+
+/*
+ * This file is meant to be included by comedi/drivers/ni_routes.c
+ */
+
+#include "../../comedi.h"
+#include "../ni_routes.h"
+
+#include "ni_device_routes/pxi-6030e.c"
+#include "ni_device_routes/pci-6070e.c"
+#include "ni_device_routes/pci-6220.c"
+#include "ni_device_routes/pci-6221.c"
+#include "ni_device_routes/pxi-6224.c"
+#include "ni_device_routes/pxi-6225.c"
+#include "ni_device_routes/pci-6229.c"
+#include "ni_device_routes/pci-6251.c"
+#include "ni_device_routes/pxi-6251.c"
+#include "ni_device_routes/pxie-6251.c"
+#include "ni_device_routes/pci-6254.c"
+#include "ni_device_routes/pci-6259.c"
+#include "ni_device_routes/pci-6534.c"
+#include "ni_device_routes/pci-6602.c"
+#include "ni_device_routes/pci-6713.c"
+#include "ni_device_routes/pci-6723.c"
+#include "ni_device_routes/pci-6733.c"
+#include "ni_device_routes/pxi-6733.c"

Is there any particular reason why these need to be #include'd rather than separately compiled and linked? Would it be a lot harder to maintain if separately compiled and linked?

Including .c files in .c files is kind of frowned upon a lot. (Yes, I know the ni_*mio drivers do it currently....) To make matters worse, I think your next patch also #include's this .c file into another .c file.

+
+static const struct ni_device_routes *device_routes_list[] = {
+	&pxi_6030e_device_routes,
+	&pci_6070e_device_routes,
+	&pci_6220_device_routes,
+	&pci_6221_device_routes,
+	&pxi_6224_device_routes,
+	&pxi_6225_device_routes,
+	&pci_6229_device_routes,
+	&pci_6251_device_routes,
+	&pxi_6251_device_routes,
+	&pxie_6251_device_routes,
+	&pci_6254_device_routes,
+	&pci_6259_device_routes,
+	&pci_6534_device_routes,
+	&pci_6602_device_routes,
+	&pci_6713_device_routes,
+	&pci_6723_device_routes,
+	&pci_6733_device_routes,
+	&pxi_6733_device_routes,
+};

Needs more 'const'-ification, e.g:

static const struct ni_device_routes * const device_routes_list[] = {

To avoid having to use ARRAY_SIZE(device_routes_list), especially if changed to be externally linked, perhaps the list should be terminated with a NULL pointer.

diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
new file mode 100644
index 000000000000..093019c7f8ab
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
@@ -0,0 +1,637 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
+/*
+ *  comedi/drivers/ni_routing/ni_device_routes/pci-6070e.c
+ *  List of valid routes for specific NI boards.
+ *
+ *  COMEDI - Linux Control and Measurement Device Interface
+ *  Copyright (C) 2016 Spencer E. Olson <olsonse@xxxxxxxxx>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ */
+
+/*
+ * This file is meant to be included by
+ * comedi/drivers/ni_routing/ni_device_routes.c
+ */
+
+#include "../../../comedi.h"
+#include "../../ni_routes.h"
+
+static struct ni_device_routes pci_6070e_device_routes = {

These 'struct ni_device_routes' variables should also be declared 'const'.

+	.device = "pci-6070e",
+	.routes = (struct ni_route_set[]){

The 'routes' member of 'struct ni_device_routes' should be declared 'const struct ni_route_set *' and the compound literal used to initialize it should be of type 'const struct ni_route_set[]'.

+		{
+			.dest = NI_PFI(0),
+			.src = (int[]){

The 'src' member of 'struct ni_route_set' should be declared 'const int *', and the compound literal used to initialize it should be of type 'const int[]'.

+				NI_AI_StartTrigger,
+				0, /* Termination */
+			}
+		},

[snipped similar code]

diff --git a/drivers/staging/comedi/drivers/ni_routing/ni_route_values.c b/drivers/staging/comedi/drivers/ni_routing/ni_route_values.c
new file mode 100644
index 000000000000..9b2c6e65d300
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/ni_route_values.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
+/*
+ *  comedi/drivers/ni_routing/ni_route_values.c
+ *  Route information for NI boards.
+ *
+ *  COMEDI - Linux Control and Measurement Device Interface
+ *  Copyright (C) 2016 Spencer E. Olson <olsonse@xxxxxxxxx>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ */
+
+/*
+ * This file includes the tables that are a list of all the values of various
+ * signals routes available on NI hardware.  In many cases, one does not
+ * explicitly make these routes, rather one might indicate that something is
+ * used as the source of one particular trigger or another (using
+ * *_src=TRIG_EXT).
+ *
+ * This file is meant to be included by comedi/drivers/ni_routes.c
+ */
+
+#include "../../comedi.h"
+
+#define B(x)	((x) - NI_NAMES_BASE)
+
+/** Marks a register value as valid, implemented, and tested. */
+#define V(x)	(((x) & 0x7f) | 0x80)
+
+#ifndef NI_ROUTE_VALUE_EXTERNAL_CONVERSION
+	/** Marks a register value as implemented but needing testing. */
+	#define I(x)	V(x)
+	/** Marks a register value as not implemented. */
+	#define U(x)	0x0
+
+	typedef u8 register_type;
+#else
+	/** Marks a register value as implemented but needing testing. */
+	#define I(x)	(((x) & 0x7f) | 0x100)
+	/** Marks a register value as not implemented. */
+	#define U(x)	(((x) & 0x7f) | 0x200)
+
+	#define MARKED_V(x)	(((x) & 0x80) != 0)
+	#define MARKED_I(x)	(((x) & 0x100) != 0)
+	#define MARKED_U(x)	(((x) & 0x200) != 0)
+
+	/* need more space to store extra marks */
+	typedef u16 register_type;
+#endif
+
+/* Mask out the marking bit(s). */
+#define UNMARK(x)	((x) & 0x7f)
+
+/*
+ * Gi_SRC(x,1) implements Gi_Src_SubSelect = 1
+ *
+ * This appears to only really be a valid MUX for m-series devices.
+ */
+#define Gi_SRC(val, subsel)	((val) | ((subsel) << 6))
+
+/**
+ * struct family_route_values - Register values for all routes for a particular
+ *				family.
+ * @family: lower-case string representation of a specific series or family of
+ *	    devices from National Instruments where each member of this family
+ *	    shares the same register values for the various signal MUXes.  It
+ *	    should be noted that not all devices of any family have access to
+ *	    all routes defined.
+ * @register_values: Table of all register values for various signal MUXes on
+ *	    National Instruments devices.  The first index of this table is the
+ *	    signal destination (i.e. identification of the signal MUX).  The
+ *	    second index of this table is the signal source (i.e. input of the
+ *	    signal MUX).
+ */
+struct family_route_values {
+	const char *family;
+	const register_type register_values[NI_NUM_NAMES][NI_NUM_NAMES];
+};
+
+#include "ni_route_values/ni_660x.c"
+#include "ni_route_values/ni_eseries.c"
+#include "ni_route_values/ni_mseries.c"
+
+static const struct family_route_values *all_route_values[] = {
+	&ni_660x_route_values,
+	&ni_eseries_route_values,
+	&ni_mseries_route_values,
+};

The same comments apply here as for "ni_routes.c" above, regarding .c file inclusion versus separate compilation and linking, regarding the 'const'-ification of the variables, and regarding possible termination of this list with a NULL pointer.

[snipped the ni_route_values/*.c files]

diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/.gitignore b/drivers/staging/comedi/drivers/ni_routing/tools/.gitignore
new file mode 100644
index 000000000000..3bf7967f1352
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/.gitignore
@@ -0,0 +1,4 @@
+comedi_h.py
+*.pyc
+ni_values.py
+convert_c_to_py
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/Makefile b/drivers/staging/comedi/drivers/ni_routing/tools/Makefile
new file mode 100644
index 000000000000..3f2736b9f35e
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/Makefile
@@ -0,0 +1,67 @@
+# this make file is simply to help autogenerate these files:
+# 	ni_route_values.h
+#	ni_device_routes.h
+# in order to do this, we are also generating a python representation (using
+# ctypesgen) of ../../comedi.h.
+# This allows us to sort NI signal/terminal names numerically to use a binary
+# search through the device_routes tables to find valid routes.
+
+ALL:
+	@echo Typical targets:
+	@echo "\`make csv-files\`"
+	@echo "  Creates new csv-files using content of c-files of existing"
+	@echo "  ni_routing/* content.  New csv files are placed in csv"
+	@echo "  sub-directory."
+	@echo "\`make c-files\`"
+	@echo "  Creates new c-files using content of csv sub-directory.  These"
+	@echo "  new c-files can be compared to the active content in the"
+	@echo "  ni_routing directory."
+	@echo "\`make csv-blank\`"
+	@echo "  Create a new blank csv file.  This is useful for establishing a"
+	@echo "  new data table for either a device family \(less likely\) or a"
+	@echo "  specific board of an existing device family \(more likely\)."
+	@echo "\`make clean\`"
+	@echo "  Remove all generated files/directories."
+	@echo "\`make everything\`"
+	@echo "  Build all csv-files, then all new c-files."
+
+everything : csv-files c-files csv-blank
+
+CPPFLAGS=-D"BIT(x)=(1UL<<(x))" -D__user=
+
+comedi_h.py : ../../../comedi.h
+	ctypesgen.py $< --include "sys/ioctl.h" --cpp 'gcc -E $(CPPFLAGS)' -o $@
+
+convert_c_to_py:
+	gcc -g convert_c_to_py.c -o convert_c_to_py -std=c99

It probably doesn't matter for these maintenance utilities, but the kernel itself is compiled with '-std=gnu89'.

+
+ni_values.py: convert_c_to_py
+	./convert_c_to_py
+
+csv-files : ni_values.py comedi_h.py
+	./convert_py_to_csv.py
+
+csv-blank :
+	./make_blank_csv.py
+	@echo New blank csv signal table in csv/blank_route_table.csv
+
+c-files : comedi_h.py
+	./convert_csv_to_c.py --route_values --device_routes
+
+clean :
+	$(RM) -f comedi_h.py ni_values.py convert_c_to_py *.pyc
+	$(RM) -rf c/ csv/
+
+# Note:  One could also use ctypeslib in order to generate these files.  The
+# caveat is that ctypeslib does not do a great job at handling macro functions.
+# The make rules are as follows:
+# comedi.h.xml : ../../comedi.h
+# 	# note that we have to use PWD here to avoid h2xml finding a system
+# 	# installed version of the comedilib/comedi.h file
+# 	h2xml ${PWD}/../../comedi.h -c -D__user="" -D"BIT(x)=(1<<(x))" \
+# 		-o comedi.h.xml
+#
+# comedi_h.py : comedi.h.xml
+# 	xml2py ./comedi.h.xml -o comedi_h.py
+# clean :
+# 	rm -f comedi.h.xml comedi_h.py comedi_h.pyc
diff --git a/drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c b/drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c
new file mode 100644
index 000000000000..e9dae31f4706
--- /dev/null
+++ b/drivers/staging/comedi/drivers/ni_routing/tools/convert_c_to_py.c
@@ -0,0 +1,161 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* vim: set ts=8 sw=8 noet tw=80 nowrap: */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <errno.h>
+#include <stdlib.h>
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef int8_t  s8;
+#define __user
+#define BIT(x)  (1UL << (x))
+
+#define NI_ROUTE_VALUE_EXTERNAL_CONVERSION 1
+
+#include "../ni_route_values.c"
+#include "../ni_device_routes.c"
+
+#include <stdio.h>
+
+#define RVij(rv, src, dest)	((rv)->register_values[(dest)][(src)])
+
+/*
+ * write out
+ * {
+ *   "family" : "<family-name>",
+ *   "register_values": {
+ *      <destination0>:[src0, src1, ...],
+ *      <destination0>:[src0, src1, ...],
+ *      ...
+ *   }
+ * }
+ */
+void family_write(const struct family_route_values *rv, FILE *fp)
+{
+	fprintf(fp,
+		"  \"%s\" : {\n"
+		"    # dest -> {src0:val0, src1:val1, ...}\n"
+		, rv->family);
+	for (unsigned int dest = NI_NAMES_BASE;
+	     dest < (NI_NAMES_BASE + NI_NUM_NAMES);
+	     ++dest) {
+		unsigned int src = NI_NAMES_BASE;
+
+		for (; src < (NI_NAMES_BASE + NI_NUM_NAMES) &&
+		     RVij(rv, B(src), B(dest)) == 0; ++src)
+		;
+
+		if (src >= (NI_NAMES_BASE + NI_NUM_NAMES))
+			continue; /* no data here */
+
+		fprintf(fp, "    %u : {\n", dest);
+		for (src = NI_NAMES_BASE; src < (NI_NAMES_BASE + NI_NUM_NAMES);
+		     ++src) {
+			register_type r = RVij(rv, B(src), B(dest));
+			const char *M;
+
+			if (r == 0) {
+				continue;
+			} else if (MARKED_V(r)) {
+				M = "V";
+			} else if (MARKED_I(r)) {
+				M = "I";
+			} else if (MARKED_U(r)) {
+				M = "U";
+			} else {
+				fprintf(stderr,
+					"Invalid register marking %s[%u][%u] = %u\n",
+					rv->family, dest, src, r);
+				exit(1);
+			}
+
+			fprintf(fp, "      %u : \"%s(%u)\",\n",
+				src, M, UNMARK(r));
+		}
+		fprintf(fp, "    },\n");
+	}
+	fprintf(fp, "  },\n\n");
+}
+
+bool is_valid_ni_sig(unsigned int sig)
+{
+	return (sig >= NI_NAMES_BASE) && (sig < (NI_NAMES_BASE + NI_NUM_NAMES));
+}
+
+/*
+ * write out
+ * {
+ *   "family" : "<family-name>",
+ *   "register_values": {
+ *      <destination0>:[src0, src1, ...],
+ *      <destination0>:[src0, src1, ...],
+ *      ...
+ *   }
+ * }
+ */
+void device_write(const struct ni_device_routes *dR, FILE *fp)
+{
+	fprintf(fp,
+		"  \"%s\" : {\n"
+		"    # dest -> [src0, src1, ...]\n"
+		, dR->device);
+
+	unsigned int i = 0;
+
+	while (dR->routes[i].dest != 0) {
+		if (!is_valid_ni_sig(dR->routes[i].dest)) {
+			fprintf(stderr,
+				"Invalid NI signal value [%u] for destination %s.[%u]\n",
+				dR->routes[i].dest, dR->device, i);
+			exit(1);
+		}
+
+		fprintf(fp, "    %u : [", dR->routes[i].dest);
+
+		unsigned int j = 0;
+
+		while (dR->routes[i].src[j] != 0) {
+			if (!is_valid_ni_sig(dR->routes[i].src[j])) {
+				fprintf(stderr,
+					"Invalid NI signal value [%u] for source %s.[%u].[%u]\n",
+					dR->routes[i].src[j], dR->device, i, j);
+				exit(1);
+			}
+
+			fprintf(fp, "%u,", dR->routes[i].src[j]);
+
+			++j;
+		}
+		fprintf(fp, "],\n");
+
+		++i;
+	}
+	fprintf(fp, "  },\n\n");
+}
+
+int main(void)
+{
+	int n_families = sizeof(all_route_values)   / sizeof(void *);
+	int n_devices  = sizeof(device_routes_list) / sizeof(void *);

The more legitimate way to get the length of the array is 'sizeof(array) / sizeof(array[0])'. But maybe these will be changed to NULL-terminated lists anyway?

+
+	FILE *fp = fopen("ni_values.py", "w");
+
+	/* write route register values */
+	fprintf(fp, "ni_route_values = {\n");
+	for (int i = 0; i < n_families; ++i)
+		family_write(all_route_values[i], fp);
+	fprintf(fp, "}\n\n");
+
+	/* write valid device routes */
+	fprintf(fp, "ni_device_routes = {\n");
+	for (int i = 0; i < n_devices; ++i)
+		device_write(device_routes_list[i], fp);
+	fprintf(fp, "}\n");
+
+	/* finish; close file */
+	fclose(fp);
+	return 0;
+}

[I don't really have any comments on the maintenance scripts in Python, but I guess they'll need some minor tweaks to do the requested constification changes to the C code.]

--
-=( Ian Abbott <abbotti@xxxxxxxxx> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268.  Registered address:    )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux