usb的库文件:usb.mem.c,文档不够详细,就两个函数 读了好久,没明白,没辙了,求教,下面贴一个从memory拷贝到PMA的函数: /******************************************************************************* * Function Name : UserToPMABufferCopy * Description : Copy a buffer from user memory area to packet memory area (PMA) * Input : - pbUsrBuf: pointer to user memory area. * - wPMABufAddr: address into PMA. * - wNBytes: no. of bytes to be copied. * Output : None. * Return : None . *******************************************************************************/ 35 void UserToPMABufferCopy(u8 *pbUsrBuf, u16 wPMABufAddr, u16 wNBytes) 36 { 37 u32 n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ 38 u32 i, temp1, temp2; 39 u16 *pdwVal; 40 pdwVal = (u16 *)(wPMABufAddr * 2 + PMAAddr); 41 for (i = n; i != 0; i--) 42 { 43 temp1 = (u16) * pbUsrBuf; 44 pbUsrBuf++; 45 temp2 = temp1 | (u16) * pbUsrBuf << 8; 46 *pdwVal++ = temp2; 47 pdwVal++; 48 pbUsrBuf++; 49 } 50 }
问题: 1. 40行为什么要(wPMABufAddr * 2 + PMAAddr)?wPMABufAddr 不就是buffer的地址么? 2. 47行为什么还要 pdwVal++,是为了32位数据对齐么?这样的话会不会导致buffer中有空间浪费?相当于我们使用了32位buffer中的低16位。 |