u-boot中网口处理--软件部分

u-boot中DM9000驱动分析

1. CSRs和PHY reg读写。

 1 static u16
 2 phy_read(int reg)
 3 {
 4     u16 val;
 5
 6     /* Fill the phyxcer register into REG_0C */
 7     DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
 8     DM9000_iow(DM9000_EPCR, 0xc);    /* Issue phyxcer read command */
 9     udelay(100);        /* Wait read complete */
10     DM9000_iow(DM9000_EPCR, 0x0);    /* Clear phyxcer read command */
11     val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL);
12
13     /* The read data keeps on REG_0D & REG_0E */
14     DM9000_DBG("phy_read(%d): %d\n", reg, val);
15     return val;
16 }

phy_read

 1 static void
 2 phy_write(int reg, u16 value)
 3 {
 4
 5     /* Fill the phyxcer register into REG_0C */
 6     DM9000_iow(DM9000_EPAR, DM9000_PHY | reg);
 7
 8     /* Fill the written data into REG_0D & REG_0E */
 9     DM9000_iow(DM9000_EPDRL, (value & 0xff));
10     DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff));
11     DM9000_iow(DM9000_EPCR, 0xa);    /* Issue phyxcer write command */
12     udelay(500);        /* Wait write complete */
13     DM9000_iow(DM9000_EPCR, 0x0);    /* Clear phyxcer write command */
14     DM9000_DBG("phy_write(reg:%d, value:%d)\n", reg, value);
15 }

phy_write

 1 static u8
 2 DM9000_ior(int reg)
 3 {
 4     u32     val;
 5
 6     VALIDATE_ADDR_PORT(reg)
 7
 8     val = *(u16*)DM9000_DATA;
 9
10     val &= 0xffff;
11
12     return (u8)val;
13 }

DM9000_ior

1 static void
2 DM9000_iow(int reg, u8 value)
3 {
4     VALIDATE_ADDR_PORT(reg)
5
6     *(u16*)(DM9000_DATA) =     (u16)value;
7 }

DM9000_iow

1 #define    VALIDATE_ADDR_PORT(p) 2     if( m_uLastAddressPort != (p) ) 3         { 4             *(u16*)(DM9000_IO)  =(u16)(p);5             m_uLastAddressPort = (p);6         }

VALIDATE_ADDR_PORT

2. 网口收发

 1 int
 2 eth_rx(void)
 3 {
 4     u8 rxbyte, *rdptr = (u8 *) NetRxPackets[0];
 5     int     errors=0;
 6     u16        RxLen;
 7
 8     u32     desc;
 9     PDM9000_RX_DESCRIPTOR    pdesc;
10
11     DM9000_ior(DM9000_RSR);
12     DM9000_ior(DM9000_ROCR);
13
14     for(pdesc=(PDM9000_RX_DESCRIPTOR)&desc;;)
15     {
16         // probe first byte
17         desc = DeviceReadDataWithoutIncrement();
18         DM9000_DBG("1:\tdesc is 0x%x\n",desc);
19
20         // check if packet available, 01h means available, 00h means no data
21         if(pdesc->bState != 0x01)
22         {
23             RxLen = 0;
24             break;
25         }
26
27         // get the data descriptor again
28         desc = DeviceReadData();
29         DM9000_DBG("2:\tdesc is 0x%x\n",desc);
30
31         DM9000_DBG("len is 0x%x\n",pdesc->nLength);
32
33         DeviceReadString(rdptr,pdesc->nLength);
34
35         // check status, as specified in DM9000_RXSR,
36         // the following bits are error
37         // <3> PLE
38         // <2> AE
39         // <1> CE
40         // <0> FOE
41         if(pdesc->bStatus & MAKE_MASK4(3,2,1,0))
42         {
43             errors++;
44             continue;
45         } // of error happens
46
47         RxLen =pdesc->nLength;
48
49         break;
50     } // of forever read loop
51
52     /* Pass to upper layer */
53     DM9000_DBG("passing packet to upper layer\n");
54     NetReceive(NetRxPackets[0], RxLen);
55     return RxLen;
56 }

eth_rx

 1 int
 2 eth_send(volatile void *packet, int length)
 3 {
 4     unsigned int loop;
 5 #if 0
 6     for(loop = 0; loop<length;loop++)
 7     {
 8         printf("%02x ",*((char *)packet+loop));
 9     }
10     printf("\n");
11 #endif
12     DeviceWriteString((u8*)packet,length);
13
14     DM9000_iow(DM9000_TXPLH,HIGH_BYTE(length));
15     DM9000_iow(DM9000_TXPLL,LOW_BYTE(length));
16
17     // TXCR<0>, issue TX request
18     DM9000_iow(DM9000_TCR, MAKE_MASK(0));
19
20
21     DM9000_DBG("transmit done\n\n");
22     return 0;
23 }

eth_send

数据接收时首先比对包头4个字节,第一个字节必须是0x01,第3,4字节是数据长度(减去开头的4个字节)。

接收完数据后再比对第二字节(DM9000 RSR),确认是否又错误发生。

用到的编程技巧是读取的包头4个字节直接赋值给一个u32,最低字节即为01,高两位为包长度。

时间: 2024-08-09 06:32:30

u-boot中网口处理--软件部分的相关文章

Spring Boot中Redis的使用

软件152   高光顺 redis介绍 Redis是目前业界使用最广泛的内存数据存储.相比memcached,Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化.除此之外,Redis还提供一些类数据库的特性,比如事务,HA,主从库.可以说Redis兼具了缓存系统和数据库的一些特性,因此有着丰富的应用场景.本文介绍Redis在Spring Boot中两个典型的应用场景. 如何使用 1.引入 spring-boot-starter-redis <depe

3.Spring Boot中使用Swagger2构建强大的RESTful API文档

原文:http://www.jianshu.com/p/8033ef83a8ed 由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这些终端会共用很多底层业务逻辑,因此我们会抽象出这样一层来同时服务于多个移动端或者Web前端. 这样一来,我们的RESTful API就有可能要面对多个开发人员或多个开发团队:IOS开发.Android开发或是Web开发

spring-boot实战【10】【转】:Spring Boot中使用@Async实现异步调用

什么是"异步调用"? "异步调用"对应的是"同步调用",同步调用指程序按照定义顺序依次执行,每一行程序都必须等待上一行程序执行完成之后才能执行:异步调用指程序在顺序执行时,不等待异步调用的语句返回结果就执行后面的程序. 同步调用 下面通过一个简单示例来直观的理解什么是同步调用: 定义Task类,创建三个处理函数分别模拟三个执行任务的操作,操作消耗时间随机取(10秒内) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

spring-boot实战【07】【转】:Spring Boot中Web应用的统一异常处理

我们在做Web应用的时候,请求处理过程中发生错误是非常常见的情况.Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来展示异常内容. 选择一个之前实现过的Web应用(Chapter3-1-2)为基础,启动该应用,访问一个不存在的URL,或是修改处理内容,直接抛出异常,如: 1 2 3 4 @RequestMapping("/hello") public String hello() throws Exce

spring-boot实战【09】【转】:Spring Boot中使用@Scheduled创建定时任务

我们在编写Spring Boot应用中经常会遇到这样的场景,比如:我需要定时地发送一些短信.邮件之类的操作,也可能会定时地检查和监控一些标志.参数等. 创建定时任务 在Spring Boot中编写定时任务是非常简单的事,下面通过实例介绍如何在Spring Boot中创建定时任务,实现每过5秒输出一下当前时间. 在Spring Boot的主类中加入@EnableScheduling注解,启用定时任务的配置 1 2 3 4 5 6 7 8 9 10 @SpringBootApplication @E

spring-boot实战【12】:Spring Boot中使用JavaMailSender发送邮件

相信使用过Spring的众多开发者都知道Spring提供了非常好用的JavaMailSender接口实现邮件发送.在Spring Boot的Starter模块中也为此提供了自动化配置.下面通过实例看看如何在Spring Boot中使用JavaMailSender发送邮件. 快速入门 在Spring Boot的工程中的pom.xml中引入spring-boot-starter-mail依赖: 1 2 3 4 <dependency> <groupId>org.springframew

再谈Spring Boot中的乱码和编码问题

编码算不上一个大问题,即使你什么都不管,也有很大的可能你不会遇到任何问题,因为大部分框架都有默认的编码配置,有很多是UTF-8,那么遇到中文乱码的机会很低,所以很多人也忽视了. Spring系列产品大量运用在网站开发中,而Spring Boot是为了简化配置而出现的,理论上讲Spring Boot应该默认配置UTF-8为默认编码,但是网络上依然可以看到很多关于Spring Boot乱码的文章,大部分解决方案沿用Spring MVC的方案,自定义EncodingFilter. 但是仔细查看Spri

Spring Boot中的注解

文章来源:http://www.tuicool.com/articles/bQnMra 在Spring Boot中几乎可以完全弃用xml配置文件,本文的主题是分析常用的注解. Spring最开始是为了解决EJB等大型企业框架对应用程序的侵入性,因此大量依靠配置文件来“非侵入式”得给POJO增加功能,然而,从Spring 3.x开始,Spring被外界最为诟病的一点就是配置繁多,号称“配置地狱”,各种xml文件,出了问题非常难排查.从Spring 4.x开始,Spring.io提供了三种方式编织B

Spring Boot中使用Swagger2生成RESTful API文档(转)

效果如下图所示: 添加Swagger2依赖 在pom.xml中加入Swagger2的依赖 <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <versi