浏览代码

[DeviceDriver][wlan] Add device ops to wlan.

armink 6 年之前
父节点
当前提交
59a4e4b2b7
共有 2 个文件被更改,包括 36 次插入1 次删除
  1. 18 1
      components/drivers/wlan/wlan_dev.c
  2. 18 0
      components/drivers/wlan/wlan_lwip.c

+ 18 - 1
components/drivers/wlan/wlan_dev.c

@@ -754,6 +754,18 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args)
     return err;
 }
 
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops wlan_ops =
+{
+    _rt_wlan_dev_init,
+    RT_NULL,
+    RT_NULL,
+    RT_NULL,
+    RT_NULL,
+    _rt_wlan_dev_control
+};
+#endif
+
 rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data)
 {
     rt_err_t err = RT_EOK;
@@ -765,13 +777,18 @@ rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, con
     }
 
     rt_memset(wlan, 0, sizeof(struct rt_wlan_device));
-
+    
+#ifdef RT_USING_DEVICE_OPS
+    wlan->device.ops = &wlan_ops;
+#else
     wlan->device.init       = _rt_wlan_dev_init;
     wlan->device.open       = RT_NULL;
     wlan->device.close      = RT_NULL;
     wlan->device.read       = RT_NULL;
     wlan->device.write      = RT_NULL;
     wlan->device.control    = _rt_wlan_dev_control;
+#endif
+
     wlan->device.user_data  = RT_NULL;
 
     wlan->device.type = RT_Device_Class_NetIf;

+ 18 - 0
components/drivers/wlan/wlan_lwip.c

@@ -372,6 +372,18 @@ static rt_err_t rt_wlan_lwip_protocol_send(rt_device_t device, struct pbuf *p)
 #endif
 }
 
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops wlan_lwip_ops =
+{
+    RT_NULL,
+    RT_NULL,
+    RT_NULL,
+    RT_NULL,
+    RT_NULL,
+    rt_wlan_lwip_protocol_control
+};
+#endif
+
 static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot *prot, struct rt_wlan_device *wlan)
 {
     struct eth_device *eth = RT_NULL;
@@ -417,12 +429,18 @@ static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot *
     rt_memset(lwip_prot, 0, sizeof(struct lwip_prot_des));
 
     eth = &lwip_prot->eth;
+
+#ifdef RT_USING_DEVICE_OPS
+    eth->parent.ops        = &wlan_lwip_ops;
+#else
     eth->parent.init       = RT_NULL;
     eth->parent.open       = RT_NULL;
     eth->parent.close      = RT_NULL;
     eth->parent.read       = RT_NULL;
     eth->parent.write      = RT_NULL;
     eth->parent.control    = rt_wlan_lwip_protocol_control;
+#endif
+
     eth->parent.user_data  = wlan;
     eth->eth_rx     = RT_NULL;
     eth->eth_tx     = rt_wlan_lwip_protocol_send;