zoukankan      html  css  js  c++  java
  • STM32 USB Host Library 学习笔记 (1) USB_OTG_ReadPacket() USB_ReadPacket()

     1 /**
     2 * @brief  USB_OTG_ReadPacket : Reads a packet from the Rx FIFO
     3 * @param  pdev : Selected device
     4 * @param  dest : Destination Pointer
     5 * @param  bytes : No. of bytes
     6 * @retval None
     7 */
     8 void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev, 
     9                          uint8_t *dest, 
    10                          uint16_t len)
    11 {
    12   uint32_t i=0;
    13   //uint32_t count32b = (len + 3) / 4;
    14   uint32_t count32b = (len) / 4;
    15   uint32_t count8b = (len) & 3;
    16   
    17   __IO uint32_t *fifo = pdev->regs.DFIFO[0];
    18   
    19   for ( i = 0; i < count32b; i++, dest += 4 )
    20   {
    21     *(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo);
    22     
    23   }
    24   
    25   if ( count8b )
    26   {
    27     count32b = USB_OTG_READ_REG32(fifo);
    28     while ( count8b > 0 )
    29     {
    30       *dest = count32b;
    31       count32b >>= 8;
    32       dest++;
    33       count8b--;      
    34     }
    35   }
    36 return ((void *)dest); 37 }
    
    

    /** @file stm32f4xx_ll_usb.c
      * @author MCD Application Team
      * @version V1.1.0
      * @date 19-June-2014
      * @brief USB Low Layer HAL module driver.
      */


    /*
    * * @brief USB_ReadPacket : read a packet from the Tx FIFO associated * with the EP/channel * @param USBx : Selected device * @param src : source pointer * @param ch_ep_num : endpoint or host channel number * @param len : Noumber of bytes to read * @param dma: USB dma enabled or disabled * This parameter can be one of the these values: * 0 : DMA feature not used * 1 : DMA feature used * @retval pointer to desctination buffer */ void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len) { uint32_t i=0; uint32_t count32b = (len + 3) / 4; for ( i = 0; i < count32b; i++, dest += 4 ) { *(__packed uint32_t *)dest = USBx_DFIFO(0); // dest buffer overflow if (len != n*4) } return ((void *)dest); }

  • 相关阅读:
    回归分析举例
    用js实现在文本框中检测字数和限制字数功能
    深入理解CSS盒子模型
    CSS盒子模型小剖析
    iphone开发“关闭键盘的例子”
    最全的CSS浏览器兼容问题整理(IE6.0、IE7.0 与 FireFox)
    Soap UI 负载测试
    应聘时最漂亮的回答! 留着 早晚用的上 2012
    SOAP UI 简单使用
    乔布斯做管理的十条戒律
  • 原文地址:https://www.cnblogs.com/shangdawei/p/2667125.html
Copyright © 2011-2022 走看看