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 ...
随机推荐
- maven 错误处理
如果是方法找不到或者返回参数变了,那么肯定是包被升级了,那么到仓库下把对应的包删掉,然后maven自动下载最新的. 如果是包找不到,或者类找不到,那么把maven ->update maven可 ...
- 【转载】PL/SQL配置连接ORACLE
一.需安装ORACL客户端. 配置文件路径: E:\Oracle\product\10.1.0\Client_3\NETWORK\ADMIN\tnsnames.ora 内容如下: # TNSNAMES ...
- Eclipse Xml编译错误Referenced file contains errors - spring-beans-4.0.xsd
本文转自:http://josh-persistence.iteye.com/blog/2125420 在eclipse中,有时候在xml文件中,特别是于Spring相关的配置文件中,会出现一些不影响 ...
- 【LeetCode】34. Search for a Range
Search for a Range Given a sorted array of integers, find the starting and ending position of a give ...
- POJ 3006 Dirichlet's Theorem on Arithmetic Progressions (素数)
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS Memory Limit: 65536K Total Submi ...
- Tomcat配置+JSP页面模板修改UTF-8
A.修改Tomcat端口号步骤:1.找到Tomcat目录下的conf文件夹2.进入conf文件夹里面找到server.xml文件3.打开server.xml文件4.在server.xml文件里面找到下 ...
- Clipboard.GetImage() Clipboard获取粘贴板内容为null的解决办法
将线程启动模式设置为 sta 单线程 简介 STA: Single-Thread Apartment, 中文叫单线程套间.就是在COM库初始化的时候创建一个内存结构,然后让它和调用CoIn ...
- matplotlib热图
1.基础知识点回顾 1.plot(x, y, marker='D')表示绘制折线图,marker设置样式菱形. 2.scatter(x, y, marker='s', color='r')绘制散点图, ...
- jQuery.ajax() 如何设置 Headers 中的 Accept 内容
其实很简单,首先如果是常见类型,则请直接设置 dataType 属性 $.ajax({ dataType: "json", type: "get", succe ...
- [Python]南邮OJ代码备份爬虫
之前看过Python学习的经验,说以project为导向学习. 自己分析了一下,一般接触Python的都有一定的其它语言基础,对于程序设计的基本逻辑,语法都有一个大概的了解.而Python这样的脚本语 ...