Nut/OS  5.0.5
API Reference
otgd_fs_cal.h
Go to the documentation of this file.
00001 /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
00002 * File Name          : otgd_fs_cal.h
00003 * Author             : STMicroelectronics
00004 * Version            : V3.1.1
00005 * Date               : 04/07/2010
00006 * Description        : Header of OTG FS Device Core Access Layer interface.
00007 ********************************************************************************
00008 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00009 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
00010 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
00011 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
00012 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
00013 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00014 *******************************************************************************/
00015 #ifndef __OTG_CORE_H__
00016 #define __OTG_CORE_H__
00017 
00018 
00019 #include <arch/cm3/stm/stm32xxxx.h>
00020 #include <dev/usb_stm32/usb_type.h>
00021 #include <stdint.h>
00022 
00023 #if defined ( __CC_ARM   )
00024   #define __packed        __packed                     
00025 #elif defined ( __ICCARM__ )
00026   #define __packed        __packed                     
00027 #elif defined   (  __GNUC__  )
00028   #define __packed        __attribute__ ((__packed__)) 
00029 #elif defined   (  __TASKING__  )                      
00030   #define __packed
00031 #endif /* __CC_ARM */
00032 
00033 /*******************************************************************************
00034                                 define and types
00035 *******************************************************************************/
00036 
00037 #define DEVICE_MODE_ENABLED
00038 
00039 #ifndef NULL
00040 #define NULL ((void *)0)
00041 #endif
00042 
00043 
00044 #define DEV_EP_TX_DIS       0x0000
00045 #define DEV_EP_TX_STALL     0x0010
00046 #define DEV_EP_TX_NAK       0x0020
00047 #define DEV_EP_TX_VALID     0x0030
00048 
00049 #define DEV_EP_RX_DIS       0x0000
00050 #define DEV_EP_RX_STALL     0x1000
00051 #define DEV_EP_RX_NAK       0x2000
00052 #define DEV_EP_RX_VALID     0x3000
00053 
00054 /*****************          GLOBAL DEFINES          ***************************/
00055 
00056 #define GAHBCFG_TXFEMPTYLVL_EMPTY              1
00057 #define GAHBCFG_TXFEMPTYLVL_HALFEMPTY          0
00058 
00059 #define GAHBCFG_GLBINT_ENABLE                  1
00060 #define GAHBCFG_INT_DMA_BURST_SINGLE           0
00061 #define GAHBCFG_INT_DMA_BURST_INCR             1
00062 #define GAHBCFG_INT_DMA_BURST_INCR4            3
00063 #define GAHBCFG_INT_DMA_BURST_INCR8            5
00064 #define GAHBCFG_INT_DMA_BURST_INCR16           7
00065 #define GAHBCFG_DMAENABLE                      1
00066 #define GAHBCFG_TXFEMPTYLVL_EMPTY              1
00067 #define GAHBCFG_TXFEMPTYLVL_HALFEMPTY          0
00068 
00069 #define GRXSTS_PKTSTS_IN                       2
00070 #define GRXSTS_PKTSTS_IN_XFER_COMP             3
00071 #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR          5
00072 #define GRXSTS_PKTSTS_CH_HALTED                7
00073 
00074 #define DEVICE_MODE                            0
00075 #define HOST_MODE                              1
00076 
00077 /*****************           DEVICE DEFINES         ***************************/
00078 
00079 #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ     0
00080 #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ     1
00081 #define DSTS_ENUMSPD_LS_PHY_6MHZ               2
00082 #define DSTS_ENUMSPD_FS_PHY_48MHZ              3
00083 
00084 #define DCFG_FRAME_INTERVAL_80                 0
00085 #define DCFG_FRAME_INTERVAL_85                 1
00086 #define DCFG_FRAME_INTERVAL_90                 2
00087 #define DCFG_FRAME_INTERVAL_95                 3
00088 
00089 #define DEP0CTL_MPS_64                         0
00090 #define DEP0CTL_MPS_32                         1
00091 #define DEP0CTL_MPS_16                         2
00092 #define DEP0CTL_MPS_8                          3
00093 
00094 #define EP_SPEED_LOW                           0
00095 #define EP_SPEED_FULL                          1
00096 #define EP_SPEED_HIGH                          2
00097 
00098 #define EP_TYPE_CTRL                           0
00099 #define EP_TYPE_ISOC                           1
00100 #define EP_TYPE_BULK                           2
00101 #define EP_TYPE_INTR                           3
00102 
00103 #define STS_GOUT_NAK                           1
00104 #define STS_DATA_UPDT                          2
00105 #define STS_XFER_COMP                          3
00106 #define STS_SETUP_COMP                         4
00107 #define STS_SETUP_UPDT                         6
00108 
00109 
00110 
00111 
00112 typedef enum {
00113 
00114   USB_OTG_OK,
00115   USB_OTG_FAIL
00116 
00117 }USB_OTG_Status;
00118 
00119 typedef struct USB_OTG_hc
00120 {
00121   uint8_t       hc_num;
00122   uint8_t       dev_addr ;
00123   uint8_t        ep_num;
00124   uint8_t       ep_is_in;
00125   uint8_t       speed;
00126   uint8_t       ep_type;
00127   uint16_t       max_packet;
00128   uint8_t       data_pid;
00129   uint16_t       multi_count;
00130   uint8_t        *xfer_buff;
00131   uint32_t       xfer_len;
00132 }
00133 USB_OTG_HC , *PUSB_OTG_HC;
00134 
00135 typedef struct USB_OTG_ep
00136 {
00137   uint8_t        num;
00138   uint8_t        is_in;
00139   uint32_t       tx_fifo_num;
00140   uint32_t       type;
00141   uint8_t        data_pid_start;
00142   uint8_t        even_odd_frame;
00143   uint32_t       maxpacket;
00144   uint8_t        *xfer_buff;
00145   uint32_t       xfer_len;
00146   uint32_t       xfer_count;
00147 }
00148 
00149 USB_OTG_EP , *PUSB_OTG_EP;
00150 
00151 /********************************************************************************
00152                                       MACRO'S
00153 ********************************************************************************/
00154 
00155 #define CLEAR_IN_EP_INTR(epnum,intr) \
00156   diepint.d32=0; \
00157   diepint.b.intr = 1; \
00158   WRITE_REG32(&core_regs.inep_regs[epnum]->dev_in_ep_int,diepint.d32);
00159 
00160 #define CLEAR_OUT_EP_INTR(epnum,intr) \
00161   doepint.d32=0; \
00162   doepint.b.intr = 1; \
00163   WRITE_REG32(&core_regs.outep_regs[epnum]->dev_out_ep_int,doepint.d32);
00164 
00165 
00166 #define READ_REG32(reg)  (*(__IO uint32_t *)reg)
00167 
00168 #define WRITE_REG32(reg,value) (*(__IO uint32_t *)reg = value)
00169 
00170 #define MODIFY_REG32(reg,clear_mask,set_mask) \
00171   WRITE_REG32(reg, (((READ_REG32(reg)) & ~clear_mask) | set_mask ) )
00172 
00173 
00174 //#define uDELAY(usec)  udelay(usec)
00175 //#define mDELAY(msec)  uDELAY(msec * 1000)
00176 
00177 #define _OTGD_FS_GATE_PHYCLK     *(__IO uint32_t*)(0x50000E00) = 0x03
00178 #define _OTGD_FS_UNGATE_PHYCLK   *(__IO uint32_t*)(0x50000E00) = 0x00
00179 
00180 /*******************************************************************************
00181                    this can be changed for real time base
00182 *******************************************************************************/
00183 /*static void udelay (const uint32_t usec)
00184 {
00185   uint32_t count = 0;
00186   const uint32_t utime = usec * 10;
00187   do
00188   {
00189     if ( ++count > utime )
00190     {
00191       return ;
00192     }
00193   }
00194   while (1);
00195 }*/
00196 /********************************************************************************
00197                      EXPORTED FUNCTIONS FROM THE OTGD_FS_CAL LAYER
00198 ********************************************************************************/
00199 USB_OTG_Status  OTGD_FS_CoreInit(void);
00200 USB_OTG_Status  OTGD_FS_SetAddress(uint32_t BaseAddress);
00201 USB_OTG_Status  OTGD_FS_EnableGlobalInt(void);
00202 USB_OTG_Status  OTGD_FS_DisableGlobalInt(void);
00203 
00204 USB_OTG_Status  USB_OTG_CoreInitHost(void);
00205 USB_OTG_Status  USB_OTG_EnableHostInt(void);
00206 USB_OTG_Status  USB_OTG_DisableHostInt(void);
00207 
00208 void*  OTGD_FS_ReadPacket(uint8_t *dest, uint16_t bytes);
00209 USB_OTG_Status OTGD_FS_WritePacket(uint8_t *src, uint8_t ch_ep_num, uint16_t bytes);
00210 
00211 USB_OTG_Status  USB_OTG_HcInit(USB_OTG_HC *hc);
00212 USB_OTG_Status  USB_OTG_StartXfer(USB_OTG_HC *hc);
00213 
00214 uint32_t USB_OTG_ResetPort( void);
00215 
00216 uint32_t USB_OTG_ReadHPRT0(void);
00217 uint32_t OTGD_FS_ReadDevAllInEPItr(void);
00218 uint32_t OTGD_FS_ReadCoreItr(void);
00219 uint32_t OTGD_FS_ReadOtgItr (void);
00220 uint32_t USB_OTG_ReadHostAllChannels_intr (void);
00221 uint8_t IsHostMode(void);
00222 uint8_t IsDeviceMode(void);
00223 USB_OTG_Status USB_OTG_HcInit(USB_OTG_HC *hc);
00224 USB_OTG_Status USB_OTG_HcHalt(uint8_t hc_num);
00225 
00226 USB_OTG_Status  OTGD_FS_FlushTxFifo (uint32_t num);
00227 USB_OTG_Status  OTGD_FS_FlushRxFifo (void);
00228 USB_OTG_Status  OTGD_FS_SetHostMode (void);
00229 
00230 USB_OTG_Status OTGD_FS_PhyInit(void);
00231 USB_OTG_Status USB_OTG_HcStartXfer(USB_OTG_HC *hc);
00232 
00233 USB_OTG_Status OTGD_FS_CoreInitDev (void);
00234 USB_OTG_Status  OTGD_FS_EnableDevInt(void);
00235 USB_OTG_Status  OTGD_FS_EP0Activate(void);
00236 USB_OTG_Status  OTGD_FS_EPActivate(USB_OTG_EP *ep);
00237 USB_OTG_Status  OTGD_FS_EPDeactivate(USB_OTG_EP *ep);
00238 
00239 USB_OTG_Status  OTGD_FS_EPStartXfer(USB_OTG_EP *ep);
00240 USB_OTG_Status OTGD_FS_EP0StartXfer(USB_OTG_EP *ep);
00241 
00242 USB_OTG_Status  OTGD_FS_EPSetStall(USB_OTG_EP *ep);
00243 USB_OTG_Status  OTGD_FS_EPClearStall(USB_OTG_EP *ep);
00244 uint32_t OTGD_FS_ReadDevAllOutEp_itr(void);
00245 uint32_t OTGD_FS_ReadDevOutEP_itr(USB_OTG_EP *ep);
00246 uint32_t OTGD_FS_ReadDevAllInEPItr(void);
00247 
00248 
00249 uint32_t OTGD_FS_Dev_GetEPStatus(USB_OTG_EP *ep);
00250 void OTGD_FS_Dev_SetEPStatus(USB_OTG_EP *ep, uint32_t Status);
00251 void OTGD_FS_Dev_SetRemoteWakeup(void);
00252 void OTGD_FS_Dev_ResetRemoteWakeup(void);
00253 
00254 
00255 #endif
00256 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
00257