Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
宁楠萍
rt-thread
提交
68df79e8
R
rt-thread
项目概览
宁楠萍
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
68df79e8
编写于
9月 03, 2020
作者:
S
sheltonyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp/at32] add link detecting thread for ethernet driver
上级
f3d1e711
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
0 deletion
+44
-0
bsp/at32/Libraries/rt_drivers/drv_eth.c
bsp/at32/Libraries/rt_drivers/drv_eth.c
+44
-0
未找到文件。
bsp/at32/Libraries/rt_drivers/drv_eth.c
浏览文件 @
68df79e8
...
...
@@ -31,6 +31,9 @@
#define ETH_RXBUFNB 4
#define ETH_TXBUFNB 2
#define LINK_THREAD_STACK_SIZE 256
#define LINK_THREAD_PREORITY 21
extern
ETH_DMADESCTypeDef
*
DMATxDescToSet
;
extern
ETH_DMADESCTypeDef
*
DMARxDescToGet
;
extern
ETH_DMADESCTypeDef
*
DMAPTPTxDescToSet
;
...
...
@@ -38,6 +41,8 @@ extern ETH_DMADESCTypeDef *DMAPTPRxDescToGet;
static
ETH_DMADESCTypeDef
DMARxDscrTab
[
ETH_RXBUFNB
],
DMATxDscrTab
[
ETH_TXBUFNB
];
static
rt_uint8_t
Rx_Buff
[
ETH_RXBUFNB
][
ETH_MAX_PACKET_SIZE
],
Tx_Buff
[
ETH_TXBUFNB
][
ETH_MAX_PACKET_SIZE
];
static
struct
rt_thread
eth_link_thread
;
static
rt_uint8_t
eth_link_stack
[
LINK_THREAD_STACK_SIZE
];
#define MAX_ADDR_LEN 6
/* Gloable variables ---------------------------------------------------------*/
...
...
@@ -634,6 +639,37 @@ struct pbuf *rt_at32_eth_rx(rt_device_t dev)
return
p
;
}
static
void
eth_link_thread_entry
(
void
*
paramter
)
{
uint8_t
linked_down
=
1
;
struct
netif
*
pnetif
=
at32_eth_device
.
parent
.
netif
;
while
(
1
){
if
((
ETH_ReadPHYRegister
(
PHY_ADDRESS
,
PHY_BSR
)
&
PHY_Linked_Status
)
&&
(
linked_down
==
1
))
{
/* link up */
linked_down
=
0
;
#ifndef RT_LWIP_DHCP
pnetif
->
ip_addr
=
inet_addr
(
RT_LWIP_IPADDR
);
pnetif
->
gw
=
inet_addr
(
RT_LWIP_GWADDR
);
pnetif
->
netmask
=
inet_addr
(
RT_LWIP_MSKADDR
);
#else
IP4_ADDR
(
&
(
pnetif
->
ip_addr
),
0
,
0
,
0
,
0
);
IP4_ADDR
(
&
(
pnetif
->
netmask
),
0
,
0
,
0
,
0
);
IP4_ADDR
(
&
(
pnetif
->
gw
),
0
,
0
,
0
,
0
);
#endif
eth_device_linkchange
(
&
(
at32_eth_device
.
parent
),
RT_TRUE
);
}
else
if
(
!
(
ETH_ReadPHYRegister
(
PHY_ADDRESS
,
PHY_BSR
)
&
PHY_Linked_Status
)
&&
(
linked_down
==
0
))
{
/* link down */
linked_down
=
1
;
eth_device_linkchange
(
&
(
at32_eth_device
.
parent
),
RT_FALSE
);
}
rt_thread_mdelay
(
500
);
}
}
/* interrupt service routine */
void
ETH_IRQHandler
(
void
)
{
...
...
@@ -707,9 +743,17 @@ static int rt_hw_at32_eth_init(void)
/* register eth device */
state
=
eth_device_init
(
&
(
at32_eth_device
.
parent
),
"e0"
);
if
(
RT_EOK
==
state
)
{
LOG_D
(
"emac device init success"
);
state
=
rt_thread_init
(
&
eth_link_thread
,
"eth_link_detect"
,
eth_link_thread_entry
,
RT_NULL
,
&
eth_link_stack
[
0
],
LINK_THREAD_STACK_SIZE
,
LINK_THREAD_PREORITY
,
20
);
if
(
state
==
RT_EOK
)
{
rt_thread_startup
(
&
eth_link_thread
);
}
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录