lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /*******************************************************************************
|
| 2 | * °æÈ¨ËùÓÐ (C)2010, ÉîÛÚÊÐÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
|
| 3 | *
|
| 4 | * ÎļþÃû³Æ£º drv_usb3slave.c
|
| 5 | * Îļþ±êʶ£º
|
| 6 | * ÄÚÈÝÕªÒª£º
|
| 7 | * ÆäËü˵Ã÷£º zx297520 project
|
| 8 | * µ±Ç°°æ±¾£º 1.0
|
| 9 | * ×÷¡¡¡¡Õߣº tangjian
|
| 10 | * Íê³ÉÈÕÆÚ£º
|
| 11 | *
|
| 12 | *
|
| 13 | *******************************************************************************/
|
| 14 |
|
| 15 |
|
| 16 | /*
|
| 17 | **==================================================================
|
| 18 | ** Include files
|
| 19 | **==================================================================
|
| 20 | */
|
| 21 | #include <commond.h>
|
| 22 | #include "drv_usb3slave.h"
|
| 23 | #include "config.h"
|
| 24 | #include <asm/string.h>
|
| 25 |
|
| 26 | /*zloader±àÒëÑ¡ÏîΪnostdlib,ÆÁ±ÎµôÏÂÃæµÄÍ·Îļþ*/
|
| 27 | //#include <stdlib.h>
|
| 28 | //#include <string.h>
|
| 29 |
|
| 30 | /*
|
| 31 | **==================================================================
|
| 32 | ** Global Variables
|
| 33 | **==================================================================
|
| 34 | */
|
| 35 | /* Èí¼þÓÃÀ´¼Ç¼ËùÓÐdeviceÏà¹ØµÄÐÅÏ¢µÄÈ«¾Ö½á¹¹Ìå*/
|
| 36 |
|
| 37 | extern __align(4) dwc_device_descriptor_t Para_Section device_desc ;
|
| 38 | extern __align(4) dwc_config_all_t Para_Section desc ;
|
| 39 | extern __align(4) dwc_string_descriptor_t Para_Section * pStrDescIdx[] ;
|
| 40 | extern __align(4) dwc_dev_qual_descriptor_t Para_Section dev_qual_desc ;
|
| 41 | __align(EVENT_BUFFERS_SIZE*4) T_USB3Slave_EventBuf Para_Section *gp_USB3Slave_EventBuf; //EventBufÒÔEVENT_BUFFERS_SIZE*4×Ö½Ú¶ÔÆë
|
| 42 | __align(16) T_USB3Slave_TRBToHW Para_Section USB3Slave_TRB ; //TRBÒÔ16×Ö½Ú¶ÔÆë
|
| 43 | __align(16) T_USB3Slave_TRBToHW Para_Section USB3Slave_TRB_EP[4] ; //TRBÒÔ16×Ö½Ú¶ÔÆë
|
| 44 | __align(16) T_USB3Slave_CtrlReq Para_Section pCtrlReq ; /**< ¿ØÖÆÇëÇó */
|
| 45 | T_USB3Slave_SlaveObj Para_Section g_USB3Slave={0};
|
| 46 | u8 g_needSetStall = 0;
|
| 47 | u32 g_debugFaultVal = 0;
|
| 48 |
|
| 49 | __align(EVENT_BUFFERS_SIZE*4) T_USB3Slave_EventBuf Para_Section USB3Slave_EventBuf; //EventBufÒÔEVENT_BUFFERS_SIZE*4×Ö½Ú¶ÔÆë
|
| 50 |
|
| 51 | extern void usb_timeout_usdelay(u32 us);
|
| 52 | #if 0
|
| 53 | static inline void delay(unsigned long loops)
|
| 54 | {
|
| 55 | /*
|
| 56 | __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
|
| 57 | "bne 1b":"=r" (loops):"0"(loops));
|
| 58 | */
|
| 59 | }
|
| 60 |
|
| 61 | static inline void udelay(unsigned long us)
|
| 62 | {
|
| 63 | delay(us * 200); /* approximate */
|
| 64 | }
|
| 65 |
|
| 66 | void usdelay(unsigned us)
|
| 67 | {
|
| 68 | udelay(us);
|
| 69 | }
|
| 70 | #endif
|
| 71 |
|
| 72 | static T_USB3Slave_Ep *USB3Slave_GetEpObj(T_USB3Slave_SlaveObj *ptUsb3Slave, u16 uwIndex_le)
|
| 73 | {
|
| 74 | T_USB3Slave_Ep *ptDep;
|
| 75 | u32 udEpnum;
|
| 76 |
|
| 77 | udEpnum = (uwIndex_le & USB_ENDPOINT_NUMBER_MASK) << 1;
|
| 78 |
|
| 79 | if ( USB_DIR_IN == (uwIndex_le & USB_ENDPOINT_DIR_MASK))
|
| 80 | udEpnum |= 1;
|
| 81 |
|
| 82 | ptDep = &(ptUsb3Slave->tEps[udEpnum]);
|
| 83 |
|
| 84 | /*if (ptDep->udFlags & EP_ENABLED)*/
|
| 85 | return (T_USB3Slave_Ep*)ptDep;
|
| 86 |
|
| 87 | //return (T_USB3Slave_Ep*)NULL;
|
| 88 | }
|
| 89 |
|
| 90 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 91 | * @brief Ïò¶ËµãдÃüÁîµÄͨÓú¯Êý
|
| 92 | *
|
| 93 | * ¹¦ÄÜÏêÊö:
|
| 94 | * - USB3Slave_SendDevEpCmd º¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 95 | * - Ïò¶ËµãдÃüÁîµÄͨÓú¯Êý
|
| 96 | *
|
| 97 | * ²ÎÊý¸ÅÊö:
|
| 98 | * - ptUsb3Slave: usb3 É豸½á¹¹Ìå
|
| 99 | * - udEp: ¶ËµãºÅ
|
| 100 | * - udCmd: ÃüÁî,ÊÇÓÉDEPCMD¼Ä´æÆ÷µÄCmdTypÓò·¢ÆðµÄ¡£
|
| 101 | * -00h: Reserved
|
| 102 | * -01h: Set Endpoint Configuration
|
| 103 | * -02h: Set Endpoint Resource Configuration
|
| 104 | * -03h: Get Endpoint State
|
| 105 | * -04h: Set Stall
|
| 106 | * -05h: Clear Stall
|
| 107 | * -06h: Start Transfer
|
| 108 | * -07h: Update Transfer
|
| 109 | * -08h: End Transfer
|
| 110 | * -09h: Start New Configuration
|
| 111 | * - ptParams: ÃüÁî²ÎÊý
|
| 112 | *
|
| 113 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 114 | * - ´íÎóÂë
|
| 115 | *
|
| 116 | * ÆäËû˵Ã÷:
|
| 117 | * -
|
| 118 | *
|
| 119 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 120 |
|
| 121 | static u32 USB3Slave_SendDevEpCmd(T_USB3Slave_SlaveObj *ptUsb3Slave, u32 udEp,
|
| 122 | u32 udCmd, T_USB3Slave_EpCmdPara *ptParams)
|
| 123 | {
|
| 124 | volatile u32 udTimeout = 500;
|
| 125 | u32 udRegValue;
|
| 126 |
|
| 127 |
|
| 128 | REG32(ptUsb3Slave->udRegs_base + DEPCMDPAR0(udEp)) = ptParams->Parameter0;
|
| 129 | REG32(ptUsb3Slave->udRegs_base + DEPCMDPAR1(udEp)) = ptParams->Parameter1;
|
| 130 | REG32(ptUsb3Slave->udRegs_base + DEPCMDPAR2(udEp)) = ptParams->Parameter2;
|
| 131 |
|
| 132 | REG32(ptUsb3Slave->udRegs_base + DEPCMD(udEp)) = udCmd | USB3Slave_DEPCMD_CMDACT_1;
|
| 133 | // Ïòcmd¼Ä´æÆ÷µÚ10λд1ºó(command active)£¬¿ØÖÆÆ÷»á×Ô¶¯°Ñ¸ÃλÖÃ0
|
| 134 |
|
| 135 | do
|
| 136 | {
|
| 137 | udRegValue = REG32(ptUsb3Slave->udRegs_base + DEPCMD(udEp));
|
| 138 |
|
| 139 | if(!(udRegValue & USB3Slave_DEPCMD_CMDACT_1)) break;
|
| 140 |
|
| 141 | udTimeout--;
|
| 142 |
|
| 143 | if(!udTimeout)
|
| 144 | {
|
| 145 | return ERR_FAIL;
|
| 146 | }
|
| 147 | } while(1);
|
| 148 |
|
| 149 | return SOK;
|
| 150 | }
|
| 151 |
|
| 152 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 153 | * @brief TRB½á¹¹ÌåλÓòÐÎʽת»»³ÉTRBÕûÌå½á¹¹ÌåÐÎʽ£¬±ãÓÚ¶ÔTRBÕûÌå²Ù×÷¡£
|
| 154 | *
|
| 155 | * ¹¦ÄÜÏêÊö:
|
| 156 | * - USB3Slave_TrbToHWº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 157 | * - TRB½á¹¹ÌåλÓòÐÎʽת»»³ÉTRB½á¹¹ÌåÕûÌåÐÎʽ£¬±ãÓÚ¶ÔTRBÕûÌå²Ù×÷¡£
|
| 158 | *
|
| 159 | * ²ÎÊý¸ÅÊö:
|
| 160 | * - ptTrbBit: TRBλÓòÐÎʽ½á¹¹Ìå
|
| 161 | * - ptTrbRaw: TRB ÕûÌå½á¹¹ÌåÐÎʽ
|
| 162 | *
|
| 163 | * ·µ »Ø Öµ: ÎÞ
|
| 164 | *
|
| 165 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 166 | static void USB3Slave_TrbToHW(T_USB3Slave_TRB *ptTrbBit, T_USB3Slave_TRBToHW *ptTrbRaw)
|
| 167 | {
|
| 168 | ptTrbRaw->udBpl = ptTrbBit->bplh & DATA_32BIT_MASK;
|
| 169 | ptTrbRaw->udBph = 0;
|
| 170 | ptTrbRaw->udSize = ptTrbBit->len_pcm.udVal;
|
| 171 | /* HWO is written last */
|
| 172 | ptTrbRaw->udCtrl = ptTrbBit->control.udVal;
|
| 173 | }
|
| 174 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 175 | * @brief ÔÚ¿ªÊ¼ÅäÖÃ֮ǰ£¬ÒªÏȸøep0дÃüÁî9:¿ªÊ¼ÐµÄÅäÖÃstart new configuration
|
| 176 | *
|
| 177 | * ¹¦ÄÜÏêÊö:
|
| 178 | * - USB3Slave_StartCfg º¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 179 | * - ÔÚ¿ªÊ¼ÅäÖÃ֮ǰ£¬ÒªÏȸøep0дÃüÁî9£¬´ËÃüÁî²ÎÊýΪ0
|
| 180 | *
|
| 181 | * ²ÎÊý¸ÅÊö:
|
| 182 | * - ptUsb3Slave: usb 3.0É豸½á¹¹Ìå
|
| 183 | * - ptDep: ¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 184 | *
|
| 185 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 186 | * - ´íÎóÂë
|
| 187 | *
|
| 188 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 189 | static u32 USB3Slave_StartCfg(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_Ep *ptDep)
|
| 190 | {
|
| 191 | T_USB3Slave_EpCmdPara tParams = {0};
|
| 192 | u32 udCmd;
|
| 193 |
|
| 194 | /* ÏòDEPCMD дÃüÁî9 */ /*Ö´ÐÐCMD9£¬Ôڶ˵ã0ºÍ2µÄÇé¿ö£¬Ò»°ãÖ»Ôڶ˵ã0£¬¶Ëµã2ÓеãÑо¿*/
|
| 195 | if (0 == ptDep->udEpNum)
|
| 196 | {
|
| 197 | udCmd = USB3Slave_DEPCMD_DEPSTARTCFG;
|
| 198 | return USB3Slave_SendDevEpCmd(ptUsb3Slave, ptDep->udEpNum, udCmd, &tParams);
|
| 199 | }
|
| 200 | return SOK;
|
| 201 | }
|
| 202 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 203 | * @brief ¶Ô¶Ëµã½øÐÐÅäÖÃ
|
| 204 | *
|
| 205 | * ¹¦ÄÜÏêÊö:
|
| 206 | * - USB3Slave_SetEpCfgCmdº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 207 | * - ¶Ô¶Ëµã½øÐÐÅäÖÃ
|
| 208 | *
|
| 209 | * ²ÎÊý¸ÅÊö:
|
| 210 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 211 | * - ptDep: ¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 212 | *
|
| 213 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 214 | * - ´íÎóÂë
|
| 215 | *
|
| 216 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 217 | static u32 USB3Slave_SetEpCfgCmd(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_Ep *ptDep)
|
| 218 | {
|
| 219 | T_USB3Slave_EpCmdPara tParams = {0};
|
| 220 |
|
| 221 | if((0 == ptDep->udEpNum)||(1 == ptDep->udEpNum))
|
| 222 | ptDep->ucType = USB_ENDPOINT_XFER_CONTROL; //¼Ç¼¶ËµãµÄ´«ÊäÀàÐÍ
|
| 223 | else
|
| 224 | ptDep->ucType = USB_ENDPOINT_XFER_BULK;
|
| 225 |
|
| 226 |
|
| 227 | tParams.Parameter0 = DEPCFG_EP_TYPE(ptDep->ucType & USB_ENDPOINT_XFERTYPE_MASK) \
|
| 228 | | DEPCFG_MAX_PACKET_SIZE(ptDep->udMaxPacket & 0xffff)
|
| 229 | | DEPCFG_BURST_SIZE(ptDep->udMaxBurst);
|
| 230 | /*
|
| 231 | * We must use the lower 16 TX FIFOs even though
|
| 232 | * HW might have more
|
| 233 | */
|
| 234 | if (ptDep->udDirection)
|
| 235 | tParams.Parameter0 |= DEPCFG_FIFO_NUMBER(ptDep->udEpNum >> 1);
|
| 236 |
|
| 237 | if((0 == ptDep->udEpNum)||(1 == ptDep->udEpNum))
|
| 238 | tParams.Parameter1 = DEPCFG_XFER_COMPLETE_EN | DEPCFG_XFER_NOT_READY_EN;
|
| 239 | else
|
| 240 | tParams.Parameter1 = DEPCFG_XFER_COMPLETE_EN;
|
| 241 |
|
| 242 | /*
|
| 243 | * We are doing 1:1 mapping for endpoints, meaning
|
| 244 | * Physical Endpoints 2 maps to Logical Endpoint 2 and
|
| 245 | * so on. We consider the direction bit as part of the physical
|
| 246 | * endpoint number. So USB endpoint 0x81 is 0x03.
|
| 247 | */
|
| 248 | tParams.Parameter1 |= DEPCFG_EP_NUMBER(ptDep->udEpNum);
|
| 249 |
|
| 250 | return USB3Slave_SendDevEpCmd(ptUsb3Slave, ptDep->udEpNum,
|
| 251 | USB3Slave_DEPCMD_SETEPCONFIG, &tParams);
|
| 252 | }
|
| 253 |
|
| 254 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 255 | * @brief Ϊÿ¸ö¶ËµãÉèÖô«Êä×ÊÔ´¸öÊý
|
| 256 | *
|
| 257 | * ¹¦ÄÜÏêÊö:
|
| 258 | * - USB3Slave_SetXferResourceº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 259 | * - Ϊÿ¸ö¶ËµãÉèÖô«Êä×ÊÔ´¸öÊý
|
| 260 | *
|
| 261 | * ²ÎÊý¸ÅÊö:
|
| 262 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 263 | * - ptDep: ¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 264 | *
|
| 265 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 266 | * - ´íÎóÂë
|
| 267 | *
|
| 268 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 269 | static u32 USB3Slave_SetXferResource(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_Ep *ptDep)
|
| 270 | {
|
| 271 | T_USB3Slave_EpCmdPara tParams;
|
| 272 |
|
| 273 | memset(&tParams, 0x00, sizeof(tParams));
|
| 274 |
|
| 275 | tParams.Parameter0 = DEPXFERCFG_NUM_XFER_RES(1);
|
| 276 | /* ÉèÖô«Êä×ÊÔ´*/
|
| 277 | return USB3Slave_SendDevEpCmd(ptUsb3Slave, ptDep->udEpNum,
|
| 278 | USB3Slave_DEPCMD_SETTRANSFRESOURCE, &tParams);
|
| 279 | }
|
| 280 |
|
| 281 |
|
| 282 | /**
|
| 283 | * __dwc3_gadget_ep_enable - Initializes a HW endpoint
|
| 284 | * @ptDep: endpoint to be initialized
|
| 285 | * @ptDesc: USB Endpoint Descriptor
|
| 286 | *
|
| 287 | * Caller should take care of locking
|
| 288 | */
|
| 289 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 290 | * @brief ³õʼ»¯Ò»¸öÓ²¼þ¶Ëµã£¬°üÀ¨¿ªÊ¼ÅäÖá¢Èý²ÎÅäÖᢴ«Êä×ÊÔ´ÅäÖã¬Èí¼þtrbÉèÖø³Öµµ½Ó²¼þÉ豸trbÖÐ
|
| 291 | *
|
| 292 | * ¹¦ÄÜÏêÊö:
|
| 293 | * - USB3Slave_CfgEpº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 294 | * - ʹÄÜÒ»¸öÓ²¼þ¶Ëµã£¬°üÀ¨¿ªÊ¼ÅäÖá¢Èý²ÎÅäÖᢴ«Êä×ÊÔ´ÅäÖã¬Èí¼þtrbÉèÖø³Öµµ½Ó²¼þÉ豸trbÖÐ
|
| 295 | *
|
| 296 | * ²ÎÊý¸ÅÊö:
|
| 297 | * - ptDep: ³õʼ»¯¶Ëµã£¬¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 298 | * - ptDesc: USB ¶ËµãÃèÊö·û
|
| 299 | * - ptComp_desc: ¶Ëµãcompanion ÃèÊö·û
|
| 300 | *
|
| 301 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 302 | * - ´íÎóÂë
|
| 303 | *
|
| 304 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 305 | static u32 USB3Slave_CfgEp(T_USB3Slave_Ep *ptDep)
|
| 306 | {
|
| 307 | T_USB3Slave_SlaveObj *pUSB3Slv = &g_USB3Slave;
|
| 308 |
|
| 309 | if (!(ptDep->udFlags & EP_ENABLED))
|
| 310 | {
|
| 311 | //step0:ep0¶ËµãÅäÖÿªÊ¼£¬Ö´ÐÐcmd=9£¬start new conguration
|
| 312 | USB3Slave_StartCfg(pUSB3Slv, ptDep);
|
| 313 | }
|
| 314 |
|
| 315 | //step1:Ö´ÐÐcmd1£¬SET EP CONFIG
|
| 316 | USB3Slave_SetEpCfgCmd(pUSB3Slv, ptDep);
|
| 317 |
|
| 318 | //step2:Ö´ÐÐcmd2£¬Set Endpoint Transfer Resource Configuration £¬param0 = 1
|
| 319 |
|
| 320 | if (!(ptDep->udFlags & EP_ENABLED))
|
| 321 | {
|
| 322 | USB3Slave_SetXferResource(pUSB3Slv, ptDep);
|
| 323 |
|
| 324 | ptDep->udFlags |= EP_ENABLED;
|
| 325 | if(global.need_enum ==1)
|
| 326 | {
|
| 327 |
|
| 328 | //step3:active ep ,0xc720 £¬Ò»¸ö¶Ëµã¶ÔÓÚÒ»¸öbit
|
| 329 | REG32(pUSB3Slv->udRegs_base + DWC3_DALEPENA)|= (1u<<ptDep->udEpNum);
|
| 330 | }
|
| 331 |
|
| 332 | }
|
| 333 |
|
| 334 | return SOK;
|
| 335 | }
|
| 336 |
|
| 337 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 338 | * @brief ep0·¢ËÍÊý¾Ý
|
| 339 | *
|
| 340 | * ¹¦ÄÜÏêÊö:
|
| 341 | * - USB3Slave_Ep0StartXferº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 342 | * - ep0·¢ËÍÊý¾Ý
|
| 343 | *
|
| 344 | * ²ÎÊý¸ÅÊö:
|
| 345 | * - ptUsb3Slave: É豸ÀàÐÅÏ¢µÄ½á¹¹Ìå
|
| 346 | * - ucEpnum: ¶ËµãºÅ
|
| 347 | * - udBufAddr: ÊäÈëµØÖ·
|
| 348 | * - udLen: ³¤¶È
|
| 349 | * - udType: TRB¿ØÖÆÀàÐÍ
|
| 350 | *
|
| 351 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 352 | * - ÀàÐÍÂë
|
| 353 | *
|
| 354 | * ÆäËû˵Ã÷:
|
| 355 | * -
|
| 356 | *
|
| 357 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 358 | static u32 USB3Slave_Ep0StartXfer(T_USB3Slave_SlaveObj *ptUsb3Slave, u8 ucEpnum, u32 udBufAddr,
|
| 359 | u32 udLen, u32 udType)
|
| 360 | {
|
| 361 | T_USB3Slave_EpCmdPara tParams;
|
| 362 | T_USB3Slave_TRBToHW *ptTrbRaw;
|
| 363 | T_USB3Slave_TRB tTrbBit;
|
| 364 | T_USB3Slave_Ep *ptDep;
|
| 365 |
|
| 366 | ptDep = &(ptUsb3Slave->tEps[ucEpnum]);
|
| 367 |
|
| 368 | ptUsb3Slave->ptEp0TRB = ptDep->ptTRB;
|
| 369 | ptTrbRaw = ptUsb3Slave->ptEp0TRB;
|
| 370 |
|
| 371 | memset(&tTrbBit, 0, sizeof(tTrbBit));
|
| 372 |
|
| 373 | tTrbBit.control.bit.TRBCTL = udType;
|
| 374 | tTrbBit.bplh =udBufAddr ;
|
| 375 | tTrbBit.len_pcm.bit.BUFSIZ = udLen;
|
| 376 |
|
| 377 | tTrbBit.control.bit.HWO = 1;
|
| 378 | tTrbBit.control.bit.LST = 1;
|
| 379 | /*tTrbBit.control.bit.IOC = 1;
|
| 380 | tTrbBit.control.bit.ISP_IMI = 1;*/
|
| 381 |
|
| 382 | USB3Slave_TrbToHW(&tTrbBit, ptTrbRaw);
|
| 383 |
|
| 384 | memset(&tParams, 0, sizeof(tParams));
|
| 385 | tParams.Parameter0 = 0; /*tTrbBit¸ß32λµØÖ·£¬Ä¬ÈÏΪ0*/
|
| 386 | tParams.Parameter1 = (u32)((u32)(ptUsb3Slave->ptEp0TRB)& (u32)0xFFFFFFFF);/* ys */
|
| 387 |
|
| 388 | USB3Slave_SendDevEpCmd(ptUsb3Slave, ptDep->udEpNum,
|
| 389 | USB3Slave_DEPCMD_STARTTRANSFER, &tParams);
|
| 390 | ptDep->udFlags |= EP_BUSY;
|
| 391 |
|
| 392 | //»ñµÃ´«Êä×ÊÔ´Ë÷Òý
|
| 393 | ptDep->ucResTransIdx = (REG32(ptUsb3Slave->udRegs_base + ((u32)DEPCMD(ptDep->udEpNum)>>16)));
|
| 394 |
|
| 395 | ptUsb3Slave->eEp0NextEvent = EP0_COMPLETE;
|
| 396 |
|
| 397 | return SOK;
|
| 398 | }
|
| 399 |
|
| 400 |
|
| 401 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 402 | * @brief ch 9.4.5,״̬½×¶Î·µ»ØµÄÊý¾Ý
|
| 403 | *
|
| 404 | * ¹¦ÄÜÏêÊö:
|
| 405 | * - USB3Slave_Ep0HandleStatusº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 406 | * - ch 9.4.5,״̬½×¶Î·µ»ØµÄÊý¾Ý
|
| 407 | *
|
| 408 | * ²ÎÊý¸ÅÊö:
|
| 409 | * - ptUsb3Slave: É豸ÀàÐÅÏ¢µÄ½á¹¹Ìå
|
| 410 | * - ptCtrlReq: ±ê×¼ÇëÇóÃüÁî²ÎÊý
|
| 411 | *
|
| 412 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 413 | * - ´íÎóÂë
|
| 414 | *
|
| 415 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 416 | static u32 USB3Slave_Ep0HandleStatus(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_CtrlReq *ptCtrlReq)
|
| 417 | {
|
| 418 | T_USB3Slave_Ep *ptDep;
|
| 419 | u32 udRetVal,udRecip;
|
| 420 | u16 uwUsb_status = 0;
|
| 421 | u16 *puwResponse_pkt;
|
| 422 | u32 udDirection;
|
| 423 |
|
| 424 | udRecip = ptCtrlReq->bmRequestType & USB_RECIP_MASK;
|
| 425 | switch (udRecip)
|
| 426 | {
|
| 427 | case USB_RECIP_DEVICE:
|
| 428 | {
|
| 429 | /*
|
| 430 | * We are self-powered. U1/U2/LTM will be set later
|
| 431 | * once we handle this states. RemoteWakeup is 0 on SS
|
| 432 | */
|
| 433 | uwUsb_status |= ptUsb3Slave->udIsSelfPowered << USB_DEVICE_SELF_POWERED;
|
| 434 | break;
|
| 435 | }
|
| 436 | case USB_RECIP_INTERFACE:
|
| 437 | {
|
| 438 | /*
|
| 439 | * Function Remote Wake Capable D0
|
| 440 | * Function Remote Wakeup D1
|
| 441 | */
|
| 442 | break;
|
| 443 | }
|
| 444 | case USB_RECIP_ENDPOINT:
|
| 445 | {
|
| 446 | ptDep = USB3Slave_GetEpObj(ptUsb3Slave, ptCtrlReq->wIndex);
|
| 447 | if (!ptDep)
|
| 448 | return ERR_INVPARAMS;
|
| 449 | if (ptDep->udFlags & EP_STALL)
|
| 450 | uwUsb_status = 1 << USB_ENDPOINT_HALT;
|
| 451 | break;
|
| 452 | }
|
| 453 | default:
|
| 454 | {
|
| 455 | return ERR_INVPARAMS;
|
| 456 | }
|
| 457 | };
|
| 458 |
|
| 459 | puwResponse_pkt = (u16 *) ptUsb3Slave->aucSetupBuf;
|
| 460 | *puwResponse_pkt = uwUsb_status;
|
| 461 |
|
| 462 | ptDep = &(ptUsb3Slave->tEps[0]);
|
| 463 |
|
| 464 | udDirection = ptDep->udFlags & EP0_DIR_IN;
|
| 465 |
|
| 466 | if (ptUsb3Slave->eEp0State != EP0_DATA_PHASE) //ÕâÀïµÈ´ýµÄ״̬¿ÉÄÜÓÐÎÊÌ⣬ÓдýÑо¿£¬pxp
|
| 467 | {
|
| 468 | return 0;
|
| 469 | }
|
| 470 |
|
| 471 | udRetVal = USB3Slave_Ep0StartXfer(ptUsb3Slave, udDirection,
|
| 472 | (u32)ptUsb3Slave->aucSetupBuf, sizeof(*puwResponse_pkt),
|
| 473 | TRBCTL_CONTROL_DATA);
|
| 474 | ptDep->udFlags &= ~(EP_PENDING_REQUEST | EP0_DIR_IN);
|
| 475 | return udRetVal;
|
| 476 | }
|
| 477 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 478 | * @brief ÉèÖÃhaltÌØÐÔ
|
| 479 | *
|
| 480 | * ¹¦ÄÜÏêÊö:
|
| 481 | * - USB3Slave_EpSetHaltº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 482 | * - ÉèÖÃhaltÌØÐÔ
|
| 483 | *
|
| 484 | * ²ÎÊý¸ÅÊö:
|
| 485 | * - ptDep: ¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 486 | * - udValue: 0ʱÇå³ýstallÌØÐÔ£¬1ʱÉèÖÃstallÌØÐÔ
|
| 487 | *
|
| 488 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 489 | * - ´íÎóÂë
|
| 490 | *
|
| 491 | * ÆäËû˵Ã÷:
|
| 492 | * -
|
| 493 | *
|
| 494 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 495 | static u32 USB3Slave_EpSetHalt(T_USB3Slave_Ep *ptDep, u32 udValue)
|
| 496 | {
|
| 497 | T_USB3Slave_EpCmdPara tParams;
|
| 498 | T_USB3Slave_SlaveObj *pUSB3Slv = &g_USB3Slave;
|
| 499 | u32 udRetVal;
|
| 500 |
|
| 501 | memset(&tParams, 0x00, sizeof(tParams));
|
| 502 |
|
| 503 | if (udValue)
|
| 504 | {
|
| 505 | if (0 == ptDep->udEpNum || 1 == ptDep->udEpNum)
|
| 506 | {
|
| 507 | /*
|
| 508 | * Whenever EP0 is stalled, we will restart
|
| 509 | * the state machine, thus moving back to
|
| 510 | * Setup Phase
|
| 511 | */
|
| 512 | pUSB3Slv->eEp0State = EP0_SETUP_PHASE;
|
| 513 | }
|
| 514 | printf("USB3Slave_EpSetHalt");
|
| 515 | // udRetVal = USB3Slave_SendDevEpCmd(pUSB3Slv, ptDep->udEpNum,
|
| 516 | // USB3Slave_DEPCMD_CLEARSTALL, &tParams);
|
| 517 | if(((global.need_enum ==0) || (1 == g_USB3Slave.udUSBSate))&&g_needSetStall!=1)
|
| 518 | {
|
| 519 | udRetVal = USB3Slave_SendDevEpCmd(pUSB3Slv, ptDep->udEpNum,
|
| 520 | USB3Slave_DEPCMD_CLEARSTALL, &tParams);
|
| 521 | }
|
| 522 | else
|
| 523 | {
|
| 524 | g_needSetStall = 0;
|
| 525 | pUSB3Slv->eEp0NextEvent = EP0_COMPLETE;
|
| 526 | udRetVal = USB3Slave_SendDevEpCmd(pUSB3Slv, ptDep->udEpNum,
|
| 527 | USB3Slave_DEPCMD_SETSTALL, &tParams);
|
| 528 |
|
| 529 | USB3Slave_Ep0StartXfer(pUSB3Slv, 0, (u32)(pUSB3Slv->tCtrlReq), 8,
|
| 530 | TRBCTL_CONTROL_SETUP);
|
| 531 | }
|
| 532 |
|
| 533 | }
|
| 534 |
|
| 535 | return udRetVal;
|
| 536 | }
|
| 537 |
|
| 538 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 539 | * @brief ÉèÖÃep0ÌØÐÔ
|
| 540 | *
|
| 541 | * ¹¦ÄÜÏêÊö:
|
| 542 | * - USB3Slave_Ep0HandleFeatureº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 543 | * - ÉèÖÃep0ÌØÐÔ
|
| 544 | *
|
| 545 | * ²ÎÊý¸ÅÊö:
|
| 546 | * - ptUsb3Slave: É豸ÐÅÏ¢µÄ½á¹¹Ìå
|
| 547 | * - ptCtrlReq: ±ê×¼ÇëÇóÃüÁî²ÎÊý
|
| 548 | * - udSet: 1ʱÉèÖÃÌØÐÔ£¬0ʱÇå³ýÌØÐÔ
|
| 549 | *
|
| 550 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 551 | * - ´íÎóÂë
|
| 552 | *
|
| 553 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 554 | static u32 USB3Slave_Ep0HandleFeature(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_CtrlReq *ptCtrlReq, u32 udSet)
|
| 555 | {
|
| 556 | T_USB3Slave_Ep *ptDep;
|
| 557 | u32 udRecip;
|
| 558 | u32 udIndex;
|
| 559 | u32 udRet;
|
| 560 |
|
| 561 | udIndex = ptCtrlReq->wIndex;
|
| 562 | udRecip = ptCtrlReq->bmRequestType & USB_RECIP_MASK;
|
| 563 | switch (udRecip)
|
| 564 | {
|
| 565 | case USB_RECIP_ENDPOINT:
|
| 566 | {
|
| 567 |
|
| 568 | ptDep = USB3Slave_GetEpObj(ptUsb3Slave, udIndex);
|
| 569 | if (!ptDep)
|
| 570 | return ERR_INVPARAMS;
|
| 571 | udRet = USB3Slave_EpSetHalt(ptDep, udSet);
|
| 572 | if (udRet)
|
| 573 | return ERR_INVPARAMS;
|
| 574 | break;
|
| 575 | }
|
| 576 | default:
|
| 577 | return ERR_INVPARAMS;
|
| 578 | };
|
| 579 |
|
| 580 | return SOK;
|
| 581 | }
|
| 582 |
|
| 583 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 584 | * @brief ÉèÖÃep0µØÖ·
|
| 585 | *
|
| 586 | * ¹¦ÄÜÏêÊö:
|
| 587 | * - USB3Slave_Ep0SetAddrº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 588 | * - ÉèÖÃep0µØÖ·
|
| 589 | *
|
| 590 | * ²ÎÊý¸ÅÊö:
|
| 591 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 592 | * - ptCtrlReq: ±ê×¼ÇëÇóÃüÁî²ÎÊý
|
| 593 | *
|
| 594 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 595 | * - ´íÎóÂë
|
| 596 | *
|
| 597 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 598 | static u32 USB3Slave_Ep0SetAddr(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_CtrlReq *ptCtrlReq)
|
| 599 | {
|
| 600 | u32 udAddr;
|
| 601 | u32 udRegVal;
|
| 602 |
|
| 603 | udAddr = ptCtrlReq->wValue;
|
| 604 |
|
| 605 | udRegVal = REG32(ptUsb3Slave->udRegs_base + DWC3_DCFG);
|
| 606 | udRegVal &= ~(DWC3_DCFG_DEVADDR_MASK);
|
| 607 | udRegVal |= DWC3_DCFG_DEVADDR(udAddr);
|
| 608 | REG32(ptUsb3Slave->udRegs_base + DWC3_DCFG) = udRegVal;
|
| 609 |
|
| 610 | if (udAddr)
|
| 611 | ptUsb3Slave->eDevState = ADDRESS_STATE;
|
| 612 | else
|
| 613 | ptUsb3Slave->eDevState = DEFAULT_STATE;
|
| 614 |
|
| 615 | return SOK;
|
| 616 | }
|
| 617 |
|
| 618 |
|
| 619 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 620 | * @brief »ñÈ¡É豸ÃèÊö·û£¬ÉèÖÃÃèÊö·ûÁôÓнӿڣ¬µ«Ôݲ»ÊµÏÖ
|
| 621 | *
|
| 622 | * ¹¦ÄÜÏêÊö:
|
| 623 | * - USB3Slave_Ep0HandleDescº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 624 | * - »ñÈ¡É豸ÃèÊö·û£¬ÉèÖÃÃèÊö·ûÁôÓнӿڣ¬µ«Ôݲ»ÊµÏÖ
|
| 625 | *
|
| 626 | * ²ÎÊý¸ÅÊö:
|
| 627 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 628 | * - ptCtrlReq: ±ê×¼ÇëÇóÃüÁî²ÎÊý
|
| 629 | * - udIsSet:
|
| 630 | *
|
| 631 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 632 | * - ´íÎóÂë
|
| 633 | *
|
| 634 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 635 | static u32 USB3Slave_Ep0HandleDesc(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_CtrlReq *ptCtrlReq, u32 udIsSet)
|
| 636 | {
|
| 637 |
|
| 638 | u32 udLen = 0;
|
| 639 | u32 udDirection = 0;
|
| 640 | u16 uwValue = ptCtrlReq->wValue;
|
| 641 | u8 ucIdx =(u8)(ptCtrlReq->wValue &0xff);
|
| 642 | u32 udRetVal = 0;
|
| 643 | T_USB3Slave_Ep * ptDep = &ptUsb3Slave->tEps[1];
|
| 644 | u16 temp = uwValue >> 8;
|
| 645 |
|
| 646 | if( USB_DT_DEVICE == temp )
|
| 647 | {
|
| 648 | udDirection = 1;
|
| 649 | udLen = MIN(sizeof(dwc_device_descriptor_t), ptCtrlReq->wLength);
|
| 650 | udRetVal = USB3Slave_Ep0StartXfer(ptUsb3Slave, udDirection,
|
| 651 | (u32)&device_desc, udLen,
|
| 652 | TRBCTL_CONTROL_DATA);
|
| 653 | ptUsb3Slave->eEp0State = EP0_DATA_PHASE;
|
| 654 |
|
| 655 | }
|
| 656 | else if( USB_DT_CONFIG == temp)
|
| 657 | {
|
| 658 | udDirection = 1;
|
| 659 | udLen = MIN(sizeof(dwc_config_all_t), ptCtrlReq->wLength);
|
| 660 | udRetVal = USB3Slave_Ep0StartXfer(ptUsb3Slave, udDirection,
|
| 661 | (u32)&desc, udLen,
|
| 662 | TRBCTL_CONTROL_DATA);
|
| 663 | ptUsb3Slave->eEp0State=EP0_DATA_PHASE;
|
| 664 |
|
| 665 | }
|
| 666 | else if( USB_DT_STRING == temp)
|
| 667 | {
|
| 668 | udDirection = 1;
|
| 669 | if(ucIdx > 5)
|
| 670 | {
|
| 671 | USB3Slave_EpSetHalt(ptDep,1);
|
| 672 | }
|
| 673 | else
|
| 674 | {
|
| 675 | udLen = MIN(((dwc_string_descriptor_t*)(pStrDescIdx[ucIdx]))->bLength, ptCtrlReq->wLength);
|
| 676 | udRetVal = USB3Slave_Ep0StartXfer(ptUsb3Slave, udDirection,
|
| 677 | (u32)pStrDescIdx[ucIdx], udLen,
|
| 678 | TRBCTL_CONTROL_DATA);
|
| 679 | ptUsb3Slave->eEp0State=EP0_DATA_PHASE;
|
| 680 | }
|
| 681 |
|
| 682 | }
|
| 683 |
|
| 684 | else if( USB_DT_DEVICE_QUALIFIER == temp)
|
| 685 | {
|
| 686 | udDirection = 1;
|
| 687 | udLen =MIN(sizeof(dwc_dev_qual_descriptor_t), ptCtrlReq->wLength);
|
| 688 | udRetVal = USB3Slave_Ep0StartXfer(ptUsb3Slave, udDirection,
|
| 689 | (u32)&dev_qual_desc, udLen,
|
| 690 | TRBCTL_CONTROL_DATA);
|
| 691 | ptUsb3Slave->eEp0State = EP0_DATA_PHASE;
|
| 692 |
|
| 693 | }
|
| 694 | else
|
| 695 |
|
| 696 | {
|
| 697 | USB3Slave_EpSetHalt(ptDep,1);
|
| 698 |
|
| 699 | }
|
| 700 |
|
| 701 | return udRetVal;
|
| 702 |
|
| 703 | }
|
| 704 |
|
| 705 | /*¸Ãº¯Êý¾ßÌåʵÏÖÓдýÌÖÂÛ£¬pxp */
|
| 706 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 707 | * @brief ÉèÖÃep0ÅäÖÃ
|
| 708 | *
|
| 709 | * ¹¦ÄÜÏêÊö:
|
| 710 | * - USB3Slave_Ep0HandleCfgº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 711 | * - ÉèÖÃep0ÅäÖÃ
|
| 712 | *
|
| 713 | * ²ÎÊý¸ÅÊö:
|
| 714 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 715 | * - ptCtrlReq: ±ê×¼ÇëÇóÃüÁî²ÎÊý
|
| 716 | * - udIsSet:
|
| 717 | *
|
| 718 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 719 | * - ´íÎóÂë
|
| 720 | *
|
| 721 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 722 | static u32 USB3Slave_Ep0HandleCfg(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_CtrlReq *ptCtrlReq, u32 udIsSet)
|
| 723 | {
|
| 724 | u32 udCfg;
|
| 725 | udCfg = ptCtrlReq->wValue;
|
| 726 |
|
| 727 | if (udIsSet && udCfg)
|
| 728 | {
|
| 729 | ptUsb3Slave->eDevState = CONFIGURED_STATE;
|
| 730 | REG32(ptUsb3Slave->udRegs_base + DWC3_DALEPENA) = 0x3f;
|
| 731 |
|
| 732 | #if SIM_EN == EMULATION
|
| 733 | REG32(ARM_PORTA)=0x30;
|
| 734 | #endif
|
| 735 |
|
| 736 | return SOK;
|
| 737 | }
|
| 738 | return SOK;
|
| 739 | }
|
| 740 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 741 | * @brief ep0±ê×¼ÇëÇóÀàÐÍ
|
| 742 | *
|
| 743 | * ¹¦ÄÜÏêÊö:
|
| 744 | * - USB3Slave_Ep0Requestº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 745 | * - ep0±ê×¼ÇëÇóÀàÐÍ
|
| 746 | *
|
| 747 | * ²ÎÊý¸ÅÊö:
|
| 748 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 749 | * - ptCtrlReq: ±ê×¼ÇëÇóÃüÁî²ÎÊý
|
| 750 | * -bmRequestType: ¾ö¶¨Êý¾Ý´«Êä·½ÏòºÍ½ÓÊÕÕßÀàÐÍ¡£
|
| 751 | * -bRequest : ¾ßÌåÇëÇóÀàÐÍ¡£
|
| 752 | * -wValue : ×Ö³¤Óò,¸ù¾Ý²»Í¬µÄÇëÇóº¬Òå¸Ä±ä
|
| 753 | * -wIndex : ×Ö³¤Óò,¸ù¾Ý²»Í¬µÄÇëÇóº¬Òå¸Ä±ä.µäÐÍÓÃÓÚ´«ËÍË÷Òý»òÆ«ÒÆ.
|
| 754 | * -wLength : ÈçÓÐÊý¾Ý´«Ëͽ׶Î,´ËΪÊý¾Ý×Ö½ÚÊý.
|
| 755 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 756 | * - ´íÎóÂë
|
| 757 | *
|
| 758 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 759 | static u32 USB3Slave_Ep0Request(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_CtrlReq *ptCtrlReq)
|
| 760 | {
|
| 761 | u32 udRet = 0;
|
| 762 | T_USB3Slave_Ep *ptDep0 = 0;
|
| 763 | u8 temp = 0;
|
| 764 | //tj Ôö¼ÓÅжÏbmRequestTypeÊÇ·ñΪ±ê×¼ÃüÁÈç¹û²»ÊÇ£¬Ö±½Ó»Østall
|
| 765 | if(UT_GET_TYPE(ptCtrlReq->bmRequestType)!=UT_STANDARD)
|
| 766 | {
|
| 767 | ptDep0 = USB3Slave_GetEpObj(ptUsb3Slave,ptCtrlReq->wIndex);
|
| 768 | USB3Slave_EpSetHalt(ptDep0, 1);
|
| 769 | printf"command err.\n");
|
| 770 | return 1;
|
| 771 | }
|
| 772 | temp = ptCtrlReq->bRequest;
|
| 773 | if( USB_REQ_GET_STATUS == temp)
|
| 774 |
|
| 775 | {
|
| 776 | printf("USB_REQ_GET_STATUS\n");
|
| 777 | udRet = USB3Slave_Ep0HandleStatus(ptUsb3Slave, ptCtrlReq);
|
| 778 |
|
| 779 | }
|
| 780 | else if(USB_REQ_CLEAR_FEATURE == temp)
|
| 781 | {
|
| 782 | printf("USB_REQ_CLEAR_FEATURE\n");
|
| 783 | // udRet = USB3Slave_Ep0HandleFeature(ptUsb3Slave, ptCtrlReq, 0);
|
| 784 | udRet = USB3Slave_Ep0HandleFeature(ptUsb3Slave, ptCtrlReq, 1);
|
| 785 |
|
| 786 | }
|
| 787 | else if( USB_REQ_SET_ADDRESS == temp)
|
| 788 | {
|
| 789 |
|
| 790 | printf("USB_REQ_SET_ADDRESS\n");
|
| 791 | udRet = USB3Slave_Ep0SetAddr(ptUsb3Slave, ptCtrlReq);
|
| 792 |
|
| 793 | }
|
| 794 | else if( USB_REQ_GET_DESCRIPTOR == temp)
|
| 795 | {
|
| 796 | printf("USB_REQ_GET_DESCRIPTOR\n");
|
| 797 | udRet = USB3Slave_Ep0HandleDesc(ptUsb3Slave, ptCtrlReq,0);
|
| 798 |
|
| 799 | }
|
| 800 | else if( USB_REQ_SET_CONFIGURATION == temp)
|
| 801 | {
|
| 802 |
|
| 803 | printf("USB_REQ_SET_CONFIGURATION\n");
|
| 804 | udRet = USB3Slave_Ep0HandleCfg(ptUsb3Slave, ptCtrlReq,1);
|
| 805 |
|
| 806 | }
|
| 807 | else
|
| 808 | {
|
| 809 |
|
| 810 | printf("USB3Slave_EpSetHalt\n");
|
| 811 | USB3Slave_EpSetHalt(ptDep0, 1);
|
| 812 | }
|
| 813 |
|
| 814 |
|
| 815 | return udRet;
|
| 816 | }
|
| 817 |
|
| 818 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 819 | * @brief ep0 setup ½×¶Î
|
| 820 | *
|
| 821 | * ¹¦ÄÜÏêÊö:
|
| 822 | * - USB3Slave_Ep0InspectSetupº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 823 | * - ep0 setup ½×¶Î
|
| 824 | *
|
| 825 | * ²ÎÊý¸ÅÊö:
|
| 826 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 827 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 828 | *
|
| 829 | * ·µ »Ø Öµ: ÎÞ
|
| 830 | *
|
| 831 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 832 | static void USB3Slave_Ep0InspectSetup(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 833 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 834 | {
|
| 835 | u32 udRetVal = 0;
|
| 836 | u16 uwLen = 0;
|
| 837 | T_USB3Slave_CtrlReq *ptCtrlReq = (ptUsb3Slave->tCtrlReq);
|
| 838 |
|
| 839 | uwLen = ptCtrlReq->wLength;
|
| 840 | /*Èç¹ûÊý¾Ý³¤¶ÈΪ0£¬±íʾûÓÐÊý¾Ý½×¶Î,Á½¸ö½×¶Î£¬Èç¹ûÓÐÊý¾Ý½×¶Î£¬Èý¸ö½×¶Î*/
|
| 841 | if (!uwLen)
|
| 842 | {
|
| 843 | ptUsb3Slave->udThreeStageSetup = FALSE;
|
| 844 | ptUsb3Slave->udEp0ExpectIn = FALSE;
|
| 845 | ptUsb3Slave->eEp0NextEvent = EP0_NRDY_STATUS;
|
| 846 | }
|
| 847 | else
|
| 848 | {
|
| 849 | ptUsb3Slave->udThreeStageSetup = TRUE;
|
| 850 | ptUsb3Slave->udEp0ExpectIn = !!(ptCtrlReq->bmRequestType & USB_DIR_IN);
|
| 851 | ptUsb3Slave->eEp0NextEvent = EP0_NRDY_DATA;
|
| 852 | }
|
| 853 | printf("USB3Slave_Ep0Request\n");
|
| 854 | udRetVal = USB3Slave_Ep0Request(ptUsb3Slave,ptCtrlReq);
|
| 855 |
|
| 856 | if (udRetVal == USB_GADGET_DELAYED_STATUS)
|
| 857 | ptUsb3Slave->udDelayedStatus = TRUE;
|
| 858 | }
|
| 859 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 860 | * @brief ep0 data½×¶Î
|
| 861 | *
|
| 862 | * ¹¦ÄÜÏêÊö:
|
| 863 | * - USB3Slave_Ep0CmpltDataº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 864 | * - ep0 data½×¶Î
|
| 865 | *
|
| 866 | * ²ÎÊý¸ÅÊö:
|
| 867 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 868 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 869 | *
|
| 870 | * ·µ »Ø Öµ: ÎÞ
|
| 871 | *
|
| 872 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 873 | static void USB3Slave_Ep0CmpltData(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 874 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 875 | {
|
| 876 | /*bootÀïÃæÃ»ÓеȺò¶ÓÁУ¬ÕâÀïÔݲ»×öÈκδ¦Àí*/
|
| 877 | }
|
| 878 |
|
| 879 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 880 | * @brief ep0 status ½×¶Î£¬½áÊø±¾´Î¿ØÖÆ´«Ê䣬״̬»Ø¹é
|
| 881 | *
|
| 882 | * ¹¦ÄÜÏêÊö:
|
| 883 | * - USB3Slave_Ep0CmpltRequestº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 884 | * - ep0 status ½×¶Î£¬½áÊø±¾´Î¿ØÖÆ´«Ê䣬״̬»Ø¹é
|
| 885 | *
|
| 886 | * ²ÎÊý¸ÅÊö:
|
| 887 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 888 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 889 | *
|
| 890 | * ·µ »Ø Öµ: ÎÞ
|
| 891 | *
|
| 892 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 893 | static void USB3Slave_Ep0CmpltRequest(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 894 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 895 | {
|
| 896 | if(ptUsb3Slave->eDevState == CONFIGURED_STATE)
|
| 897 | {
|
| 898 | ptUsb3Slave->udUSBSate = 1;
|
| 899 | #if SIM_EN == EMULATION
|
| 900 | REG32(ARM_PORTA)=0x31;
|
| 901 | #endif
|
| 902 |
|
| 903 | }
|
| 904 | ptUsb3Slave->eEp0State = EP0_SETUP_PHASE;
|
| 905 | USB3Slave_Ep0StartXfer(ptUsb3Slave, 0, (u32)(ptUsb3Slave->tCtrlReq), 8,
|
| 906 | TRBCTL_CONTROL_SETUP);
|
| 907 |
|
| 908 | }
|
| 909 |
|
| 910 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 911 | * @brief ´¦Àíxfercompleteʼþ
|
| 912 | *
|
| 913 | * ¹¦ÄÜÏêÊö:
|
| 914 | * - USB3Slave_Ep0XferCmpltº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 915 | * - ´¦Àíxfercompleteʼþ
|
| 916 | *
|
| 917 | * ²ÎÊý¸ÅÊö:
|
| 918 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 919 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 920 | *
|
| 921 | * ·µ »Ø Öµ: ÎÞ
|
| 922 | *
|
| 923 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 924 | /*´¦Àíxfercompleteʼþ*/
|
| 925 | static void USB3Slave_Ep0XferCmplt(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 926 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 927 | {
|
| 928 | T_USB3Slave_Ep *ptDep = &(ptUsb3Slave->tEps[ptEpEvt->udEndpoint_number]);
|
| 929 |
|
| 930 | ptDep->udFlags &= ~EP_BUSY;
|
| 931 | ptUsb3Slave->udSetupPacketPending = 0;
|
| 932 | switch (ptUsb3Slave->eEp0State)
|
| 933 | {
|
| 934 | case EP0_SETUP_PHASE:
|
| 935 | {
|
| 936 | USB3Slave_Ep0InspectSetup(ptUsb3Slave, ptEpEvt);
|
| 937 | break;
|
| 938 | }
|
| 939 | case EP0_DATA_PHASE:
|
| 940 | {
|
| 941 | USB3Slave_Ep0CmpltData(ptUsb3Slave, ptEpEvt);
|
| 942 | break;
|
| 943 | }
|
| 944 | case EP0_STATUS_PHASE:
|
| 945 | {
|
| 946 | USB3Slave_Ep0CmpltRequest(ptUsb3Slave, ptEpEvt);
|
| 947 | break;
|
| 948 | }
|
| 949 | default:
|
| 950 | {
|
| 951 | break;
|
| 952 | }
|
| 953 | }
|
| 954 | }
|
| 955 |
|
| 956 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 957 | * @brief ¿ªÊ¼´«Ê䣬¿ØÖƽ¨Á¢½×¶Î
|
| 958 | *
|
| 959 | * ¹¦ÄÜÏêÊö:
|
| 960 | * - USB3Slave_Ep0OutStartº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 961 | * - ¿ªÊ¼´«Ê䣬¿ØÖƽ¨Á¢½×¶ÎµÄͨÓýӿÚ
|
| 962 | *
|
| 963 | * ²ÎÊý¸ÅÊö:
|
| 964 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 965 | *
|
| 966 | * ·µ »Ø Öµ: ÎÞ
|
| 967 | *
|
| 968 | * ÆäËû˵Ã÷:
|
| 969 | * -
|
| 970 | *
|
| 971 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 972 | static void USB3Slave_Ep0OutStart(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 973 | {
|
| 974 | USB3Slave_Ep0StartXfer(ptUsb3Slave, 0, (u32)(ptUsb3Slave->tCtrlReq), 8,
|
| 975 | TRBCTL_CONTROL_SETUP);
|
| 976 |
|
| 977 | }
|
| 978 |
|
| 979 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 980 | * @brief ¿ØÖƽ¨Á¢½×¶ÎͨÓýӿÚ
|
| 981 | *
|
| 982 | * ¹¦ÄÜÏêÊö:
|
| 983 | * - USB3Slave_Ep0DoCtrlSetupº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 984 | * - ¿ØÖƽ¨Á¢½×¶ÎͨÓýӿÚ
|
| 985 | *
|
| 986 | * ²ÎÊý¸ÅÊö:
|
| 987 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 988 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 989 | *
|
| 990 | * ·µ »Ø Öµ: ÎÞ
|
| 991 | *
|
| 992 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 993 | static void USB3Slave_Ep0DoCtrlSetup(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 994 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 995 | {
|
| 996 | USB3Slave_Ep0OutStart(ptUsb3Slave);
|
| 997 | }
|
| 998 |
|
| 999 |
|
| 1000 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1001 | * @brief ¿ØÖÆ×´Ì¬½×¶Î£¬¿ªÊ¼´«Ê䣬ÕÙ»½¶Ëµã½á¹¹Ìå½øÐд¦Àí
|
| 1002 | *
|
| 1003 | * ¹¦ÄÜÏêÊö:
|
| 1004 | * - USB3Slave_Ep0DoCtrlStatusº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1005 | * - ¿ØÖÆ×´Ì¬½×¶Î£¬¿ªÊ¼´«Ê䣬ÕÙ»½¶Ëµã½á¹¹Ìå½øÐд¦Àí
|
| 1006 | *
|
| 1007 | * ²ÎÊý¸ÅÊö:
|
| 1008 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1009 | * - udEpnum: ¶ËµãºÅ
|
| 1010 | *
|
| 1011 | * ·µ »Ø Öµ: ÎÞ
|
| 1012 | *
|
| 1013 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1014 | static void USB3Slave_Ep0DoCtrlStatus(T_USB3Slave_SlaveObj *ptUsb3Slave, u32 udEpnum)
|
| 1015 | {
|
| 1016 | u32 udType;
|
| 1017 | T_USB3Slave_Ep *ptDep = &(ptUsb3Slave->tEps[udEpnum]);
|
| 1018 | /* È·¶¨¿ØÖÆ´«ÊäµÄ״̬ÀàÐÍ */
|
| 1019 | udType = ptUsb3Slave->udThreeStageSetup ? TRBCTL_CONTROL_STATUS3
|
| 1020 | : TRBCTL_CONTROL_STATUS2;
|
| 1021 | /* ·¢Æð¿ªÊ¼´«ÊäÃüÁµÈ´ýÖжϲúÉú */
|
| 1022 | USB3Slave_Ep0StartXfer(ptUsb3Slave, ptDep->udEpNum,
|
| 1023 | (u32)(ptUsb3Slave->tCtrlReq), 0, udType);
|
| 1024 | }
|
| 1025 |
|
| 1026 |
|
| 1027 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1028 | * @brief ¿ØÖÆÊý¾Ý½×¶Î
|
| 1029 | *
|
| 1030 | * ¹¦ÄÜÏêÊö:
|
| 1031 | * - USB3Slave_Ep0DoCtrlDataº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1032 | * - ¿ØÖÆÊý¾Ý½×¶Î
|
| 1033 | *
|
| 1034 | * ²ÎÊý¸ÅÊö:
|
| 1035 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1036 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 1037 | *
|
| 1038 | * ·µ »Ø Öµ: ÎÞ
|
| 1039 | *
|
| 1040 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1041 | static void USB3Slave_Ep0DoCtrlData(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 1042 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 1043 | {
|
| 1044 | if (ptEpEvt->udEndpoint_number)
|
| 1045 | ptUsb3Slave->tEps[ptEpEvt->udEndpoint_number].udFlags |= EP0_DIR_IN;
|
| 1046 |
|
| 1047 | /* linuxÇý¶¯ÀﻹÊÇÈ¥ÅжÏÇëÇó¶ÓÁÐÊÇ·ñΪ¿Õ½øÐд¦Àí£¬ÂãÇýûÓÐÇëÇó¶ÓÁУ¬ÏÈ·Å×Å */
|
| 1048 |
|
| 1049 | }
|
| 1050 |
|
| 1051 |
|
| 1052 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1053 | * @brief ´¦Àíxfernotreadyʼþ
|
| 1054 | *
|
| 1055 | * ¹¦ÄÜÏêÊö:
|
| 1056 | * - USB3Slave_Ep0XferNotReadyº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1057 | * - ´¦Àíxfernotreadyʼþ
|
| 1058 | *
|
| 1059 | * ²ÎÊý¸ÅÊö:
|
| 1060 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1061 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 1062 | *
|
| 1063 | * ·µ »Ø Öµ: ÎÞ
|
| 1064 | *
|
| 1065 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1066 | static void USB3Slave_Ep0XferNotReady(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 1067 | const T_USB3Slave_EpEvt *ptEpEvt)
|
| 1068 | {
|
| 1069 | u8 usb3Event = 0;
|
| 1070 | T_USB3Slave_Ep * ptDep = &ptUsb3Slave->tEps[0];
|
| 1071 | ptUsb3Slave->udSetupPacketPending = 1;
|
| 1072 | /*
|
| 1073 | * This part is very tricky: If we has just handled
|
| 1074 | * XferNotReady(Setup) and we're now expecting a
|
| 1075 | * XferComplete but, instead, we receive another
|
| 1076 | * XferNotReady(Setup), we should STALL and restart
|
| 1077 | * the state machine.
|
| 1078 | *
|
| 1079 | * In all other cases, we just continue waiting
|
| 1080 | * for the XferComplete event.
|
| 1081 | *
|
| 1082 | * We are a little bit unsafe here because we're
|
| 1083 | * not trying to ensure that last event was, indeed,
|
| 1084 | * XferNotReady(Setup).
|
| 1085 | *
|
| 1086 | * Still, we don't expect any condition where that
|
| 1087 | * should happen and, even if it does, it would be
|
| 1088 | * another error condition.
|
| 1089 | */
|
| 1090 | /*
|
| 1091 | if ((1 == ptUsb3Slave->udEventsequence) && (EP0_COMPLETE == ptUsb3Slave->eEp0NextEvent))
|
| 1092 | {
|
| 1093 | switch (ptEpEvt->EventStatus)
|
| 1094 | {
|
| 1095 | case DEPEVT_STATUS_CONTROL_SETUP:
|
| 1096 | {
|
| 1097 | IC_DBG(IC_DEBUG_INFO, "Unexpected XferNotReady(Setup)\n");
|
| 1098 | break;
|
| 1099 | }
|
| 1100 | case DEPEVT_STATUS_CONTROL_DATA:
|
| 1101 | {
|
| 1102 | IC_DBG(IC_DEBUG_INFO, "DEPEVT_STATUS_CONTROL_DATA: XferNotReady\n");
|
| 1103 | break;
|
| 1104 | }
|
| 1105 | case DEPEVT_STATUS_CONTROL_STATUS:
|
| 1106 | break;
|
| 1107 | default:
|
| 1108 | IC_DBG(IC_DEBUG_INFO, "Uwaiting for XferComplete\n");
|
| 1109 | }
|
| 1110 | return;
|
| 1111 | }
|
| 1112 | */
|
| 1113 | usb3Event = (u8)(ptEpEvt->EventStatus);
|
| 1114 | if (DEPEVT_STATUS_CONTROL_SETUP == usb3Event)
|
| 1115 | {
|
| 1116 | printf("USB3Slave event DEPEVT_STATUS_CONTROL_SETUP\n");
|
| 1117 | ptUsb3Slave->eEp0State = EP0_SETUP_PHASE;
|
| 1118 | USB3Slave_Ep0DoCtrlSetup(ptUsb3Slave, ptEpEvt);
|
| 1119 | }
|
| 1120 | else if (DEPEVT_STATUS_CONTROL_DATA == usb3Event)
|
| 1121 | {
|
| 1122 | printf("USB3Slave event DEPEVT_STATUS_CONTROL_DATA\n");
|
| 1123 | if ( ptUsb3Slave->eEp0NextEvent == EP0_COMPLETE)
|
| 1124 | {
|
| 1125 | return;
|
| 1126 | }
|
| 1127 | ptUsb3Slave->eEp0State = EP0_DATA_PHASE;
|
| 1128 | USB3Slave_Ep0DoCtrlData(ptUsb3Slave, ptEpEvt);
|
| 1129 | }
|
| 1130 | else if (DEPEVT_STATUS_CONTROL_STATUS == usb3Event)
|
| 1131 | {
|
| 1132 | printf("USB3Slave event DEPEVT_STATUS_CONTROL_STATUS\n");
|
| 1133 | ptUsb3Slave->eEp0State = EP0_STATUS_PHASE;
|
| 1134 | USB3Slave_Ep0DoCtrlStatus(ptUsb3Slave, ptEpEvt->udEndpoint_number);
|
| 1135 | }
|
| 1136 | else if (DEPEVT_STATUS_STATUS_SETUP == usb3Event)
|
| 1137 | {
|
| 1138 | printf("USB3Slave event DEPEVT_STATUS_STATUS_SETUP\n");
|
| 1139 | g_needSetStall = 1;
|
| 1140 | USB3Slave_EpSetHalt(ptDep,1);
|
| 1141 | }
|
| 1142 | else
|
| 1143 | {
|
| 1144 | g_debugFaultVal = ptEpEvt->EventStatus;
|
| 1145 | printf("USB3Slave event default\n");
|
| 1146 | }
|
| 1147 | }
|
| 1148 |
|
| 1149 |
|
| 1150 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1151 | * @brief ´¦Àíep0¿ØÖÆÖжÏ
|
| 1152 | *
|
| 1153 | * ¹¦ÄÜÏêÊö:
|
| 1154 | * - USB3Slave_Ep0ISRº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1155 | * - ´¦Àí¿ØÖÆÖжÏ
|
| 1156 | *
|
| 1157 | * ²ÎÊý¸ÅÊö:
|
| 1158 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1159 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 1160 | *
|
| 1161 | * ·µ »Ø Öµ: ÎÞ
|
| 1162 | *
|
| 1163 | * ÆäËû˵Ã÷:
|
| 1164 | * -
|
| 1165 | *
|
| 1166 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1167 | static void USB3Slave_Ep0ISR(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_EpEvt *ptEpEvt)
|
| 1168 | {
|
| 1169 | switch (ptEpEvt->udEndpoint_event)
|
| 1170 | {
|
| 1171 | case DEPEVT_XFERCOMPLETE:
|
| 1172 | {
|
| 1173 | USB3Slave_Ep0XferCmplt(ptUsb3Slave, ptEpEvt);
|
| 1174 | break;
|
| 1175 | }
|
| 1176 | case DEPEVT_XFERNOTREADY:
|
| 1177 | {
|
| 1178 | USB3Slave_Ep0XferNotReady(ptUsb3Slave, ptEpEvt);
|
| 1179 | break;
|
| 1180 | }
|
| 1181 | default:
|
| 1182 | break;
|
| 1183 | }
|
| 1184 | }
|
| 1185 |
|
| 1186 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1187 | * @brief ָʾ´«ÊäÍê³É
|
| 1188 | *
|
| 1189 | * ¹¦ÄÜÏêÊö:
|
| 1190 | * - USB3Slave_EpXferCmpltº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1191 | * - ָʾ´«ÊäÍê³É
|
| 1192 | *
|
| 1193 | * ²ÎÊý¸ÅÊö:
|
| 1194 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1195 | * - ptDep: ¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 1196 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 1197 | * - udStart_new:
|
| 1198 | *
|
| 1199 | * ·µ »Ø Öµ: ÎÞ
|
| 1200 | *
|
| 1201 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1202 | static void USB3Slave_EpXferCmplt(T_USB3Slave_SlaveObj *ptUsb3Slave,
|
| 1203 | T_USB3Slave_Ep *ptDep, const T_USB3Slave_EpEvt *ptEpEvt,u32 udStart_new)
|
| 1204 | {
|
| 1205 |
|
| 1206 | u32 udXfercount;
|
| 1207 | T_USB3Slave_TRB *tTrbBit;
|
| 1208 |
|
| 1209 | tTrbBit = (T_USB3Slave_TRB *)ptDep->ptTRB ;
|
| 1210 | udXfercount = ptDep->udLen - tTrbBit->len_pcm.bit.BUFSIZ;
|
| 1211 |
|
| 1212 | if((0x0 == ptDep->udDirection) && (0x2 == ptDep->ucType))
|
| 1213 | ptUsb3Slave->eDevState = BULKOUT_CMPL;
|
| 1214 | if((0x1 == ptDep->udDirection) && (0x2 == ptDep->ucType))
|
| 1215 | ptUsb3Slave->eDevState = BULKIN_CMPL;
|
| 1216 |
|
| 1217 | ptDep->udFlags &= ~EP_BUSY;
|
| 1218 | ptDep->ucResTransIdx = 0;
|
| 1219 |
|
| 1220 |
|
| 1221 | if(ptDep->fnUsbCb)
|
| 1222 | ptDep->fnUsbCb((u32)(ptDep->pPara), 0, udXfercount, ptDep->udLen);
|
| 1223 | }
|
| 1224 |
|
| 1225 | static void USB3Slave_Init_TRB(T_USB3Slave_Ep *ptDep)
|
| 1226 | {
|
| 1227 | T_USB3Slave_TRBToHW *ptTrbRaw;
|
| 1228 | T_USB3Slave_TRB tTrbBit;
|
| 1229 |
|
| 1230 | ptTrbRaw = ptDep->ptTRB;
|
| 1231 |
|
| 1232 | memset(&tTrbBit, 0, sizeof(tTrbBit));
|
| 1233 |
|
| 1234 | tTrbBit.control.bit.CHN = 0;
|
| 1235 | tTrbBit.control.bit.LST = 1;
|
| 1236 | tTrbBit.control.bit.TRBCTL = TRBCTL_NORMAL;
|
| 1237 | tTrbBit.control.bit.HWO = 1;
|
| 1238 |
|
| 1239 | tTrbBit.len_pcm.bit.BUFSIZ = ptDep->udLen;
|
| 1240 |
|
| 1241 | tTrbBit.bplh=(u64)(ptDep->pudAddrData);
|
| 1242 |
|
| 1243 |
|
| 1244 | USB3Slave_TrbToHW(&tTrbBit, ptTrbRaw);
|
| 1245 | }
|
| 1246 |
|
| 1247 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1248 | * @brief ÆÕͨ¶Ëµã½øÐÐÊý¾Ý´«Êä
|
| 1249 | *
|
| 1250 | * ¹¦ÄÜÏêÊö:
|
| 1251 | * - USB3Slave_EpStartXferº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1252 | * - ÆÕͨ¶Ëµã½øÐÐÊý¾Ý´«Êä
|
| 1253 | *
|
| 1254 | * ²ÎÊý¸ÅÊö:
|
| 1255 | * - ptDep: ¶ËµãÐÅÏ¢½á¹¹Ìå
|
| 1256 | * - uwCmd_param: ÃüÁî²ÎÊý
|
| 1257 | * - udStart_new:
|
| 1258 | *
|
| 1259 | * ·µ »Ø Öµ: ÀàÐÍ:INT
|
| 1260 | * - ´íÎóÂë
|
| 1261 | *
|
| 1262 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1263 | /*ÆÕͨ¶Ëµã½øÐÐÊý¾Ý´«Êä*/
|
| 1264 | static u32 USB3Slave_EpStartXfer(T_USB3Slave_Ep *ptDep, u16 uwCmd_param,
|
| 1265 | u32 udStart_new)
|
| 1266 | {
|
| 1267 | T_USB3Slave_EpCmdPara tParams;
|
| 1268 | T_USB3Slave_SlaveObj *pUSB3Slv = &g_USB3Slave;
|
| 1269 | u32 udCmd;
|
| 1270 |
|
| 1271 | USB3Slave_Init_TRB(ptDep); //ÅäÖÃTRB
|
| 1272 | memset(&tParams, 0, sizeof(tParams));
|
| 1273 |
|
| 1274 | tParams.Parameter0 = 0; /*trb¸ß32λµØÖ·£¬Ä¬ÈÏΪ0*/
|
| 1275 | tParams.Parameter1 = (u32)((u32)(ptDep->ptTRB)& (u32)0xFFFFFFFF);/* ys */
|
| 1276 |
|
| 1277 | if (udStart_new)
|
| 1278 | udCmd = USB3Slave_DEPCMD_STARTTRANSFER;
|
| 1279 | else
|
| 1280 | udCmd = USB3Slave_DEPCMD_UPDATETRANSFER;
|
| 1281 |
|
| 1282 | udCmd |= USB2Slave_DEPCMD_PARAM(uwCmd_param); //0
|
| 1283 |
|
| 1284 | USB3Slave_SendDevEpCmd(pUSB3Slv, ptDep->udEpNum, udCmd, &tParams);
|
| 1285 |
|
| 1286 | return SOK;
|
| 1287 | }
|
| 1288 |
|
| 1289 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1290 | * @brief ¶ËµãÀàÐ͵ÄeventÖжϴ¦Àí³ÌÐò
|
| 1291 | *
|
| 1292 | * ¹¦ÄÜÏêÊö:
|
| 1293 | * - USB3Slave_EpISRº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1294 | * - ¶ËµãÀàÐ͵ÄeventÖжϴ¦Àí³ÌÐò
|
| 1295 | *
|
| 1296 | * ²ÎÊý¸ÅÊö:
|
| 1297 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1298 | * - ptEpEvt: ¶ËµãÀàÐÍʼþ
|
| 1299 | *
|
| 1300 | * ·µ »Ø Öµ: ÎÞ
|
| 1301 | *
|
| 1302 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1303 | static void USB3Slave_EpISR(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_EpEvt *ptEpEvt)
|
| 1304 | {
|
| 1305 | T_USB3Slave_Ep *ptDep;
|
| 1306 |
|
| 1307 | u8 ucEpnum = ptEpEvt->udEndpoint_number;
|
| 1308 |
|
| 1309 | ptDep = &(ptUsb3Slave->tEps[ucEpnum]);
|
| 1310 |
|
| 1311 | if (0 == ucEpnum || 1 == ucEpnum)
|
| 1312 | {
|
| 1313 | USB3Slave_Ep0ISR(ptUsb3Slave, ptEpEvt);
|
| 1314 | return;
|
| 1315 | }
|
| 1316 |
|
| 1317 | switch (ptEpEvt->udEndpoint_event)
|
| 1318 | {
|
| 1319 | case DEPEVT_XFERCOMPLETE:
|
| 1320 | {
|
| 1321 | USB3Slave_EpXferCmplt(ptUsb3Slave, ptDep, ptEpEvt, 1);
|
| 1322 | break;
|
| 1323 | }
|
| 1324 | default:
|
| 1325 | break;
|
| 1326 | }
|
| 1327 |
|
| 1328 | }
|
| 1329 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1330 | * @brief É豸¸´Î»Öжϴ¦Àí
|
| 1331 | *
|
| 1332 | * ¹¦ÄÜÏêÊö:
|
| 1333 | * - USB3Slave_ResetISRº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1334 | * - É豸¸´Î»Öжϴ¦Àí
|
| 1335 | *
|
| 1336 | * ²ÎÊý¸ÅÊö:
|
| 1337 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1338 | *
|
| 1339 | * ·µ »Ø Öµ: ÎÞ
|
| 1340 | *
|
| 1341 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1342 | static void USB3Slave_ResetISR(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1343 | {
|
| 1344 | u32 udRegVal;
|
| 1345 |
|
| 1346 | printf("R");
|
| 1347 | //tangjian:±êÖ¾usbÁ¬½Ó
|
| 1348 | global.g_Connet = 1;
|
| 1349 |
|
| 1350 | /* Reset device address to zero */
|
| 1351 | udRegVal = REG32(ptUsb3Slave->udRegs_base + DWC3_DCFG);
|
| 1352 | udRegVal &= ~(0x7f<<3);
|
| 1353 | REG32(ptUsb3Slave->udRegs_base + DWC3_DCFG) = udRegVal;
|
| 1354 |
|
| 1355 | }
|
| 1356 |
|
| 1357 |
|
| 1358 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1359 | * @brief »ñÈ¡usb 3.0×ÜÏßʱÖÓ
|
| 1360 | *
|
| 1361 | * ¹¦ÄÜÏêÊö:
|
| 1362 | * - USB3Slave_UpdateRamClkSelº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1363 | * - »ñÈ¡usb 3.0×ÜÏßʱÖÓ
|
| 1364 | *
|
| 1365 | * ²ÎÊý¸ÅÊö:
|
| 1366 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1367 | * - ucSpeed: ָʾÁ¬½ÓËÙ¶È
|
| 1368 | *
|
| 1369 | * ·µ »Ø Öµ: ÎÞ
|
| 1370 | *
|
| 1371 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1372 | static void USB3Slave_UpdateRamClkSel(T_USB3Slave_SlaveObj *ptUsb3Slave, u32 ucSpeed)
|
| 1373 | {
|
| 1374 | u32 udRegVal;
|
| 1375 | /*
|
| 1376 | * RAMClkSel is reset to 0 after USB reset, so it must be reprogrammed
|
| 1377 | * each time on Connect Done.
|
| 1378 | */
|
| 1379 |
|
| 1380 | /* ÅäÖÃGCTL¼Ä´æÆ÷,sel bus = 0*/
|
| 1381 | udRegVal = REG32(ptUsb3Slave->udRegs_base + DWC3_GCTL);
|
| 1382 | udRegVal &= ~(0x3<<6);
|
| 1383 | REG32(ptUsb3Slave->udRegs_base + DWC3_GCTL) = udRegVal;
|
| 1384 | }
|
| 1385 |
|
| 1386 |
|
| 1387 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1388 | * @brief É豸Á¬½ÓÖжϴ¦Àí
|
| 1389 | *
|
| 1390 | * ¹¦ÄÜÏêÊö:
|
| 1391 | * - USB3Slave_ConnectdoneISR º¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1392 | * - É豸Á¬½ÓÖжϴ¦Àí
|
| 1393 | *
|
| 1394 | * ²ÎÊý¸ÅÊö:
|
| 1395 | * - ptUsb3Slave: É豸ÀàÐÅÏ¢½á¹¹Ìå
|
| 1396 | *
|
| 1397 | * ·µ »Ø Öµ: ÎÞ
|
| 1398 | *
|
| 1399 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1400 | static void USB3Slave_ConnectdoneISR(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1401 | {
|
| 1402 | T_USB3Slave_Ep *ptDep;
|
| 1403 | u32 udRegVal;
|
| 1404 | u8 ucSpeed;
|
| 1405 |
|
| 1406 | printf("D");
|
| 1407 |
|
| 1408 |
|
| 1409 | udRegVal = REG32(ptUsb3Slave->udRegs_base + DWC3_DSTS);
|
| 1410 | ucSpeed = udRegVal&0x7;
|
| 1411 |
|
| 1412 | ptUsb3Slave->ucSpeed = ucSpeed;
|
| 1413 | USB3Slave_UpdateRamClkSel(ptUsb3Slave, ucSpeed);
|
| 1414 | if(USB3_HIGHSPEED == ucSpeed)
|
| 1415 | {
|
| 1416 |
|
| 1417 | printf("2");
|
| 1418 | ptUsb3Slave->tEps[2].udMaxPacket = 512;
|
| 1419 | ptUsb3Slave->tEps[3].udMaxPacket = 512;
|
| 1420 | ptUsb3Slave->tEps[4].udMaxPacket = 512;
|
| 1421 | ptUsb3Slave->tEps[5].udMaxPacket = 512;
|
| 1422 | ptUsb3Slave->eDeviceSpeedType = USB30_SPEED_HIGH;
|
| 1423 | desc.atTxEP[0].wMaxPacketSize = USB_HIGHSPEED_BULK_MAXSIZE;
|
| 1424 | desc.atRxEP[0].wMaxPacketSize = USB_HIGHSPEED_BULK_MAXSIZE;
|
| 1425 | desc.atTxEP1[0].wMaxPacketSize = USB_HIGHSPEED_BULK_MAXSIZE;
|
| 1426 | desc.atRxEP1[0].wMaxPacketSize = USB_HIGHSPEED_BULK_MAXSIZE;
|
| 1427 | }
|
| 1428 | else if(USB3_FULLSPEED == ucSpeed)
|
| 1429 | {
|
| 1430 |
|
| 1431 | printf("1");
|
| 1432 | ptUsb3Slave->tEps[2].udMaxPacket = 64;
|
| 1433 | ptUsb3Slave->tEps[3].udMaxPacket = 64;
|
| 1434 | ptUsb3Slave->tEps[4].udMaxPacket = 64;
|
| 1435 | ptUsb3Slave->tEps[5].udMaxPacket = 64;
|
| 1436 | ptUsb3Slave->eDeviceSpeedType = USB30_SPEED_FULL;
|
| 1437 | desc.atTxEP[0].wMaxPacketSize = USB_FULLSPEED_BULK_MAXSIZE;
|
| 1438 | desc.atRxEP[0].wMaxPacketSize = USB_FULLSPEED_BULK_MAXSIZE;
|
| 1439 | desc.atTxEP1[0].wMaxPacketSize = USB_FULLSPEED_BULK_MAXSIZE;
|
| 1440 | desc.atRxEP1[0].wMaxPacketSize = USB_FULLSPEED_BULK_MAXSIZE;
|
| 1441 | }
|
| 1442 | //tangjian:ÉèÖÃep0µÄ¶ËµãÐÅÏ¢
|
| 1443 |
|
| 1444 | ptDep = &(ptUsb3Slave->tEps[0]);
|
| 1445 | USB3Slave_SetEpCfgCmd(ptUsb3Slave, ptDep);
|
| 1446 | ptDep = &(ptUsb3Slave->tEps[1]);
|
| 1447 | USB3Slave_SetEpCfgCmd(ptUsb3Slave, ptDep);
|
| 1448 |
|
| 1449 | #if SIM_EN == EMULATION
|
| 1450 |
|
| 1451 | REG32(REG_GPIO_OUT)=5;
|
| 1452 | // while(REG32(REG_GPIO_IN)!=0xFF);
|
| 1453 | usdelay(1);
|
| 1454 | REG32(REG_GPIO_OUT)=0;
|
| 1455 |
|
| 1456 | REG32(REG_GPIO_OUT)=6;
|
| 1457 | // while(REG32(REG_GPIO_IN)!=0xFF);
|
| 1458 | usdelay(1);
|
| 1459 | REG32(REG_GPIO_OUT)=0;
|
| 1460 |
|
| 1461 | REG32(REG_GPIO_OUT)=7;
|
| 1462 | // while(REG32(REG_GPIO_IN)!=0xFF);
|
| 1463 | usdelay(1);
|
| 1464 | REG32(REG_GPIO_OUT)=0;
|
| 1465 |
|
| 1466 | REG32(REG_GPIO_OUT)=8;
|
| 1467 | // while(REG32(REG_GPIO_IN)!=0xFF);
|
| 1468 | usdelay(1);
|
| 1469 | REG32(REG_GPIO_OUT)=0;
|
| 1470 |
|
| 1471 | #endif
|
| 1472 |
|
| 1473 |
|
| 1474 | }
|
| 1475 |
|
| 1476 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1477 | * @brief É豸Öжϴ¦Àí(¶Ï¿ª¡¢¸´Î»¡¢Á¬½Ó¡¢»½ÐÑ¡¢Á¬½Ó״̬¸Ä±ä¡¢EOPF¡¢ÃüÁîÍê³É¡¢Òç³ö¡¢´íÎó)
|
| 1478 | *
|
| 1479 | * ¹¦ÄÜÏêÊö:
|
| 1480 | * - USB3Slave_DevISRº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1481 | * - É豸Öжϴ¦Àí(¶Ï¿ª¡¢¸´Î»¡¢Á¬½Ó¡¢»½ÐÑ¡¢Á¬½Ó״̬¸Ä±ä¡¢EOPF¡¢ÃüÁîÍê³É¡¢Òç³ö¡¢´íÎó)
|
| 1482 | *
|
| 1483 | * ²ÎÊý¸ÅÊö:
|
| 1484 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1485 | * - ptDevEvt: É豸ÀàÐÍʼþ
|
| 1486 | *
|
| 1487 | * ·µ »Ø Öµ: ÎÞ
|
| 1488 | *
|
| 1489 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1490 |
|
| 1491 | static void USB3Slave_DevISR(T_USB3Slave_SlaveObj *ptUsb3Slave, const T_USB3Slave_DevEvt *ptDevEvt)
|
| 1492 | {
|
| 1493 | switch (ptDevEvt->udType)
|
| 1494 | {
|
| 1495 | case DEVICE_EVENT_RESET:
|
| 1496 | {
|
| 1497 | USB3Slave_ResetISR(ptUsb3Slave);
|
| 1498 | break;
|
| 1499 | }
|
| 1500 | case DEVICE_EVENT_CONNECT_DONE:
|
| 1501 | {
|
| 1502 | USB3Slave_ConnectdoneISR(ptUsb3Slave);
|
| 1503 | break;
|
| 1504 | }
|
| 1505 | case DEVICE_EVENT_EOPF:
|
| 1506 | {
|
| 1507 | printf("S");
|
| 1508 | break;
|
| 1509 | }
|
| 1510 | default:
|
| 1511 | break;
|
| 1512 | }
|
| 1513 | }
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1518 | * @brief ´¦Àí²»Í¬µÄÖжϺ¯ÊýÈë¿Ú
|
| 1519 | *
|
| 1520 | * ¹¦ÄÜÏêÊö:
|
| 1521 | * - USB3Slave_ProcessEvtEntryº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1522 | * - ´¦Àí²»Í¬µÄÖжϺ¯ÊýÈë¿Ú
|
| 1523 | *
|
| 1524 | * ²ÎÊý¸ÅÊö:
|
| 1525 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1526 | * - ptEvt: ±íʾevent buffer ÄÚÈÝ
|
| 1527 | *
|
| 1528 | * ·µ »Ø Öµ: ÎÞ
|
| 1529 | *
|
| 1530 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1531 | static void USB3Slave_ProcessEvtEntry(T_USB3Slave_SlaveObj *ptUsb3Slave, T_USB3Slave_Event *ptEvt)
|
| 1532 | {
|
| 1533 | /* Endpoint IRQ, handle it and return early */
|
| 1534 | /*0bit 0ÊÇÉ豸¶ËµãÖÐ¶Ï 1ÊÇÉ豸ÖжÏ*/
|
| 1535 | if (0 == ptEvt->tType.udIs_devspec)
|
| 1536 | USB3Slave_EpISR(ptUsb3Slave, &ptEvt->tEpEvt); /* tDepevt */
|
| 1537 | else
|
| 1538 | USB3Slave_DevISR(ptUsb3Slave, &ptEvt->tDevEvt);
|
| 1539 | }
|
| 1540 |
|
| 1541 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1542 | * @brief ´¦Àíevent buffer ÖеÄevent,·Ö·¢²»Í¬event bufferÖмǼµÄÖжϣ¬ÔÙµ÷ÓÃÕæÕýµÄÖжÏÈë¿Ú³ÌÐò
|
| 1543 | *
|
| 1544 | * ¹¦ÄÜÏêÊö:
|
| 1545 | * - USB3Slave_ProcessEvtBufº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1546 | * - ´¦Àíevent buffer ÖеÄevent,·Ö·¢²»Í¬event bufferÖмǼµÄÖжϣ¬ÔÙµ÷ÓÃÕæÕýµÄÖжÏÈë¿Ú³ÌÐò
|
| 1547 | *
|
| 1548 | * ²ÎÊý¸ÅÊö:
|
| 1549 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1550 | * - udBufNum: ±íʾevent bufferÖÐij¸öevent
|
| 1551 | *
|
| 1552 | * ·µ »Ø Öµ: ÎÞ
|
| 1553 | *
|
| 1554 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1555 | static void USB3Slave_ProcessEvtBuf(T_USB3Slave_SlaveObj *ptUsb3Slave, u32 udBufNum)
|
| 1556 | {
|
| 1557 | T_USB3Slave_EventBuf *ptevt;
|
| 1558 | T_USB3Slave_Event ptEvt;
|
| 1559 | u32 udLeft;
|
| 1560 | u32 udCount;
|
| 1561 |
|
| 1562 | //step0:ÔÚÖжϴ¦Àíº¯ÊýÖлñÈ¡event count£¬À´ÅжÏÓм¸¸öʼþ£¬²¢×÷ÏàÓ¦µÄ´¦Àí
|
| 1563 | udCount = REG32((ptUsb3Slave->udRegs_base + GEVNTCOUNT(udBufNum)));
|
| 1564 | if(!udCount)
|
| 1565 | return;
|
| 1566 | ptevt = ptUsb3Slave->ptEvtBuffs;
|
| 1567 | udLeft = udCount;
|
| 1568 | ptUsb3Slave->udEventsequence = 1;/* ys */
|
| 1569 | //step1:´¦ÀíÏàÓ¦µÄʼþ
|
| 1570 | while (udLeft > 0)
|
| 1571 | {
|
| 1572 | ptEvt.udRaw = ptevt->EvtBuf[ptevt->udLpos];
|
| 1573 |
|
| 1574 | USB3Slave_ProcessEvtEntry(ptUsb3Slave, &ptEvt);
|
| 1575 | /*
|
| 1576 | * XXX we wrap around correctly to the next entry as almost all
|
| 1577 | * entries are 4 bytes in size. There is one entry which has 12
|
| 1578 | * bytes which is a regular entry followed by 8 bytes data. ATM
|
| 1579 | * I don't know how things are organized if were get next to the
|
| 1580 | * a boundary so I worry about that once we try to handle that.
|
| 1581 | */
|
| 1582 | ptevt->udLpos = (ptevt->udLpos + 1) % EVENT_BUFFERS_SIZE;
|
| 1583 | udLeft -= 4;
|
| 1584 | ptUsb3Slave->udEventsequence++;
|
| 1585 | }
|
| 1586 |
|
| 1587 | /*When read, returns the number of valid events in the Event Buffer (in bytes).
|
| 1588 | When written, hardware decrements the count by the value written.
|
| 1589 | The interrupt line remains high when count is not 0.*/
|
| 1590 | REG32(ptUsb3Slave->udRegs_base + GEVNTCOUNT(udBufNum)) = udCount;
|
| 1591 | }
|
| 1592 |
|
| 1593 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1594 | * @brief ÖжÏÈë¿Úº¯Êý
|
| 1595 | *
|
| 1596 | * ¹¦ÄÜÏêÊö:
|
| 1597 | * - USB3Slave_ISRº¯ÊýÊôÓÚ½Ó¿Úº¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1598 | * - ÖжÏÈë¿Úº¯Êý
|
| 1599 | *
|
| 1600 | * ²ÎÊý¸ÅÊö:
|
| 1601 | * - udIntNo: ÖжϺÅ
|
| 1602 | * - udPara: ÖжϲÎÊý
|
| 1603 | *
|
| 1604 | * ·µ »Ø Öµ: ÎÞ
|
| 1605 | *
|
| 1606 | * ÆäËû˵Ã÷:
|
| 1607 | * -
|
| 1608 | *
|
| 1609 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1610 | void USB3Slave_ISR(u32 udIntNo,u32 udPara)
|
| 1611 | {
|
| 1612 | T_USB3Slave_SlaveObj *pUSB3Slv = &g_USB3Slave;
|
| 1613 | u32 udIndex ;
|
| 1614 |
|
| 1615 | for (udIndex = 0; udIndex < pUSB3Slv->udNumEvtBufs; udIndex++)
|
| 1616 | {
|
| 1617 | USB3Slave_ProcessEvtBuf(pUSB3Slv,udIndex);
|
| 1618 | }
|
| 1619 |
|
| 1620 | }
|
| 1621 |
|
| 1622 | /*³õʼ»¯ÓÃÓڼǼÉ豸ËùÓÐÐÅÏ¢µÄÈ«¾Ö½á¹¹Ìå*/
|
| 1623 | /*Ò»´ÎÐÔд²»ÍêÕû£¬ ÔÚ´úÂë²¹³äµÄ¹ý³ÌÖÐÂýÂýÌí¼Ó*/
|
| 1624 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1625 | * @brief ³õʼ»¯È«¾Ö½á¹¹ÌåptUsb3Slave
|
| 1626 | *
|
| 1627 | * ¹¦ÄÜÏêÊö:
|
| 1628 | * - USB3Slave_Initº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1629 | * - ³õʼ»¯½á¹¹ÌåÄÚÈ«¾Ö±äÁ¿
|
| 1630 | *
|
| 1631 | * ²ÎÊý¸ÅÊö:
|
| 1632 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1633 | *
|
| 1634 | * ·µ »Ø Öµ: ÎÞ
|
| 1635 | *
|
| 1636 | * ÆäËû˵Ã÷:
|
| 1637 | * -
|
| 1638 | *
|
| 1639 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1640 | static void USB3Slave_Init(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1641 | {
|
| 1642 | T_USB3Slave_HWPARAMS *parms = &ptUsb3Slave->tHwParams;
|
| 1643 |
|
| 1644 | gp_USB3Slave_EventBuf = &USB3Slave_EventBuf;
|
| 1645 | ptUsb3Slave->udRegs_base = SYS_USB_BASE;
|
| 1646 | ptUsb3Slave->eSpeedMode = USB3_HIGHSPEED;
|
| 1647 |
|
| 1648 | parms->udHwparams0 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS0);
|
| 1649 | parms->udHwparams1 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS1);
|
| 1650 | parms->udHwparams2 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS2);
|
| 1651 | parms->udHwparams3 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS3);
|
| 1652 | parms->udHwparams4 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS4);
|
| 1653 | parms->udHwparams5 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS5);
|
| 1654 | parms->udHwparams6 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS6);
|
| 1655 | parms->udHwparams7 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS7);
|
| 1656 | parms->udHwparams8 = REG32(ptUsb3Slave->udRegs_base + GHWPARAMS8);
|
| 1657 |
|
| 1658 | ptUsb3Slave->udNumEvtBufs = (parms->udHwparams1&(0x3f<<15))>>15; //»ñÈ¡event_int_num
|
| 1659 | // if(global.need_enum ==0)
|
| 1660 | {
|
| 1661 | gp_USB3Slave_EventBuf->udLength = EVENT_BUFFERS_SIZE*4;
|
| 1662 | gp_USB3Slave_EventBuf->udLpos = 0;
|
| 1663 | }
|
| 1664 |
|
| 1665 | ptUsb3Slave->ptEvtBuffs = gp_USB3Slave_EventBuf;
|
| 1666 |
|
| 1667 | ptUsb3Slave->tCtrlReq = &pCtrlReq;
|
| 1668 | }
|
| 1669 |
|
| 1670 |
|
| 1671 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1672 | * @brief ¼Ç¼event bufferµØÖ·µ½¿ØÖÆÆ÷¼Ä´æÆ÷ÖÐ
|
| 1673 | *
|
| 1674 | * ¹¦ÄÜÏêÊö:
|
| 1675 | * - USB3Slave_EvtBufSetupº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1676 | * - ¼Ç¼event bufferµØÖ·µ½¿ØÖÆÆ÷¼Ä´æÆ÷ÖÐ
|
| 1677 | *
|
| 1678 | * ²ÎÊý¸ÅÊö:
|
| 1679 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1680 | *
|
| 1681 | * ·µ »Ø Öµ: ÀàÐÍ:INT
|
| 1682 | * - ´íÎóÂë
|
| 1683 | *
|
| 1684 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1685 | static void USB3Slave_EvtBufSetup(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1686 | {
|
| 1687 | T_USB3Slave_EventBuf *ptevt;
|
| 1688 | u32 udIndex = 0;
|
| 1689 | u32 udTemp_data;/*ÓÃÀ´±£´æµØÖ·µÄ*/
|
| 1690 |
|
| 1691 | ptevt = ptUsb3Slave->ptEvtBuffs;
|
| 1692 | udTemp_data = (u32)&ptevt->EvtBuf;
|
| 1693 | REG32(ptUsb3Slave->udRegs_base + GEVNTADRLO(udIndex)) = udTemp_data;
|
| 1694 | REG32(ptUsb3Slave->udRegs_base + GEVNTADRHI(udIndex)) = 0;
|
| 1695 | REG32(ptUsb3Slave->udRegs_base + GEVNTSIZ(udIndex)) = ptevt->udLength & 0xffff;
|
| 1696 | REG32(ptUsb3Slave->udRegs_base + GEVNTCOUNT(udIndex)) = ptevt->udLpos;
|
| 1697 | }
|
| 1698 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1699 | * @brief ¼Ç¼event bufferµØÖ·µ½¿ØÖÆÆ÷¼Ä´æÆ÷ÖÐ
|
| 1700 | *
|
| 1701 | * ¹¦ÄÜÏêÊö:
|
| 1702 | * - USB3Slave_EvtBufSetupº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1703 | * - ¼Ç¼event bufferµØÖ·µ½¿ØÖÆÆ÷¼Ä´æÆ÷ÖÐ
|
| 1704 | *
|
| 1705 | * ²ÎÊý¸ÅÊö:
|
| 1706 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1707 | *
|
| 1708 | * ·µ »Ø Öµ: ÀàÐÍ:INT
|
| 1709 | * - ´íÎóÂë
|
| 1710 | *
|
| 1711 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1712 |
|
| 1713 | static void USB3Slave_EvtBufRestore(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1714 | {
|
| 1715 | /*T_USB3Slave_EventBuf *ptevt;
|
| 1716 | u32 udIndex = 0;
|
| 1717 | u32 udTemp_data;
|
| 1718 | ptevt = ptUsb3Slave->ptEvtBuffs;
|
| 1719 | udTemp_data = (u32)&ptevt->EvtBuf;
|
| 1720 | REG32(ptUsb3Slave->udRegs_base + GEVNTADRLO(udIndex)) = udTemp_data;
|
| 1721 | REG32(ptUsb3Slave->udRegs_base + GEVNTADRHI(udIndex)) = 0;
|
| 1722 | REG32(ptUsb3Slave->udRegs_base + GEVNTSIZ(udIndex)) = ptevt->udLength & 0xffff;
|
| 1723 | REG32(ptUsb3Slave->udRegs_base + GEVNTCOUNT(udIndex)) = ptevt->udLpos;*/
|
| 1724 | u32 udRegVal;
|
| 1725 | u8 ucSpeed;
|
| 1726 |
|
| 1727 | T_USB3Slave_EventBuf *ptevt;
|
| 1728 | u32 udIndex = 0;
|
| 1729 | ptevt = ptUsb3Slave->ptEvtBuffs;
|
| 1730 | ptUsb3Slave->ptEvtBuffs = (T_USB3Slave_EventBuf *)(REG32(ptUsb3Slave->udRegs_base + GEVNTADRLO(udIndex)));
|
| 1731 | ptevt->udLength =REG32(ptUsb3Slave->udRegs_base + GEVNTSIZ(udIndex));
|
| 1732 | // ptevt->udLpos = REG32(ptUsb3Slave->udRegs_base + GEVNTCOUNT(udIndex)) ;
|
| 1733 | ptUsb3Slave->tCtrlReq = (T_USB3Slave_CtrlReq *)(*(u32 *)(*(u32 *)(0x0200c804)));
|
| 1734 |
|
| 1735 | udRegVal = REG32(ptUsb3Slave->udRegs_base + DWC3_DSTS);
|
| 1736 | ucSpeed = udRegVal&0x7;
|
| 1737 | ptUsb3Slave->ucSpeed = ucSpeed;
|
| 1738 | }
|
| 1739 |
|
| 1740 |
|
| 1741 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1742 | * @brief ÅäÖö˵ã0£¬¿ªÊ¼µÈ´ý½øÐпØÖÆ´«Êä
|
| 1743 | *
|
| 1744 | * ¹¦ÄÜÏêÊö:
|
| 1745 | * - USB3Slave_StartCtrlXferº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1746 | * - ÅäÖö˵ã0£¬¿ªÊ¼µÈ´ý½øÐпØÖÆ´«Êä
|
| 1747 | *
|
| 1748 | * ²ÎÊý¸ÅÊö:
|
| 1749 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1750 | *
|
| 1751 | * ·µ »Ø Öµ: ÎÞ
|
| 1752 | *
|
| 1753 | * ÆäËû˵Ã÷:
|
| 1754 | * -
|
| 1755 | *
|
| 1756 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1757 | static void USB3Slave_StartCtrlXfer(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1758 | {
|
| 1759 | T_USB3Slave_Ep *ptDep;
|
| 1760 | u32 udIndex;
|
| 1761 |
|
| 1762 | for (udIndex=0; udIndex < 2; udIndex++) /*//MAX_EPS*2 2¶Ëµãbulk out£¬3¶Ëµãbulk in 4¶Ëµãintr out£¬5¶Ëµã intr in*/
|
| 1763 | {
|
| 1764 | ptDep = &(ptUsb3Slave->tEps[udIndex]);
|
| 1765 | ptDep->ptTRB= &USB3Slave_TRB; //tjÿ¸ö¶ËµãʹÓÃͬһ¸ötrb mem
|
| 1766 | ptDep->udEpNum = udIndex;
|
| 1767 | if(global.need_enum ==1)
|
| 1768 | {
|
| 1769 | USB3Slave_CfgEp(ptDep);
|
| 1770 | }
|
| 1771 | }
|
| 1772 | ptUsb3Slave->eEp0State = EP0_SETUP_PHASE;
|
| 1773 | //Ö´ÐÐcmd6±íʾstart transfer¡£
|
| 1774 | USB3Slave_Ep0StartXfer(ptUsb3Slave, 0, (u32)(ptUsb3Slave->tCtrlReq), 8, TRBCTL_CONTROL_SETUP);
|
| 1775 | }
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1780 | * @brief ³õʼ»¯¶Ëµã½á¹¹Ì壬ÒÔ¼°¶ÔÓ¦¼Ä´æÆ÷ÅäÖÃ(¶ËµãºÅ£¬¶Ëµã״̬£¬´«Êä·½Ïò£¬°ü´óС)
|
| 1781 | *
|
| 1782 | * ¹¦ÄÜÏêÊö:
|
| 1783 | * - USB3Slave_InitEpº¯ÊýÊôÓÚÄÚ²¿º¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1784 | * - ³õʼ»¯¶Ëµã½á¹¹Ì壬ÒÔ¼°¶ÔÓ¦¼Ä´æÆ÷ÅäÖÃ(¶ËµãºÅ£¬¶Ëµã״̬£¬´«Êä·½Ïò£¬°ü´óС)
|
| 1785 | *
|
| 1786 | * ²ÎÊý¸ÅÊö:
|
| 1787 | * - ptUsb3Slave: É豸ÐÅÏ¢½á¹¹Ìå
|
| 1788 | *
|
| 1789 | * ·µ »Ø Öµ: ÎÞ
|
| 1790 | *
|
| 1791 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1792 | static void USB3Slave_InitEp(T_USB3Slave_SlaveObj *ptUsb3Slave)
|
| 1793 | {
|
| 1794 | T_USB3Slave_Ep *ptDep;
|
| 1795 | u32 udIndex;
|
| 1796 | /* u32 udFifoNum = 0,udTxfram_space; */
|
| 1797 | for (udIndex = 0; udIndex < ENDPOINTS_NUM; udIndex++)
|
| 1798 | {
|
| 1799 | ptDep = &(ptUsb3Slave->tEps[udIndex]);
|
| 1800 | ptDep->udEpNum = udIndex;
|
| 1801 | ptDep->eEpState = EP_IDLE;
|
| 1802 | ptDep->udFlags = 0; //tj add ¶¨ÒåflagĬÈÏΪ0
|
| 1803 | ptDep->udMaxBurst = 0; //tj add ÓÃÓÚburst size 0-15 : 1-16
|
| 1804 | ptDep->udDirection = udIndex & 1;/*¶¨Òå´«Êä·½Ïò*/
|
| 1805 | if (0 == udIndex|| 1 == udIndex)
|
| 1806 | {
|
| 1807 | ptDep->udMaxPacket = EP0_PACKET_SIZE;/*ÐÒ鹿¶¨¿ØÖÆ´«Êä×î´ó°ü´óС512*/
|
| 1808 | }
|
| 1809 | else
|
| 1810 | {
|
| 1811 | ptDep->udMaxPacket = HS_MAX_PACKET_SIZE;
|
| 1812 | }
|
| 1813 | }
|
| 1814 | }
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 | /**-------------------------------------------------------------------------------------------------------------------@n
|
| 1819 | * @brief ³õʼ»¯¼Ä´æÆ÷
|
| 1820 | *
|
| 1821 | * ¹¦ÄÜÏêÊö:
|
| 1822 | * - USB3Slave_Init º¯ÊýÊôÓÚ½Ó¿Úº¯Êý, Æä¹¦ÄÜÊÇ:
|
| 1823 | * - ³õʼ»¯¼Ä´æÆ÷
|
| 1824 | *
|
| 1825 | * ²ÎÊý¸ÅÊö:
|
| 1826 | * - eUSBSpeedType: USB É豸ËÙ¶ÈÀàÐÍ
|
| 1827 | *
|
| 1828 | * ·µ »Ø Öµ: ÀàÐÍ:u32
|
| 1829 | * - ´íÎóÂë
|
| 1830 | *
|
| 1831 | * ÆäËû˵Ã÷:
|
| 1832 | * -
|
| 1833 | *
|
| 1834 | *--------------------------------------------------------------------------------------------------------------------*/
|
| 1835 | u32 USB3Slave_Ctrl_Init(void)
|
| 1836 | {
|
| 1837 | u32 udRegValue, i = 0;
|
| 1838 |
|
| 1839 | T_USB3Slave_SlaveObj *pUSB3Slv = &g_USB3Slave;
|
| 1840 | //step0: ¶Ô½á¹¹Ìåg_USB3Slave½øÐи³Öµ
|
| 1841 | USB3Slave_Init(pUSB3Slv);
|
| 1842 |
|
| 1843 | //step1:DCTL£¬¶Ô¿ØÖÆÆ÷½øÐÐÈí¸´Î»
|
| 1844 | if(global.need_enum ==1)
|
| 1845 | {
|
| 1846 |
|
| 1847 | REG32(pUSB3Slv->udRegs_base + DWC3_DCTL) |= DWC3_DCTL_CSFTRST;
|
| 1848 | while(1)
|
| 1849 | {
|
| 1850 | i++;
|
| 1851 | usdelay(10);
|
| 1852 | udRegValue =REG32(pUSB3Slv->udRegs_base + DWC3_DCTL);
|
| 1853 | if ((!(udRegValue & DWC3_DCTL_CSFTRST))||(i>0x1000))/*¸´Î»Íê±Ïºó¸Ãλ×Ô¶¯ÇåÁã*/
|
| 1854 | break;
|
| 1855 | }
|
| 1856 | }
|
| 1857 | //step2:ÅäÖÃUSB2 PHY */ //0x0007a510
|
| 1858 | /*bit3: 0:8bit 1:16bit
|
| 1859 | bit4: 0:utmi 1:ulpi
|
| 1860 | bit[13:10] 5:16bit utmi 9:8bit utim/ulpi*/
|
| 1861 | if(global.need_enum ==1)
|
| 1862 | {
|
| 1863 | #if(SIM_EN == FPGA)
|
| 1864 | #if (USB_PHY == ULPI)
|
| 1865 | udRegValue = 0x7a510|(1<<9); //0xf<<15+0x9<<10+0x1<<4+0x0<<3;
|
| 1866 | #elif (USB_PHY == UTMI)
|
| 1867 | udRegValue = 0x00001408|(1<<9);//0x0<<15|0x5<<10|0x0<<4+0x1<<3;
|
| 1868 | #endif
|
| 1869 | #elif ((SIM_EN == ASIC) || (SIM_EN == EMULATION))
|
| 1870 | udRegValue = 0x00002400|(1<<9);//0x0<<15|0x9<<10|0x0<<4+0x0<<3;
|
| 1871 | #endif
|
| 1872 |
|
| 1873 |
|
| 1874 | REG32(pUSB3Slv->udRegs_base + DWC3_GUSB2PHYCFG(0)) = udRegValue;
|
| 1875 |
|
| 1876 | //step3:DCTL£¬¶Ô¿ØÖÆÆ÷ÔٴνøÐÐÈí¸´Î»
|
| 1877 | REG32(pUSB3Slv->udRegs_base + DWC3_DCTL) |= DWC3_DCTL_CSFTRST;
|
| 1878 | while(1)
|
| 1879 | {
|
| 1880 | i++;
|
| 1881 | usdelay(10);
|
| 1882 | udRegValue =REG32(pUSB3Slv->udRegs_base + DWC3_DCTL);
|
| 1883 | if ((!(udRegValue & DWC3_DCTL_CSFTRST))||(i>0x1000))/*¸´Î»Íê±Ïºó¸Ãλ×Ô¶¯ÇåÁã*/
|
| 1884 | break;
|
| 1885 | }
|
| 1886 |
|
| 1887 | }
|
| 1888 | //step4:´Óparams1ÖлñÈ¡eventnum£¬Ó²¼þĬÈÏΪ1,ÅäÖÃevent_buffer
|
| 1889 | if(global.need_enum ==1)
|
| 1890 | {
|
| 1891 |
|
| 1892 | USB3Slave_EvtBufSetup(pUSB3Slv);
|
| 1893 | }
|
| 1894 | else
|
| 1895 | {
|
| 1896 | USB3Slave_EvtBufRestore(pUSB3Slv);
|
| 1897 | }
|
| 1898 |
|
| 1899 | //step5: ÅäÖüĴæÆ÷c110£¬°üº¬ÅäÖÃdev mode,ÅäÖÃc700,°üº¬high speed
|
| 1900 | if(global.need_enum ==1)
|
| 1901 | {
|
| 1902 |
|
| 1903 | udRegValue = REG32(pUSB3Slv->udRegs_base + DWC3_GCTL);
|
| 1904 | udRegValue = (udRegValue & 0xffff0000) | 0x200c;//ÔÀ´ÊÇ0x2008 scaledown
|
| 1905 | udRegValue = udRegValue & (~(1<<17)); // In the real hardware, this bit must be set to 1'b0
|
| 1906 | udRegValue = udRegValue & (~(1<<16));//2012.11.9,never attempts three more times to connect at SS
|
| 1907 | #if SIM_EN == EMULATION
|
| 1908 | udRegValue = (udRegValue & 0xffff0000) | 0x2008;
|
| 1909 | udRegValue = udRegValue|(0x3<<4); //lanxiang scaledown
|
| 1910 | udRegValue = udRegValue|(1<<16);
|
| 1911 | #endif
|
| 1912 | REG32(pUSB3Slv->udRegs_base + DWC3_GCTL) = udRegValue;
|
| 1913 |
|
| 1914 | udRegValue = REG32(pUSB3Slv->udRegs_base + DWC3_DCFG);
|
| 1915 | udRegValue &= ~(DWC3_DCFG_SPEED_MASK); //0Ϊhigh speed
|
| 1916 | udRegValue &= (~(0x1f<<17));
|
| 1917 | udRegValue |= pUSB3Slv->eSpeedMode | (1<<17) ; /*1×óÒÆ17ΪÀ´×ÔÑéÖ¤ÂãÇý£¬Óдý·ÖÎö£¬pxp*/
|
| 1918 | REG32(pUSB3Slv->udRegs_base + DWC3_DCFG)= udRegValue;
|
| 1919 | }
|
| 1920 | pUSB3Slv->eDeviceSpeedType = USB30_SPEED_UNKNOWN;
|
| 1921 |
|
| 1922 | //step6:³õʼ»¯EP¶Ëµã£¬bootÖÐÖ»Óõ½0£¬1£¬2£¬3£¬4£¬5£¬ÆäËüµÄ¿ÉÒÔ¿¼ÂDz»Òª¡£
|
| 1923 |
|
| 1924 | USB3Slave_InitEp(pUSB3Slv);
|
| 1925 |
|
| 1926 | //step7:ÅäÖÃÖжÏ(reset , connect done)ʹÄÜ£¬ÈíÁ¬½Ó£¬µÚ31bitÅäÖÃΪrun
|
| 1927 | if(global.need_enum ==1)
|
| 1928 | {
|
| 1929 | udRegValue = REG32(pUSB3Slv->udRegs_base + DWC3_DEVTEN);
|
| 1930 | udRegValue = udRegValue | (DWC3_DEVTEN_CONNECTDONEEN | DWC3_DEVTEN_USBRSTEN|DWC3_DEVTEN_USBSUSPENDEN);
|
| 1931 | //udRegValue = udRegValue & (~(1<<6)) & (~(1<<7));
|
| 1932 | REG32(pUSB3Slv->udRegs_base + DWC3_DEVTEN) = udRegValue;
|
| 1933 | }
|
| 1934 | //step8:start control tranfer
|
| 1935 | USB3Slave_StartCtrlXfer(pUSB3Slv);
|
| 1936 | if(global.need_enum ==1)
|
| 1937 | {
|
| 1938 |
|
| 1939 | //step9:run softconnect
|
| 1940 | udRegValue = REG32(pUSB3Slv->udRegs_base + DWC3_DCTL);
|
| 1941 | udRegValue |= (1U<<31); //tj add 31bit for run or stop,correspond to softdisconnect
|
| 1942 | REG32(pUSB3Slv->udRegs_base + DWC3_DCTL) = udRegValue;
|
| 1943 |
|
| 1944 |
|
| 1945 | #if SIM_EN == EMULATION
|
| 1946 | //for hsic
|
| 1947 | REG32(REG_GPIO_OUT)=2;
|
| 1948 | // while(REG32(REG_GPIO_IN)!=0xFF);
|
| 1949 | usdelay(1);
|
| 1950 | REG32(REG_GPIO_OUT)=0;
|
| 1951 | #endif
|
| 1952 | }
|
| 1953 |
|
| 1954 | return SOK;
|
| 1955 | }
|
| 1956 |
|
| 1957 |
|
| 1958 | u32 USB3_RecvOutData(u32 dwEPNo, u8 *pchBuf, u32 dwLen, F_USB_CB fnUsbCb, void *pPara)
|
| 1959 | {
|
| 1960 | T_USB3Slave_Ep *ptDep;
|
| 1961 | T_USB3Slave_SlaveObj *ptUsb3Slave = &g_USB3Slave;
|
| 1962 |
|
| 1963 | ptDep = &(ptUsb3Slave->tEps[dwEPNo]);
|
| 1964 |
|
| 1965 | ptDep->pudAddrData =(u32*)pchBuf;
|
| 1966 | ptDep->udLen = dwLen;
|
| 1967 | ptDep->fnUsbCb = fnUsbCb;
|
| 1968 | ptDep->pPara = pPara;
|
| 1969 |
|
| 1970 | USB3Slave_EpStartXfer(ptDep, 0, 1);
|
| 1971 |
|
| 1972 | #if SIM_EN == EMULATION
|
| 1973 | REG32(ARM_PORTA)=0x80;
|
| 1974 | #endif
|
| 1975 |
|
| 1976 | return SOK;
|
| 1977 | }
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 | u32 USB3_SendInData(u32 dwEPNo, u8 *pchBuf, u32 dwLen, F_USB_CB fnUsbCb, void *pPara)
|
| 1982 | {
|
| 1983 |
|
| 1984 | T_USB3Slave_Ep *ptDep;
|
| 1985 | T_USB3Slave_SlaveObj *ptUsb3Slave = &g_USB3Slave;
|
| 1986 |
|
| 1987 | ptDep = &(ptUsb3Slave->tEps[dwEPNo]);
|
| 1988 |
|
| 1989 | ptDep->pudAddrData = (u32*)pchBuf;
|
| 1990 | ptDep->udLen = dwLen;
|
| 1991 | ptDep->fnUsbCb = fnUsbCb;
|
| 1992 | ptDep->pPara = pPara;
|
| 1993 |
|
| 1994 | USB3Slave_EpStartXfer(ptDep, 0, 1);
|
| 1995 |
|
| 1996 | #if SIM_EN == EMULATION
|
| 1997 | REG32(ARM_PORTA)=0x82;
|
| 1998 | #endif
|
| 1999 |
|
| 2000 | return SOK;
|
| 2001 | }
|
| 2002 |
|
| 2003 | u32 USB3Slave_IsNeedZero(u32 dwLen)
|
| 2004 | {
|
| 2005 | T_USB3Slave_Ep *ptDep;
|
| 2006 | T_USB3Slave_SlaveObj *ptUsb3Slave = &g_USB3Slave;
|
| 2007 | u32 udMaxPacket;
|
| 2008 |
|
| 2009 | if (ptUsb3Slave->ucSpeed == USB3_HIGHSPEED)
|
| 2010 | {
|
| 2011 | udMaxPacket = HS_MAX_PACKET_SIZE;
|
| 2012 | }
|
| 2013 | else if (ptUsb3Slave->ucSpeed == USB3_FULLSPEED)
|
| 2014 | {
|
| 2015 | udMaxPacket = FS_MAX_PACKET_SIZE;
|
| 2016 | }
|
| 2017 | if (dwLen%udMaxPacket == 0)
|
| 2018 | {
|
| 2019 | return TRUE;
|
| 2020 | }
|
| 2021 | else
|
| 2022 | {
|
| 2023 | return FALSE;
|
| 2024 | }
|
| 2025 | }
|
| 2026 |
|
| 2027 | /*ö¾Ùº¯Êý*/
|
| 2028 | u32 USB3Slave_CDC_Enum(void)
|
| 2029 | {
|
| 2030 | T_USB3Slave_Ep *ptDep;
|
| 2031 | u32 dwCount=0;
|
| 2032 | u32 dwCount1=0;
|
| 2033 | u32 udIndex;
|
| 2034 |
|
| 2035 |
|
| 2036 | global.g_Connet = 0;
|
| 2037 | USB3Slave_Ctrl_Init();
|
| 2038 | if(global.need_enum ==0)
|
| 2039 | {
|
| 2040 | for (udIndex=2; udIndex < 6; udIndex++) /*//MAX_EPS*2 2¶Ëµãbulk out£¬3¶Ëµãbulk in 4¶Ëµãintr out£¬5¶Ëµã intr in*/
|
| 2041 | {
|
| 2042 | ptDep = &(g_USB3Slave.tEps[udIndex]);
|
| 2043 | ptDep->ptTRB= &USB3Slave_TRB_EP[udIndex-2]; //tjÿ¸ö¶ËµãʹÓÃͬһ¸ötrb mem
|
| 2044 | ptDep->udEpNum = udIndex;
|
| 2045 |
|
| 2046 | //USB3Slave_CfgEp(ptDep);
|
| 2047 | }
|
| 2048 | }
|
| 2049 | if(global.need_enum ==1)
|
| 2050 | {
|
| 2051 | while(1)
|
| 2052 | {
|
| 2053 | USB3Slave_ISR(0,0);
|
| 2054 | if(0 == global.g_Connet)
|
| 2055 | {
|
| 2056 | dwCount++;
|
| 2057 | usb_timeout_usdelay(50000);
|
| 2058 | if(dwCount>(4000*global.g_USB_TIMEOUT))
|
| 2059 | return 1;
|
| 2060 |
|
| 2061 | }
|
| 2062 | else if(1 == g_USB3Slave.udUSBSate)
|
| 2063 | {
|
| 2064 | for (udIndex=2; udIndex < 6; udIndex++) /*//MAX_EPS*2 2¶Ëµãbulk out£¬3¶Ëµãbulk in 4¶Ëµãintr out£¬5¶Ëµã intr in*/
|
| 2065 | {
|
| 2066 | ptDep = &(g_USB3Slave.tEps[udIndex]);
|
| 2067 | ptDep->ptTRB= &USB3Slave_TRB_EP[udIndex-2]; //tjÿ¸ö¶ËµãʹÓÃͬһ¸ötrb mem
|
| 2068 | ptDep->udEpNum = udIndex;
|
| 2069 | USB3Slave_CfgEp(ptDep);
|
| 2070 | }
|
| 2071 | break;
|
| 2072 | }
|
| 2073 | else
|
| 2074 | {
|
| 2075 | dwCount1++;
|
| 2076 | usb_timeout_usdelay(50000);
|
| 2077 | if(dwCount1>(200000*global.g_USB_TIMEOUT))
|
| 2078 | {
|
| 2079 | return 1;
|
| 2080 | }
|
| 2081 |
|
| 2082 | }
|
| 2083 | }
|
| 2084 | }
|
| 2085 | return 0;
|
| 2086 | }
|
| 2087 |
|
| 2088 | extern void USB_Boot(void);
|
| 2089 | extern void USB_Pll_Clk_Rst_InitEnv(void);
|
| 2090 |
|
| 2091 | void USB3Slave_boot(void)
|
| 2092 | {
|
| 2093 | u32 dwConnect;
|
| 2094 | global.g_USB_MODE = 0;
|
| 2095 | global.need_enum = 0;
|
| 2096 | // 1:config clock
|
| 2097 | if(global.need_enum ==1)
|
| 2098 | {
|
| 2099 | USB_Pll_Clk_Rst_InitEnv();
|
| 2100 | }
|
| 2101 | // 2:USB30_CDC_Enum
|
| 2102 | dwConnect = USB3Slave_CDC_Enum();
|
| 2103 | if(1==dwConnect)
|
| 2104 | {
|
| 2105 | printf("NOLINK\n");
|
| 2106 | return ;
|
| 2107 | }
|
| 2108 |
|
| 2109 | #if 0//SIM_EN == EMULATION
|
| 2110 | REG32(ARM_PORTA)=0x32;
|
| 2111 | #endif
|
| 2112 | printf("FAILED\n");
|
| 2113 | }
|
| 2114 |
|
| 2115 | /** @} */
|
| 2116 |
|
| 2117 |
|