Re: [PATCH 06/15] staging: comedi: add interface to ni routing table information
On 12/10/16 12:05, Spencer E. Olson wrote: Adds interface and associated unittests for accessing/looking-up/validating the new ni routing table information. Signed-off-by: Spencer E. Olson --- drivers/staging/comedi/Kconfig | 4 + drivers/staging/comedi/drivers/Makefile| 1 + drivers/staging/comedi/drivers/ni_routes.c | 321 +++ drivers/staging/comedi/drivers/ni_routes.h | 315 +++ drivers/staging/comedi/drivers/ni_stc.h| 4 + drivers/staging/comedi/drivers/tests/Makefile | 3 +- .../staging/comedi/drivers/tests/ni_routes_test.c | 596 + 7 files changed, 1243 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/comedi/drivers/ni_routes.c create mode 100644 drivers/staging/comedi/drivers/ni_routes.h create mode 100644 drivers/staging/comedi/drivers/tests/ni_routes_test.c diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index e7255f8..7d614f4 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1105,6 +1105,7 @@ config COMEDI_NI_TIOCMD depends on HAS_DMA select COMEDI_NI_TIO select COMEDI_MITE + select COMEDI_NI_ROUTES endif # COMEDI_PCI_DRIVERS @@ -1319,4 +1320,7 @@ config COMEDI_NI_LABPC_ISADMA config COMEDI_NI_TIO tristate +config COMEDI_NI_ROUTES + tristate + endif # COMEDI diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index ff4fb78..f374739 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -137,6 +137,7 @@ obj-$(CONFIG_COMEDI_VMK80XX)+= vmk80xx.o obj-$(CONFIG_COMEDI_MITE) += mite.o obj-$(CONFIG_COMEDI_NI_TIO)+= ni_tio.o obj-$(CONFIG_COMEDI_NI_TIOCMD) += ni_tiocmd.o +obj-$(CONFIG_COMEDI_NI_ROUTES) += ni_routes.o obj-$(CONFIG_COMEDI_NI_LABPC) += ni_labpc_common.o obj-$(CONFIG_COMEDI_NI_LABPC_ISADMA) += ni_labpc_isadma.o diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c new file mode 100644 index 000..3f3c3db --- /dev/null +++ b/drivers/staging/comedi/drivers/ni_routes.c @@ -0,0 +1,321 @@ +/* vim: set ts=8 sw=8 noet tw=80 nowrap: */ +/* + * comedi/drivers/ni_routes.c + * Route information for NI boards. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2016 Spencer E. Olson + * + * 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. + */ + +#include +#include +#include + +#include "../comedi.h" + +#include "ni_routes.h" +#include "ni_routing/ni_route_values.c" +#include "ni_routing/ni_device_routes.c" + +/* + * This is defined in ni_routing/ni_route_values.c: + * #define B(x)((x) - NI_NAMES_BASE) + */ + +/* + * This is defined in ni_routing/ni_route_values.c to identify clearly elements + * of the table that were set. In other words, entries that are zero are + * invalid. To get the value to use for the register, one must mask out the + * high bit. + * + * #define V(x)((x) | 0x80) + */ + +/* Mask out the valid-value marking bit. */ +#define UnV(x) ((x) & (~(0x80))) + +#define RVi(table, src, dest) (table)[(src) * NI_NUM_NAMES + (dest)] + +static const size_t route_table_size = NI_NUM_NAMES * NI_NUM_NAMES; + +/* + * Find the proper route_values and ni_device_routes tables for this particular + * device. + * + * Return: -ENODATA if either was not found; 0 if both were found. + */ +static inline int ni_find_device_routes(const char *device_family, + const char *board_name, + struct ni_route_tables *tables) We generally don't use 'inline' in .c files, only in .h files. That applies to the other functions in this file too, especially the externally linked ones. [snip] diff --git a/drivers/staging/comedi/drivers/ni_routes.h b/drivers/staging/comedi/drivers/ni_routes.h new file mode 100644 index 000..9422cf5 --- /dev/null +++ b/drivers/staging/comedi/drivers/ni_routes.h @@ -0,0 +1,315 @@ +/* vim: set ts=8 sw=8 noet tw=80 nowrap: */ +/* + * comedi/drivers/ni_routes.h + * Route information for NI boards. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2016 Spencer E. Olson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as publis
[PATCH 06/15] staging: comedi: add interface to ni routing table information
Adds interface and associated unittests for accessing/looking-up/validating the new ni routing table information. Signed-off-by: Spencer E. Olson --- drivers/staging/comedi/Kconfig | 4 + drivers/staging/comedi/drivers/Makefile| 1 + drivers/staging/comedi/drivers/ni_routes.c | 321 +++ drivers/staging/comedi/drivers/ni_routes.h | 315 +++ drivers/staging/comedi/drivers/ni_stc.h| 4 + drivers/staging/comedi/drivers/tests/Makefile | 3 +- .../staging/comedi/drivers/tests/ni_routes_test.c | 596 + 7 files changed, 1243 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/comedi/drivers/ni_routes.c create mode 100644 drivers/staging/comedi/drivers/ni_routes.h create mode 100644 drivers/staging/comedi/drivers/tests/ni_routes_test.c diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index e7255f8..7d614f4 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1105,6 +1105,7 @@ config COMEDI_NI_TIOCMD depends on HAS_DMA select COMEDI_NI_TIO select COMEDI_MITE + select COMEDI_NI_ROUTES endif # COMEDI_PCI_DRIVERS @@ -1319,4 +1320,7 @@ config COMEDI_NI_LABPC_ISADMA config COMEDI_NI_TIO tristate +config COMEDI_NI_ROUTES + tristate + endif # COMEDI diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile index ff4fb78..f374739 100644 --- a/drivers/staging/comedi/drivers/Makefile +++ b/drivers/staging/comedi/drivers/Makefile @@ -137,6 +137,7 @@ obj-$(CONFIG_COMEDI_VMK80XX)+= vmk80xx.o obj-$(CONFIG_COMEDI_MITE) += mite.o obj-$(CONFIG_COMEDI_NI_TIO)+= ni_tio.o obj-$(CONFIG_COMEDI_NI_TIOCMD) += ni_tiocmd.o +obj-$(CONFIG_COMEDI_NI_ROUTES) += ni_routes.o obj-$(CONFIG_COMEDI_NI_LABPC) += ni_labpc_common.o obj-$(CONFIG_COMEDI_NI_LABPC_ISADMA) += ni_labpc_isadma.o diff --git a/drivers/staging/comedi/drivers/ni_routes.c b/drivers/staging/comedi/drivers/ni_routes.c new file mode 100644 index 000..3f3c3db --- /dev/null +++ b/drivers/staging/comedi/drivers/ni_routes.c @@ -0,0 +1,321 @@ +/* vim: set ts=8 sw=8 noet tw=80 nowrap: */ +/* + * comedi/drivers/ni_routes.c + * Route information for NI boards. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 2016 Spencer E. Olson + * + * 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. + */ + +#include +#include +#include + +#include "../comedi.h" + +#include "ni_routes.h" +#include "ni_routing/ni_route_values.c" +#include "ni_routing/ni_device_routes.c" + +/* + * This is defined in ni_routing/ni_route_values.c: + * #define B(x)((x) - NI_NAMES_BASE) + */ + +/* + * This is defined in ni_routing/ni_route_values.c to identify clearly elements + * of the table that were set. In other words, entries that are zero are + * invalid. To get the value to use for the register, one must mask out the + * high bit. + * + * #define V(x)((x) | 0x80) + */ + +/* Mask out the valid-value marking bit. */ +#define UnV(x) ((x) & (~(0x80))) + +#define RVi(table, src, dest) (table)[(src) * NI_NUM_NAMES + (dest)] + +static const size_t route_table_size = NI_NUM_NAMES * NI_NUM_NAMES; + +/* + * Find the proper route_values and ni_device_routes tables for this particular + * device. + * + * Return: -ENODATA if either was not found; 0 if both were found. + */ +static inline int ni_find_device_routes(const char *device_family, + const char *board_name, + struct ni_route_tables *tables) +{ + const struct ni_device_routes *dr = NULL; + const u8 *rv = NULL; + int i; + + /* First, find the register_values table for this device family */ + for (i = 0; i < ARRAY_SIZE(all_route_values); ++i) { + if (memcmp(all_route_values[i].family, device_family, + strnlen(device_family, 30)) == 0) { + rv = &all_route_values[i].register_values[0][0]; + break; + } + } + + if (!rv) + return -ENODATA; + + /* Second, find the set of routes valid for this device. */ + for (i = 0; i < ARRAY_SIZE(device_routes_list); ++i) { + if (memcmp(device_routes_list[i].device, board_name, + strnlen(board_name, 30)) == 0