[PATCH 022/111] LEON: added network device configuration helper function

Daniel Hellstrom daniel at gaisler.com
Thu Feb 26 16:38:24 UTC 2015


---
 c/src/lib/libbsp/sparc/Makefile.am                 |    4 +
 c/src/lib/libbsp/sparc/leon2/Makefile.am           |    5 ++
 c/src/lib/libbsp/sparc/leon2/preinstall.am         |    4 +
 c/src/lib/libbsp/sparc/leon3/Makefile.am           |    6 ++
 c/src/lib/libbsp/sparc/leon3/preinstall.am         |    6 ++
 .../sparc/shared/include/network_interface_add.h   |   47 +++++++++++++++
 .../sparc/shared/net/network_interface_add.c       |   62 ++++++++++++++++++++
 7 files changed, 134 insertions(+), 0 deletions(-)
 create mode 100644 c/src/lib/libbsp/sparc/shared/include/network_interface_add.h
 create mode 100644 c/src/lib/libbsp/sparc/shared/net/network_interface_add.c

diff --git a/c/src/lib/libbsp/sparc/Makefile.am b/c/src/lib/libbsp/sparc/Makefile.am
index 719feba..cbd2a14 100644
--- a/c/src/lib/libbsp/sparc/Makefile.am
+++ b/c/src/lib/libbsp/sparc/Makefile.am
@@ -83,6 +83,10 @@ EXTRA_DIST += shared/include/b1553brm.h
 EXTRA_DIST += shared/i2c/i2cmst.c
 EXTRA_DIST += shared/include/i2cmst.h
 
+# Network configuration
+EXTRA_DIST += shared/net/network_interface_add.c
+EXTRA_DIST += shared/include/network_interface_add.h
+
 # Driver Manager
 EXTRA_DIST += shared/drvmgr/ambapp_bus.c
 EXTRA_DIST += shared/drvmgr/ambapp_bus_grlib.c
diff --git a/c/src/lib/libbsp/sparc/leon2/Makefile.am b/c/src/lib/libbsp/sparc/leon2/Makefile.am
index 008e203..3f29d46 100644
--- a/c/src/lib/libbsp/sparc/leon2/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon2/Makefile.am
@@ -166,6 +166,11 @@ leon_open_eth_rel_CPPFLAGS +=  -D__INSIDE_RTEMS_BSD_TCPIP_STACK__
 leon_open_eth_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
 endif
 
+# BSP Network configuration
+include_HEADERS += ../../sparc/shared/include/network_interface_add.h
+libbsp_a_SOURCES += ../../sparc/shared/net/network_interface_add.c
+endif
+
 libbsp_a_LIBADD = \
     ../../../libcpu/@RTEMS_CPU@/access.rel \
     ../../../libcpu/@RTEMS_CPU@/cache.rel \
diff --git a/c/src/lib/libbsp/sparc/leon2/preinstall.am b/c/src/lib/libbsp/sparc/leon2/preinstall.am
index ab2498d..11dae63 100644
--- a/c/src/lib/libbsp/sparc/leon2/preinstall.am
+++ b/c/src/lib/libbsp/sparc/leon2/preinstall.am
@@ -166,3 +166,7 @@ $(PROJECT_INCLUDE)/drvmgr/leon2_amba_bus.h: ../../sparc/shared/include/drvmgr/le
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/drvmgr/leon2_amba_bus.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/drvmgr/leon2_amba_bus.h
 
+$(PROJECT_INCLUDE)/network_interface_add.h: ../../sparc/shared/include/network_interface_add.h $(PROJECT_INCLUDE)/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/network_interface_add.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/network_interface_add.h
+endif
diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am b/c/src/lib/libbsp/sparc/leon3/Makefile.am
index dee5d57..dae3ecc 100644
--- a/c/src/lib/libbsp/sparc/leon3/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am
@@ -191,6 +191,12 @@ leon_greth_rel_CPPFLAGS += -D__INSIDE_RTEMS_BSD_TCPIP_STACK__
 leon_greth_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
 endif
 
+# BSP Network configuration
+if HAS_NETWORKING
+include_HEADERS += ../../sparc/shared/include/network_interface_add.h
+libbsp_a_SOURCES += ../../sparc/shared/net/network_interface_add.c
+endif
+
 EXTRA_DIST = shmsupp/README
 if HAS_MP
 # shmsupp
diff --git a/c/src/lib/libbsp/sparc/leon3/preinstall.am b/c/src/lib/libbsp/sparc/leon3/preinstall.am
index 631a7f0..41f7d6d 100644
--- a/c/src/lib/libbsp/sparc/leon3/preinstall.am
+++ b/c/src/lib/libbsp/sparc/leon3/preinstall.am
@@ -193,3 +193,9 @@ PREINSTALL_FILES += $(PROJECT_INCLUDE)/drvmgr/ambapp_bus_grlib.h
 $(PROJECT_INCLUDE)/drvmgr/ambapp_bus.h: ../../sparc/shared/include/drvmgr/ambapp_bus.h $(PROJECT_INCLUDE)/drvmgr/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/drvmgr/ambapp_bus.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/drvmgr/ambapp_bus.h
+
+if HAS_NETWORKING
+$(PROJECT_INCLUDE)/network_interface_add.h: ../../sparc/shared/include/network_interface_add.h $(PROJECT_INCLUDE)/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/network_interface_add.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/network_interface_add.h
+endif
diff --git a/c/src/lib/libbsp/sparc/shared/include/network_interface_add.h b/c/src/lib/libbsp/sparc/shared/include/network_interface_add.h
new file mode 100644
index 0000000..761e48b
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/shared/include/network_interface_add.h
@@ -0,0 +1,47 @@
+/*  Network interface register help function
+ * 
+ *  COPYRIGHT (c) 2008.
+ *  Cobham Gaisler AB.
+ *
+ *  This function adds a network interface to the 
+ *  rtems_bsdnet_config.ifconfig linked list of interfaces.
+ *  The interface configuration is taken from the user defined
+ *  array interface_configs. This function is useful for PnP
+ *  systems when an unknown number of interfaces are available.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in found in the file LICENSE in this distribution or at
+ *  http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef __NETWORK_INTERFACE_ADD_H__
+#define __NETWORK_INTERFACE_ADD_H__
+
+#include <rtems/rtems_bsdnet.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Interface configuration description */
+struct ethernet_config {
+	char	*ip_addr;	/* IP address */
+	char	*ip_netmask;	/* IP Netmask */
+	char	eth_adr[6];	/* Ethernet hardware MAC address */
+};
+
+/* Array with configurations for all interfaces in the system
+ * Must be defined by the user.
+ */
+extern struct ethernet_config interface_configs[];
+
+/* Routine adding interface to rtems_bsdnet_config.ifconfig linked 
+ * list of interfaces.
+ */
+int network_interface_add(struct rtems_bsdnet_ifconfig *interface);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTEMS_NETWORKCONFIG_H_ */
diff --git a/c/src/lib/libbsp/sparc/shared/net/network_interface_add.c b/c/src/lib/libbsp/sparc/shared/net/network_interface_add.c
new file mode 100644
index 0000000..6e3a58a
--- /dev/null
+++ b/c/src/lib/libbsp/sparc/shared/net/network_interface_add.c
@@ -0,0 +1,62 @@
+/*  Network interface register help function
+ * 
+ *  COPYRIGHT (c) 2008.
+ *  Cobham Gaisler AB.
+ *
+ *  This function adds a network interface to the 
+ *  rtems_bsdnet_config.ifconfig linked list of interfaces.
+ *  The interface configuration is taken from the user defined
+ *  array interface_configs. This function is useful for PnP
+ *  systems when an unknown number of interfaces are available.
+ *
+ *  The license and distribution terms for this file may be
+ *  found in found in the file LICENSE in this distribution or at
+ *  http://www.rtems.com/license/LICENSE.
+ */
+
+#include <rtems/rtems_bsdnet.h>
+#include <stdio.h>
+
+#include <network_interface_add.h>
+
+extern struct rtems_bsdnet_config rtems_bsdnet_config;
+
+/* Number of interfaces taken */
+int network_interface_cnt = 0;
+
+int network_interface_add(struct rtems_bsdnet_ifconfig *interface)
+{
+	struct ethernet_config *cfg = NULL;
+	int i, last_entry = 1;
+
+	/* Init interface description */
+	interface->next = NULL;
+
+	cfg = &interface_configs[network_interface_cnt];
+	for(i=0; i<6; i++) {
+		if ( cfg->eth_adr[i] != 0 ) {
+			last_entry = 0;
+			break;
+		}
+	}
+	/* Do we have a valid configuration? */
+	if ( last_entry == 0 ) {
+		cfg = &interface_configs[network_interface_cnt];
+
+		interface->ip_address = cfg->ip_addr;
+		interface->ip_netmask = cfg->ip_netmask;
+		interface->hardware_address = cfg->eth_adr;
+
+		network_interface_cnt++;
+	} else {
+		interface->ip_address = NULL;
+		interface->ip_netmask = NULL;
+		interface->hardware_address = NULL;
+	}
+
+	/* Insert interface first into list */
+	interface->next = rtems_bsdnet_config.ifconfig;
+	rtems_bsdnet_config.ifconfig = interface;
+
+	return 0;
+}
-- 
1.7.0.4




More information about the devel mailing list