Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / flight / pios / stm32f10x / libraries / STM32_USB-FS-Device_Driver / src / usb_mem.c
blob5b12a2038c07e6d9d858964eee91d511a4ac0ca9
1 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
2 * File Name : usb_mem.c
3 * Author : MCD Application Team
4 * Version : V3.2.1
5 * Date : 07/05/2010
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 *******************************************************************************/
15 #ifndef STM32F10X_CL
17 /* Includes ------------------------------------------------------------------*/
18 #include "usb_lib.h"
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.
33 * Output : None.
34 * Return : None .
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;
40 uint16_t *pdwVal;
41 pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr);
42 for (i = n; i != 0; i--)
44 temp1 = (uint16_t) * pbUsrBuf;
45 pbUsrBuf++;
46 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
47 *pdwVal++ = temp2;
48 pdwVal++;
49 pbUsrBuf++;
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.
58 * Output : None.
59 * Return : None.
60 *******************************************************************************/
61 void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
63 uint32_t n = (wNBytes + 1) >> 1;/* /2*/
64 uint32_t i;
65 uint32_t *pdwVal;
66 pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
67 for (i = n; i != 0; i--)
69 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
70 pbUsrBuf++;
74 #endif /* STM32F10X_CL */
75 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/