gio_usbtest.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:4k
- /*
- * 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.10.00.23 07-02-03 (ddk-b12)" */
- /*
- * ======== gio_usbtest.c ========
- *
- * This example demonstrates the use of the USB IOM driver with GIO APIs and
- * USB mini-driver.
- * This is the loopback application where data is read
- * from an input GIO channel, then sent back via an output channel.
- *
- * The following objects need to be created in the DSP/BIOS
- * configuration for this application:
- *
- * * A UDEV object, which links in a user device driver. In this
- * case the UDEV is the USB IOM device driver.
- * * A TSK object, with the function to run the function defined in this file.
- * * A LOG named trace for debug and status output.
- * * A SEM object used to block until the USB bus is connected. See
- * GIO_control(readChan, C5509_USB_DEVICECONNECT,...); */
- #include <std.h>
- #include <gio.h>
- #include <iom.h>
- #include <log.h>
- #include <sem.h>
- #include <sys.h>
- #include <c5509_usb.h>
- #define DATASIZE 32 /* data size in madus */
- #define USBBUFSIZE (DATASIZE + 1) /* first word reserved for transfer size */
- /*
- * statically configured objects
- */
- extern LOG_Obj trace;
- extern SEM_Obj usbDeviceConnect; /* sem posted when host enumerates bus */
- Void main()
- {
- LOG_printf(&trace, "test started");
- }
- /*
- * ======== myUsbTask ========
- * This task is set by cdb config tool to start IO
- */
- Void myUsbTask()
- {
- Int status;
- Uns usbBuf[USBBUFSIZE];
- Uns requestSize;
- GIO_Handle readChan, writeChan;
- C5509_USB_AppCallback deviceConnectCb = {
- (C5509_USB_TappCallback)SEM_post,
- &usbDeviceConnect /* semaphore to post when connected */
- };
- C5509_USB_StateInfo info;
- /* create bulk type dsp input channel for USB OUT(from host) endpoint #2 */
- readChan = GIO_create( "/udevUsb2", IOM_INPUT, NULL, NULL, NULL);
- if (readChan == NULL) {
- SYS_abort("Create input channel FAILED.");
- }
-
- /* create bulk type dsp output channel for USB IN(to host) endpoint #2 */
- writeChan = GIO_create( "/udevUsb2", IOM_OUTPUT, NULL, NULL, NULL);
-
- if (writeChan == NULL ) {
- SYS_abort("Create output channel FAILED.");
- }
- /*
- * Connect the device to the host.
- * The deviceConnectCb Fxn(SEM_post) will get called with arg(sem handle)
- * when connection is made(host enumerated bus) or immediately called if
- * bus is already connected.
- */
- GIO_control(readChan, C5509_USB_DEVICECONNECT, &deviceConnectCb);
- SEM_pend(&usbDeviceConnect, SYS_FOREVER);/* block until bus is connected */
- GIO_control(readChan, C5509_USB_GETSTATEINFO, &info);
- LOG_printf(&trace, "current USB config # = %dn", info.usbCurConfig);
- for (;;) {
- requestSize = DATASIZE; /* data request size */
-
- /* wait for data on this channel */
- status = GIO_read(readChan, &usbBuf, &requestSize);
- if (status != IOM_COMPLETED) {
- SYS_abort("GIO_read FAILED.");
- }
- /*
- * Do any data processing here.
- * Note: The first field of usbBuf contains the actual
- * USB data byte count. This count field is used by the USB device.
- */
- /* echo data back to host */
- status = GIO_write(writeChan, &usbBuf, &requestSize);
- if (status != IOM_COMPLETED) {
- SYS_abort("GIO_write FAILED.");
- }
- }
- }