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); }

 

posted @ 2012-09-01 22:02  IAmAProgrammer  阅读(3614)  评论(0编辑  收藏  举报