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

📄 usb_req.c

📁 使用5509A的usb的程序代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************/
/* Copyright (C) 2001  Texas Instruments, Inc.  All Rights Reserved.          */
/*                                                                            */
/*  File Name   : usb_req.c                                                   */
/*  Project     : TMS320VC5509 USB Module Support                             */
/*  Author      : C5000 H/W Applications                                      */
/*                                                                            */
/*  Version     : 0.1                                                         */
/*  Date        : 30 Apr 2001                                                 */
/*  Updated     :                                                             */
/*                                                                            */
/*  Description : USB Chapter 9 standard device request handlers.             */
/*                Users can expand the USB request handling capabilities by   */
/*                adding new members in the USB request table and supplying   */
/*                associated request handler routines.                        */
/*                                                                            */
/******************************************************************************/
/*
 *  USB Test Component Copyright (C) 2004, Spectrum Digital, Inc.  All Rights Reserved.
 */

#include "csl.h"
#include "csl_usb.h"
#include "string.h"
#include "usb_req.h"

#include <csl_gpio.h>
#include <csl_irq.h>

#include "DspSysCfg.h"

#include "DspBoard_const.h"




Uint16 usbCurDevStat    = 0x01;  // Self Powered
Uint16 usbCurConfigStat = 0x00;  // Device start with config = 0
Uint16 usbCurIntrfcStat = 0x00;  // Only interface 0 supported
Uint16 gen_purpose_buffer[7];    // first 2 bytes for xfer byte count
                                 // next 12 bytes are for usb data

/******************************************************************************/
/*                                                                            */
/*       USB descriptors defined in usb_catdscr.c                             */
/*                                                                            */
/******************************************************************************/
extern const Uint16 device_descriptor[];
extern const Uint16 configuration_descriptor[];
extern USB_DataStruct configuration_descriptor_link;
extern Uint16 string_descriptor_langid[];
extern char *string_descriptor[];



// Endpt2BuffLen以byte为单位,为方面后面usb传输用 ----by mark
extern Uint16 Endpt2BuffLen;
extern Uint16 Endpt2Buff[];

/* Spectrum Data */
extern Uint32 mcaData[];
extern Uint32 mcaData512[];
extern Uint32 mcaData1024[];
extern Uint32 mcaData2048[];
extern Uint32 mcaDataCRC[];

/*  Processing Method  */
extern Uint16 indicatorOfProcMeth ;

/*   intput polarity */
extern Uint16 indicatorOfPolarity ;

extern Uint16  indexUSB  ;
extern Uint16  mcaTranLength ;
extern Uint16  nTranContent ; 


/* Variable to indicate whether collecting is going */
extern Bool bCollectingIsOn ;   

/*  Variable to record the variable counts of the events */ 
extern Uint32 nRecordMissed  ;
extern Uint32 nRecordOverFlow  ;
extern Uint32 nRecordCorrect  ;
extern Uint32 nRecordDMA0Miss  ;
extern Uint32 nRecordDMA1Miss ;
extern Uint32 nRecordDMA2Miss ;

/* Variable to assist the Time function */
extern Uint32 nRecordTime ;

extern Uint32 i32 ;

/* Mass Storage Class Request */
#define USB_GET_MAX_LUN             0x80FE
#define USB_MASS_STORAGE_RESET      0xFF


// add by mark
// Request = ((USB_Setup.bmRequestType&0xC0)<<8)|USB_Setup.bRequest;
#define USB_VENDOR_CLEAR            0x400c
#define USB_VENDOR_QUERY            0xC00d
#define USB_VENDOR_SET_INT3         0x400e

#define USB_VENDOR_DEVICE_START     0x4011
#define USB_VENDOR_DEVICE_STOP      0x4012
#define USB_VENDOR_DEVICE_CLEAR     0x4013
#define USB_VENDOR_DEVICE_GET_TIME         0xC014
#define USB_VENDOR_DEVICE_GET_COUNT        0xC015
#define USB_VENDOR_DEVICE_SET_CHANNEL      0x4016
#define USB_VENDOR_DEVICE_GET_CHANNEL      0xC017   
#define USB_VENDOR_DEVICE_START_READ       0x4018
#define USB_VENDOR_DEVICE_SET_PROC_METH    0x4019  
#define USB_VENDOR_DEVICE_GET_PROC_METH    0xC01A   
#define USB_VENDOR_DEVICE_SET_POLARITY     0x401B
#define USB_VENDOR_DEVICE_GET_POLARITY     0xC01C   


USB_REQUEST_RET USB_reqMassStorageReset(USB_REQUEST_ARGS)
{
    /* ======== USB_MASS_STORAGE_RESET ======== */
    /* Respond with no data */
    USB_postTransaction(hInEp, 0, 0, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);

    return(USB_REQUEST_GET_ACK);
}
USB_REQUEST_RET USB_reqGetMaxLun(USB_REQUEST_ARGS)
{
    /* ======== USB_GET_MAX_LUN ======== */
    /* Respond by return N - 1 logical units */

    gen_purpose_buffer[1] = 0;
    USB_postTransaction(hInEp, 1, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);

    return(USB_REQUEST_GET_ACK);
}


// 初始化数据  ---- by mark
USB_REQUEST_RET USB_reqVendorClear(USB_REQUEST_ARGS)
{
    //Uint16       i;
    
    // 初始化 ----by mark 
    //for ( i = 0 ; i < Endpt2BuffLen>>1 ; i++ )
    {
    //    Endpt2Buff[ i ] = 1 ;
    }
    
    return(USB_REQUEST_SEND_ACK);
}


//   ---- by mark
USB_REQUEST_RET USB_reqVendorQuery(USB_REQUEST_ARGS)
{    
//    gen_purpose_buffer[1] = indexI ;
//    bTransferd = USB_postTransaction(hInEp, 2, (void *)&nTemp, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
    USB_postTransaction(hInEp, 2, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);

    return(USB_REQUEST_GET_ACK);    
}

//   ---- by mark
USB_REQUEST_RET USB_reqVendorSetInt(USB_REQUEST_ARGS)
{
    //uiLed = GPIO_RGET( IODATA );    
    //uiLed = uiLed ^ 0x2 ;
    //GPIO_RSET( IODATA , uiLed );
    // change GPIO1   
    //GPIO_RSET( IODATA , ( GPIO_RGET( IODATA ) ^ 0x2 ) );   
	
    return(USB_REQUEST_SEND_ACK);
}


/* Vendor request to start the collecting */
//   ---- by mark    
USB_REQUEST_RET USB_reqVendorDeviceStart(USB_REQUEST_ARGS)
{
    indexUSB = 0 ;        
    
    /* To handshake with CPLD ,indicating the DSP is on */
    GPIO_RSET( IODATA , ( GPIO_RGET( IODATA ) & 0xbf ) );  /* GPIO6="0" */	
	
	IRQ_enable( IRQ_EVT_INT2 ) ;      
	bCollectingIsOn = TRUE ;	
	
	GPIO_RSET( IODATA , ( GPIO_RGET( IODATA ) | 0x42 ) );  /* GPIO6="1", GPIO1="1" */	

    return(USB_REQUEST_SEND_ACK);
}


/* Vendor request to stop the collecting */
//   ---- by mark
USB_REQUEST_RET USB_reqVendorDeviceStop(USB_REQUEST_ARGS)
{
    IRQ_disable( IRQ_EVT_INT2 ) ;   
    bCollectingIsOn = FALSE ;   
    
    GPIO_RSET( IODATA , ( GPIO_RGET( IODATA ) & 0xbd ) );    /* GPIO6="0", GPIO1="0" */
    
    return(USB_REQUEST_SEND_ACK);
}


//   ---- by mark
USB_REQUEST_RET USB_reqVendorDeviceClear(USB_REQUEST_ARGS)
{
    for ( i32 = 0 ; i32 < ChannelAmount ; i32 ++ )
    {        
        mcaData[ i32 ] = 0 ;
    }
        
    for ( i32 = 0 ; i32 < 512 ; i32 ++ )
    {
        mcaData512[ i32 ] = 0 ;    
    }     
        
    for ( i32 = 0 ; i32 < 1024 ; i32 ++ )
    {
        mcaData1024[ i32 ] = 0 ;
        //mcaData1024[ i32 ] = i32+1000 ;    
    }     
        
    for ( i32 = 0 ; i32 < 2048 ; i32 ++ )
    {
        mcaData2048[ i32 ] = 0 ;
    }     
        
    for ( i32 = 0 ; i32 < 15 ; i32 ++ )
    {
        mcaDataCRC[ i32 ] = 0xFFFFFFFF ;
    }
    mcaDataCRC[ 15 ] = 0 ;
    
    nRecordTime = 0 ; 
    nRecordCorrect = 0 ;
    nRecordOverFlow = 0 ;
    nRecordMissed = 0 ;
    nRecordDMA0Miss = 0 ;
    nRecordDMA1Miss = 0 ;
    nRecordDMA2Miss = 0 ;
    
    return(USB_REQUEST_SEND_ACK);
}

//   ---- by mark
// 获取时间,还没有作
// 获取采集时间:命令 0x14,无输入值。返回值时间,暂定1 unsigned int
USB_REQUEST_RET USB_reqVendorDeviceGetTime(USB_REQUEST_ARGS)
{
//    memcpy ( gen_purpose_buffer + 1 , (void *) nRecordTime , 2 );    
    gen_purpose_buffer[1] = nRecordTime & 0xFFFF;
    gen_purpose_buffer[2] = ( nRecordTime & 0xFFFF0000 )>> 16;
    
    USB_postTransaction(hInEp, 4, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
    
    return(USB_REQUEST_GET_ACK);    
}



//   ---- by mark
//  记录脉冲计数,过载脉冲计数,未处理脉冲计数(unsigned int)
USB_REQUEST_RET USB_reqVendorDeviceGetCount(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[1] = nRecordCorrect & 0xFFFF;
    gen_purpose_buffer[2] = ( nRecordCorrect & 0xFFFF0000 )>> 16;
    gen_purpose_buffer[3] = nRecordOverFlow & 0xFFFF;
    gen_purpose_buffer[4] = ( nRecordOverFlow & 0xFFFF0000 )>> 16;
    gen_purpose_buffer[5] = nRecordMissed & 0xFFFF;
    gen_purpose_buffer[6] = ( nRecordMissed & 0xFFFF0000 )>> 16;
    

//    memcpy( gen_purpose_buffer + 3 , (void *)nTemp32 , 2 ) ;
//    memcpy( gen_purpose_buffer + 5 , (void *)&nRecordMissed , 2 ) ;

    USB_postTransaction(hInEp, 12, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
  
    
    return(USB_REQUEST_GET_ACK);    
}


//   ---- by mark
//  设置主机读取缓冲大小
USB_REQUEST_RET USB_reqVendorDeviceSetChannel(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[ 0 ] = (Uint16)(USB_Setup->wValue) ;
    if ( ( gen_purpose_buffer[0]==512 ) |
         (gen_purpose_buffer[0]==1024 ) |
         (gen_purpose_buffer[0]==2048 ) |
         (gen_purpose_buffer[0]==8192 ) )
    {
        mcaTranLength = gen_purpose_buffer[0]  ;
    }
    return(USB_REQUEST_SEND_ACK);
}
 

//   ---- by mark
//  获取主机读取缓冲大小
USB_REQUEST_RET USB_reqVendorDeviceGetChannel(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[1] = mcaTranLength;
        
    USB_postTransaction(hInEp, 2, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
    
    return(USB_REQUEST_GET_ACK);    
}


//   ---- by mark
USB_REQUEST_RET USB_reqVendorDeviceStartRead(USB_REQUEST_ARGS)
{    
    mcaDataCRC[ 15 ] = 0 ;  // clear the last CRC data
    indexUSB = 0;      // first transfer
    nTranContent = 2 ; // data transfer stage
    
    return(USB_REQUEST_SEND_ACK);
}


//   ---- by mark
//  设置当前脉冲幅度获取算法
USB_REQUEST_RET USB_reqVendorDeviceSetProcMeth(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[ 0 ] = (Uint16)(USB_Setup->wValue) ;
    if ( ( gen_purpose_buffer[0]== PROCESSING_TOP_VALUE ) |
         (gen_purpose_buffer[0]== PROCESSING_TR_FILTER ) |
         (gen_purpose_buffer[0]== PROCESSING_3PT_FITTING ) )         
    {
        indicatorOfProcMeth = gen_purpose_buffer[0]  ;
    }
    return(USB_REQUEST_SEND_ACK);
}   

//   ---- by mark
//  获取当前脉冲幅度获取算法
USB_REQUEST_RET USB_reqVendorDeviceGetProcMeth(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[1] = indicatorOfProcMeth;
        
    USB_postTransaction(hInEp, 2, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
    
    return(USB_REQUEST_GET_ACK);     
}  

//   ---- by mark
//  设置当前脉冲输入极性
USB_REQUEST_RET USB_reqVendorDeviceSetPolarity(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[ 0 ] = (Uint16)(USB_Setup->wValue) ;
    if ( ( gen_purpose_buffer[0]== POLARITY_POS ) |         
         (gen_purpose_buffer[0]== POLARITY_NEG ) )         
    {
        indicatorOfPolarity = gen_purpose_buffer[0]  ;
    }
    return(USB_REQUEST_SEND_ACK);
}   

//   ---- by mark
//  获取当前脉冲输入极性
USB_REQUEST_RET USB_reqVendorDeviceGetPolarity(USB_REQUEST_ARGS)
{
    gen_purpose_buffer[1] = indicatorOfPolarity;
        
    USB_postTransaction(hInEp, 2, (void *)&gen_purpose_buffer, USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
    
    return(USB_REQUEST_GET_ACK);     
}  


/******************************************************************************/
/*                                                                            */
/*       USB Request Table.  USB control(enpoint0) parse through this         */
/*       table and calls the routine that matches the request sent by         */
/*       the host.                                                            */
/*                                                                            */
/******************************************************************************/

USB_request_struct USB_ReqTable[] =
{
    { USB_REQUEST_GET_STATUS         , USB_reqGetStatus },
    { USB_REQUEST_CLEAR_FEATURE      , USB_reqClearFeature },
    { USB_REQUEST_SET_FEATURE        , USB_reqSetFeature },

⌨️ 快捷键说明

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