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

📄 sdc.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 4 页
字号:

        // Set DMA VF Channel 1 ready
        SETREG32(&g_pIPU->IPU_CHA_BUF1_RDY,
                CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_DMA_CHA_READY));

        g_iSDCFGNextBuffer = 0;
    }

	// Save last address in case we need to restore later.
	g_SDCFGBuf_Saved = (UINT32) pAddr->QuadPart;

}

void ForegroundWindowRestore()
{
	PHYSICAL_ADDRESS phyAddr;

    // Re-enable foreground
	ForegroundWindowEnable();

    // Restore last active buffer to foreground
	phyAddr.QuadPart = g_SDCFGBuf_Saved;
	ForegroundWindowSetSrcBuffer(&phyAddr);
}

//------------------------------------------------------------------------------
//
// Function: ForegroundWindowSetOffset
//
// This function sets up the window offset for the foreground plane.
//
// Parameters:
//      left
//          [in] X coordinate of the foreground plane in the
//          display window.
//
//      top
//          [in] Y coordinate of the foreground plane in the
//          display window.
//
// Returns:
//      None.
//------------------------------------------------------------------------------
void ForegroundWindowSetOffset(POINT *ptWinOffset)
{
    // Set the top or the Y coordinate of the foreground plane
    INSREG32BF(&g_pIPU->SDC_FG_POS,
                IPU_SDC_FG_POS_FGYP, g_pCurrentPanel->VSTARTWIDTH + ptWinOffset->y);

    // Set the left or the X coordinate of the foreground plane
    INSREG32BF(&g_pIPU->SDC_FG_POS,
                IPU_SDC_FG_POS_FGXP, g_pCurrentPanel->HSTARTWIDTH + ptWinOffset->x);
}

//------------------------------------------------------------------------------
//
// Function: ForegroundWindowEnable
//
// This function enables the foreground window.
//
// Parameters:
//      None.
//
// Returns:
//      None.
//------------------------------------------------------------------------------
void ForegroundWindowEnable(void)
{
    UINT32 oldVal, newVal, iMask, iBitval;

    // If FG_EN = 1, bail out
    if (EXTREG32BF(&g_pIPU->SDC_COM_CONF, IPU_SDC_COM_CONF_FG_EN) == IPU_ENABLE)
    {
        return;
    }

    // Set to double buffer mode

    // Compute bitmask and shifted bit value for DB mode sel register
    iMask = CSP_BITFMASK(IPU_DMA_CHA_DMASDC_1);
    iBitval = CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_DUB_BUF);

    // Use interlocked function to set DB Mode sel to 1.
    do
    {
        oldVal = INREG32(&g_pIPU->IPU_CHA_DB_MODE_SEL);
        newVal = (oldVal & (~iMask)) | iBitval;
    } while (InterlockedTestExchange(&g_pIPU->IPU_CHA_DB_MODE_SEL,
                oldVal, newVal) != oldVal);

    SETREG32(&g_pIPU->IPU_CHA_CUR_BUF,
            CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_IPU_CHA_CUR_BUF_CLEAR));

    // Enable DMA VF Channel 1

    // Compute bitmask and shifted bit value for IDMAC enable reg.
    iMask = CSP_BITFMASK(IPU_DMA_CHA_DMASDC_1);
    iBitval = CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_ENABLE);

    // Use interlocked function to Enable DMA VF Channel 1.
    do
    {
        oldVal = INREG32(&g_pIPU->IDMAC_CHA_EN);
        newVal = (oldVal & (~iMask)) | iBitval;
    } while (InterlockedTestExchange(&g_pIPU->IDMAC_CHA_EN,
                oldVal, newVal) != oldVal);

    // Enable VF foreground

    // Compute bitmask and shifted bit value for IDMAC enable reg.
    iMask = CSP_BITFMASK(IPU_SDC_COM_CONF_FG_EN);
    iBitval = CSP_BITFVAL(IPU_SDC_COM_CONF_FG_EN, IPU_ENABLE);

    // Use interlocked function to set FG_EN = 1 (Foreground is enabled)
    do
    {
        oldVal = INREG32(&g_pIPU->SDC_COM_CONF);
        newVal = (oldVal & (~iMask)) | iBitval;
    } while (InterlockedTestExchange(&g_pIPU->SDC_COM_CONF,
                oldVal, newVal) != oldVal);

    return;
}

//------------------------------------------------------------------------------
//
// Function: ForegroundWindowDisable
//
// This function disables the foreground window.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success; FALSE if failure.
//------------------------------------------------------------------------------
BOOL ForegroundWindowDisable(void)
{
    UINT32 uTempReg, uTempReg1, uTempReg2, uCount = 0;
    UINT32 oldVal, newVal, iMask, iBitval;

    // initalize ... for the first time through
    uTempReg = INREG32(&g_pIPU->IDMAC_CHA_BUSY);
    uTempReg1 = INREG32(&g_pIPU->IPU_CHA_BUF0_RDY);
    uTempReg2 = INREG32(&g_pIPU->IPU_CHA_BUF1_RDY);

    // We can't disable tasks until the active channels
    // have completed their current frames.  Make sure
    // that buffers aren't set as ready (indicating that
    // they are yet to start) and that channels are
    // not busy (indicating that channels are still running).
    while ((uTempReg1 & (1 << GRAPHICS_DMA_CHANNEL)) || (uTempReg2 & (1 << GRAPHICS_DMA_CHANNEL))
        || (uTempReg & (1 << GRAPHICS_DMA_CHANNEL)))
    {
        if (uCount <= DELAYTIMEOUT)
        {
            //..give up the remainder of time slice
            Sleep(0);
            uCount++;

            //.. need to check after the sleep delay
            uTempReg = INREG32(&g_pIPU->IDMAC_CHA_BUSY);
            uTempReg1 = INREG32(&g_pIPU->IPU_CHA_BUF0_RDY);
            uTempReg2 = INREG32(&g_pIPU->IPU_CHA_BUF1_RDY);
        }
        else
        {
            //.. there is something wrong ....break out
            return FALSE;
        }
    }

    // Set FG_EN = 0 (Foreground is disabled)
    INSREG32BF(&g_pIPU->SDC_COM_CONF,
                IPU_SDC_COM_CONF_FG_EN, IPU_DISABLE);

    // Set up chaining register
    INSREG32BF(&g_pIPU->IPU_FS_DISP_FLOW,
                IPU_IPU_FS_DISP_FLOW_SDC1_SRC_SEL, 0);

    // Compute bitmask and shifted bit value for idmac register
    iMask = CSP_BITFMASK(IPU_DMA_CHA_DMASDC_1);
    iBitval = CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_DISABLE);

    // Use interlocked function to Disable DMA SDC Channel 1.
    do
    {
        oldVal = INREG32(&g_pIPU->IDMAC_CHA_EN);
        newVal = (oldVal & (~iMask)) | iBitval;
    } while (InterlockedTestExchange(&g_pIPU->IDMAC_CHA_EN,
                oldVal, newVal) != oldVal);

    // Return double-buffer mode to 0 so that we will restart correctly
    // upon next init.

    // Compute bitmask and shifted bit value for idmac register
    iMask = CSP_BITFMASK(IPU_DMA_CHA_DMASDC_1);
    iBitval = CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_SIG_BUF);

    // Use interlocked function to set DB mode to 0.
    do
    {
        oldVal = INREG32(&g_pIPU->IPU_CHA_DB_MODE_SEL);
        newVal = (oldVal & (~iMask)) | iBitval;
    } while (InterlockedTestExchange(&g_pIPU->IPU_CHA_DB_MODE_SEL,
                oldVal, newVal) != oldVal);

	// Set next buffer to the BUF_0 for when FG is next started.
    g_iSDCFGNextBuffer = 0;

    return TRUE;

}


//------------------------------------------------------------------------------
//
// Function: DisplayPlaneIsBusy
//
// This function queries whether or not the specified display
// plane is currently busy displaying data.
//
// Parameters:
//      dispPlane
//          [in] Specifies whether to query for the background
//          (DisplayPlane_0) or foreground plane (DisplayPlane_1).
//
// Returns:
//      TRUE if specified plane is busy; FALSE if not busy.
//------------------------------------------------------------------------------
BOOL DisplayPlaneIsBusy(DisplayPlane dispPlane)
{
    BOOL retval = FALSE;

    if (dispPlane == DisplayPlane_0)
    {
        // Poll Background Channel DMA channel busy bit.  If bit is set,
        // background window is busy.
        if (EXTREG32BF(&g_pIPU->IDMAC_CHA_BUSY, IPU_DMA_CHA_DMASDC_0))
        {
            retval = TRUE;
        }
    }
    else if (dispPlane == DisplayPlane_1)
    {
        // Poll Background Channel DMA channel busy bit.  If bit is set,
        // background window is busy.
        if (EXTREG32BF(&g_pIPU->IDMAC_CHA_BUSY, IPU_DMA_CHA_DMASDC_1))
        {
            retval = TRUE;
        }
    }
    else
    {
        DEBUGMSG(SDC_ERROR,
                 (TEXT("%s(): Invalid display plane specified.\r\n"), __WFUNCTION__));
    }

    return retval;
}

//------------------------------------------------------------------------------
//
// Function: DisplayPlaneWaitForNotBusy
//
// This function waits for the specified display
// plane to complete processing the current frame.  If
// the plane is not busy, this function returns immediately.
//
// Parameters:
//      dispPlane
//          [in] Specifies whether to query for the background
//          (DisplayPlane_0) or foreground plane (DisplayPlane_1).
//
// Returns:
//      None.
//------------------------------------------------------------------------------
void DisplayPlaneWaitForNotBusy(DisplayPlane dispPlane)
{
    UINT32 oldCtrl, newCtrl, ctrlMask, ctrlBitval;

    if (dispPlane == DisplayPlane_0)
    {
        // First Check if the plane is busy
        // If it is not, we return.
        if (DisplayPlaneIsBusy(DisplayPlane_0))
        {
            // Background plane is busy, so we must enable and
            // wait for an EOF interrupt

            // Compute bitmask and shifted bit value for ctrl register
            ctrlMask = CSP_BITFMASK(IPU_DMA_CHA_DMASDC_0);
            ctrlBitval = CSP_BITFVAL(IPU_DMA_CHA_DMASDC_0, IPU_ENABLE);

            // Use interlocked function to update control registers
            do
            {
                oldCtrl = INREG32(&g_pIPU->IPU_INT_CTRL_1);
                newCtrl = (oldCtrl & (~ctrlMask)) | ctrlBitval;
            } while (InterlockedTestExchange(&g_pIPU->IPU_INT_CTRL_1,
                        oldCtrl, newCtrl) != oldCtrl);

            if (WaitForSingleObject(g_hSDCBGIntrEvent, 1000 * (1/50)) == WAIT_TIMEOUT)
            {
                DEBUGMSG(SDC_ERROR,
                         (TEXT("%s(): Waiting for SDC BG EOF interrupt time out!\r\n"), __WFUNCTION__));
            }

            // We have received our interrupt, so we can clear the
            // status bit (write-1-to-clear).
            OUTREG32(&g_pIPU->IPU_INT_STAT_1,
                CSP_BITFVAL(IPU_DMA_CHA_DMASDC_0, 1));
        }

        return;
    }
    else if (dispPlane == DisplayPlane_1)
    {
        // First Check if the plane is busy
        // If it is not, we return.
        if (DisplayPlaneIsBusy(DisplayPlane_1))
        {
            // Foreground plane is busy, so we must
            // wait for an EOF interrupt

            // Compute bitmask and shifted bit value for ctrl register
            ctrlMask = CSP_BITFMASK(IPU_DMA_CHA_DMASDC_1);
            ctrlBitval = CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, IPU_ENABLE);

            // Use interlocked function to update control registers
            do
            {
                oldCtrl = INREG32(&g_pIPU->IPU_INT_CTRL_1);
                newCtrl = (oldCtrl & (~ctrlMask)) | ctrlBitval;
            } while (InterlockedTestExchange(&g_pIPU->IPU_INT_CTRL_1,
                        oldCtrl, newCtrl) != oldCtrl);

            if (WaitForSingleObject(g_hSDCFGIntrEvent, 1000 * (1/50)) == WAIT_TIMEOUT)
            {
                DEBUGMSG(SDC_ERROR,
                         (TEXT("%s(): Waiting for SDC FG EOF interrupt time out!\r\n"), __WFUNCTION__));
            }

            // We have received our interrupt, so we can clear the
            // status bit (write-1-to-clear).
            OUTREG32(&g_pIPU->IPU_INT_STAT_1,
                CSP_BITFVAL(IPU_DMA_CHA_DMASDC_1, 1));
        }

        return;
    }
    else
    {
        DEBUGMSG(SDC_ERROR,
                 (TEXT("%s(): Invalid display plane specified.\r\n"), __WFUNCTION__));
    }
}


//------------------------------------------------------------------------------
//
// Function: PeekandPoke
//
// This function is a backdoor entrypoint into the driver. Since the driver can
// give you access to the information that you want.

// Parameters:
//        None
//
// Returns:
//      None.
//
//------------------------------------------------------------------------------
BOOL PeekandPoke( PDEBUG_INFO pvIn)
{
    if ( TRUE == pvIn->bWriteFlag )
    {
        OUTREG32( ((UINT8*)g_pIPU + pvIn->uReg), pvIn->uValue);
    }
    else
    {
        pvIn->uValue = INREG32((UINT8*)g_pIPU + pvIn->uReg);
    }

    return TRUE;
}

⌨️ 快捷键说明

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