Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2120129
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2012-06-19 14:50:15

感觉书上UsbEp0SendData函数写得太麻烦,于是修改了一下,感觉还是可以用的,呵呵!
1. UsbEp0SendData的代码

点击(此处)折叠或打开

  1. uint8* pSendBuf;
  2. uint8 remain_len;
  3. void UsbEp0SendData()
  4. {
  5.     //SendBuf[7]是端点0最大包长
  6.     if(remain_len == DevDesc[7])
  7.     {
  8.         print_hex_buf(pSendBuf, DevDesc[7]);
  9.         D12WriteEndpBuf(pSendBuf, DevDesc[7], 1);
  10.         D12WriteEndpBuf(pSendBuf, 0, 1);
  11.         remain_len = 0;
  12.         return ;
  13.     }

  14.     if(remain_len < DevDesc[7])
  15.     {
  16.         print_hex_buf(pSendBuf, remain_len);
  17.         D12WriteEndpBuf(pSendBuf, remain_len, 1);
  18.         remain_len = 0;
  19.         pSendBuf = NULL;
  20.         return ;
  21.     }    
  22.     if(remain_len > DevDesc[7])
  23.     {
  24.         print_hex_buf(pSendBuf, DevDesc[7]);
  25.         D12WriteEndpBuf(pSendBuf, DevDesc[7], 1);
  26.         pSendBuf += DevDesc[7];
  27.         remain_len -= DevDesc[7];
  28.         return ;
  29.     }
  30.     return ;
  31. }
每次要发送时(以发送设备描述符DeviceDesc为例):

点击(此处)折叠或打开

  1. case GD_DEVICE:    
  2.       my_printf("GD_DEVICE=0x%x\n",GD_DEVICE);                        
  3.       pSendBuf = DevDesc;
  4.       remain_len = DevDesc[0];
  5.       UsbEp0SendData();                         
  6.       break;
pSendData指向要发送的描述符,remain_len是指要发送的数据长度

2. 为了让程序上看起来更清晰一些,增加UsbEp0SendAck函数。

点击(此处)折叠或打开

  1. void UsbEp0SendAck(void)
  2. {
  3.     D12WriteEndpBuf(pSendBuf, 0, 1); //pSendBuf没有用到,即使为空也没有关系
  4. }

阅读(3007) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~