From 7a80d315894dd60b36dffdb8436d1c640314b5a3 Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Tue, 19 May 2015 09:54:14 +0200
Subject: [PATCH] sys: auto_init: add auto initialization for dev_eth

---
 sys/auto_init/Makefile                   |  4 ++
 sys/auto_init/auto_init.c                |  5 ++
 sys/auto_init/dev_eth/Makefile           |  3 ++
 sys/auto_init/dev_eth/dev_eth_autoinit.c | 36 +++++++++++++++
 sys/include/dev_eth_autoinit.h           | 58 ++++++++++++++++++++++++
 5 files changed, 106 insertions(+)
 create mode 100644 sys/auto_init/dev_eth/Makefile
 create mode 100644 sys/auto_init/dev_eth/dev_eth_autoinit.c
 create mode 100644 sys/include/dev_eth_autoinit.h

diff --git a/sys/auto_init/Makefile b/sys/auto_init/Makefile
index f4594496de..c913303873 100644
--- a/sys/auto_init/Makefile
+++ b/sys/auto_init/Makefile
@@ -12,4 +12,8 @@ ifneq (,$(filter auto_init_ng_netif,$(USEMODULE)))
 DIRS += netif
 endif
 
+ifneq (,$(filter dev_eth_autoinit,$(USEMODULE)))
+DIRS += $(RIOTBASE)/sys/auto_init/dev_eth
+endif
+
 include $(RIOTBASE)/Makefile.base
diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c
index fc287e2e48..2ff3c8b489 100644
--- a/sys/auto_init/auto_init.c
+++ b/sys/auto_init/auto_init.c
@@ -103,6 +103,11 @@
 #include "net/ng_udp.h"
 #endif
 
+#ifdef MODULE_DEV_ETH_AUTOINIT
+#include "net/dev_eth.h"
+#include "dev_eth_autoinit.h"
+#endif
+
 #define ENABLE_DEBUG (0)
 #include "debug.h"
 
diff --git a/sys/auto_init/dev_eth/Makefile b/sys/auto_init/dev_eth/Makefile
new file mode 100644
index 0000000000..347f229678
--- /dev/null
+++ b/sys/auto_init/dev_eth/Makefile
@@ -0,0 +1,3 @@
+MODULE = dev_eth_autoinit
+
+include $(RIOTBASE)/Makefile.base
diff --git a/sys/auto_init/dev_eth/dev_eth_autoinit.c b/sys/auto_init/dev_eth/dev_eth_autoinit.c
new file mode 100644
index 0000000000..fc37fe7c81
--- /dev/null
+++ b/sys/auto_init/dev_eth/dev_eth_autoinit.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+#include "net/dev_eth.h"
+#include "dev_eth_autoinit.h"
+
+#ifdef MODULE_NG_NATIVENET
+#include "dev_eth_tap.h"
+#endif
+
+#ifdef MODULE_ENCX24J600
+#include "encx24j600.h"
+encx24j600_t dev_eth_encx24j600;
+#endif
+
+dev_eth_t * const dev_eth_devices[] = {
+#ifdef MODULE_NG_NATIVENET
+    [DEV_ETH_TAP] = (dev_eth_t*)&dev_eth_tap,
+#endif
+#ifdef MODULE_ENCX24J600
+    [DEV_ETH_ENCX24J600] = (dev_eth_t*)&dev_eth_encx24j600,
+#endif
+};
+
+void dev_eth_autoinit(void)
+{
+#ifdef MODULE_ENCX24J600
+    /* TODO: use sensible defines */
+    encx24j600_setup(&dev_eth_encx24j600, SPI_0, GPIO_1, GPIO_2);
+#endif
+}
diff --git a/sys/include/dev_eth_autoinit.h b/sys/include/dev_eth_autoinit.h
new file mode 100644
index 0000000000..58fe198f09
--- /dev/null
+++ b/sys/include/dev_eth_autoinit.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @defgroup    sys_net_dev_eth dev_eth auto setup
+ * @ingroup     sys_net_eth
+ * @file
+ * @brief       Automatically setup available ethernet devices
+ * @{
+ *
+ * @brief       header for dev_eth automatic initialization
+ *
+ * @author      Kaspar Schleiser <kaspar@schleiser.de>
+ */
+
+#ifndef DEV_ETH_AUTOINIT_H
+#define DEV_ETH_AUTOINIT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief enum for available ethernet devices
+ */
+enum {
+#ifdef MODULE_NG_NATIVENET
+    DEV_ETH_TAP,
+#endif
+#ifdef MODULE_ENCX24J600
+    DEV_ETH_ENCX24J600,
+#endif
+    /* must be last: */
+    NUM_DEV_ETH
+};
+
+/**
+ * @brief Array of const pointers to available ethernet devices
+ */
+extern dev_eth_t *const dev_eth_devices[];
+
+/**
+ * @brief Automatically sets up available dev_eth ethernet devices
+ *
+ * ... by calling the respective *_setup() functions if available.
+ */
+void dev_eth_autoinit(void);
+
+#ifdef __cplusplus
+}
+#endif
+/** @} */
+#endif /* DEV_ETH_AUTOINIT_H */
-- 
GitLab