summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorGuEe-GUI <[email protected]>2026-07-22 21:45:41 +0800
committerRbb666 <[email protected]>2026-08-06 09:43:10 +0800
commitfae3992d1496b2eae09721440033b21220cb16c6 (patch)
treef846056f5c441161e560394fca314bc0c5fded25 /components
parent71fd997662993ababc5f0861422fe09d6647018e (diff)
[dm][ethernet] Add ethernet for DM
Signed-off-by: GuEe-GUI <[email protected]>
Diffstat (limited to 'components')
-rwxr-xr-xcomponents/drivers/Kconfig1
-rw-r--r--components/drivers/ethernet/Kconfig11
-rw-r--r--components/drivers/ethernet/SConscript21
-rw-r--r--components/drivers/ethernet/ethernet_dm.c47
-rw-r--r--components/drivers/ethernet/ethernet_dm.h20
5 files changed, 100 insertions, 0 deletions
diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig
index 58192e98a6..f412357349 100755
--- a/components/drivers/Kconfig
+++ b/components/drivers/Kconfig
@@ -7,6 +7,7 @@ rsource "serial/Kconfig"
rsource "can/Kconfig"
rsource "adc/Kconfig"
rsource "clock_time/Kconfig"
+rsource "ethernet/Kconfig"
rsource "i2c/Kconfig"
rsource "phy/Kconfig"
rsource "misc/Kconfig"
diff --git a/components/drivers/ethernet/Kconfig b/components/drivers/ethernet/Kconfig
new file mode 100644
index 0000000000..deb89f4e5d
--- /dev/null
+++ b/components/drivers/ethernet/Kconfig
@@ -0,0 +1,11 @@
+menuconfig RT_USING_ETHERNET
+ bool "Using Ethernet device drivers"
+ depends on RT_USING_DM
+ depends on RT_USING_SAL
+ depends on RT_USING_NETDEV
+ depends on RT_USING_LWIP
+ default n
+
+if RT_USING_ETHERNET
+ osource "$(SOC_DM_ETHERNET_DIR)/Kconfig"
+endif
diff --git a/components/drivers/ethernet/SConscript b/components/drivers/ethernet/SConscript
new file mode 100644
index 0000000000..f292627b5f
--- /dev/null
+++ b/components/drivers/ethernet/SConscript
@@ -0,0 +1,21 @@
+from building import *
+
+group = []
+
+if not GetDepend(['RT_USING_ETHERNET']):
+ Return('group')
+
+cwd = GetCurrentDir()
+list = os.listdir(cwd)
+CPPPATH = [cwd + '/../include']
+
+src = ['ethernet_dm.c']
+
+group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ group = group + SConscript(os.path.join(d, 'SConscript'))
+
+Return('group')
diff --git a/components/drivers/ethernet/ethernet_dm.c b/components/drivers/ethernet/ethernet_dm.c
new file mode 100644
index 0000000000..77560d7141
--- /dev/null
+++ b/components/drivers/ethernet/ethernet_dm.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-11-25 GuEe-GUI first version
+ */
+
+#include <drivers/core/dm.h>
+
+#include "ethernet_dm.h"
+
+static rt_uint32_t _qrand32(rt_uint32_t seed)
+{
+ rt_uint32_t ret;
+ static rt_uint32_t next = 1;
+
+ next = next * 1103515245 + 12345;
+
+ ret = (rt_uint32_t)(next / 65536) % 32768;
+
+ if (seed)
+ {
+ ret *= seed;
+ }
+
+ return ret;
+}
+
+void ethernet_random_addr(struct eth_device *eth, rt_uint8_t *addr)
+{
+ rt_tick_t tick = rt_tick_get();
+ rt_uint32_t rand = (_qrand32(tick) << 16) | _qrand32(tick);
+ const char *name = rt_dm_dev_get_name(&eth->parent);
+
+ addr[5] = ((rt_uint8_t *)&rand)[3];
+ addr[4] = ((rt_uint8_t *)&rand)[2];
+ addr[3] = name[0] & 0xf;
+ addr[2] = name[1] & 0xf;
+ addr[1] = ((rt_uint8_t *)&rand)[1];
+ addr[0] = ((rt_uint8_t *)&rand)[0];
+
+ addr[0] &= 0xfe; /* Clear multicast bit */
+ addr[0] |= 0x02; /* Set local assignment bit (IEEE802) */
+}
diff --git a/components/drivers/ethernet/ethernet_dm.h b/components/drivers/ethernet/ethernet_dm.h
new file mode 100644
index 0000000000..a846b065d6
--- /dev/null
+++ b/components/drivers/ethernet/ethernet_dm.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2023-11-25 GuEe-GUI first version
+ */
+
+#ifndef __ETHERNET_DM_H__
+#define __ETHERNET_DM_H__
+
+#include <rtthread.h>
+
+#include <netif/ethernetif.h>
+
+void ethernet_random_addr(struct eth_device *eth, rt_uint8_t *addr);
+
+#endif /* __ETHERNET_DM_H__ */