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

📄 gio_usbtest.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)" */
/* 
 *  ======== 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 # = %d\n", 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.");
        }
    }
}


⌨️ 快捷键说明

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