📄 adi_adv717x.c
字号:
// Application program should open the new PPI device, set its data flow method,
// load the buffer(s) for the new PPI device & enable the dataflow
break;
// CASE (Set PPI Device status (OPEN/CLOSE PPI))
case (ADI_ADV717x_CMD_SET_PPI_STATUS):
// check the PPI mode
if ((ADI_ADV717x_SET_PPI_STATUS) Value == ADI_ADV717x_PPI_OPEN)
{
// check if the PPI device is already open
if (pADV717x->ppiHandle== NULL)
// if not, open the PPI Device, else do nothing
Result = PPI_Open(PDDHandle);
}
else // this should be to close the PPI device
// Close any PPI device presently being used by ADV717x
Result = PPI_Close(PDDHandle);
break;
/*************************************
TWI related commands
*************************************/
// CASE (Set TWI Device Number that will be used access ADV717x device registers)
case (ADI_ADV717x_CMD_SET_TWI_DEVICE_NUMBER):
// Update the TWI device number
pADV717x->twiDeviceNumber = u8Value;
break;
// CASE (Set TWI Configuration table specific to the application)
case (ADI_ADV717x_CMD_SET_TWI_CONFIG_TABLE):
// Update the TWI Configuration table
pADV717x->twiConfigTable = (ADI_DEV_CMD_VALUE_PAIR*) Value;
break;
// CASE (Set TWI address for the ADV717x device)
case (ADI_ADV717x_CMD_SET_TWI_DEVICE_ADDRESS):
// Update the TWI device number
pADV717x->twiDeviceAddress = u32Value;
break;
default: // command not supported or recogonised
if (pADV717x->ppiHandle) // if PPI device is already opened
// pass the unknown command to PPI
Result = adi_dev_Control( pADV717x->ppiHandle, Command, Value );
else
Result = ADI_ADV717x_RESULT_CMD_NOT_SUPPORTED; // return error as unknown command
break;
}
return(Result);
}
/*********************************************************************
Function: ppiCallbackFunction
Description: Fields the callback from the PPI Driver
*********************************************************************/
static void ppiCallbackFunction (
void* DeviceHandle,
u32 Event,
void* pArg
){
ADI_ADV717x *pADV717x = (ADI_ADV717x *)DeviceHandle;
#if defined(ADI_DEV_DEBUG)
if (ValidatePDDHandle(DeviceHandle) != ADI_DEV_RESULT_SUCCESS) // verify the DM handle
return;
#endif
// simply pass the callback along to the Device Manager Callback without interpretation
(pADV717x->DMCallback)(pADV717x->DMHandle,Event,pArg);
}
/*********************************************************************
Function: DeviceAccessFunction
Description: Function specific to ADV717x driver passed to Device access service
*********************************************************************/
static u32 DeviceAccessFunction (
void* Handle, // AD717x driver Argument passed back by the device access service
u16 *AD717xRegAddr, // AD717x Register address being configured
u16 AD717xRegValue, // Value of AD717x Register address being configured
ADI_DEVICE_ACCESS_MODE access_mode // present access mode of ADV717x
) {
ADI_ADV717x *pADV717x = (ADI_ADV717x *)Handle;
u32 Result = ADI_DEV_RESULT_SUCCESS;
#if defined(ADI_DEV_DEBUG)
if ((Result = ValidatePDDHandle(Handle)) != ADI_DEV_RESULT_SUCCESS) // verify the DM handle
return (Result);
#endif
if (access_mode == ADI_DEVICE_ACCESS_PRE_WRITE)
{
switch(*AD717xRegAddr)
{
// ADV717x_MR0 Register
case ADV717x_MR0:
if (AD717xRegValue & 0x01) // is bit 0 of MR0 = 1?
// video is of PAL format
pADV717x->adv717x_semaphores.NTSC_PALflag = 1; // mark as ADV717x in PAL mode
else
// else, it is NTSC
pADV717x->adv717x_semaphores.NTSC_PALflag = 0; // mark as ADV717x in NTSC mode
if (!pADV717x->adv717x_semaphores.ADV717x_mode) // is ADV717x in standard video mode?
{
if (pADV717x->adv717x_semaphores.NTSC_PALflag)
pADV717x->PPIFrameLines = 625; // PAL
else
pADV717x->PPIFrameLines = 525; // NTSC
if (pADV717x->ppiHandle) // if PPI device is already opened
// update the PPI Frame lines count
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void*)pADV717x->PPIFrameLines );
}
break;
// ADV717x_TMR0 Register
case ADV717x_TMR0:
// Check ADV717x mode
// is ADV717x configured in a non-standard video out mode?
if((AD717xRegValue & 0x06) && (pADV717x->adv717x_semaphores.ADV717x_mode))
{
// Check dataflow status
if(pADV717x->adv717x_semaphores.dataflow == TRUE)
// if dataflow is on, disable dataflow before changing the video mode
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)FALSE );
// on occurance of error, return the error code
#ifdef ADI_DEV_DEBUG
if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// PPI in output mode with 1,2 or 3 frame syncs
pADV717x->PPIControl |= 0x000C; // set transfer type as 3
// update flag to indicate ADV717x is in non-standard mode
pADV717x->adv717x_semaphores.ADV717x_mode = 1;
if (pADV717x->ppiHandle) // if PPI device is already opened
// update the PPI control register
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_PPI_CMD_SET_CONTROL_REG, (void*)pADV717x->PPIControl );
// on occurance of error, return the error code
#ifdef ADI_DEV_DEBUG
if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// Check dataflow status
if(pADV717x->adv717x_semaphores.dataflow == TRUE)
// if dataflow is previously on, re-enable the dataflow
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE );
}
else // ADV717x operates in standard mode
{
// previously ADV717x was in non-standard mode
if (pADV717x->adv717x_semaphores.ADV717x_mode)
{
// Check dataflow status
if(pADV717x->adv717x_semaphores.dataflow == TRUE)
// if dataflow is on, disable dataflow before changing the video mode
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)FALSE );
// on occurance of error, return the error code
#ifdef ADI_DEV_DEBUG
if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// mark flag as ADV717x_mode flag as in standard mode
pADV717x->adv717x_semaphores.ADV717x_mode = 0;
// clear triple frame sync flag as ADV717x operates in standard mode
pADV717x->adv717x_semaphores.TripleFrameSync= 0;
// Client should set frame sync count when changing to non-standar mode
pADV717x->adv717x_semaphores.FSCount = 0; // Standard video mode
// Configure PPI output with ITU 656 standard data
//(Unpack enabled,Transfer Entire field,PPI in output mode)
#if defined (__ADSPBF561__)
pADV717x->PPIControl = 0x0186; // PPI output with ITU 656 standard data & DMA32 enabled
#else // for BF533 & BF537
pADV717x->PPIControl = 0x0086; // PPI output with ITU 656 standard data
#endif
// Update Frame Line Count
if (pADV717x->adv717x_semaphores.NTSC_PALflag)
pADV717x->PPIFrameLines = 625; // PAL
else
pADV717x->PPIFrameLines = 525; // NTSC
if (pADV717x->ppiHandle) // if PPI device is already opened
{
// update the PPI control register
if ((Result = adi_dev_Control( pADV717x->ppiHandle, ADI_PPI_CMD_SET_CONTROL_REG,
(void*)pADV717x->PPIControl )) != ADI_DEV_RESULT_SUCCESS)
return (Result);
// update the PPI Frame lines count
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void*)pADV717x->PPIFrameLines );
}
// on occurance of error, return the error code
#ifdef ADI_DEV_DEBUG
if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// Check dataflow status
if(pADV717x->adv717x_semaphores.dataflow == TRUE)
// if dataflow is previously on, re-enable the dataflow
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE );
}
}
break;
default:
break;
}
}
return (Result);
}
// Debug build only
#ifdef ADI_DEV_DEBUG
/*********************************************************************
Function: ValidatePDDHandle
Description: Validates a PDD handle
*********************************************************************/
static int ValidatePDDHandle(
ADI_DEV_PDD_HANDLE PDDHandle
) {
unsigned int i;
for (i = 0; i < ADI_ADV717x_NUM_DEVICES; i++)
{
if (PDDHandle == (ADI_DEV_PDD_HANDLE)&Device[i])
return (ADI_DEV_RESULT_SUCCESS);
}
return (ADI_DEV_RESULT_BAD_PDD_HANDLE);
}
#endif // Debug build only
/*********************************************************************
Entry point for device manager
*********************************************************************/
#ifdef ADI_ADV7170_DEVICE
ADI_DEV_PDD_ENTRY_POINT ADIADV7170EntryPoint = {
#endif
#ifdef ADI_ADV7171_DEVICE
ADI_DEV_PDD_ENTRY_POINT ADIADV7171EntryPoint = {
#endif
#ifdef ADI_ADV7174_DEVICE
ADI_DEV_PDD_ENTRY_POINT ADIADV7174EntryPoint = {
#endif
#ifdef ADI_ADV7179_DEVICE
ADI_DEV_PDD_ENTRY_POINT ADIADV7179EntryPoint = {
#endif
adi_pdd_Open,
adi_pdd_Close,
adi_pdd_Read,
adi_pdd_Write,
adi_pdd_Control,
adi_pdd_SequentialIO
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -