Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32_USB-FS-Device_Driver / src / usb_mem.c
blob46074cc6cd4b11df5a8897a2a5136903e5c164f6
1 /**
2 ******************************************************************************
3 * @file usb_mem.c
4 * @author MCD Application Team
5 * @version V4.0.0
6 * @date 28-August-2012
7 * @brief Utility functions for memory transfers to/from PMA
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
17 * http://www.st.com/software_license_agreement_liberty_v2
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
25 ******************************************************************************
28 /* Includes ------------------------------------------------------------------*/
29 #include "usb_lib.h"
31 /* Private typedef -----------------------------------------------------------*/
32 /* Private define ------------------------------------------------------------*/
33 /* Private macro -------------------------------------------------------------*/
34 /* Private variables ---------------------------------------------------------*/
35 /* Extern variables ----------------------------------------------------------*/
36 /* Private function prototypes -----------------------------------------------*/
37 /* Private functions ---------------------------------------------------------*/
39 /*******************************************************************************
40 * Function Name : UserToPMABufferCopy
41 * Description : Copy a buffer from user memory area to packet memory area (PMA)
42 * Input : - pbUsrBuf: pointer to user memory area.
43 * - wPMABufAddr: address into PMA.
44 * - wNBytes: no. of bytes to be copied.
45 * Output : None.
46 * Return : None .
47 *******************************************************************************/
48 void UserToPMABufferCopy(const uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
50 uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
51 uint32_t i, temp1, temp2;
52 uint16_t *pdwVal;
53 pdwVal = (uint16_t *)(wPMABufAddr * 2 + PMAAddr);
54 for (i = n; i != 0; i--)
56 temp1 = (uint16_t) * pbUsrBuf;
57 pbUsrBuf++;
58 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
59 *pdwVal++ = temp2;
60 pdwVal++;
61 pbUsrBuf++;
65 /*******************************************************************************
66 * Function Name : PMAToUserBufferCopy
67 * Description : Copy a buffer from user memory area to packet memory area (PMA)
68 * Input : - pbUsrBuf = pointer to user memory area.
69 * - wPMABufAddr = address into PMA.
70 * - wNBytes = no. of bytes to be copied.
71 * Output : None.
72 * Return : None.
73 *******************************************************************************/
74 void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
76 uint32_t n = (wNBytes + 1) >> 1;/* /2*/
77 uint32_t i;
78 uint32_t *pdwVal;
79 pdwVal = (uint32_t *)(wPMABufAddr * 2 + PMAAddr);
80 for (i = n; i != 0; i--)
82 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
83 pbUsrBuf++;
87 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/