Merge branch 'master' of github.com:RT-Thread/rt-thread
This commit is contained in:
commit
3478420fad
|
@ -1,23 +1,35 @@
|
|||
说明: 本BSP可以如下演示
|
||||
默认演示realtouch GUI效果,并提供了一个贪吃的demo用于演示
|
||||
|
||||
目前支持的功能有
|
||||
1). LWIP(可以打开LWIP选项,不过尚存在bug,不建议使用)
|
||||
2). 文件系统支持,支持ELM FatFS,UFFS,JFFS2
|
||||
3). RTGUI支持
|
||||
目前SVN中的RTGUI源码可以直接用于simulator。
|
||||
如果读者想快速在simulator上体验RTGUI,那么不需要修改任何文件,首先在命令行中使用
|
||||
scons --target=vs -s
|
||||
生成工程后,打开project.vsproj编译,即可看到realtouch的ui出现,然后执行
|
||||
在finsh中执行snake_main(),即可运行贪吃蛇demo
|
||||
|
||||
再补充说明一点,RTGUI的最新源码目前是托管在git上。
|
||||
github网页:https://github.com/RT-Thread/RTGUI
|
||||
如果要使用rtgui中的最新源码,共有两种方法。
|
||||
一 平台及组件支持
|
||||
目前rtconfig.py中支持的编译器有
|
||||
1). msvc 用于windows平台
|
||||
此平台支持的组件
|
||||
kernel
|
||||
finsh
|
||||
LWIP
|
||||
DFS, ELM FatFS, UFFS, JFFS2, DFS_WIN32
|
||||
RTGUI
|
||||
APP MODULE
|
||||
2). mingw 用于windows平台
|
||||
kernel
|
||||
finsh
|
||||
DFS, ELM FatFS, UFFS, DFS_WIN32
|
||||
RTGUI
|
||||
APP MODULE
|
||||
3). gcc 用于linux平台
|
||||
kernel
|
||||
finsh
|
||||
DFS, ELM FatFS, UFFS
|
||||
RTGUI
|
||||
|
||||
二 组件配置
|
||||
1) RTGUI
|
||||
当前代码中已经不含RTGUI源码,因此读者需要配置一下才能在simulator中使用RTGUI
|
||||
RTGUI的最新源码目前是托管在github上:https://github.com/RT-Thread/RTGUI
|
||||
共有两种方法。
|
||||
方法1 添加环境变量
|
||||
向系统环境变量中加入RTT_RTGUI,其值为刚才github上下载的rtgui源码包的路径。
|
||||
例如笔者的rtgui源码包解压至 F:\Project\git\rt-gui\下
|
||||
则将此环境变量配置为 F:\Project\git\rt-gui\components\rtgui
|
||||
向系统加入RTT_RTGUI环境变量,其值为刚才github上下载的rtgui源码包的路径。
|
||||
例如笔者的rtgui源码包解压至 F:\Project\git\rt-gui\下, 则将此环境变量配置为 F:\Project\git\rt-gui\components\rtgui
|
||||
方法2 不添加环境变量
|
||||
打开SConstruct文件,
|
||||
....
|
||||
|
@ -37,106 +49,105 @@
|
|||
1)#号表示注释,类似于c语言中的//,
|
||||
2)其中15行的路径为你的RTGUI路径源码,注意不是压缩包路径,而是压缩包路径下的 components\rtgui目录的绝对路径。
|
||||
|
||||
1 编译:
|
||||
1.1 使用Visual Studio(2005以上版本)
|
||||
在命令行中执行 scons --target=vs -s 可以生成vs2005的工程,名为project.vsproj
|
||||
|
||||
编译后运行
|
||||
|
||||
1.2 使用scons编译,在当前目录中打开cmd,输入
|
||||
scons -j4
|
||||
编译完成后会在当前目录下生成 rtthrad-win32.exe,双击即可运行。
|
||||
三 编译
|
||||
1) 使用Visual Studio(2005以上版本)
|
||||
在当前目录中打开cmd,输入命令
|
||||
`scons --target=vs -s`
|
||||
可以生成project.vsproj,双击运行
|
||||
|
||||
2. 测试文件系统
|
||||
运行:
|
||||
编译后运行,会弹出CMD命令行窗口,可以看到控制台的输出信息,如下所示
|
||||
|
||||
\ | /
|
||||
- RT - Thread Operating System
|
||||
/ | \ 1.1.0 build Oct 21 2012
|
||||
2006 - 2012 Copyright by rt-thread team
|
||||
init jffs2 lock mutex okay
|
||||
hello, world
|
||||
finsh>>fatfs initialzation failed!
|
||||
uffs initialzation failed!
|
||||
jffs2 initialzation failed!
|
||||
thread 29e4 exit
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
thread 2898 exit
|
||||
|
||||
注意上面的信息显示,fatfs/uffs/jffs2均挂载失败,这是因为我们还没有为sd.bin创建fat分区,并且sd上也没有目录用于挂载jffs2和uffs。
|
||||
|
||||
并且此时当前bsp目录下,新增了三个文件用于模拟sd卡,nand flash与nor flash,它们是
|
||||
sd.bin--模拟SD卡,挂载fat,大小为16M
|
||||
nand.bin-模拟nand flash,挂载uffs,参数page=2048+64bytes,block=64pages,16M
|
||||
nor.bin--模拟nor flash,挂载jffs2,型号为sst25vf,2M
|
||||
|
||||
按下回车,出现finsh,然后输入如下命令格式化sd.bin
|
||||
2) 命令行编译
|
||||
修改rtconfig.py, 配置合适的编译器(msvc/mingw/gcc),及其路径
|
||||
在当前目录中打开cmd,输入命令
|
||||
`scons -j4`
|
||||
编译完成后会在当前目录下生成 rtthrad-win32.exe,双击即可运行。
|
||||
|
||||
四 程序测试
|
||||
1) 测试文件系统
|
||||
此时当前目录下,新增了三个文件
|
||||
sd.bin--模拟SD卡,挂载fat,大小为16M
|
||||
nand.bin-模拟nand flash,挂载uffs,参数page=2048+64bytes,block=64pages,16M
|
||||
nor.bin--模拟nor flash,挂载jffs2,型号为sst25vf,2M
|
||||
第一次启动时,会看到fatfs挂在失败。
|
||||
按下回车,出现finsh,然后输入`mkfs("elm", "sd0")`格式化SD卡,如下所示
|
||||
finsh>>mkfs("elm", "sd0")
|
||||
0, 0x00000000
|
||||
finsh>>
|
||||
然后重启程序,就可以看到fatfs挂载成功了
|
||||
|
||||
关闭程序重新运行,此时可以看到fatfs挂载成功,不过jffs2和uffs依然失败,如下所示。
|
||||
\ | /
|
||||
- RT - Thread Operating System
|
||||
/ | \ 1.1.0 build Oct 21 2012
|
||||
2006 - 2012 Copyright by rt-thread team
|
||||
init jffs2 lock mutex okay
|
||||
hello, world
|
||||
finsh>>fatfs initialized!
|
||||
uffs initialzation failed!
|
||||
jffs2 initialzation failed!
|
||||
|
||||
这是因为sd上还没有目录来用于挂载jffs2和uffs,在finsh中输入如下命令在sd上创建nand与nor文件夹,分别用于挂载uffs与jffs2文件系统。
|
||||
2) 测试RTGUI
|
||||
启动后就会看到GUI窗口,分辨率800x480,此时在finsh中输入snake_main()并回车,即可运行贪吃蛇程序
|
||||
|
||||
finsh>>mkdir("/nand")
|
||||
0, 0x00000000
|
||||
finsh>>mkdir("/nor")
|
||||
0, 0x00000000
|
||||
finsh>>
|
||||
然后再次关闭程序后重新运行,此时可以看到jffs2与uffs挂载成功。
|
||||
3) 测试APP module
|
||||
rtconfig.h中需要打开RT_USING_MODULE
|
||||
|
||||
最终输出如下所示:
|
||||
a. 生成rtthread.def文件
|
||||
使用msv编译主程序时需要此文件,使用MingW编译主程序时不需要
|
||||
msvc需要此文件才能生成正确导出符号的rtthread.dll和rtthread-win32.exe。
|
||||
此目录下默认自带了一个rtthread.def文件,当修改了rtconfig.h,禁用了某些组件时,则需要重新生成rtthread.def文件.
|
||||
生成方法:
|
||||
需要借助MingW工具,修改rtconfig.py中CROSS_TOOL为'mingw',然后打开CMD执行`scons --def`就会自动更新rtthread.def。
|
||||
|
||||
\ | /
|
||||
- RT - Thread Operating System
|
||||
/ | \ 1.1.0 build Oct 21 2012
|
||||
2006 - 2012 Copyright by rt-thread team
|
||||
init jffs2 lock mutex okay
|
||||
hello, world
|
||||
finsh>>fatfs initialized!
|
||||
os : system memory alloc 320 bytes
|
||||
flsh: ECC size 24
|
||||
flsh: UFFS consume spare data size 34
|
||||
os : system memory alloc 83520 bytes
|
||||
os : system memory alloc 52400 bytes
|
||||
os : system memory alloc 2048 bytes
|
||||
tree: DIR 0, FILE 0, DATA 0
|
||||
uffs initialized!
|
||||
jffs2 initialized!
|
||||
thread 2fb4 exit
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
hello, world
|
||||
thread 312c exit
|
||||
b. 生成主程序
|
||||
主程序可以使用msvc和mingw生成
|
||||
如果rtconfig.h中的使能了RTGUI,则需要参考第二节第1小节配置RTGUI
|
||||
a.1 使用msvc
|
||||
修改rtconfig.py中CROSS_TOOL为'msvc'
|
||||
首先要保证当前目录下有合适的rtthread.def文件,如果没有对默认的rtconfig.h作修改,则使用默认的rtthread.def即可
|
||||
CMD命令行执行`scons -j4`,即可生成rtthread.dll和 rtthread-win32.exe
|
||||
a.2 使用mingw
|
||||
修改rtconfig.py中CROSS_TOOL为'mingw'
|
||||
CMD命令行执行`scons -j4`,这就会生成 rtthread.dll和 rtthread-win32.exe
|
||||
|
||||
Ok,到现在,一个完整的文件系统测试环境就搭建完毕了,enjoy~~
|
||||
c. 生成app module
|
||||
进入testdll目录,再次修改 testdll/SConstruct, 同样需要配置RTT_RTGUI路径,同 1中3)
|
||||
在此目录下执行
|
||||
`scons --app=basicapp`
|
||||
就会在 basicapp/building目录下生成 basicapp.dll。
|
||||
|
||||
3 测试RTGUI
|
||||
启动后就会看到GUI窗口,分辨率800×480串口,并出现图形界面。
|
||||
此时在finsh中输入 snake_main()并回车,即可运行贪吃蛇程序。
|
||||
然后运行simulator目录下的 rtthread-win32.exe, 在finsh中运行
|
||||
`exec("/testdll/basicapp/building/basicapp.dll")`
|
||||
如果觉得这个路径太长,就把 basicapp.dll复制到 simualtor目录下,执行
|
||||
`exec("/basicapp.dll")`
|
||||
|
||||
如果想编译RTGUI应用,如testdll目录下的snake,则需要对RTGUI打一点补丁,共有两个方法
|
||||
1. 注释掉 //#define RTGUI_USING_CAST_CHECK`
|
||||
找到rtgui_config.h源码,注释掉如下语句
|
||||
//#define RTGUI_USING_CAST_CHECK`
|
||||
|
||||
然后在testdll目录下打开CMD窗口,执行`scons --app=snake`,才可以正确编译,如果不注释掉上面的宏,则会出现链接错误。
|
||||
|
||||
2. 不注释掉#define RTGUI_USING_CAST_CHECK`
|
||||
那么需要如下两个补丁
|
||||
1) 修改testdll/SConstruct文件
|
||||
diff --git a/bsp/simulator/testdll/SConstruct b/bsp/simulator/testdll/SConstruct
|
||||
index 3324f88..005289c 100644
|
||||
--- a/bsp/simulator/testdll/SConstruct
|
||||
+++ b/bsp/simulator/testdll/SConstruct
|
||||
@@ -70,6 +70,7 @@ env.Append(CCFLAGS=rtconfig.CFLAGS)
|
||||
env.Append(LINKFLAGS=rtconfig.LFLAGS)
|
||||
env.Append(CPPPATH=CPPPATH)
|
||||
env.Append(LIBS='rtthread', LIBPATH='../')
|
||||
+env.Append(CPPDEFINES=['RTT_IN_MODULE'])
|
||||
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
||||
|
||||
PrepareModuleBuilding(env, RTT_ROOT)
|
||||
|
||||
2) 修改RTGUI源码
|
||||
diff --git a/components/rtgui/include/rtgui/rtgui_object.h b/components/rtgui/include/rtgui/rtgui_object.h
|
||||
index 57fd47f..b32ee17 100644
|
||||
--- a/components/rtgui/include/rtgui/rtgui_object.h
|
||||
+++ b/components/rtgui/include/rtgui/rtgui_object.h
|
||||
@@ -56,7 +56,12 @@ extern "C" {
|
||||
typedef struct rtgui_type rtgui_type_t;
|
||||
#define RTGUI_TYPE(type) (struct rtgui_type*)&(_rtgui_##type)
|
||||
|
||||
+#ifdef RTT_IN_MODULE
|
||||
+#define DECLARE_CLASS_TYPE(type) _declspec(dllimport) const struct rtgui_type _rtgui_##type
|
||||
+#else
|
||||
#define DECLARE_CLASS_TYPE(type) extern const struct rtgui_type _rtgui_##type
|
||||
+#endif
|
||||
+
|
||||
#define DEFINE_CLASS_TYPE(type, name, parent, constructor, destructor, size) \
|
||||
const struct rtgui_type _rtgui_##type = { \
|
||||
name, \
|
||||
|
||||
然后再编译snake,可以正确生成。测试方法同basicapp
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,15 +12,16 @@
|
|||
* 2010-07-07 Bernard fix send mail to mailbox issue.
|
||||
* 2011-07-30 mbbill port lwIP 1.4.0 to RT-Thread
|
||||
* 2012-04-10 Bernard add more compatible with RT-Thread.
|
||||
* 2012-11-12 Bernard The network interface can be initialized
|
||||
* 2012-11-12 Bernard The network interface can be initialized
|
||||
* after lwIP initialization.
|
||||
* 2013-02-28 aozima fixed list_tcps bug: ipaddr_ntoa isn't reentrant.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
|
@ -29,21 +30,21 @@
|
|||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
@ -71,8 +72,8 @@
|
|||
*/
|
||||
struct eth_tx_msg
|
||||
{
|
||||
struct netif *netif;
|
||||
struct pbuf *buf;
|
||||
struct netif *netif;
|
||||
struct pbuf *buf;
|
||||
};
|
||||
|
||||
static struct rt_mailbox eth_tx_thread_mb;
|
||||
|
@ -99,288 +100,288 @@ static char eth_rx_thread_stack[RT_LWIP_ETHTHREAD_STACKSIZE];
|
|||
|
||||
static err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
struct eth_tx_msg msg;
|
||||
struct eth_device* enetif;
|
||||
struct eth_tx_msg msg;
|
||||
struct eth_device* enetif;
|
||||
|
||||
enetif = (struct eth_device*)netif->state;
|
||||
enetif = (struct eth_device*)netif->state;
|
||||
|
||||
/* send a message to eth tx thread */
|
||||
msg.netif = netif;
|
||||
msg.buf = p;
|
||||
if (rt_mb_send(ð_tx_thread_mb, (rt_uint32_t) &msg) == RT_EOK)
|
||||
{
|
||||
/* waiting for ack */
|
||||
rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER);
|
||||
}
|
||||
/* send a message to eth tx thread */
|
||||
msg.netif = netif;
|
||||
msg.buf = p;
|
||||
if (rt_mb_send(ð_tx_thread_mb, (rt_uint32_t) &msg) == RT_EOK)
|
||||
{
|
||||
/* waiting for ack */
|
||||
rt_sem_take(&(enetif->tx_ack), RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t eth_netif_device_init(struct netif *netif)
|
||||
{
|
||||
struct eth_device *ethif;
|
||||
struct eth_device *ethif;
|
||||
|
||||
ethif = (struct eth_device*)netif->state;
|
||||
if (ethif != RT_NULL)
|
||||
{
|
||||
rt_device_t device;
|
||||
ethif = (struct eth_device*)netif->state;
|
||||
if (ethif != RT_NULL)
|
||||
{
|
||||
rt_device_t device;
|
||||
|
||||
/* get device object */
|
||||
device = (rt_device_t) ethif;
|
||||
if (rt_device_init(device) != RT_EOK)
|
||||
{
|
||||
return ERR_IF;
|
||||
}
|
||||
/* get device object */
|
||||
device = (rt_device_t) ethif;
|
||||
if (rt_device_init(device) != RT_EOK)
|
||||
{
|
||||
return ERR_IF;
|
||||
}
|
||||
|
||||
/* copy device flags to netif flags */
|
||||
netif->flags = ethif->flags;
|
||||
/* copy device flags to netif flags */
|
||||
netif->flags = ethif->flags;
|
||||
|
||||
/* set default netif */
|
||||
if (netif_default == RT_NULL)
|
||||
netif_set_default(ethif->netif);
|
||||
/* set default netif */
|
||||
if (netif_default == RT_NULL)
|
||||
netif_set_default(ethif->netif);
|
||||
|
||||
#if LWIP_DHCP
|
||||
if (ethif->flags & NETIF_FLAG_DHCP)
|
||||
{
|
||||
/* if this interface uses DHCP, start the DHCP client */
|
||||
dhcp_start(ethif->netif);
|
||||
}
|
||||
else
|
||||
if (ethif->flags & NETIF_FLAG_DHCP)
|
||||
{
|
||||
/* if this interface uses DHCP, start the DHCP client */
|
||||
dhcp_start(ethif->netif);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* set interface up */
|
||||
netif_set_up(ethif->netif);
|
||||
}
|
||||
{
|
||||
/* set interface up */
|
||||
netif_set_up(ethif->netif);
|
||||
}
|
||||
|
||||
#ifdef LWIP_NETIF_LINK_CALLBACK
|
||||
netif_set_link_up(ethif->netif);
|
||||
netif_set_link_up(ethif->netif);
|
||||
#endif
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
return ERR_IF;
|
||||
return ERR_IF;
|
||||
}
|
||||
|
||||
/* Keep old drivers compatible in RT-Thread */
|
||||
rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flags)
|
||||
{
|
||||
struct netif* netif;
|
||||
struct netif* netif;
|
||||
|
||||
netif = (struct netif*) rt_malloc (sizeof(struct netif));
|
||||
if (netif == RT_NULL)
|
||||
{
|
||||
rt_kprintf("malloc netif failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
rt_memset(netif, 0, sizeof(struct netif));
|
||||
netif = (struct netif*) rt_malloc (sizeof(struct netif));
|
||||
if (netif == RT_NULL)
|
||||
{
|
||||
rt_kprintf("malloc netif failed\n");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
rt_memset(netif, 0, sizeof(struct netif));
|
||||
|
||||
/* set netif */
|
||||
dev->netif = netif;
|
||||
/* device flags, which will be set to netif flags when initializing */
|
||||
dev->flags = flags;
|
||||
/* link changed status of device */
|
||||
dev->link_changed = 0x00;
|
||||
dev->parent.type = RT_Device_Class_NetIf;
|
||||
/* register to RT-Thread device manager */
|
||||
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
|
||||
rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);
|
||||
/* set netif */
|
||||
dev->netif = netif;
|
||||
/* device flags, which will be set to netif flags when initializing */
|
||||
dev->flags = flags;
|
||||
/* link changed status of device */
|
||||
dev->link_changed = 0x00;
|
||||
dev->parent.type = RT_Device_Class_NetIf;
|
||||
/* register to RT-Thread device manager */
|
||||
rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
|
||||
rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);
|
||||
|
||||
/* set name */
|
||||
netif->name[0] = name[0];
|
||||
netif->name[1] = name[1];
|
||||
/* set name */
|
||||
netif->name[0] = name[0];
|
||||
netif->name[1] = name[1];
|
||||
|
||||
/* set hw address to 6 */
|
||||
netif->hwaddr_len = 6;
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = ETHERNET_MTU;
|
||||
/* set hw address to 6 */
|
||||
netif->hwaddr_len = 6;
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = ETHERNET_MTU;
|
||||
|
||||
/* get hardware MAC address */
|
||||
rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);
|
||||
/* get hardware MAC address */
|
||||
rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);
|
||||
|
||||
/* set output */
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = ethernetif_linkoutput;
|
||||
/* set output */
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = ethernetif_linkoutput;
|
||||
|
||||
/* if tcp thread has been started up, we add this netif to the system */
|
||||
if (rt_thread_find("tcpip") != RT_NULL)
|
||||
{
|
||||
struct ip_addr ipaddr, netmask, gw;
|
||||
/* if tcp thread has been started up, we add this netif to the system */
|
||||
if (rt_thread_find("tcpip") != RT_NULL)
|
||||
{
|
||||
struct ip_addr ipaddr, netmask, gw;
|
||||
|
||||
#if !LWIP_DHCP
|
||||
IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
|
||||
IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
|
||||
IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
|
||||
IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
|
||||
IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
|
||||
IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
|
||||
#else
|
||||
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
|
||||
IP4_ADDR(&gw, 0, 0, 0, 0);
|
||||
IP4_ADDR(&netmask, 0, 0, 0, 0);
|
||||
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
|
||||
IP4_ADDR(&gw, 0, 0, 0, 0);
|
||||
IP4_ADDR(&netmask, 0, 0, 0, 0);
|
||||
#endif
|
||||
|
||||
netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t eth_device_init(struct eth_device * dev, char *name)
|
||||
{
|
||||
rt_uint8_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
||||
rt_uint8_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
||||
|
||||
#if LWIP_DHCP
|
||||
/* DHCP support */
|
||||
flags |= NETIF_FLAG_DHCP;
|
||||
/* DHCP support */
|
||||
flags |= NETIF_FLAG_DHCP;
|
||||
#endif
|
||||
|
||||
#if LWIP_IGMP
|
||||
/* IGMP support */
|
||||
flags |= NETIF_FLAG_IGMP;
|
||||
/* IGMP support */
|
||||
flags |= NETIF_FLAG_IGMP;
|
||||
#endif
|
||||
|
||||
return eth_device_init_with_flag(dev, name, flags);
|
||||
return eth_device_init_with_flag(dev, name, flags);
|
||||
}
|
||||
|
||||
rt_err_t eth_device_ready(struct eth_device* dev)
|
||||
{
|
||||
if (dev->netif)
|
||||
/* post message to Ethernet thread */
|
||||
return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
||||
else
|
||||
return ERR_OK; /* netif is not initialized yet, just return. */
|
||||
if (dev->netif)
|
||||
/* post message to Ethernet thread */
|
||||
return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
||||
else
|
||||
return ERR_OK; /* netif is not initialized yet, just return. */
|
||||
}
|
||||
|
||||
rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up)
|
||||
{
|
||||
rt_uint32_t level;
|
||||
rt_uint32_t level;
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
dev->link_changed = 0x01;
|
||||
if (up == RT_TRUE)
|
||||
dev->link_status = 0x01;
|
||||
else
|
||||
dev->link_status = 0x00;
|
||||
rt_hw_interrupt_enable(level);
|
||||
level = rt_hw_interrupt_disable();
|
||||
dev->link_changed = 0x01;
|
||||
if (up == RT_TRUE)
|
||||
dev->link_status = 0x01;
|
||||
else
|
||||
dev->link_status = 0x00;
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
/* post message to ethernet thread */
|
||||
return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
||||
/* post message to ethernet thread */
|
||||
return rt_mb_send(ð_rx_thread_mb, (rt_uint32_t)dev);
|
||||
}
|
||||
|
||||
/* Ethernet Tx Thread */
|
||||
static void eth_tx_thread_entry(void* parameter)
|
||||
{
|
||||
struct eth_tx_msg* msg;
|
||||
struct eth_tx_msg* msg;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (rt_mb_recv(ð_tx_thread_mb, (rt_uint32_t*)&msg, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
struct eth_device* enetif;
|
||||
while (1)
|
||||
{
|
||||
if (rt_mb_recv(ð_tx_thread_mb, (rt_uint32_t*)&msg, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
struct eth_device* enetif;
|
||||
|
||||
RT_ASSERT(msg->netif != RT_NULL);
|
||||
RT_ASSERT(msg->buf != RT_NULL);
|
||||
RT_ASSERT(msg->netif != RT_NULL);
|
||||
RT_ASSERT(msg->buf != RT_NULL);
|
||||
|
||||
enetif = (struct eth_device*)msg->netif->state;
|
||||
if (enetif != RT_NULL)
|
||||
{
|
||||
/* call driver's interface */
|
||||
if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("transmit eth packet failed\n");
|
||||
}
|
||||
}
|
||||
enetif = (struct eth_device*)msg->netif->state;
|
||||
if (enetif != RT_NULL)
|
||||
{
|
||||
/* call driver's interface */
|
||||
if (enetif->eth_tx(&(enetif->parent), msg->buf) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("transmit eth packet failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* send ACK */
|
||||
rt_sem_release(&(enetif->tx_ack));
|
||||
}
|
||||
}
|
||||
/* send ACK */
|
||||
rt_sem_release(&(enetif->tx_ack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Ethernet Rx Thread */
|
||||
static void eth_rx_thread_entry(void* parameter)
|
||||
{
|
||||
struct eth_device* device;
|
||||
struct eth_device* device;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (rt_mb_recv(ð_rx_thread_mb, (rt_uint32_t*)&device, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
struct pbuf *p;
|
||||
while (1)
|
||||
{
|
||||
if (rt_mb_recv(ð_rx_thread_mb, (rt_uint32_t*)&device, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
struct pbuf *p;
|
||||
|
||||
/* check link status */
|
||||
if (device->link_changed)
|
||||
{
|
||||
int status;
|
||||
rt_uint32_t level;
|
||||
/* check link status */
|
||||
if (device->link_changed)
|
||||
{
|
||||
int status;
|
||||
rt_uint32_t level;
|
||||
|
||||
level = rt_hw_interrupt_disable();
|
||||
status = device->link_status;
|
||||
device->link_changed = 0x00;
|
||||
rt_hw_interrupt_enable(level);
|
||||
level = rt_hw_interrupt_disable();
|
||||
status = device->link_status;
|
||||
device->link_changed = 0x00;
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
if (status)
|
||||
netifapi_netif_set_link_up(device->netif);
|
||||
else
|
||||
netifapi_netif_set_link_down(device->netif);
|
||||
}
|
||||
if (status)
|
||||
netifapi_netif_set_link_up(device->netif);
|
||||
else
|
||||
netifapi_netif_set_link_down(device->netif);
|
||||
}
|
||||
|
||||
/* receive all of buffer */
|
||||
while (1)
|
||||
{
|
||||
p = device->eth_rx(&(device->parent));
|
||||
if (p != RT_NULL)
|
||||
{
|
||||
/* notify to upper layer */
|
||||
if( device->netif->input(p, device->netif) != ERR_OK )
|
||||
{
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: Input error\n"));
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LWIP_ASSERT("Should not happen!\n",0);
|
||||
}
|
||||
}
|
||||
/* receive all of buffer */
|
||||
while (1)
|
||||
{
|
||||
p = device->eth_rx(&(device->parent));
|
||||
if (p != RT_NULL)
|
||||
{
|
||||
/* notify to upper layer */
|
||||
if( device->netif->input(p, device->netif) != ERR_OK )
|
||||
{
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: Input error\n"));
|
||||
pbuf_free(p);
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
else break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LWIP_ASSERT("Should not happen!\n",0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void eth_system_device_init()
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
rt_err_t result = RT_EOK;
|
||||
|
||||
/* initialize Rx thread.
|
||||
* initialize mailbox and create Ethernet Rx thread */
|
||||
result = rt_mb_init(ð_rx_thread_mb, "erxmb",
|
||||
ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4,
|
||||
RT_IPC_FLAG_FIFO);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
/* initialize Rx thread.
|
||||
* initialize mailbox and create Ethernet Rx thread */
|
||||
result = rt_mb_init(ð_rx_thread_mb, "erxmb",
|
||||
ð_rx_thread_mb_pool[0], sizeof(eth_rx_thread_mb_pool)/4,
|
||||
RT_IPC_FLAG_FIFO);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
|
||||
result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, RT_NULL,
|
||||
ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack),
|
||||
RT_LWIP_ETHTHREAD_PRIORITY, 16);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
result = rt_thread_startup(ð_rx_thread);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
result = rt_thread_init(ð_rx_thread, "erx", eth_rx_thread_entry, RT_NULL,
|
||||
ð_rx_thread_stack[0], sizeof(eth_rx_thread_stack),
|
||||
RT_LWIP_ETHTHREAD_PRIORITY, 16);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
result = rt_thread_startup(ð_rx_thread);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
|
||||
/* initialize Tx thread */
|
||||
/* initialize mailbox and create Ethernet Tx thread */
|
||||
result = rt_mb_init(ð_tx_thread_mb, "etxmb",
|
||||
ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4,
|
||||
RT_IPC_FLAG_FIFO);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
/* initialize Tx thread */
|
||||
/* initialize mailbox and create Ethernet Tx thread */
|
||||
result = rt_mb_init(ð_tx_thread_mb, "etxmb",
|
||||
ð_tx_thread_mb_pool[0], sizeof(eth_tx_thread_mb_pool)/4,
|
||||
RT_IPC_FLAG_FIFO);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
|
||||
result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL,
|
||||
ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack),
|
||||
RT_ETHERNETIF_THREAD_PREORITY, 16);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
result = rt_thread_init(ð_tx_thread, "etx", eth_tx_thread_entry, RT_NULL,
|
||||
ð_tx_thread_stack[0], sizeof(eth_tx_thread_stack),
|
||||
RT_ETHERNETIF_THREAD_PREORITY, 16);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
|
||||
result = rt_thread_startup(ð_tx_thread);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
result = rt_thread_startup(ð_tx_thread);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
|
@ -436,12 +437,12 @@ FINSH_FUNCTION_EXPORT(set_if, set network interface address);
|
|||
#include <lwip/dns.h>
|
||||
void set_dns(char* dns_server)
|
||||
{
|
||||
struct ip_addr addr;
|
||||
|
||||
if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr))
|
||||
{
|
||||
dns_setserver(0, &addr);
|
||||
}
|
||||
struct ip_addr addr;
|
||||
|
||||
if ((dns_server != RT_NULL) && ipaddr_aton(dns_server, &addr))
|
||||
{
|
||||
dns_setserver(0, &addr);
|
||||
}
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(set_dns, set DNS server address);
|
||||
#endif
|
||||
|
@ -451,11 +452,16 @@ void list_if(void)
|
|||
rt_ubase_t index;
|
||||
struct netif * netif;
|
||||
|
||||
rt_enter_critical();
|
||||
|
||||
netif = netif_list;
|
||||
|
||||
while( netif != RT_NULL )
|
||||
{
|
||||
rt_kprintf("network interface: %c%c%s\n", netif->name[0], netif->name[1], (netif == netif_default)?" (Default)":"");
|
||||
rt_kprintf("network interface: %c%c%s\n",
|
||||
netif->name[0],
|
||||
netif->name[1],
|
||||
(netif == netif_default)?" (Default)":"");
|
||||
rt_kprintf("MTU: %d\n", netif->mtu);
|
||||
rt_kprintf("MAC: ");
|
||||
for (index = 0; index < netif->hwaddr_len; index ++)
|
||||
|
@ -489,6 +495,8 @@ void list_if(void)
|
|||
}
|
||||
}
|
||||
#endif /**< #if LWIP_DNS */
|
||||
|
||||
rt_exit_critical();
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(list_if, list network interface information);
|
||||
|
||||
|
@ -496,42 +504,62 @@ FINSH_FUNCTION_EXPORT(list_if, list network interface information);
|
|||
#include <lwip/tcp.h>
|
||||
#include <lwip/tcp_impl.h>
|
||||
|
||||
void list_tcps()
|
||||
void list_tcps(void)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
extern struct tcp_pcb *tcp_active_pcbs;
|
||||
extern union tcp_listen_pcbs_t tcp_listen_pcbs;
|
||||
extern struct tcp_pcb *tcp_tw_pcbs;
|
||||
extern const char *tcp_state_str[];
|
||||
rt_uint32_t num = 0;
|
||||
struct tcp_pcb *pcb;
|
||||
char local_ip_str[16];
|
||||
char remote_ip_str[16];
|
||||
|
||||
rt_enter_critical();
|
||||
rt_kprintf("Active PCB states:\n");
|
||||
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
|
||||
{
|
||||
rt_kprintf("%s:%d <==> %s:%d snd_nxt %d rcv_nxt %d ",
|
||||
ipaddr_ntoa(&(pcb->local_ip)), pcb->local_port,
|
||||
ipaddr_ntoa(&(pcb->remote_ip)), pcb->remote_port,
|
||||
pcb->snd_nxt, pcb->rcv_nxt);
|
||||
rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
||||
}
|
||||
extern struct tcp_pcb *tcp_active_pcbs;
|
||||
extern union tcp_listen_pcbs_t tcp_listen_pcbs;
|
||||
extern struct tcp_pcb *tcp_tw_pcbs;
|
||||
extern const char *tcp_state_str[];
|
||||
|
||||
rt_kprintf("Listen PCB states:\n");
|
||||
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next)
|
||||
{
|
||||
rt_kprintf("local port %d ", pcb->local_port);
|
||||
rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
||||
}
|
||||
rt_enter_critical();
|
||||
rt_kprintf("Active PCB states:\n");
|
||||
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next)
|
||||
{
|
||||
strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
|
||||
strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip)));
|
||||
|
||||
rt_kprintf("TIME-WAIT PCB states:\n");
|
||||
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next)
|
||||
{
|
||||
rt_kprintf("%s:%d <==> %s:%d snd_nxt %d rcv_nxt %d ",
|
||||
ipaddr_ntoa(&(pcb->local_ip)), pcb->local_port,
|
||||
ipaddr_ntoa(&(pcb->remote_ip)), pcb->remote_port,
|
||||
pcb->snd_nxt, pcb->rcv_nxt);
|
||||
rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
||||
}
|
||||
rt_exit_critical();
|
||||
rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ",
|
||||
num++,
|
||||
local_ip_str,
|
||||
pcb->local_port,
|
||||
remote_ip_str,
|
||||
pcb->remote_port,
|
||||
pcb->snd_nxt,
|
||||
pcb->rcv_nxt);
|
||||
rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
||||
}
|
||||
|
||||
rt_kprintf("Listen PCB states:\n");
|
||||
num = 0;
|
||||
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next)
|
||||
{
|
||||
rt_kprintf("#%d local port %d ", num++, pcb->local_port);
|
||||
rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
||||
}
|
||||
|
||||
rt_kprintf("TIME-WAIT PCB states:\n");
|
||||
num = 0;
|
||||
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next)
|
||||
{
|
||||
strcpy(local_ip_str, ipaddr_ntoa(&(pcb->local_ip)));
|
||||
strcpy(remote_ip_str, ipaddr_ntoa(&(pcb->remote_ip)));
|
||||
|
||||
rt_kprintf("#%d %s:%d <==> %s:%d snd_nxt 0x%08X rcv_nxt 0x%08X ",
|
||||
num++,
|
||||
local_ip_str,
|
||||
pcb->local_port,
|
||||
remote_ip_str,
|
||||
pcb->remote_port,
|
||||
pcb->snd_nxt,
|
||||
pcb->rcv_nxt);
|
||||
rt_kprintf("state: %s\n", tcp_state_str[pcb->state]);
|
||||
}
|
||||
rt_exit_critical();
|
||||
}
|
||||
FINSH_FUNCTION_EXPORT(list_tcps, list all of tcp connections);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue