Prechádzať zdrojové kódy

Merge pull request #17 from xiangxistu/master

【增加】支持 EC20 通信模块
朱天龙 (Armink) 6 rokov pred
rodič
commit
460754842f
4 zmenil súbory, kde vykonal 116 pridanie a 6 odobranie
  1. 4 3
      README.md
  2. 4 0
      SConscript
  3. 5 3
      class/ppp_device_air720.c
  4. 103 0
      class/ppp_device_ec20.c

+ 4 - 3
README.md

@@ -12,7 +12,7 @@ PPP Device 软件包特点如下:
 
 * 提供 CHAT 方式初始化功能,方便设备移植;
 
-目前 PPP 功能支持 Luat Air720,China mobile M6312,  SIMCOM SIM800 模块,后续会接入更多蜂窝模块。
+目前 PPP 功能支持 Luat Air720,Quectel EC20,China mobile M6312,  SIMCOM SIM800 模块,后续会接入更多蜂窝模块。
 
 
 
@@ -56,8 +56,8 @@ ppp_device 软件包遵循 Apache-2.0 许可,详见 LICENSE 文件。
 [*] PPP DEVICE: lwIP PPP porting for Cellular Module( 2G/3G/4G )
     [ ]   Enable debug log output
     [ ]   Enbale authorize connect feature
-    [*]   Enable lin status detect feature
-    (1)     Link status detecct timeout
+    [*]   Enable link status detect feature
+    (10)     Link status detecct timeout
           Select Internet Service Provider (china mobile)  --->
           Select modem type (Luat Air720)  --->
     [*]    Enable ppp device sample
@@ -180,6 +180,7 @@ msh />ping www.baidu.com
 * 如果网络环境不好,建议关闭 Enable lin status detect feature 选项,或调整成大一点的时间
 * RT_LWIP_TCPTHREAD_STACKSIZE 需要配置为不小于 2048,及时在 network 组件中修改
 * 不要忘记打开串口
+* 对于开启模块电源控制引脚的开发者,要注意模块的启动时间;通常模块启动时间较长,这时会出现长时间拨号不成功的问题,一定要注意模块的启动时间,避免造成使用上的一些障碍。
 
 ## 5. 联系方式
 

+ 4 - 0
SConscript

@@ -9,6 +9,10 @@ src += Glob('samples/ppp_sample.c')
 if GetDepend(['PPP_DEVICE_USING_AIR720']):
     src += Glob('class/ppp_device_air720.c')
 
+# EC20
+if GetDepend(['PPP_DEVICE_USING_EC20']):
+    src += Glob('class/ppp_device_ec20.c')
+
 # M6312
 if GetDepend(['PPP_DEVICE_USING_M6312']):
     src += Glob('class/ppp_device_m6312.c')

+ 5 - 3
class/ppp_device_air720.c

@@ -27,7 +27,7 @@
 #define AIR720_POWER_PIN -1
 #endif
 
-#define AIR720_WARTING_TIME_BASE 500
+#define AIR720_WARTING_TIME_BASE 2000
 
 static const struct modem_chat_data rst_mcd[] =
 {
@@ -48,8 +48,9 @@ static rt_err_t ppp_air720_prepare(struct ppp_device *device)
     if (device->power_pin >= 0)
     {
         rt_pin_write(device->power_pin, AIR720_POWER_OFF);
-        rt_thread_mdelay(AIR720_WARTING_TIME_BASE);
+        rt_thread_mdelay(AIR720_WARTING_TIME_BASE / 20);
         rt_pin_write(device->power_pin, AIR720_POWER_ON);
+        rt_thread_mdelay(AIR720_WARTING_TIME_BASE);
     }
     else
     {
@@ -88,7 +89,8 @@ int ppp_air720_register(void)
     if (ppp_device->power_pin >= 0)
     {
         rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
-        rt_pin_write(ppp_device->power_pin, AIR720_POWER_OFF);
+        rt_pin_write(ppp_device->power_pin, AIR720_POWER_ON);
+        rt_thread_mdelay(AIR720_WARTING_TIME_BASE);
     }
     ppp_device->ops = &air720_ops;
 

+ 103 - 0
class/ppp_device_ec20.c

@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author         Notes
+ * 2019-08-15    xiangxistu      the first version
+ */
+
+#include <ppp_device.h>
+#include <ppp_chat.h>
+#include <rtdevice.h>
+
+#define DBG_TAG    "ppp.ec20"
+
+#ifdef PPP_DEVICE_DEBUG
+#define DBG_LVL   DBG_LOG
+#else
+#define DBG_LVL   DBG_INFO
+#endif
+#include <rtdbg.h>
+
+
+#define EC20_POWER_ON  PIN_LOW
+#define EC20_POWER_OFF PIN_HIGH
+#ifndef EC20_POWER_PIN
+#include <drv_gpio.h>
+#define EC20_POWER_PIN GET_PIN(A, 11)
+#endif
+
+#define EC20_WARTING_TIME_BASE 2000
+
+static const struct modem_chat_data rst_mcd[] =
+{
+    {"+++",          MODEM_CHAT_RESP_NOT_NEED,        30, 1, RT_TRUE},
+    {"ATH",          MODEM_CHAT_RESP_OK,              30, 1, RT_FALSE},
+};
+
+static const struct modem_chat_data mcd[] =
+{
+    {"AT",           MODEM_CHAT_RESP_OK,              10, 1, RT_FALSE},
+    {"ATE0",         MODEM_CHAT_RESP_OK,              1,  1, RT_FALSE},
+    {PPP_APN_CMD,    MODEM_CHAT_RESP_OK,              1,  5, RT_FALSE},
+    {PPP_DAIL_CMD,   MODEM_CHAT_RESP_CONNECT,         1, 30, RT_FALSE},
+};
+
+static rt_err_t ppp_ec20_prepare(struct ppp_device *device)
+{
+    if (device->power_pin >= 0)
+    {
+        rt_pin_write(device->power_pin, EC20_POWER_OFF);
+        rt_thread_mdelay(EC20_WARTING_TIME_BASE / 20);
+        rt_pin_write(device->power_pin, EC20_POWER_ON);
+        rt_thread_mdelay(EC20_WARTING_TIME_BASE / 2 + EC20_WARTING_TIME_BASE);
+    }
+    else
+    {
+        rt_err_t err;
+        err = modem_chat(device->uart, rst_mcd, sizeof(rst_mcd) / sizeof(rst_mcd[0]));
+        if (err)
+            return err;
+    }
+    return modem_chat(device->uart, mcd, sizeof(mcd) / sizeof(mcd[0]));
+}
+
+/* ppp_ec20_ops for ppp_device_ops , a common interface */
+static struct ppp_device_ops ec20_ops =
+{
+    .prepare = ppp_ec20_prepare,
+};
+
+/**
+ * register ec20 into ppp_device
+ *
+ * @return  =0:   ppp_device register successfully
+ *          <0:   ppp_device register failed
+ */
+int ppp_ec20_register(void)
+{
+    struct ppp_device *ppp_device = RT_NULL;
+
+    ppp_device = rt_malloc(sizeof(struct ppp_device));
+    if(ppp_device == RT_NULL)
+    {
+        LOG_E("No memory for ec20 ppp_device.");
+        return -RT_ENOMEM;
+    }
+
+    ppp_device->power_pin = EC20_POWER_PIN;
+    if (ppp_device->power_pin >= 0)
+    {
+        rt_pin_mode(ppp_device->power_pin, PIN_MODE_OUTPUT);
+        rt_pin_write(ppp_device->power_pin, EC20_POWER_ON);
+        rt_thread_mdelay(EC20_WARTING_TIME_BASE / 2 + EC20_WARTING_TIME_BASE);
+    }
+    ppp_device->ops = &ec20_ops;
+
+    LOG_D("ppp ec20 is registering ppp_device");
+
+    return ppp_device_register(ppp_device, PPP_DEVICE_NAME, RT_NULL, RT_NULL);
+}
+INIT_COMPONENT_EXPORT(ppp_ec20_register);