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

📄 iusbprocesscommand.c.bak

📁 How to control USB interface under SZ platform
💻 BAK
字号:
#include "USB_pptt.h"
#include "USB_pdef.h"
#include "USB_pvar.h"
#include "DMA_pptt.h"

U8      _gUsbDrvNum;
U16     _gUsbDrvBuf[2][256];
U8      _gUsbCurBuf;
P_U16   _gpUsbBufPtr;
U8      _gUsbNumSector;
U16     _gUsbCurSector;
U8      _gUsbPacketCount;

const U16 _gUsbDrvParam[256] = {
    0x80,0x00,0xF4,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 

    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
    };
    
void _iUsbProcessCommand()
{
    U16 command[4];
    U8  i;
    
    /* get command from endpoint FIFO */
    for (i=0; i<4; i++)
    {
        command[i] = _reg_USB_EP3_FDAT;
    }

    /* extract start sector and number of sectors */    
    _gUsbCurSector = ((command[1] & 0xFF) << 8) | ((command[1] >> 8) & 0xFF);
    _gUsbNumSector = command[0] & 0xFF;
    _gUsbDrvNum = (((U8) command[2]) >> 4) & 1;
        
    /* handle various commands */
    if ((command[2] & 0x00A0) == 0x00A0)    // i.e. read drive parameters
    {
        if (_gUsbDrvStatus[_gUsbDrvNum] == USB_DRV_NOT_READY)
        {
            _reg_USB_EP4_FCTRL |= 0x20000000;
            _reg_USB_EP4_FDAT = 0xFF04; // drive not ready
        }
        else    // i.e. status == USB_DRV_READY
        {
            if ((*((_gUsbCallbacks->Drv[_gUsbDrvNum]).driveStatus))() ==
                USB_DRV_NOT_READY)
            {
                _reg_USB_EP4_FCTRL |= 0x20000000;
                _reg_USB_EP4_FDAT = 0xFF04; // drive not ready
            }
            else
            {
                // This command read the parameter of the disk.
                // The parameter block is not originally stored in the file system.
                // However, to simply the operation, we make use of an unused
                // sector (sector 16) to store the parameter of the disk.
                // And then, we pretend that it is a ordinally file system read
                // operation to return the data requested
                _gUsbNumSector = 0;     // no need to read from disk
                _gpUsbBufPtr = (P_U8)&_gUsbDrvParam[0];
                command[2] = 0x00F0;
            }
        }
    }

    if ((command[2] & 0x00E0) == 0x00E0)    // i.e. disk read/write
    {
        if (_gUsbMode == USB_USE_INTR_ONLY)
        {
            if (command[3] == 0x2001)       // i.e. read operation */
            {
                if (_gUsbNumSector > 0)     // read data to buffer
                {
                    _gUsbCurBuf = 0;
                    _gpUsbBufPtr = (P_U8)&_gUsbDrvBuf[0][0];
                    _iUsbReadSector(0);
                    if (_gUsbNumSector > 0)
                        _iUsbReadSector(1);
                }
                _gUsbPacketCount = 0;   // count #packets tx'ed
                // write first 2 packets to FIFO
                for (i=0; i<31; i++)
                {
                    _reg_USB_EP4_FDAT = _gpUsbBufPtr;
                }
                _gUsbPacketCount++;
                _reg_USB_EP4_FCTRL |= 0x20000000;   // next write is last one in packet
                _reg_USB_EP4_FDAT = _gUsbDrvBuf[_gUsbCurBuf][31];

                for (i=0; i<31; i++)
                {
                    _reg_USB_EP4_FDAT = _gUsbDrvBuf[_gUsbCurBuf][32+i];
                }
                _reg_USB_EP4_FCTRL |= 0x20000000;   // next write is last one in packet
                _reg_USB_EP4_FDAT = _gUsbDrvBuf[_gUsbCurBuf][63];
                _reg_USB_EP4_MASK = ENABLE_EOF; // enable EOF interrupt
            }
/*                else    // write operation
                {
                    _gUsbCounter = _gUsbNumSector*8;
                    _reg_USB_EP3_MASK = ENABLE_EOT & ENABLE_EOF;
                    // EOT interrupt is for command and EOF interrupt is for data
                }            
*/                
        }
/*        
        else    // i.e. USB_USE_DMA
        {
                if (command[3] == 0x2001)  // i.e. read operation
                {
                    _gUsbDMAconfig.RequestSource = USB_DMA_SOURCE_EP4;
                    _gUsbDMAconfig.Mask = DMA_REQUESTSOURCE;
                    _DmaConfigChannel(_gUsbDMAchNum, (P_DMA_CONFIG)&_gUsbDMAconfig);
                    _DmaStartTransfer(_gUsbDMAchNum, (P_VOID)(_gpUsbReadWrite), 
                                      (P_VOID)_reg_USB_EP4_FDAT, _gUsbNumSector*512, DMA_MEMTOIO);
                }
                else    // write operation
                {
                    _gUsbDMAconfig.RequestSource = USB_DMA_SOURCE_EP3;
                    _gUsbDMAconfig.Mask = DMA_REQUESTSOURCE;
                    _DmaConfigChannel(_gUsbDMAchNum, (P_DMA_CONFIG)&_gUsbDMAconfig);
                    _DmaStartTransfer(_gUsbDMAchNum, (P_VOID)_reg_USB_EP3_FDAT, 
                                      (P_VOID)(_gpUsbReadWrite), _gUsbNumSector*512, DMA_IOTOMEM);
                }
        }                
*/        
    }
}

⌨️ 快捷键说明

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