Sergey Pastor / grbl1
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers usb_sil.c Source File

usb_sil.c

00001 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
00002 * File Name          : usb_sil.c
00003 * Author             : MCD Application Team
00004 * Version            : V3.2.1
00005 * Date               : 07/05/2010
00006 * Description        : Simplified Interface Layer for Global Initialization and 
00007 *                      Endpoint Rea/Write operations.
00008 ********************************************************************************
00009 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00010 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
00011 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
00012 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
00013 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
00014 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00015 *******************************************************************************/
00016 
00017 /* Includes ------------------------------------------------------------------*/
00018 #include "usb_lib.h"
00019 
00020 /* Private typedef -----------------------------------------------------------*/
00021 /* Private define ------------------------------------------------------------*/
00022 /* Private macro -------------------------------------------------------------*/
00023 /* Private variables ---------------------------------------------------------*/
00024 /* Extern variables ----------------------------------------------------------*/
00025 /* Private function prototypes -----------------------------------------------*/
00026 /* Private functions ---------------------------------------------------------*/
00027 
00028 /*******************************************************************************
00029 * Function Name  : USB_SIL_Init
00030 * Description    : Initialize the USB Device IP and the Endpoint 0.
00031 * Input          : None.
00032 * Output         : None.
00033 * Return         : Status.
00034 *******************************************************************************/
00035 uint32_t USB_SIL_Init(void)
00036 {
00037 #ifndef STM32F10X_CL
00038   
00039   /* USB interrupts initialization */
00040   /* clear pending interrupts */
00041   _SetISTR(0);
00042   wInterrupt_Mask = IMR_MSK;
00043   /* set interrupts mask */
00044   _SetCNTR(wInterrupt_Mask);
00045   
00046 #else
00047   
00048   /* Perform OTG Device initialization procedure (including EP0 init) */
00049   OTG_DEV_Init();
00050   
00051 #endif /* STM32F10X_CL */
00052 
00053   return 0;
00054 }
00055 
00056 /*******************************************************************************
00057 * Function Name  : USB_SIL_Write
00058 * Description    : Write a buffer of data to a selected endpoint.
00059 * Input          : - bEpAddr: The address of the non control endpoint.
00060 *                  - pBufferPointer: The pointer to the buffer of data to be written
00061 *                    to the endpoint.
00062 *                  - wBufferSize: Number of data to be written (in bytes).
00063 * Output         : None.
00064 * Return         : Status.
00065 *******************************************************************************/
00066 uint32_t USB_SIL_Write(uint8_t bEpAddr, uint8_t* pBufferPointer, uint32_t wBufferSize)
00067 {
00068 #ifndef STM32F10X_CL
00069 
00070   /* Use the memory interface function to write to the selected endpoint */
00071   UserToPMABufferCopy(pBufferPointer, GetEPTxAddr(bEpAddr & 0x7F), wBufferSize);
00072 
00073   /* Update the data length in the control register */
00074   SetEPTxCount((bEpAddr & 0x7F), wBufferSize);
00075   
00076 #else
00077   
00078    /* Use the PCD interface layer function to write to the selected endpoint */
00079    PCD_EP_Write (bEpAddr, pBufferPointer, wBufferSize); 
00080    
00081 #endif /* STM32F10X_CL */
00082 
00083   return 0;
00084 }
00085 
00086 /*******************************************************************************
00087 * Function Name  : USB_SIL_Read
00088 * Description    : Write a buffer of data to a selected endpoint.
00089 * Input          : - bEpAddr: The address of the non control endpoint.
00090 *                  - pBufferPointer: The pointer to which will be saved the 
00091 *                     received data buffer.
00092 * Output         : None.
00093 * Return         : Number of received data (in Bytes).
00094 *******************************************************************************/
00095 uint32_t USB_SIL_Read(uint8_t bEpAddr, uint8_t* pBufferPointer)
00096 {
00097   uint32_t DataLength = 0;
00098 
00099 #ifndef STM32F10X_CL
00100 
00101   /* Get the number of received data on the selected Endpoint */
00102   DataLength = GetEPRxCount(bEpAddr & 0x7F);
00103   
00104   /* Use the memory interface function to write to the selected endpoint */
00105   PMAToUserBufferCopy(pBufferPointer, GetEPRxAddr(bEpAddr & 0x7F), DataLength);
00106 
00107 #else
00108   
00109   USB_OTG_EP *ep;
00110 
00111   /* Get the structure pointer of the selected Endpoint */
00112   ep = PCD_GetOutEP(bEpAddr);
00113   
00114   /* Get the number of received data */
00115   DataLength = ep->xfer_len;
00116   
00117   /* Use the PCD interface layer function to read the selected endpoint */
00118   PCD_EP_Read (bEpAddr, pBufferPointer, DataLength);
00119   
00120 #endif /* STM32F10X_CL */
00121 
00122   /* Return the number of received data */
00123   return DataLength;
00124 }
00125 
00126 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/