csl_cdc.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 
00037 #ifndef _CSL_CDC_H_
00038 #define _CSL_CDC_H_
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 #include <cslr.h>
00045 #include <csl_error.h>
00046 #include <csl_types.h>
00047 #include <cslr_usb.h>
00048 #include <csl_usb.h>
00049 #include <soc.h>
00050 #include <csl_general.h>
00051 
00052 
00071 /*****************************************************************************\
00072           USB CDC global macro declarations                                   *
00073 \*****************************************************************************/
00079 #define CSL_CDC_PORT_MAX                                1
00080 #define CSL_CDC_NO_ENDPTOBJECT                          8
00081 
00083 #define CSL_CDC_ERROR_BASE                             (CSL_EUSB_FIRST)
00084 
00085 #define CSL_CDC_INVALID_REQUEST_HANDLER                (CSL_CDC_ERROR_BASE - 1)
00086 
00088 #define CSL_CDC_INTR_IN_EP                                  CSL_USB_EP1
00089 #define CSL_CDC_BULK_OUT_EP                                 CSL_USB_EP2
00090 #define CSL_CDC_BULK_IN_EP                                  CSL_USB_EP3
00091 
00092 #define CSL_USB_CDC_DATA_BUF_SIZE                           512
00093 
00097 #define CSL_CDC_REQUEST_SEND_ENCAPSULATED_COMMAND           (0x2100)
00098 
00099 #define CSL_CDC_REQUEST_GET_ENCAPSULATED_RESPONSE           (0xA101)
00100 
00101 #define CSL_CDC_REQUEST_SET_COMM_FEATURE                    (0x2102)
00102 
00103 #define CSL_CDC_REQUEST_GET_COMM_FEATURE                    (0xA103)
00104 //** Host clears the settings for a particular communication feature.  */
00105 #define CSL_CDC_REQUEST_CLEAR_COMM_FEATURE                  (0x2104)
00106 
00107 #define CSL_CDC_REQUEST_SET_LINE_CODING                     (0x2120)
00108 
00109 #define CSL_CDC_REQUEST_GET_LINE_CODING                     (0xA121)
00110 
00111 #define CSL_CDC_REQUEST_SET_CONTROL_LINE_STATE              (0x2122)
00112 //** Sends special carrier modulation used to specify RS-232 style break    */
00113 #define CSL_CDC_REQUEST_SEND_BREAK                          (0x2123)
00114 
00116 #define CSL_CDC_REQUEST_ARGS     CSL_UsbDevNum         devNum,           \
00117                                  CSL_UsbSetupStruct    *usbSetup,        \
00118                                  pUsbEpHandle          hInEp,            \
00119                                  pUsbEpHandle          hOutEp,           \
00120                                  void                  *pCdc
00121 
00126 /**************************************************************************\
00127 * USB CDC global typedef declarations                                      *
00128 \**************************************************************************/
00129 
00136 typedef enum {
00137     /* Don't call request again until new SETUP                              */
00138     CSL_CDC_REQUEST_DONE = 0,
00139     /* STALL the control endpoint                                            */
00140     CSL_CDC_REQUEST_STALL,
00141     /* Send a 0 length IN packet                                             */
00142     CSL_CDC_REQUEST_SEND_ACK,
00143     /* Prepare to receive 0 length OUT packet                                */
00144     CSL_CDC_REQUEST_GET_ACK,
00145     /* Notify handler when IN data has been transmitted                      */
00146     CSL_CDC_REQUEST_DATA_IN,
00147     /* Notify handler when OUT data has been received                        */
00148     CSL_CDC_REQUEST_DATA_OUT
00149 } CSL_CdcRequestRet;
00150 
00154 typedef enum {
00156     CSL_CDC_MEDIACCESS_OVERFLOW,
00158     CSL_CDC_MEDIACCESS_SUCCESS,
00160     CSL_CDC_MEDIACCESS_NOTPRESENT,
00162     CSL_CDC_MEDIACCESS_WRITEPROTECT,
00164     CSL_CDC_MEDIACCESS_BADMEDIA
00165 } CSL_CdcMediaStatus;
00166 
00171 /**************************************************************************\
00172 * USB CDC global data structure declarations                               *
00173 \**************************************************************************/
00174 
00185 typedef struct {
00186     Uint32 dwBaudRate;
00187     Uint16 wCharFormat;
00188     Uint16 wParityType;
00189     Uint16 wDataBits;
00190 } CSL_CdcLineCoding;
00191 
00198 typedef struct CSL_CdcInitStructApp {
00200     void                    *pCdcObj;
00202     Uint16                  pId;
00204     Uint16                  vId;
00207     Uint16                  *rxBufferPtr;
00208     Uint16                  rxStartIdx;
00209     Uint16                  rxEndIdx;
00212     Uint16                  *txBufferPtr;
00213     Uint16                  txStartIdx;
00214     Uint16                  txEndIdx;
00217     Uint16                  *txWorkBufPtr;
00218     Uint16                  txWorkBufIdx;
00221     void                    (*bulkHandler)();
00224     void                    (*ctrlHandler)();
00227     void                    (*intrHandler)();
00229     void                    (*bulkInCallback)();
00231     void                    (*bulkOutCallback)();
00233     void                    (*intrInCallback)();
00234 } CSL_CdcInitStructApp;
00235 
00237 typedef CSL_CdcInitStructApp  *pCdcAppClassHandle;
00238 
00246 typedef  CSL_CdcRequestRet (*fpCDC_REQ_HANDLER)(CSL_CDC_REQUEST_ARGS);
00247 
00253 typedef struct CSL_CdcObject {
00255     Uint16                *lbaBuffer;
00257     Uint16                activityPresentFlag;
00260     CSL_UsbEpObj          bulkInEpObj;
00262     CSL_UsbEpObj          bulkOutEpObj;
00264     CSL_UsbEpObj          intrInEpObj;
00266     CSL_UsbEpObj          intrOutEpObj;
00268     CSL_CdcLineCoding   lineCoding;
00270     Uint16              controlLineState;
00271 } CSL_CdcObject;
00272 
00278 typedef struct CSL_CdcCtrlObject {
00280     CSL_UsbEpObj             ctrlInEpObj;
00282     CSL_UsbDevNum            devNum;
00284     CSL_UsbEpObj             ctrlOutEpObj;
00286     Uint16                   suspendFlag;
00288     pUsbEpHandle             hEpObjArray[CSL_USB_ENDPOINT_COUNT];
00290     CSL_UsbSetupStruct       usbSetup;
00293     Uint16                   curConfigStat;
00297     Bool                     usbSpeedCfg;
00298 } CSL_CdcCtrlObject;
00299 
00305 typedef struct CSL_CdcClassStruct {
00307     CSL_CdcCtrlObject    ctrlHandle;
00309     CSL_CdcObject        cdcHandle;
00310 } CSL_CdcClassStruct;
00311 
00313 typedef CSL_CdcClassStruct  *pCdcClassHandle;
00314 
00315 extern CSL_UsbContext     gUsbContext;
00316 extern CSL_UsbRegsOvly    usbRegisters;
00317 
00321 /**************************************************************************\
00322 * USB CDC function declarations                                            *
00323 \**************************************************************************/
00324 
00374 CSL_Status CDC_Open(pCdcAppClassHandle    pAppClassHandle);
00375 
00422 CSL_Status CDC_OpenFullspeed(pCdcAppClassHandle    pAppClassHandle);
00423 
00472 static CSL_Status CDC_Setup(pCdcAppClassHandle    pAppClassHandle,
00473                             Bool                  usbSpeedCfg);
00474 
00519 CSL_Status CDC_Close(pCdcAppClassHandle    pAppClassHandle);
00520 
00566 Uint16 CDC_GetactivityFlagStatus(void    *pCDC);
00567 
00613 Uint16 CDC_GetsuspendFlagStatus(void    *pCDC);
00614 
00673 CSL_CdcRequestRet CDC_eventHandler(pUsbContext pContext, CSL_CdcClassStruct *hCdcClass);
00674 
00729 CSL_Status CDC_bulkOutHandler(pUsbContext pContext, CSL_CdcInitStructApp *cdcAppHandle);
00730 
00779 
00785 CSL_Status CDC_bulkInHandler(pUsbContext pContext, CSL_CdcInitStructApp *cdcAppHandle);
00786 
00845  Uint16 CDC_getData(pUsbContext pContext, CSL_CdcInitStructApp *cdcAppHandle, Uint16 *data);
00846 
00906 Uint16 CDC_putData(pUsbContext pContext, CSL_CdcInitStructApp *cdcAppHandle, Uint16 *data, Uint16 size);
00907 
00913 #ifdef __cplusplus
00914 }
00915 #endif
00916 
00917 #endif    //_CSL_CDC_H_
00918