📄 prpclass.cpp
字号:
// Close events
if (m_hVfEOFEvent != NULL) {
CloseHandle(m_hVfEOFEvent);
m_hVfEOFEvent = NULL;
}
if (m_hEncEOFEvent != NULL) {
CloseHandle(m_hEncEOFEvent);
m_hEncEOFEvent = NULL;
}
if (m_hPrpIntrEvent != NULL) {
CloseHandle(m_hPrpIntrEvent);
m_hPrpIntrEvent = NULL;
}
#ifndef PRP_MEM_MODE_DLL
if (m_hVfStopEvent != NULL) {
CloseHandle(m_hVfStopEvent);
m_hVfStopEvent = NULL;
}
if (m_hEncStopEvent != NULL) {
CloseHandle(m_hEncStopEvent);
m_hEncStopEvent = NULL;
}
#endif
// Terminate threads
if (m_hPrpIntrThread != NULL) {
TerminateThread(m_hPrpIntrThread, 0);
CloseHandle(m_hPrpIntrThread);
m_hPrpIntrThread = NULL;
}
PRP_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PrpPowerUp
//
// This function initialize the interrupt and event.
// Doing this before enable Prp module.
//
// Parameters:
// None.
//
// Returns:
// TRUE : for success.
// FALSE : for failure.
//
//-----------------------------------------------------------------------------
BOOL PrpClass::PrpPowerUp()
{
PRP_FUNCTION_ENTRY();
// Enable interrupt and event
if (!PrpEventsInit()) {
DEBUGMSG(ZONE_ERROR, (TEXT("%s: PrpEventsInit failed! \r\n"), __WFUNCTION__));
PrpEventsDeinit();
return FALSE;
}
PRP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PrpPowerDown
//
// This function deinitialize the interrupt and event.
// Doing this after disable Prp Module.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PrpClass::PrpPowerDown()
{
PRP_FUNCTION_ENTRY();
// Disable interrupt and event
PrpEventsDeinit();
PRP_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: PrpEnable
//
// This function enables pre-processor.
//
// Parameters:
// None.
//
// Returns:
// TRUE : for success.
// FALSE : for failure.
//
//-----------------------------------------------------------------------------
BOOL PrpClass::PrpEnable(void)
{
PRP_FUNCTION_ENTRY();
// Enable eMMA clock
if (!BSPPrpSetClockGatingMode(TRUE)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Enable PrP failed. It probably is being used by someone. \r\n"),
__WFUNCTION__));
return FALSE;
}
// Enable pre-processor clock gating.
INSREG32BF(&m_pPrpReg->PRP_CNTL, PRP_CNTL_CLKEN, PRP_CNTL_CLKEN_ON);
// Software reset pre-processor
INSREG32BF(&m_pPrpReg->PRP_CNTL, PRP_CNTL_SWRST, PRP_CNTL_SWRST_RESET);
// Suppose it will clear itself after software reset
while (EXTREG32BF(&m_pPrpReg->PRP_CNTL, PRP_CNTL_SWRST)) {
Sleep(1); // Relinquish current time slot for other thread
}
// Enable all pre-processor interrupts
// CH2OVF is only available when CH2 flow control disabled
OUTREG32(&m_pPrpReg->PRP_INTRCNTL,
CSP_BITFMASK(PRP_INTRCNTL_RDERRIE) |
CSP_BITFMASK(PRP_INTRCNTL_CH1WERRIE) |
CSP_BITFMASK(PRP_INTRCNTL_CH2WERRIE) |
CSP_BITFMASK(PRP_INTRCNTL_CH2FCIE) |
CSP_BITFMASK(PRP_INTRCNTL_CH1FCIE) |
CSP_BITFMASK(PRP_INTRCNTL_CH2OVFIE) |
CSP_BITFMASK(PRP_INTRCNTL_LBOVFIE));
// When power up PrP Module the first time. Needn't configure PrP here.
// When Enable the module by power management, restore the current setting.
if (TRUE == m_bConfigured)
{
PrpConfigure(m_pPrpConfig);
}
PRP_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: PrpDisable
//
// This function disables pre-processor.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void PrpClass::PrpDisable(void)
{
PRP_FUNCTION_ENTRY();
// Disable pre-processor first
OUTREG32(&m_pPrpReg->PRP_CNTL, 0);
// In case there is still one last pending interrupt
// Clear interrupt status (w1c)
OUTREG32(&m_pPrpReg->PRP_INTRSTATUS,
CSP_BITFMASK(PRP_INTRSTATUS_READERR) |
CSP_BITFMASK(PRP_INTRSTATUS_CH1WRERR) |
CSP_BITFMASK(PRP_INTRSTATUS_CH2WRERR) |
CSP_BITFMASK(PRP_INTRSTATUS_CH1B1CI) |
CSP_BITFMASK(PRP_INTRSTATUS_CH1B2CI) |
CSP_BITFMASK(PRP_INTRSTATUS_CH2B1CI) |
CSP_BITFMASK(PRP_INTRSTATUS_CH2B2CI) |
CSP_BITFMASK(PRP_INTRSTATUS_CH2OVF) |
CSP_BITFMASK(PRP_INTRSTATUS_LBOVF));
// Disable interrupt
OUTREG32(&m_pPrpReg->PRP_INTRCNTL, 0);
// Disable pre-processor clock gating.
INSREG32BF(&m_pPrpReg->PRP_CNTL, PRP_CNTL_CLKEN, PRP_CNTL_CLKEN_OFF);
// Disable eMMA clock
BSPPrpSetClockGatingMode(FALSE);
PRP_FUNCTION_EXIT();
}
//------------------------------------------------------------------------------
//
// Function: PrpConfigure
//
// This function is used to configure pre-processor Registers.
//
// Parameters:
// pConfigData
// [in] Pointer to configuaration data structure.
//
// Returns:
// TRUE if success; FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL PrpClass::PrpConfigure(pPrpConfigData pConfigData)
{
PRP_FUNCTION_ENTRY();
if (pConfigData == NULL)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Invalid configuration data!\r\n"), __WFUNCTION__));
return FALSE;
}
// If it is the first time we configure the Prp module, allocate a memory
// to store the current Prp module configuration.
if (NULL == m_pPrpConfig)
{
m_pPrpConfig = (pPrpConfigData) malloc (sizeof(prpConfigData));
if (NULL == m_pPrpConfig)
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Get memory for store Prp Configure data failed!\r\n"), __WFUNCTION__));
goto _error;
}
}
if (m_pPrpConfig != pConfigData)
{
// Only if new setting comes, saving current setting.
memcpy(m_pPrpConfig,pConfigData,sizeof(prpConfigData));
}
if (!PrpConfigureInput(pConfigData))
goto _error;
if (!PrpConfigureOutput(pConfigData))
goto _error;
if (!PrpConfigureCSC(pConfigData))
goto _error;
if (!PrpConfigureResize(pConfigData))
goto _error;
// Indicates the configuration is done
m_bConfigured = TRUE;
PRP_FUNCTION_EXIT();
return TRUE;
_error:
// Make a software reset
INSREG32BF(&m_pPrpReg->PRP_CNTL, PRP_CNTL_SWRST, PRP_CNTL_SWRST_RESET);
// Suppose it will clear itself after software reset
while (EXTREG32BF(&m_pPrpReg->PRP_CNTL, PRP_CNTL_SWRST)) {
Sleep(1); // Relinquish current time slot for other thread
}
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Pre-processor configuration failed\r\n"),
__WFUNCTION__));
return FALSE;
}
//------------------------------------------------------------------------------
//
// Function: PrpConfigureInput
//
// This function configures the pre-processor input source.
//
// Parameters:
// pConfigData
// [in] Pointer to configuration data structure
//
// Returns:
// TRUE if success; FALSE if failure.
//
//------------------------------------------------------------------------------
BOOL PrpClass::PrpConfigureInput(pPrpConfigData pConfigData)
{
UINT16 nInputBytesPerLine;
PRP_FUNCTION_ENTRY();
// Get input format
m_iInputFormat = pConfigData->inputFormat;
// Alignment check
if (m_iInputFormat == prpInputFormat_YUV420) {
if ((pConfigData->inputSize.width & 0x07) ||
(pConfigData->inputSize.height & 0x01)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Input YUV420 image size is not aligned. \r\n"),
__WFUNCTION__));
return FALSE;
}
} else { // RGB, YUV422, YUV444
if (pConfigData->inputSize.width & 0x03) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Input image size is not aligned. \r\n"),
__WFUNCTION__));
return FALSE;
}
}
// Boundary check
if ((pConfigData->inputSize.width < PRP_IMAGE_MIN_WIDTH) ||
(pConfigData->inputSize.height < PRP_IMAGE_MIN_HEIGHT) ||
(pConfigData->inputSize.width > PRP_IMAGE_MAX_WIDTH) ||
(pConfigData->inputSize.height > PRP_IMAGE_MAX_HEIGHT)) {
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Input image size is invalid. \r\n"), __WFUNCTION__));
return FALSE;
}
// Setup input image size parameters
INSREG32BF(&m_pPrpReg->PRP_SOURCE_FRAME_SIZE,
PRP_SOURCE_FRAME_SIZE_PICTURE_X_SIZE, pConfigData->inputSize.width);
INSREG32BF(&m_pPrpReg->PRP_SOURCE_FRAME_SIZE,
PRP_SOURCE_FRAME_SIZE_PICTURE_Y_SIZE, pConfigData->inputSize.height);
// Setup input format parameters
switch (m_iInputFormat) {
case prpInputFormat_YUV420:
// YUV420 input only be available in Memory mode.
#ifndef PRP_MEM_MODE_DLL
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: YUV420 is an invalid input format for CSI mode. \r\n"),
__WFUNCTION__));
return FALSE;
#else
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_YUV420);
nInputBytesPerLine = pConfigData->inputSize.width * 3 / 2;
break;
#endif
case prpInputFormat_YUYV422:
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_YUV422);
OUTREG32(&m_pPrpReg->PRP_SOURCE_PIXEL_FORMAT_CNTL, 0x22000888);
nInputBytesPerLine = pConfigData->inputSize.width * 2;
break;
case prpInputFormat_YVYU422:
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_YUV422);
OUTREG32(&m_pPrpReg->PRP_SOURCE_PIXEL_FORMAT_CNTL, 0x20100888);
nInputBytesPerLine = pConfigData->inputSize.width * 2;
break;
case prpInputFormat_UYVY422:
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_YUV422);
OUTREG32(&m_pPrpReg->PRP_SOURCE_PIXEL_FORMAT_CNTL, 0x03080888);
nInputBytesPerLine = pConfigData->inputSize.width * 2;
break;
case prpInputFormat_VYUY422:
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_YUV422);
OUTREG32(&m_pPrpReg->PRP_SOURCE_PIXEL_FORMAT_CNTL, 0x01180888);
nInputBytesPerLine = pConfigData->inputSize.width * 2;
break;
case prpInputFormat_YUV444:
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_YUV444);
OUTREG32(&m_pPrpReg->PRP_SOURCE_PIXEL_FORMAT_CNTL, 0x62080888);
nInputBytesPerLine = pConfigData->inputSize.width * 4;
break;
case prpInputFormat_RGB16:
INSREG32BF(&m_pPrpReg->PRP_CNTL,
PRP_CNTL_DATA_IN_MODE, PRP_CNTL_DATA_IN_MODE_RGB16);
OUTREG32(&m_pPrpReg->PRP_SOURCE_PIXEL_FORMAT_CNTL, 0x2CA00565);
nInputBytesPerLine = pConfigData->inputSize.width * 2;
break;
case prpInputFormat_RGB32:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -