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

📄 prp_io.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//      None.
//
//------------------------------------------------------------------------------
void PRP_PowerUp(DWORD hDeviceContext)
{
    PRP_FUNCTION_ENTRY();
    PRP_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: PRP_PowerDown
//
// This function suspends power to the device. It is useful only with 
// devices that can power down under software control.
//
// Parameters:
//      hDeviceContext 
//          [in] Handle to the device context.
//
// Returns:  
//      None.
//
//------------------------------------------------------------------------------
void PRP_PowerDown(DWORD hDeviceContext)
{
    PRP_FUNCTION_ENTRY();
    PRP_FUNCTION_EXIT();
}

//------------------------------------------------------------------------------
//
// Function: PRP_IOControl
//
// This function sends a command to a device.
//
// Parameters:
//      hOpenContext
//          [in] Handle to the open context of the device. The XXX_Open 
//          function creates and returns this identifier.
//
//      dwCode
//          [in] I/O control operation to perform. These codes are 
//          device-specific and are usually exposed to developers through 
//          a header file.
//
//      pBufIn
//          [in] Pointer to the buffer containing data to transfer to the 
//          device. 
//
//      dwLenIn
//          [in] Number of bytes of data in the buffer specified for pBufIn.
//
//      pBufOut
//          [out] Pointer to the buffer used to transfer the output data 
//          from the device.
//
//      dwLenOut
//          [in] Maximum number of bytes in the buffer specified by pBufOut.
//
//      pdwActualOut
//          [out] Pointer to the DWORD buffer that this function uses to 
//          return the actual number of bytes received from the device.
//
// Returns:
//      The new data pointer for the device indicates success. A value of -1 
//      indicates failure.
//
//------------------------------------------------------------------------------
BOOL PRP_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, 
    DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
    prpConfigData *pConfigData;
    pPrpBuffers pBufs;
    UINT8 *pChannel;
    UINT32 *pFrameCount;
    UINT32 inBufSize = 0;
    UINT32 outVFBufSize = 0;
    UINT32 outEncBufSize = 0;
    BOOL bRet = FALSE;
    PVOID pDestMarshalled = NULL;      // For WinCE 6.00 pointer marshalling.
    
    // hOpenContext is a pointer to PrpClass instance!
    PrpClass *pPrp = (PrpClass *)hOpenContext;

    switch (dwCode) {
        case PRP_IOCTL_CONFIGURE:
            pConfigData = (pPrpConfigData)pBufIn;
            bRet = pPrp->PrpConfigure(pConfigData);
            DEBUGMSG(ZONE_IOCTL, 
                (TEXT("%s: PRP_IOCTL_CONFIGURE occurred\r\n"),  
                __WFUNCTION__));
            break;

        case PRP_IOCTL_START:
            pChannel = (UINT8 *)pBufIn;
            switch (*pChannel) {
                case prpChannel_Viewfinding:
                    bRet = pPrp->PrpStartVfChannel();
                    break;
                    
                case prpChannel_Encoding:
                    bRet = pPrp->PrpStartEncChannel();
                    break;
                    
                default:
                    DEBUGMSG(ZONE_ERROR, 
                        (TEXT("%s: Invalid channel selection for PRP_IOCTL_START\r\n"), 
                        __WFUNCTION__));
                    bRet = FALSE;
            }
            DEBUGMSG(ZONE_IOCTL, 
                (TEXT("%s: PRP_IOCTL_START occurred\r\n"), 
                __WFUNCTION__));
            break;

        case PRP_IOCTL_STOP:
            pChannel = (UINT8 *)pBufIn;
            switch (*pChannel) {
                case prpChannel_Viewfinding:
                    bRet = pPrp->PrpStopVfChannel();
                    break;
                    
                case prpChannel_Encoding:
                    bRet = pPrp->PrpStopEncChannel();
                    break;
                    
                default:
                    DEBUGMSG(ZONE_ERROR, 
                        (TEXT("%s: Invalid channel selection for PRP_IOCTL_STOP\r\n"), 
                        __WFUNCTION__));
                    bRet = FALSE;
            }
            DEBUGMSG(ZONE_IOCTL, 
                (TEXT("%s: PRP_IOCTL_STOP occurred\r\n"), 
                __WFUNCTION__));
            break;

        case PRP_IOCTL_ADD_BUFFERS:
            pBufs = (pPrpBuffers)pBufIn;

            inBufSize = pPrp->GetPrpInBufSize();
            outVFBufSize = pPrp->GetPrpOutVfBufSize();
            outEncBufSize = pPrp->GetPrpOutEncBufSize();

            // Only marshall InBuf buffer pointer if one was provided.
            if ((((pPrpBuffers)pBufIn)->InBuf != NULL) &&
                (inBufSize > 0))
            {
                if (FAILED(CeOpenCallerBuffer(&pDestMarshalled,
                                              ((pPrpBuffers)pBufIn)->InBuf,
                                              inBufSize,
                                              ARG_I_PTR,
                                              FALSE)))
                {
                    ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeOpenCallerBuffer() for ")
                                    TEXT("pBufIn->InBuf failed (%d)\r\n"),
                                    GetLastError()));
                    ERRORMSG(TRUE, (TEXT("((pPrpBuffers)pBufIn)->InBuf = 0x%08x, ")
                                    TEXT("pBufs->inBufLen = %d\r\n"),
                                    ((pPrpBuffers)pBufIn)->InBuf,
                                    inBufSize));
                    break;
                }

                // Save marshalled pointer for input buffer.
                pBufs->InBuf = (UINT32 *)pDestMarshalled;
            }
            else
            {
                // No need to marshall output buffer pointer since it is
                // either a NULL pointer or a zero-length buffer.
                pBufs->InBuf = ((pPrpBuffers)pBufIn)->InBuf;
            }

            // Only marshall OutVfBuf buffer pointer if one was provided.
            if ((((pPrpBuffers)pBufIn)->OutVfBuf != NULL) &&
                (outVFBufSize > 0))
            {
                if (FAILED(CeOpenCallerBuffer(&pDestMarshalled,
                                              ((pPrpBuffers)pBufIn)->OutVfBuf,
                                              outVFBufSize,
                                              ARG_O_PTR,
                                              FALSE)))
                {
                    ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeOpenCallerBuffer() for ")
                                    TEXT("pBufOut->OutVfBuf failed (%d)\r\n"),
                                    GetLastError()));
                    ERRORMSG(TRUE, (TEXT("((pPrpBuffers)pBufIn)->OutVfBuf = ")
                                    TEXT("0x%08x, pBufs->outBufLen = %d\r\n"),
                                    ((pPrpBuffers)pBufIn)->OutVfBuf,
                                    outVFBufSize));

                    // Release previously marshalled input buffer pointer.
                    if ((((pPrpBuffers)pBufIn)->InBuf != NULL) &&
                        (inBufSize > 0))
                    {
                        if (FAILED(CeCloseCallerBuffer(pBufs->InBuf,
                                                       ((pPrpBuffers)pBufIn)->InBuf,
                                                       inBufSize,
                                                       ARG_I_PTR)))
                        {
                            ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeCloseCallerBuffer() for ")
                                            TEXT("pBufIn->inputBuf failed\r\n")));
                        }
                    }
                    break;
                }

                // Save marshalled pointer output buffer.
                pBufs->OutVfBuf = (UINT32 *)pDestMarshalled;
            }
            else
            {
                // No need to marshall output buffer pointer since it is
                // either a NULL pointer or a zero-length buffer.
                pBufs->OutVfBuf = ((pPrpBuffers)pBufIn)->OutVfBuf;
            }

            // Only marshall OutEncBuf buffer pointer if one was provided.
            if ((((pPrpBuffers)pBufIn)->OutEncBuf != NULL) &&
                (outEncBufSize > 0))
            {
                if (FAILED(CeOpenCallerBuffer(&pDestMarshalled,
                                              ((pPrpBuffers)pBufIn)->OutEncBuf,
                                              outEncBufSize,
                                              ARG_O_PTR,
                                              FALSE)))
                {
                    ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeOpenCallerBuffer() for ")
                                    TEXT("pBufOut->OutEncBuf failed (%d)\r\n"),
                                    GetLastError()));
                    ERRORMSG(TRUE, (TEXT("((pPrpBuffers)pBufIn)->OutEncBuf = ")
                                    TEXT("0x%08x, pBufs->outBufLen = %d\r\n"),
                                    ((pPrpBuffers)pBufIn)->OutEncBuf,
                                    outEncBufSize));

                    // Release previously marshalled input buffer pointer.
                    if ((((pPrpBuffers)pBufIn)->InBuf != NULL) &&
                        (inBufSize > 0))
                    {
                        if (FAILED(CeCloseCallerBuffer(pBufs->InBuf,
                                                       ((pPrpBuffers)pBufIn)->InBuf,
                                                       inBufSize,
                                                       ARG_I_PTR)))
                        {
                            ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeCloseCallerBuffer() for ")
                                             TEXT("pBufIn->inputBuf failed\r\n")));
                        }
                    }

                    // Release previously marshalled OutVfBuf buffer pointer.
                    if ((((pPrpBuffers)pBufIn)->OutVfBuf != NULL) &&
                        (outVFBufSize > 0))
                    {
                        if (FAILED(CeCloseCallerBuffer(pBufs->OutVfBuf,
                                                       ((pPrpBuffers)pBufIn)->OutVfBuf,
                                                       outVFBufSize,
                                                       ARG_O_PTR)))
                        {
                            ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeCloseCallerBuffer() for ")
                                            TEXT("pBufOut->OutVfBuf failed\r\n")));
                        }
                    }
                    break;
                }

                // Save marshalled pointer output buffer.
                pBufs->OutEncBuf = (UINT32 *)pDestMarshalled;
            }
            else
            {
                // No need to marshall output buffer pointer since it is
                // either a NULL pointer or a zero-length buffer.
                pBufs->OutEncBuf = ((pPrpBuffers)pBufIn)->OutEncBuf;
            }

            bRet = pPrp->PrpAddBuffers(pBufs);

            DEBUGMSG(ZONE_IOCTL, 
                (TEXT("%s: PRP_IOCTL_ADD_BUFFERS occurred\r\n"), 
                __WFUNCTION__));

            // For WinCE 6.00 we must release the marshalled buffers here.
            if ((((pPrpBuffers)pBufIn)->OutEncBuf != NULL) &&
                (outEncBufSize > 0))
            {
                if (FAILED(CeCloseCallerBuffer(pBufs->OutEncBuf,
                                               ((pPrpBuffers)pBufIn)->OutEncBuf,
                                               outEncBufSize,
                                               ARG_O_PTR)))
                {
                    ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeCloseCallerBuffer() for ")
                                    TEXT("pBufOut->OutEncBuf failed\r\n")));
                }
            }

            if ((((pPrpBuffers)pBufIn)->OutVfBuf != NULL) &&
                (outVFBufSize > 0))
            {
                if (FAILED(CeCloseCallerBuffer(pBufs->OutVfBuf,
                                               ((pPrpBuffers)pBufIn)->OutVfBuf,
                                               outVFBufSize,
                                               ARG_O_PTR)))
                {
                    ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeCloseCallerBuffer() for ")
                                    TEXT("pBufOut->OutVfBuf failed\r\n")));
                }
            }

            if ((((pPrpBuffers)pBufIn)->InBuf != NULL) &&
                (inBufSize > 0))
            {
                if (FAILED(CeCloseCallerBuffer(pBufs->InBuf,
                                               ((pPrpBuffers)pBufIn)->InBuf,
                                               inBufSize,
                                               ARG_I_PTR)))
                {
                    ERRORMSG(TRUE, (TEXT("PRP_IOControl: CeCloseCallerBuffer() for ")
                                    TEXT("pBufIn->InBuf failed\r\n")));
                }
            }
            break;

        case PRP_IOCTL_GET_FRAME_COUNT:
            pChannel = (UINT8 *)pBufIn;
            pFrameCount = (UINT32 *)pBufOut;
            bRet = TRUE;
            switch (*pChannel) {
                case prpChannel_Viewfinding:
                    *pFrameCount = pPrp->PrpGetVfFrameCount();
                    break;
                    
                case prpChannel_Encoding:
                    *pFrameCount = pPrp->PrpGetEncFrameCount();
                    break;
                    
                default:
                    DEBUGMSG(ZONE_ERROR, 
                        (TEXT("%s: Invalid channel selection for PRP_IOCTL_GET_FRAME_COUNT\r\n"), 
                        __WFUNCTION__));
                    bRet = FALSE;
            }
            DEBUGMSG(ZONE_IOCTL, 
                (TEXT("%s: PRP_IOCTL_GET_FRAME_COUNT occurred\r\n"), 
                __WFUNCTION__));
            break;

        default:
            DEBUGMSG(ZONE_WARN, (TEXT("%s: No matching IOCTL.\r\n")));
            break;
    }

    return bRet;
}

⌨️ 快捷键说明

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