GD32F1x0: USB/GD32_USB_Device_Driver/src/usb_buf.c Source File

GD32F1x0

usb_buf.c
Go to the documentation of this file.
1 
11 /* Includes ------------------------------------------------------------------*/
12 #include "usb_buf.h"
13 
36 void FreeUserBuffer (uint8_t EpID, uint8_t Dir)
37 {
38  if (Dir == DBUF_EP_OUT)
39  {
40  _ToggleSWBUF_RX(EpID);
41  }
42  else if (Dir == DBUF_EP_IN)
43  {
44  _ToggleSWBUF_TX(EpID);
45  }
46 }
47 
55 void UserCopyToBuffer (uint8_t *UsrBuf, uint16_t BufAddr, uint16_t Bytes)
56 {
57  uint32_t n = (Bytes + 1) >> 1;
58  uint32_t i, temp;
59  uint16_t *BaseAddr = (uint16_t *)(BufAddr * 2 + PBA_Addr);
60 
61  for (i = n; i != 0; i--)
62  {
63  temp = (uint16_t) * UsrBuf;
64  UsrBuf++;
65  *BaseAddr++ = temp | (uint16_t) * UsrBuf << 8;
66  BaseAddr++;
67  UsrBuf++;
68  }
69 }
70 
78 void BufferCopyToUser (uint8_t *UsrBuf, uint16_t BufAddr, uint16_t Bytes)
79 {
80  uint32_t n = (Bytes + 1) >> 1;
81  uint32_t i;
82  uint32_t *BaseAddr = (uint32_t *)(BufAddr * 2 + PBA_Addr);
83 
84  for (i = n; i != 0; i--)
85  {
86  *(uint16_t*)UsrBuf++ = *BaseAddr++;
87  UsrBuf++;
88  }
89 }
90 
107 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
void FreeUserBuffer(uint8_t EpID, uint8_t Dir)
Free buffer used from application by toggling the SW_BUF byte.
Definition: usb_buf.c:36
#define PBA_Addr
Definition: usb_regs.h:62
#define _ToggleSWBUF_TX(EpID)
Toggle SW_BUF bit in the double buffered endpoint.
Definition: usb_regs.h:516
void BufferCopyToUser(uint8_t *UsrBuf, uint16_t BufAddr, uint16_t Bytes)
Copy a buffer from the allocation buffer area to user memory area.
Definition: usb_buf.c:78
void UserCopyToBuffer(uint8_t *UsrBuf, uint16_t BufAddr, uint16_t Bytes)
Copy a buffer from user memory area to the allocation buffer area.
Definition: usb_buf.c:55
USB buffer interface functions prototypes.
Generated by   doxygen 1.8.10