c5509_usb_control.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:6k
- /*
- * 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_mdControlChan.c ========
- * This file inmplements the _mdControlChan() function
- */
- #include <std.h>
- #include <hwi.h>
- #include <csl.h>
- #include <csl_usb.h>
- #include <_c5509_usb.h>
- #include <c5509_usb.h>
- /*
- * ======== connectDevice ========
- * This function calls USB_connectDev to pull up D+ wire so that bus
- * enumeration starts by the host.
- * Call with INTRs enabled.
- */
- Void connectDevice(C5509_USB_ChanHandle chan, C5509_USB_AppCallback * cbFxn)
- {
-
- USB_connectDev(USB0); /* connect it to upstream port */
- if (cbFxn != NULL) {
- /* save away fxn and arg to call when we are connected */
- chan->fxnConnect = cbFxn->fxn;
- chan->argConnect = cbFxn->arg;
- /*
- * Check if host has already enumerated USB.
- * busConnected is set after host reads the USB config desc.
- */
- if (_C5509_USB_devObj.busConnected == TRUE) {
- /* call connect fxn with arg */
- chan->fxnConnect(chan->argConnect);
- }
- }
- else {
- /* no callback specified so spin until bus connected ! */
- while (_C5509_USB_devObj.busConnected == FALSE);
- }
- }
- /*
- * ======== _C5509_USB_freeAllPackets ========
- * This function is called to free packets and complete IOM_FLUSH
- * for all channels
- */
- Void _C5509_USB_freeAllPackets()
- {
- Int i;
- C5509_USB_ChanHandle chan;
-
- for (i=1; i < _C5509_USB_ENDPTNUMS; i++) {
- chan = _C5509_USB_devObj.chans[i];
- if (chan) {
-
- /* abort all pending I/Os */
- _C5509_USB_removePackets( chan, IOM_ABORTED );
-
- /* complete IOM_FLUSH if any */
- _C5509_USB_flushPacketHandler( chan, chan->flushPacket );
- }
- }
- }
- /*
- * ========= resetDevice ========
- * This function is called to reset the USB device.
- * Call with INTRs disabled.
- */
- Void resetDevice()
- {
-
- /* stop all data transfer activities */
- USB_abortAllTransaction(USB0);
-
- /* reset device h/w and disconnect it from host */
- USB_resetDev(USB0);
-
- /* return packets and complete IOM_FLUSH for all channels */
- _C5509_USB_freeAllPackets();
- _C5509_USB_devObj.busConnected = FALSE;
- }
- /*
- * ======== _C5509_USB_reInitUsb ========
- * This function re-initializes usb module, set device state to default state.
- */
- Void _C5509_USB_reInitUsb()
- {
- /* reset device config number */
- _C5509_USB_devObj.stateInfo.usbCurConfig = 0x00;
-
- /* reset Alt Setting number */
- _C5509_USB_devObj.stateInfo.usbCurAltSet = 0x00;
-
- /* reconfig the USB module */
- USB_init(USB0, &_C5509_USB_devObj.eps[0], _C5509_USB_devParams->pSofTmrCnt);
- }
- /*
- * ======== _C5509_USB_mdControlChan ========
- * This function preforms various device dependent operations.
- *
- * chanp is the point to the chanObj
- *
- * cmd is the control command
- *
- * args is the optional argument.
- *
- *
- * IOM_CHAN_RESET and IOM_CHAN_TIMEDOUT are handled in the same way.
- * It aborts all pending I/Os and completes any IOM_FLUSHing .
- *
- * IOM_DEVICE_RESET dis-connects the device from host, aborts all
- * pending I/Os, completes all IOM_FLUSHes.
- * It then re-init the usb module. After that, application should
- * re-create channels and re-connect device to start I/O again.
- *
- * C5509_USB_DEVICECONNECT call connectDevice to re-start bus enumeration.
- *
- * C5509_USB_GETSTATEINFO returns USB state information in the
- * C5509_USB_StateInfo structure passed in by the application provide arg.
- * If arg is NULL an error status is returned.
- */
- Int _C5509_USB_mdControlChan(Ptr chanp, Uns cmd, Ptr args)
- {
- C5509_USB_ChanHandle chan = chanp;
- Uns imask;
- C5509_USB_AppCallback * connectCb;
- C5509_USB_StateInfo * stateInfo;
- Int status = IOM_COMPLETED;
-
- switch(cmd) {
- case IOM_CHAN_RESET:
- case IOM_CHAN_TIMEDOUT:
-
- /* discard all pending IO packets */
- imask = HWI_disable(); /* disable INTRs */
- _C5509_USB_removePackets(chan, IOM_ABORTED);
- _C5509_USB_flushPacketHandler( chan, chan->flushPacket);
- HWI_restore(imask);
- break;
- case IOM_DEVICE_RESET:
- imask = HWI_disable(); /* disable INTRs */
- resetDevice(); /* reset device */
- HWI_restore(imask);
- /*
- * re-init usb module, set state to default
- */
- _C5509_USB_reInitUsb();
- break;
- case C5509_USB_DEVICECONNECT:
- connectCb = args;
- connectDevice(chan, connectCb); /* connect the device */
- break;
-
- case C5509_USB_GETSTATEINFO:
-
- if (args == NULL) {
- return (IOM_EBADARGS);
- }
-
- stateInfo = (C5509_USB_StateInfo *)args;
- imask = HWI_disable(); /* disable INTRs */
- *stateInfo = _C5509_USB_devObj.stateInfo; /* copy to user struct */
- HWI_restore(imask);
- break;
- default:
- status = IOM_ENOTIMPL; /* cmd has not been implemented */
- break;
- } /* end switch */
- return status;
- }