u-boot中网口处理--软件部分
u-boot中DM9000驱动分析
1. CSRs和PHY reg读写。
static u16
phy_read(int reg)
{
u16 val; /* Fill the phyxcer register into REG_0C */
DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */
udelay(); /* Wait read complete */
DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */
val = (DM9000_ior(DM9000_EPDRH) << ) | DM9000_ior(DM9000_EPDRL); /* The read data keeps on REG_0D & REG_0E */
DM9000_DBG("phy_read(%d): %d\n", reg, val);
return val;
}
phy_read
static void
phy_write(int reg, u16 value)
{ /* Fill the phyxcer register into REG_0C */
DM9000_iow(DM9000_EPAR, DM9000_PHY | reg); /* Fill the written data into REG_0D & REG_0E */
DM9000_iow(DM9000_EPDRL, (value & 0xff));
DM9000_iow(DM9000_EPDRH, ((value >> ) & 0xff));
DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */
udelay(); /* Wait write complete */
DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */
DM9000_DBG("phy_write(reg:%d, value:%d)\n", reg, value);
}
phy_write
static u8
DM9000_ior(int reg)
{
u32 val; VALIDATE_ADDR_PORT(reg) val = *(u16*)DM9000_DATA; val &= 0xffff; return (u8)val;
}
DM9000_ior
static void
DM9000_iow(int reg, u8 value)
{
VALIDATE_ADDR_PORT(reg) *(u16*)(DM9000_DATA) = (u16)value;
}
DM9000_iow
#define VALIDATE_ADDR_PORT(p) \
if( m_uLastAddressPort != (p) ) \
{ \
*(u16*)(DM9000_IO) =(u16)(p);\
m_uLastAddressPort = (p);\
}
VALIDATE_ADDR_PORT
2. 网口收发
int
eth_rx(void)
{
u8 rxbyte, *rdptr = (u8 *) NetRxPackets[];
int errors=;
u16 RxLen; u32 desc;
PDM9000_RX_DESCRIPTOR pdesc; DM9000_ior(DM9000_RSR);
DM9000_ior(DM9000_ROCR); for(pdesc=(PDM9000_RX_DESCRIPTOR)&desc;;)
{
// probe first byte
desc = DeviceReadDataWithoutIncrement();
DM9000_DBG("1:\tdesc is 0x%x\n",desc); // check if packet available, 01h means available, 00h means no data
if(pdesc->bState != 0x01)
{
RxLen = ;
break;
} // get the data descriptor again
desc = DeviceReadData();
DM9000_DBG("2:\tdesc is 0x%x\n",desc); DM9000_DBG("len is 0x%x\n",pdesc->nLength); DeviceReadString(rdptr,pdesc->nLength); // check status, as specified in DM9000_RXSR,
// the following bits are error
// <3> PLE
// <2> AE
// <1> CE
// <0> FOE
if(pdesc->bStatus & MAKE_MASK4(,,,))
{
errors++;
continue;
} // of error happens RxLen =pdesc->nLength; break;
} // of forever read loop /* Pass to upper layer */
DM9000_DBG("passing packet to upper layer\n");
NetReceive(NetRxPackets[], RxLen);
return RxLen;
}
eth_rx
int
eth_send(volatile void *packet, int length)
{
unsigned int loop;
#if 0
for(loop = ; loop<length;loop++)
{
printf("%02x ",*((char *)packet+loop));
}
printf("\n");
#endif
DeviceWriteString((u8*)packet,length); DM9000_iow(DM9000_TXPLH,HIGH_BYTE(length));
DM9000_iow(DM9000_TXPLL,LOW_BYTE(length)); // TXCR<0>, issue TX request
DM9000_iow(DM9000_TCR, MAKE_MASK()); DM9000_DBG("transmit done\n\n");
return ;
}
eth_send
数据接收时首先比对包头4个字节,第一个字节必须是0x01,第3,4字节是数据长度(减去开头的4个字节)。
接收完数据后再比对第二字节(DM9000 RSR),确认是否又错误发生。
用到的编程技巧是读取的包头4个字节直接赋值给一个u32,最低字节即为01,高两位为包长度。
u-boot中网口处理--软件部分的更多相关文章
- 在Spring Boot中使用Docker在测试中进行高级功能测试
最近又学到了很多新知识,感谢优锐课老师细致地讲解,这篇博客记录下自己所学所想. 想更多地了解Spring Boot项目中的功能测试吗?这篇文章带你了解有关在测试中使用Docker容器的更多信息. 本文 ...
- Spring Boot(三):Spring Boot中的事件的使用 与Spring Boot启动流程(Event 事件 和 Listeners监听器)
前言:在讲述内容之前 希望大家对设计模式有所了解 即使你学会了本片的内容 也不知道什么时候去使用 或者为什么要这样去用 观察者模式: 观察者模式是一种对象行为模式.它定义对象间的一种一对多的依赖关系, ...
- spring boot(三):Spring Boot中Redis的使用
spring boot对常用的数据库支持外,对nosql 数据库也进行了封装自动化. redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结 ...
- Spring Boot中的事务管理
原文 http://blog.didispace.com/springboottransactional/ 什么是事务? 我们在开发企业应用时,对于业务人员的一个操作实际是对数据读写的多步操作的结合 ...
- Spring Boot中的注解
文章来源:http://www.tuicool.com/articles/bQnMra 在Spring Boot中几乎可以完全弃用xml配置文件,本文的主题是分析常用的注解. Spring最开始是为了 ...
- 在Spring Boot中使用Https
本文介绍如何在Spring Boot中,使用Https提供服务,并将Http请求自动重定向到Https. Https证书 巧妇难为无米之炊,开始的开始,要先取得Https证书.你可以向证书机构申请证书 ...
- Spring Boot中使用Swagger2构建强大的RESTful API文档
由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...
- Dubbo在Spring和Spring Boot中的使用
一.在Spring中使用Dubbo 1.Maven依赖 <dependency> <groupId>com.alibaba</groupId> <artifa ...
- VMware vSphere 服务器虚拟化之二十七桌面虚拟化之View中使用Thinapp软件虚拟化
VMware vSphere 服务器虚拟化之二十七桌面虚拟化之View中使用Thinapp软件虚拟化 VMware ThinApp 应用程序虚拟化软件是无代理解决方案,通过将应用程序隔离并封装为EXE ...
随机推荐
- MM 算法与 EM算法概述
1.MM 算法: MM算法是一种迭代优化方法,利用函数的凸性来寻找它们的最大值或最小值. MM表示 “majorize-minimize MM 算法” 或“minorize maximize MM 算 ...
- 【LeetCode】114. Distinct Subsequences
Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of ...
- SolrCloud之分布式索引及与Zookeeper的集成--转载
原文地址:http://josh-persistence.iteye.com/blog/2234411 一.概述 Lucene是一个Java语言编写的利用倒排原理实现的文本检索类库,Solr是以Luc ...
- C#中?和:?和??总结
?代表可空类型修饰符 引用类型可以使用空引用表示一个不存在的值,而值类型通常不能表示为空.为了使值类型也可为空,就可以使用可空类型?:三元表达式 int a=b>c?b:c 如果b大 ...
- nginx实战三
nginx正向代理 https://coding.net/u/aminglinux/p/nginx/git/blob/master/proxy/z_proxy.md Nginx正向代理使用场景并不多见 ...
- Python max() 函数
描述 max() 函数返回给定参数的最大值,参数可以为序列. 语法 以下是 max() 函数的语法: max( x, y, z, .... ) 参数 x -- 数值表达式. y -- 数值表达式. z ...
- Python fabs() 函数
描述 fabs() 方法返回数字的绝对值,如math.fabs(-10) 返回10.0. fabs() 函数类似于 abs() 函数,但是他有两点区别: abs() 是内置函数. fabs() 函数在 ...
- Excel操作类库最常用到的4种开源项目与MS Excel类库写操作对比分析性能
4种开源Excel读写类库与MS Excel类库写操作对比 软件开发过程中,经常需要将数据保存为.xls或.xlsx文件.之前发现微软提供的Microsoft.Office.Interop.Excel ...
- Spring mvc中DispatcherServlet详解
简介 DispatcherServlet是前端控制器设计模式的实现,提供SpringWebMVC的集中访问点,而且负责职责的分派,而且与spring IOC容器无缝集成,从而可以获得Spring的优势 ...
- SolrCloud:依据Solr Wiki的译文
本文是作者依据Apache Solr Document的译文.翻译不对或者理解不到位的地方欢迎大家指正!谢谢! Nodes, Cores, Cluster and Leaders Nodes and ...