- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

csl_cdcAux.h
Go to the documentation of this file.

    00001 /*  ============================================================================
    00002  *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2008, 2011
    00003  *
    00004  *   Use of this software is controlled by the terms and conditions found in the
    00005  *   license agreement under which this software has been supplied.
    00006  *  ============================================================================
    00007  */
    00008
    00016 /* ============================================================================
    00017  * Revision History
    00018  * ================
    00019  * 02-May-2011 Created
    00020  * ============================================================================
    00021  */
    00022
    00023 #ifndef _CSL_CDCAUX_H_
    00024 #define _CSL_CDCAUX_H_
    00025
    00026 #ifdef __cplusplus
    00027 extern "C" {
    00028 #endif
    00029
    00030 #include "csl_usbAux.h"
    00031 #include "csl_cdc.h"
    00032
    00033 #include <stdio.h>
    00034
    00091 static inline
    00092 CSL_CdcRequestRet CDC_reqSetAddress(CSL_UsbDevNum         devNum,
    00093                                     CSL_UsbSetupStruct    *usbSetup,
    00094                                     pUsbEpHandle          hInEp,
    00095                                     pUsbEpHandle          hOutEp,
    00096                                     void                  *pCdc)
    00097 {
    00098     USB_setDevAddr(devNum, (Uint16)(usbSetup->wValue));
    00099
    00100     return(CSL_CDC_REQUEST_DONE);
    00101 }
    00102
    00157 static inline
    00158 CSL_CdcRequestRet CDC_reqSetConfiguration(CSL_UsbDevNum         devNum,
    00159                                           CSL_UsbSetupStruct    *usbSetup,
    00160                                           pUsbEpHandle          hInEp,
    00161                                           pUsbEpHandle          hOutEp,
    00162                                           void                  *pCdc)
    00163 {
    00164     CSL_CdcRequestRet    retStat;
    00165
    00166     pCdcClassHandle      pCdcClassHdl;
    00167     CSL_CdcCtrlObject    *pCtrlHandle;
    00168
    00169     pCdcClassHdl = (pCdcClassHandle)(pCdc);
    00170     pCtrlHandle  = &pCdcClassHdl->ctrlHandle;
    00171
    00172     if((usbSetup->wValue == FALSE) || (usbSetup->wValue == TRUE))
    00173     {
    00174         pCtrlHandle->curConfigStat = usbSetup->wValue;
    00175
    00176         USB_setConfiguration(devNum,usbSetup->wValue);
    00177
    00178         retStat   = CSL_CDC_REQUEST_SEND_ACK;
    00179     }
    00180     else
    00181     {
    00182         /* configuration not supported, STALL the endpoint */
    00183         retStat = CSL_CDC_REQUEST_STALL;
    00184     }
    00185
    00186     return(retStat);
    00187 }
    00188
    00243 static inline
    00244 CSL_CdcRequestRet CDC_reqClearFeature(CSL_UsbDevNum         devNum,
    00245                                       CSL_UsbSetupStruct    *usbSetup,
    00246                                       pUsbEpHandle          hInEp,
    00247                                       pUsbEpHandle          hOutEp,
    00248                                       void                  *pCdc)
    00249 {
    00250     CSL_CdcRequestRet    retStat;
    00251     pUsbEpHandle         hEPx;
    00252     Uint16               endpt;  /* this is USB logical endpoint */
    00253
    00254     retStat = CSL_CDC_REQUEST_SEND_ACK;
    00255
    00256     switch(usbSetup->wValue)
    00257     {
    00258         case CSL_USB_FEATURE_ENDPOINT_STALL:
    00259             endpt = (usbSetup->wIndex) & CSL_CDC_8BIT_MASK;
    00260             hEPx = USB_epNumToHandle(devNum, endpt);
    00261             USB_clearEndptStall(hEPx);
    00262             break;
    00263
    00264         case CSL_USB_FEATURE_REMOTE_WAKEUP:
    00265             USB_setRemoteWakeup(devNum, (CSL_UsbBoolean)FALSE);
    00266             break;
    00267
    00268         default:
    00269             /* Unsupported Feature. STALL the endpoint */
    00270             retStat = CSL_CDC_REQUEST_STALL;
    00271             break;
    00272     }
    00273
    00274     return(retStat);
    00275 }
    00276
    00331 static inline
    00332 CSL_CdcRequestRet CDC_reqGetStatus(CSL_UsbDevNum         devNum,
    00333                                    CSL_UsbSetupStruct    *usbSetup,
    00334                                    pUsbEpHandle          hInEp,
    00335                                    pUsbEpHandle          hOutEp,
    00336                                    void                  *pCdc)
    00337 {
    00338     CSL_CdcRequestRet     retStat;
    00339     pCdcClassHandle       pCdcClassHdl;
    00340     CSL_CdcCtrlObject     *pCtrlHandle;
    00341     pUsbEpHandle          hEPx;
    00342     CSL_Status            status;
    00343     Uint16                endpt;   /* this is USB logical endpoint */
    00344
    00345     pCdcClassHdl = (pCdcClassHandle)(pCdc);
    00346     pCtrlHandle  = &pCdcClassHdl->ctrlHandle;
    00347     retStat      = CSL_CDC_REQUEST_GET_ACK;
    00348
    00349     switch(usbSetup->bmRequestType - CSL_CDC_REQUEST_TYPE_BASE)
    00350     {
    00351         /* Device Status to be returned */
    00352         case CSL_CDC_REQUEST_TYPE_DEVICE_STATUS:
    00353             pCtrlHandle->ctrlBuffer[0] =
    00354             (((Uint16)USB_getRemoteWakeupStat(devNum))<<1) |
    00355              CSL_CDC_CURRDEV_STAT;
    00356             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
    00357                                 CSL_USB_IOFLAG_NONE);
    00358             break;
    00359
    00360         /* Interface status is to be returned */
    00361         case CSL_CDC_REQUEST_TYPE_INTERFACE_STATUS:
    00362             pCtrlHandle->ctrlBuffer[0] = CSL_CDC_CURRDEV_STAT;
    00363             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
    00364                                 CSL_USB_IOFLAG_NONE);
    00365             break;
    00366
    00367         /* Endpoint status to be returned */
    00368         case CSL_CDC_REQUEST_TYPE_EP_STATUS:
    00369
    00370             endpt  =  usbSetup->wIndex & 0xFF;
    00371             hEPx   =  USB_epNumToHandle(devNum, endpt);
    00372             pCtrlHandle->ctrlBuffer[0] = (Uint16)USB_getEndptStall(hEPx,
    00373                                                                    &status);
    00374             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
    00375                                 CSL_USB_IOFLAG_NONE);
    00376             break;
    00377
    00378         default:
    00379             /* STALL the endpoint */
    00380             retStat = CSL_CDC_REQUEST_STALL;
    00381             break;
    00382     }
    00383
    00384     return(retStat);
    00385 }
    00386
    00441 static inline
    00442 CSL_CdcRequestRet CDC_reqSetFeature(CSL_UsbDevNum         devNum,
    00443                                     CSL_UsbSetupStruct    *usbSetup,
    00444                                     pUsbEpHandle          hInEp,
    00445                                     pUsbEpHandle          hOutEp,
    00446                                     void                  *pCdc)
    00447 {
    00448     CSL_CdcRequestRet    retStat;
    00449     pUsbEpHandle         hEPx;
    00450     Uint16               endpt;        /* this is USB logical endpoint */
    00451
    00452     retStat = CSL_CDC_REQUEST_SEND_ACK;
    00453
    00454     switch(usbSetup->wValue)
    00455     {
    00456         case CSL_USB_FEATURE_ENDPOINT_STALL:
    00457             /* updated set and clear endpoint stall to work with logical endpoint num */
    00458             endpt = (usbSetup->wIndex) & CSL_CDC_8BIT_MASK;
    00459             hEPx = USB_epNumToHandle(devNum, endpt);
    00460             USB_stallEndpt(hEPx);
    00461             break;
    00462
    00463         case CSL_USB_FEATURE_REMOTE_WAKEUP:
    00464             USB_setRemoteWakeup(devNum, (CSL_UsbBoolean)TRUE);
    00465             break;
    00466
    00467         default:
    00468             /* Feature not supported, STALL the endpoint */
    00469             retStat = CSL_CDC_REQUEST_STALL;
    00470             break;
    00471     }
    00472
    00473   return(retStat);
    00474 }
    00475
    00529 static inline
    00530 CSL_CdcRequestRet CDC_reqGetConfiguration(CSL_UsbDevNum         devNum,
    00531                                           CSL_UsbSetupStruct    *usbSetup,
    00532                                           pUsbEpHandle          hInEp,
    00533                                           pUsbEpHandle          hOutEp,
    00534                                           void                  *pCdc)
    00535 {
    00536     pCdcClassHandle       pCdcClassHdl;
    00537     CSL_CdcCtrlObject*    pCtrlHandle;
    00538
    00539     pCdcClassHdl = (pCdcClassHandle)(pCdc);
    00540     pCtrlHandle  = &pCdcClassHdl->ctrlHandle;
    00541
    00542     /* Send the current Configuration Value */
    00543     pCtrlHandle->ctrlBuffer[1] = pCtrlHandle->curConfigStat;
    00544     USB_postTransaction(hInEp, 1, (void*)&pCtrlHandle->ctrlBuffer,
    00545                         CSL_USB_IOFLAG_NONE | CSL_USB_IOFLAG_NOSHORT);
    00546
    00547     return(CSL_CDC_REQUEST_GET_ACK);
    00548 }
    00549
    00550
    00606 static inline
    00607 CSL_CdcRequestRet CDC_reqGetMaxLUN(CSL_UsbDevNum         devNum,
    00608                                    CSL_UsbSetupStruct    *usbSetup,
    00609                                    pUsbEpHandle          hInEp,
    00610                                    pUsbEpHandle          hOutEp,
    00611                                    void                  *pCdc)
    00612 {
    00613     pCdcClassHandle       pCdcClassHdl;
    00614     CSL_CdcCtrlObject*    pCtrlHandle;
    00615     CSL_CdcRequestRet     retStat;
    00616
    00617     pCdcClassHdl = (pCdcClassHandle)(pCdc);
    00618     pCtrlHandle  = &pCdcClassHdl->ctrlHandle;
    00619     pCtrlHandle->ctrlBuffer[1] = pCdcClassHdl->cdcHandle.noOfPort;
    00620
    00621     /*
    00622      * Verify the setup packet fields
    00623      * wValue - 0
    00624      * wIndex - interface number, set 0
    00625      * wLength - 1
    00626      */
    00627     if ((usbSetup->wIndex == 0) &&
    00628         (usbSetup->wLength == 1) &&
    00629         (usbSetup->wValue == 0))
    00630     {
    00631         USB_postTransaction(hInEp, 1, &pCtrlHandle->ctrlBuffer[0],
    00632                             CSL_USB_IOFLAG_NONE);
    00633
    00634         /* Receive a 0 length packet for acknowledgement */
    00635         retStat = CSL_CDC_REQUEST_GET_ACK;
    00636     }
    00637     else
    00638     {
    00639         retStat = CSL_CDC_REQUEST_STALL;
    00640     }
    00641
    00642     return (retStat);
    00643 }
    00644
    00700 static inline
    00701 CSL_CdcRequestRet CDC_reqGetInterface(CSL_UsbDevNum         devNum,
    00702                                       CSL_UsbSetupStruct    *usbSetup,
    00703                                       pUsbEpHandle          hInEp,
    00704                                       pUsbEpHandle          hOutEp,
    00705                                       void                  *pCdc)
    00706 {
    00707     pCdcClassHandle       pCdcClassHdl;
    00708     CSL_CdcCtrlObject     *pCtrlHandle;
    00709     CSL_CdcRequestRet     retStat;
    00710
    00711     pCdcClassHdl = (pCdcClassHandle)(pCdc);
    00712     pCtrlHandle  = &pCdcClassHdl->ctrlHandle;
    00713     retStat      = CSL_CDC_REQUEST_GET_ACK;
    00714
    00715     /* Compare the Interface with the bNumInterfaces byte of Configuration Descriptor */
    00716     if(usbSetup->wIndex == 0)
    00717     {
    00718         /* Send the current Interface Value */
    00719         pCtrlHandle->ctrlBuffer[1] = 0;
    00720         USB_postTransaction(hInEp, 1, &pCtrlHandle->ctrlBuffer[0],
    00721                             CSL_USB_IOFLAG_NONE);
    00722     }
    00723     else
    00724     {
    00725         /*  Interface specified doesn't exist, STALL the endpoint */
    00726         retStat = CSL_CDC_REQUEST_STALL;
    00727     }
    00728
    00729     return retStat;
    00730 }
    00731
    00787 static inline
    00788 CSL_CdcRequestRet CDC_reqSetInterface(CSL_UsbDevNum         devNum,
    00789                                       CSL_UsbSetupStruct    *usbSetup,
    00790                                       pUsbEpHandle          hInEp,
    00791                                       pUsbEpHandle          hOutEp,
    00792                                       void                  *pCdc)
    00793 {
    00794     CSL_CdcRequestRet    retStat;
    00795
    00796     if(usbSetup->wIndex == 0)
    00797     {
    00798         if (usbSetup->wValue == 0)
    00799         {
    00800             USB_setConfiguration(devNum,usbSetup->wValue);
    00801             retStat = CSL_CDC_REQUEST_SEND_ACK;
    00802         }
    00803     }
    00804     else
    00805     {
    00806         /* configuration not supported, STALL the endpoint */
    00807         retStat = CSL_CDC_REQUEST_STALL;
    00808     }
    00809
    00810     return(retStat);
    00811 }
    00812
    00813
    00817 #ifdef __cplusplus
    00818 }
    00819 #endif
    00820
    00821 #endif    // _CSL_CDCAUX_H_
    00822