您的位置:首页 > 其它

STM32 USB Host Library 学习笔记 (1) USB_OTG_ReadPacket() USB_ReadPacket()

2012-09-01 22:02 706 查看
/**
* @brief  USB_OTG_ReadPacket : Reads a packet from the Rx FIFO
* @param  pdev : Selected device
* @param  dest : Destination Pointer
* @param  bytes : No. of bytes
* @retval None
*/
void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev,
uint8_t *dest,
uint16_t len)
{
uint32_t i=0;
//uint32_t count32b = (len + 3) / 4;
uint32_t count32b = (len) / 4;
uint32_t count8b = (len) & 3;

__IO uint32_t *fifo = pdev->regs.DFIFO[0];

for ( i = 0; i < count32b; i++, dest += 4 )
{
*(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo);

}

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   }

return ((void *)dest);
}



/** @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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: