1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
2 * File Name : usb_mem.c
3 * Author : MCD Application Team
6 * Description : Utility functions for memory transfers to/from PMA
7 ********************************************************************************
8 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
9 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
10 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
11 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
12 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
13 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
14 *******************************************************************************/
17 /* Includes ------------------------------------------------------------------*/
20 /* Private typedef -----------------------------------------------------------*/
21 /* Private define ------------------------------------------------------------*/
22 /* Private macro -------------------------------------------------------------*/
23 /* Private variables ---------------------------------------------------------*/
24 /* Extern variables ----------------------------------------------------------*/
25 /* Private function prototypes -----------------------------------------------*/
26 /* Private functions ---------------------------------------------------------*/
27 /*******************************************************************************
28 * Function Name : UserToPMABufferCopy
29 * Description : Copy a buffer from user memory area to packet memory area (PMA)
30 * Input : - pbUsrBuf: pointer to user memory area.
31 * - wPMABufAddr: address into PMA.
32 * - wNBytes: no. of bytes to be copied.
35 *******************************************************************************/
36 void UserToPMABufferCopy(const uint8_t *pbUsrBuf
, uint16_t wPMABufAddr
, uint16_t wNBytes
)
38 uint32_t n
= (wNBytes
+ 1) >> 1; /* n = (wNBytes + 1) / 2 */
39 uint32_t i
, temp1
, temp2
;
41 pdwVal
= (uint16_t *)(wPMABufAddr
* 2 + PMAAddr
);
42 for (i
= n
; i
!= 0; i
--)
44 temp1
= (uint16_t) * pbUsrBuf
;
46 temp2
= temp1
| (uint16_t) * pbUsrBuf
<< 8;
52 /*******************************************************************************
53 * Function Name : PMAToUserBufferCopy
54 * Description : Copy a buffer from user memory area to packet memory area (PMA)
55 * Input : - pbUsrBuf = pointer to user memory area.
56 * - wPMABufAddr = address into PMA.
57 * - wNBytes = no. of bytes to be copied.
60 *******************************************************************************/
61 void PMAToUserBufferCopy(uint8_t *pbUsrBuf
, uint16_t wPMABufAddr
, uint16_t wNBytes
)
63 uint32_t n
= (wNBytes
+ 1) >> 1;/* /2*/
66 pdwVal
= (uint32_t *)(wPMABufAddr
* 2 + PMAAddr
);
67 for (i
= n
; i
!= 0; i
--)
69 *(uint16_t*)pbUsrBuf
++ = *pdwVal
++;
74 #endif /* STM32F10X_CL */
75 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/