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

📄 ctlsetup.c

📁 台湾凌阳方案300万数码相机源代码
💻 C
字号:
/*++

Copyright (c) 2001 Sunplus Technology Co., Ltd.

Module Name:

        ctlsetup.c

Abstract:

        Module related to setup packet of control pipe

Environment:

        Keil C51 Compiler

Revision History:

        08/28/2001      Chi-Yeh Tsai    created                 

--*/

//=============================================================================
//Header file
//=============================================================================
#include "general.h"
#include "ctlsetup.h"
#include "main.h"
#include "intr.h"
#include "stdreq.h"
#include "vndreq.h"
#include "rsvreq.h"
#include "ctlin.h"
#include "usbaudc.h"
#include "usbsidc.h"
#include "usbmsdc2.h"
#include "uiflow.h"

//=============================================================================
//Symbol
//=============================================================================
//-----------------------------------------------------------------------------
//Constant
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//Variable
//-----------------------------------------------------------------------------
PCTRL_COMMAND   G_pCtrlCommand;

idata   USHORT  G_usCtrlDataLength = 0;
idata   USHORT  G_usCtrlDataIndex = 0;
idata   UCHAR   G_ucCtrlPacketIndex = 0;
idata   UCHAR   G_UsbConnectStatus = 1; //@WYEO, 1008

xdata   UCHAR   G_ucCtrlPhase;

//=============================================================================
//Program
//=============================================================================
//-----------------------------------------------------------------------------
//CTLSETUP_Packet
//-----------------------------------------------------------------------------
void CTLSETUP_Packet(void) USING_1
/*++

Routine Description:

        process setup packet of control pipe

Arguments:

        none

Return Value:

        none

--*/
{
        UCHAR type;

        if (G_ucCtrlPhase != K_CommandPhase)
        {
                //phase transition error - setup packet should not appear
                //                         at current phase
                //Since hardware will reset the control pipe whenever
                //setup packet arrives, we just force the phase to command phase.
                G_ucCtrlPhase = K_CommandPhase;
        }

        CTLSETUP_GetSetupPacket();      //read setup packet

        G_usCtrlDataLength = G_pCtrlCommand->wLength;
        G_usCtrlDataIndex = 0x0000;

        //check Type of bmRequestType
        type = G_pCtrlCommand->bmRequestType & 0x60;
        if (type == 0x00)
        {
                CTLSETUP_StandardRequest();     //Standard Request
        }
        else if (type == 0x20)
        {
                CTLSETUP_ClassRequest();        //Class Request
        }
        else if (type == 0x40)
        {
                CTLSETUP_VendorRequest();       //Vendor Request
        }
        else //if (type == 0x60)
        {
                CTLSETUP_ReservedRequest();     //Reserved Request
        }
}

//-----------------------------------------------------------------------------
//CTLSETUP_StandardRequest
//-----------------------------------------------------------------------------
void CTLSETUP_StandardRequest(void) USING_1
/*++

Routine Description:

        process standard request of setup packet

Arguments:

        none

Return Value:

        none

--*/
{
        UCHAR xferDir;

        xferDir = G_pCtrlCommand->bmRequestType & 0x80;

        if (G_pCtrlCommand->wLength == 0)     //no data transaction
        {
                STDREQ_NoDataPhase();
                G_ucCtrlPhase = K_InResponsePhase;
                CTLIN_Packet();
        }
        else                    //data transaction
        {
                if (xferDir == 0x80)
                {
                        //in followed
                        STDREQ_PreInDataPhase();
                        G_ucCtrlPhase = K_InDataPhase;
                        CTLIN_Packet();
                }
                else
                {
                        //out followed
                        STDREQ_PreOutDataPhase();
                        G_ucCtrlPhase = K_OutDataPhase;
                }
        }
}

//-----------------------------------------------------------------------------
//CTLSETUP_ClassRequest
//-----------------------------------------------------------------------------
void CTLSETUP_ClassRequest(void) USING_1
/*++

Routine Description:

        process class request of setup packet

Arguments:

        none

Return Value:

        none

--*/
{
        UCHAR xferDir;

        xferDir = G_pCtrlCommand->bmRequestType & 0x80;

#if (USBMSDC_OPTION == 1)       //Mass Storage Device Class (Control/Bulk/Interrupt)
        if (((G_pCtrlCommand->wIndex == K_StorageInterface1) ||  //reserved:0 / bInterfaceNumber:K_StorageInterface1
             (G_pCtrlCommand->wIndex == K_StorageInterface2)) && //reserved:0 / bInterfaceNumber:K_StorageInterface2
            (G_pCtrlCommand->bRequest == 0x00) &&     //device-specific request code
            (G_pCtrlCommand->wValue == 0x0000))       //reserved:0
        {
                if (G_pCtrlCommand->wLength == 0)     //no data transaction
                {
                        USBMSDC_CbiNoDataPhase();
                        G_ucCtrlPhase = K_InResponsePhase;
                        CTLIN_Packet();
                }
                else                    //data transaction
                {
                        if (xferDir == 0x80)
                        {
                                //in followed
                                USBMSDC_CbiPreInDataPhase();
                                G_ucCtrlPhase = K_InDataPhase;
                                CTLIN_Packet();
                        }
                        else
                        {
                                //out followed
                                USBMSDC_CbiPreOutDataPhase();
                                G_ucCtrlPhase = K_OutDataPhase;
                        }
                }
        }
#endif

#if (USBMSDC_OPTION == 2)       //Mass Storage Device Class (Bulk-Only)
//richie@0204
//        if (((G_pCtrlCommand->wIndex == K_StorageInterface1) ||  //reserved:0 / bInterfaceNumber:K_StorageInterface1
//             (G_pCtrlCommand->wIndex == K_StorageInterface2)) && //reserved:0 / bInterfaceNumber:K_StorageInterface2
//             (G_pCtrlCommand->wValue == 0x0000))       //reserved:0
	//if (G_ui_status == K_UI_mass_storage)
        if ( ((G_UIStatus & 0xff00) == K_UISTATUS_USBMODE_MASS)  //yichang@replace
	   && (G_CameraOptions.Storage == K_UIOPTION_STORAGE_MSDC) )	
        {
                if (G_pCtrlCommand->wLength == 0)     //no data transaction
                {
                        USBMSDC_BoNoDataPhase();
                        G_ucCtrlPhase = K_InResponsePhase;
                        CTLIN_Packet();
                }
                else                    //data transaction
                {
                        if (xferDir == 0x80)
                        {
                                //in followed
                                USBMSDC_BoPreInDataPhase();
                                G_ucCtrlPhase = K_InDataPhase;
                                CTLIN_Packet();
                        }
                        else
                        {
                                //out followed
                                USBMSDC_BoPreOutDataPhase();
                                G_ucCtrlPhase = K_OutDataPhase;
                        }
                }
        }
#endif

#if (USBSIDC_OPTION == 1)       //Still Image Device Class (PIMA-15740)
//        if ((G_pCtrlCommand->wIndex == 0x0000) &&     //value:0
//            (G_pCtrlCommand->wValue == 0x0000))       //value:0
//richie@si0417
//	if (G_ui_status == K_UI_still_image_class)
        if ( ((G_UIStatus & 0xff00) == K_UISTATUS_USBMODE_MASS)  //yichang@replace
						//patch4.1@richie@0516
	   && (G_CameraOptions.Storage == K_UIOPTION_STORAGE_SIDC) )	
        {
                if (G_pCtrlCommand->wLength == 0)     //no data transaction
                {
                        USBSIDC_NoDataPhase();
                        G_ucCtrlPhase = K_InResponsePhase;
                        CTLIN_Packet();
                }
                else                    //data transaction
                {
                        if (xferDir == 0x80)
                        {
                                //in followed
                                USBSIDC_PreInDataPhase();
                                G_ucCtrlPhase = K_InDataPhase;
                                CTLIN_Packet();
                        }
                        else
                        {
                                //out followed
                                USBSIDC_PreOutDataPhase();
                                G_ucCtrlPhase = K_OutDataPhase;
                        }
                }
        }
#endif

#if (USBAUDC_OPTION == 1)       //Audio Device Class
        if ((G_pCtrlCommand->wIndex & 0x000f) == K_AudioControlInterface) //Interface:K_AudioControlInterface
        {
                if (G_pCtrlCommand->wLength == 0)     //no data transaction
                {
                        USBAUDC_NoDataPhase();
                        G_ucCtrlPhase = K_InResponsePhase;
                        CTLIN_Packet();
                }
                else                    //data transaction
                {
                        if (xferDir == 0x80)
                        {
                                //in followed
                                USBAUDC_PreInDataPhase();
                                G_ucCtrlPhase = K_InDataPhase;
                                CTLIN_Packet();
                        }
                        else
                        {
                                //out followed
                                USBAUDC_PreOutDataPhase();
                                G_ucCtrlPhase = K_OutDataPhase;
                        }
                }
        }
#endif
}

//-----------------------------------------------------------------------------
//CTLSETUP_VendorRequest
//-----------------------------------------------------------------------------
void CTLSETUP_VendorRequest(void) USING_1
/*++

Routine Description:

        process vendor request of setup packet

Arguments:

        none

Return Value:

        none

--*/
{
        UCHAR xferDir;

        xferDir = G_pCtrlCommand->bmRequestType & 0x80;

        if (G_pCtrlCommand->wLength == 0)     //no data transaction
        {
                VNDREQ_NoDataPhase();
                G_ucCtrlPhase = K_InResponsePhase;
                CTLIN_Packet();
        }
        else                    //data transaction
        {
                if (xferDir == 0x80)
                {
                        //in followed
                        VNDREQ_PreInDataPhase();
                        G_ucCtrlPhase = K_InDataPhase;
                        CTLIN_Packet();
                }
                else
                {
                        //out followed
                        VNDREQ_PreOutDataPhase();
                        G_ucCtrlPhase = K_OutDataPhase;
                }
        }
}

//-----------------------------------------------------------------------------
//CTLSETUP_ReservedRequest
//-----------------------------------------------------------------------------
void CTLSETUP_ReservedRequest(void) USING_1
/*++

Routine Description:

        process reserved request of setup packet

Arguments:

        none

Return Value:

        none

--*/
{
        UCHAR xferDir;

        xferDir = G_pCtrlCommand->bmRequestType & 0x80;

        if (G_pCtrlCommand->wLength == 0)     //no data transaction
        {
                RSVREQ_NoDataPhase();
                G_ucCtrlPhase = K_InResponsePhase;
                CTLIN_Packet();
        }
        else                    //data transaction
        {
                if (xferDir == 0x80)
                {
                        //in followed
                        RSVREQ_PreInDataPhase();
                        G_ucCtrlPhase = K_InDataPhase;
                        CTLIN_Packet();
                }
                else
                {
                        //out followed
                        RSVREQ_PreOutDataPhase();
                        G_ucCtrlPhase = K_OutDataPhase;
                }
        }
}

//-----------------------------------------------------------------------------
//CTLSETUP_GetSetupPacket
//-----------------------------------------------------------------------------
void CTLSETUP_GetSetupPacket(void) USING_1
/*++

Routine Description:

        get data for current setup packet

Arguments:

        none

Return Value:

        length of bulk out packet

--*/
{
        UCHAR i;

        for (i = 0; i < K_CTRL_COMMAND_SIZE; i++)
                G_ucCtrlCommand[i] = XBYTE[0x2500];
        G_pCtrlCommand = (PCTRL_COMMAND) G_ucCtrlCommand;
        G_pCtrlCommand->wValue = M_ByteSwapOfWord(G_pCtrlCommand->wValue);
        G_pCtrlCommand->wIndex = M_ByteSwapOfWord(G_pCtrlCommand->wIndex);
        G_pCtrlCommand->wLength = M_ByteSwapOfWord(G_pCtrlCommand->wLength);
}

⌨️ 快捷键说明

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