www.pudn.com > camera.rar > Cameradriver_.cpp


 
 
#include  
#include  
#include  
#include  
 
#include "Cs.h" 
#include "Csmedia.h" 
 
#include "CameraPDDProps.h" 
#include "dstruct.h" 
#include "dbgsettings.h" 
#include "CameraDriver.h" 
#include "BSP_CommonDefs.h" 
#include "PMIC_DRV.h" 
 
 
 
/* 
EXTERN_C 
BOOL CAM_PowerUp  (DWORD context)  
{ 
    NKDbgPrintfW(L"CAM_PowerUp+ %x\r\n", context); 
    CEDEVICE_POWER_STATE state = D0; 
    DWORD bytes; 
    CAMERADEVICE     * pCamDevice     = reinterpret_cast(context); 
 
    pCamDevice->AdapterHandlePowerRequests(IOCTL_POWER_SET,  
                                           0, 0, 
                                           (PUCHAR)&state, sizeof(state),  
                                           &bytes ); 
 
    NKDbgPrintfW(L"CAM_PowerUp-\r\n", context); 
 
    return 1; 
} 
 
EXTERN_C 
BOOL CAM_PowerDown(DWORD context)  
{ 
    NKDbgPrintfW(L"CAM_PowerDown+ %x\r\n", context); 
    CEDEVICE_POWER_STATE state = D4; 
    DWORD bytes; 
 
    CAMERADEVICE     * pCamDevice     = reinterpret_cast(context); 
     
    pCamDevice->AdapterHandlePowerRequests(IOCTL_POWER_SET,  
                                           0, 0, 
                                           (PUCHAR)&state, sizeof(state),  
                                           &bytes ); 
    NKDbgPrintfW(L"CAM_PowerDown-\r\n"); 
    return 1; 
} 
*/ 
 
 
 
/****************************** 
 
Purpose: To fix MS bug of power control 
Date:      20071109 
 
******************************/ 
 
EXTERN_C 
BOOL 
CAM_IOControl_COPY( 
    DWORD   dwContext, 
    DWORD   Ioctl, 
    UCHAR * pInBufUnmapped, 
    DWORD   InBufLen,  
    UCHAR * pOutBufUnmapped, 
    DWORD   OutBufLen, 
    DWORD * pdwBytesTransferred 
   ) 
{ 
    DEBUGMSG( ZONE_FUNCTION, ( _T("CAM_IOControl_COPY(%08x): IOCTL:0x%x, InBuf:0x%x, InBufLen:%d, OutBuf:0x%x, OutBufLen:0x%x)\r\n"), dwContext, Ioctl, pInBufUnmapped, InBufLen, pOutBufUnmapped, OutBufLen ) ); 
 
    UCHAR * pInBuf = NULL; 
    UCHAR * pOutBuf = NULL; 
    DWORD dwErr = ERROR_INVALID_PARAMETER; 
    BOOL  bRc   = FALSE; 
 
	pInBuf = pInBufUnmapped; 
	pOutBuf = pOutBufUnmapped; 
 
	 
    CAMERAOPENHANDLE * pCamOpenHandle = reinterpret_cast( dwContext ); 
    CAMERADEVICE     * pCamDevice     = pCamOpenHandle->pCamDevice; 
    CSPROPERTY       * pCsProp        = reinterpret_cast(pInBuf); 
 
	 
    switch ( Ioctl ) 
    { 
        // Power Management Support. 
        case IOCTL_POWER_CAPABILITIES: 
        case IOCTL_POWER_QUERY: 
        case IOCTL_POWER_SET: 
        case IOCTL_POWER_GET: 
        { 
            DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl_COPY(%08x): Power Management IOCTL\r\n"), dwContext ) ); 
			//pInBuf = pInBufUnmapped; 
			//pOutBuf = pOutBufUnmapped; 
			 
            __try  
            { 
 
                dwErr = pCamDevice->AdapterHandlePowerRequests(Ioctl, pInBuf, InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
            } 
			 
            __except ( EXCEPTION_EXECUTE_HANDLER ) 
            { 
                DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl_COPY(%08x):Exception in Power Management IOCTL"), dwContext ) ); 
            } 
            break; 
        } 
 
        case IOCTL_CS_PROPERTY: 
        { 
			//BEGIN 
			if ( ( NULL == pInBufUnmapped ) 
				 || ( InBufLen < sizeof ( CSPROPERTY ) ) 
				 || ( NULL == pdwBytesTransferred ) ) 
			{ 
				SetLastError( dwErr ); 
			 
				return bRc; 
			}			 
			 
			if ( NULL == pCsProp ) 
			{ 
				DEBUGMSG( ZONE_IOCTL|ZONE_ERROR, (_T("CAM_IOControl_COPY(%08x): Invalid Parameter.\r\n"), dwContext ) ); 
				return dwErr; 
			} 
			//END 
 
			 
            DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl_COPY(%08x): IOCTL_CS_PROPERTY\r\n"), dwContext ) ); 
 
            __try  
            { 
                dwErr = pCamDevice->AdapterHandleCustomRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
 
                if ( ERROR_NOT_SUPPORTED == dwErr ) 
                { 
                    if ( TRUE == IsEqualGUID( pCsProp->Set, CSPROPSETID_Pin ) ) 
                    {    
                        dwErr = pCamDevice->AdapterHandlePinRequests( pInBuf, InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
                    } 
                    else if ( TRUE == IsEqualGUID( pCsProp->Set, CSPROPSETID_VERSION ) ) 
                    { 
                        dwErr = pCamDevice->AdapterHandleVersion( pOutBuf, OutBufLen, pdwBytesTransferred ); 
                    } 
                    else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_VIDEOPROCAMP ) ) 
                    {    
                        dwErr = pCamDevice->AdapterHandleVidProcAmpRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
                    } 
                    else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_CAMERACONTROL ) ) 
                    {    
                        dwErr = pCamDevice->AdapterHandleCamControlRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
                    } 
                    else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_VIDEOCONTROL ) ) 
                    {    
                        dwErr = pCamDevice->AdapterHandleVideoControlRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
                    } 
                    else if ( TRUE == IsEqualGUID( pCsProp->Set, PROPSETID_VIDCAP_DROPPEDFRAMES) ) 
                    {    
                        dwErr = pCamDevice->AdapterHandleDroppedFramesRequests( pInBuf,InBufLen, pOutBuf, OutBufLen, pdwBytesTransferred ); 
                    } 
                } 
            } 
            __except ( EXCEPTION_EXECUTE_HANDLER ) 
            { 
                DEBUGMSG( ZONE_IOCTL, ( _T("CAM_IOControl_COPY(%08x):Exception in IOCTL_CS_PROPERTY"), dwContext ) ); 
            } 
 
            break; 
        } 
 
        default: 
        { 
            DEBUGMSG( ZONE_IOCTL, (_T("CAM_IOControl_COPY(%08x): Unsupported IOCTL code %u\r\n"), dwContext, Ioctl ) ); 
            dwErr = ERROR_NOT_SUPPORTED; 
 
            break; 
        } 
    } 
     
    // pass back appropriate response codes 
    SetLastError( dwErr ); 
 
    return ( ( dwErr == ERROR_SUCCESS ) ? TRUE : FALSE ); 
}