⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c5509_usb_bind.c

📁 DSP/BIOS Driver Developer Kit 1.11 The DSP/BIOS Driver Developer Kit (DDK) provides a selection of
💻 C
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DDK 1.11.00.00 11-04-03 (ddk-b13)" */
/*
 *  ======== c5509_usb_bind.c ========
 *  This file implements _mdBindDev function.
 */

#include <std.h>

#include <hwi.h>
#include <iom.h>
#include <csl.h>
#include <csl_usb.h>
#include <c5509_usb.h>
#include <_c5509_usb.h>


/*
 *  ======== control endpoint 0  ========
 *  They are accessed internally in mini-driver code.
 */
USB_EpObj _C5509_USB_usbEpObjIn0, _C5509_USB_usbEpObjOut0;

/*  
 *  ======== global C5509_USB device object ========
 */
_C5509_USB_DevObj _C5509_USB_devObj = {


    FALSE,    /* bus connected if TRUE */
    0,        /* last chapter 9 request */
    /* 
     * channel object handles
     */
    { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },

    /* 
     * Null terminated endpoint ptr array used for CSL initialization
     */
    { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },

    /*
     * USB state information C5509_USB_StateInfo.
     */
    {0,        /* current configuration number */
     0,        /* current interface number */ 
     0,        /* current alternate set number */
     1}        /* current device state, self powered */ 

};


/*
 * ======== _C5509_USB_devParams ========
 *  This pointer points to the device parameter passed by user as a 
 *  parameter of _C5509_USB_mdBindDev(...)
 */
C5509_USB_DevParams *_C5509_USB_devParams;

  
/*  
 * ======== control endpoint 0 handler ========
 *  This function is defined in file c5509_usbiom_usbctrl.c.
 */
extern Void _C5509_USB_usbCtrlHandler();

/*
 * ======== endpoint out 1 handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_OUT_EP1] due
 *   to lack of context parameter in EP handler function call.
 */
static Void endptOut1Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP1] );
}

/*
 * ======== endpoint out 2 handler ========
 *  We need the wrapper to pass __C5509_USB_devObj.chans[USB_OUT_EP2]
 */
static Void endptOut2Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP2] );
}

/*
 * ======== endpoint out 3 handler ========
 *  We need the wrapper to pass __C5509_USB_devObj.chans[USB_OUT_EP3]
 */
static Void endptOut3Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP3] );
}

/*
 * ======== endpoint out 4 handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_OUT_EP4]
 */
static Void endptOut4Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP4] );
}

/*
 * ======== endpoint out 5 handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_OUT_EP5]
 */
static Void endptOut5Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP5] );
}

/*
 * ======== endpoint out 6 handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_OUT_EP6]
 */
static Void endptOut6Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP6] );
}

/*
 * ======== endpoint out 7 handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_OUT_EP7]
 */
static Void endptOut7Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_OUT_EP7] );
}

/*
 * ======== endpoint in 1  handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP1]
 */
static Void endptIn1Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP1] );
}

/*
 * ======== endpoint in 2  handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP2]
 */
static Void endptIn2Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP2] );
}

/*
 * ======== endpoint in 3  handler ========
 * We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP3]
 */
static Void endptIn3Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP3] );
}

/*
 * ======== endpoint in 4 handler ========
 * We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP4]
 */
static Void endptIn4Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP4] );
}

/*
 * ======== endpoint in 5  handler ========
 * We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP5]
 */
static Void endptIn5Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP5] );
}

/*
 * ======== endpoint in 6  handler ========
 * We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP6]
 */
static Void endptIn6Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP6] );
}

/*
 *  ======== endpoint in 7  handler ========
 *  We need the wrapper to pass _C5509_USB_devObj.chans[USB_IN_EP7]
 */
static Void endptIn7Handler( Void ) {
    _C5509_USB_transactionHandler( _C5509_USB_devObj.chans[USB_IN_EP7] );
}

typedef Void (*EndptHandler)();  /* function pointer type */
/*
 *  ======== Endpoint handler function pointer table ========
 */
static EndptHandler endptHandler[_C5509_USB_ENDPTNUMS] = {
    _C5509_USB_usbCtrlHandler, endptOut1Handler, endptOut2Handler,
    endptOut3Handler, endptOut4Handler, endptOut5Handler, endptOut6Handler,
    endptOut7Handler, _C5509_USB_usbCtrlHandler, endptIn1Handler, endptIn2Handler,
    endptIn3Handler, endptIn4Handler, endptIn5Handler, endptIn6Handler,
    endptIn7Handler
};

/*  
 *  ======== _C5509_USB_mdBindDev ========
 *  It is called during DSP/BIOS initialization to initialize device
 *
 *  *devp is used to output global device object to IOM
 *
 *  devid is device id.
 *
 *  devParams is the device parameter. There is no default device 
 *  parameter. User is required to pass the proper device parameter so 
 *  that the necessary init work can be done.  
 */  
Int _C5509_USB_mdBindDev(Ptr *devp, Int devid, Ptr devParams)
{
    C5509_USB_EpConfig * cfgPtr;
    Int16 i;
    HWI_Attrs hwiAttrs = HWI_ATTRS;
    Int16 status;
    
                      
    *devp = &_C5509_USB_devObj; /* internal device object */

    if (devParams == NULL) {
        return IOM_EBADARGS;
    }

     _C5509_USB_devParams = devParams;

    /*
     * Check for supported driver version(s)
     */
    if (_C5509_USB_devParams->versionId > C5509_USB_VERSION_1) {
        return IOM_EBADIO;
    }
   
   

    /* 
     *  API vector address must be initialized before calling any USB API.
     */
    USB_setAPIVectorAddress(); 

    USB_initPLL(_C5509_USB_devParams->inclk, _C5509_USB_OUTCLK48MHZ, \
            _C5509_USB_devParams->plldiv);    /* init USB clock */ 

    /*
     *  init reserved endpoints EP0 OUT & EP0 IN.
     */
    _C5509_USB_devObj.eps[0] = &_C5509_USB_usbEpObjOut0;
    USB_initEndptObj( USB0, &_C5509_USB_usbEpObjOut0, USB_OUT_EP0, USB_CTRL, 
            _C5509_USB_EP0RSVDSIZE, _C5509_USB_EP0RSVDMASK, 
            _C5509_USB_usbCtrlHandler);

    _C5509_USB_devObj.eps[1] = &_C5509_USB_usbEpObjIn0;
    USB_initEndptObj(USB0, &_C5509_USB_usbEpObjIn0, USB_IN_EP0, USB_CTRL, 
            _C5509_USB_EP0RSVDSIZE, _C5509_USB_EP0RSVDMASK, 
            _C5509_USB_usbCtrlHandler);

    
    cfgPtr =  _C5509_USB_devParams->ifcConfig->epConfig;

    for (i = 0; i < _C5509_USB_devParams->ifcConfig->numEps; i++, cfgPtr++) {

        _C5509_USB_devObj.eps[i + _C5509_USB_NUMEPSRSVD] =  &cfgPtr->chanp->epObj;
       /*
        * init configured endpoints.
        */

        USB_initEndptObj(USB0, &cfgPtr->chanp->epObj, cfgPtr->epNum, 
                cfgPtr->epType, cfgPtr->epMaxPktLen,
                cfgPtr->epEvtMask, endptHandler[cfgPtr->epNum]);
    }

    /* init usb module. Only single device(USB0) supported by CSL */
    status = USB_init(USB0, &_C5509_USB_devObj.eps[0], 
            _C5509_USB_devParams->pSofTmrCnt);

    if (status != USB_TRUE) {
        return (IOM_EBADIO);        
    }
       
    /*  
     * Plug & enable the USB device interrupt.
     * For C55x if both ierx masks are equal to one, then mask only self intr.
     */
    hwiAttrs.ier0mask = _C5509_USB_devParams->ier0mask;
    hwiAttrs.ier1mask = _C5509_USB_devParams->ier1mask;
    
    HWI_dispatchPlug(IRQ_EVT_USB, (Fxn)USB_evDispatch, &hwiAttrs);

    IRQ_enable(IRQ_EVT_USB);
    
    return (IOM_COMPLETED);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -