📄 adi_adv717x.c
字号:
// array of invalid registers addresses in ADV717x.
#if defined(ADI_ADV7170_DEVICE) || defined (ADI_ADV7174_DEVICE)
// Invalid address locations in ADV7170/ADV7174
// Subcarrier register address is also listed here as they should not be accessed seperately
static u16 adv717xInvalidRegs[]={ 0x05, 0x06, 0x09, 0x0A, 0x0B, 0x0C, 0x1A, 0x1B, 0x1C, 0x1D };
#elif defined(ADI_ADV7171_DEVICE) || defined (ADI_ADV7179_DEVICE)
// Invalid address locations in ADV7171/ADV7179
// Subcarrier register address is also listed here as they should not be accessed seperately
static u16 adv717xInvalidRegs[]={ 0x05, 0x06, 0x09, 0x0A, 0x0B, 0x0C };
#endif
static ADI_DEVICE_ACCESS_VALIDATE_REGISTER ValidateRegister[] = {
sizeof(adv717xInvalidRegs)/2, // 'Count' of Invalid Register addresses in ADV717x
adv717xInvalidRegs, // array of Invalid Register addresses in ADV717x
0, // 'Count' of Read-only Register addresses in ADV717x
NULL, // pointer to array of Read-only Register addresses in ADV717x
};
// Table to select Device access type
static ADI_DEVICE_ACCESS_SELECT SelectTWIAccess[] = {
0, // Don't care in case of TWI access
ADI_DEVICE_ACCESS_LENGTH0, // 'Device' Global address (Don't care for TWI Access)
ADI_DEVICE_ACCESS_LENGTH1, // 'Device' register address length (1 byte)
ADI_DEVICE_ACCESS_LENGTH1, // 'Device' register data length (1 byte)
ADI_DEVICE_ACCESS_TYPE_TWI, // Select TWI access
};
/*********************************************************************
*
* Function: PPI_Open
*
* Description: Opens the ppi device for ADV717x video dataflow
*
*********************************************************************/
static u32 PPI_Open(
ADI_DEV_PDD_HANDLE PDDHandle // Physical Device Driver Handle
) {
// default return code
u32 Result = ADI_DEV_RESULT_SUCCESS;
// Pointer to the device driver instance
ADI_ADV717x *pADV717x = (ADI_ADV717x *)PDDHandle;
// Open the PPI driver
Result = adi_dev_Open(
pADV717x->ManagerHandle, // device manager handle
&ADIPPIEntryPoint, // ppi Entry point
pADV717x->ppiDeviceNumber, // ppi device number
pADV717x, // client handle - passed to internal callback function
&pADV717x->ppiHandle, // pointer to DM handle (for PPI driver) location
ADI_DEV_DIRECTION_OUTBOUND, // PPI used only to output video data
pADV717x->DMAHandle, // handle to the DMA manager
pADV717x->DCBHandle, // handle to the callback manager
ppiCallbackFunction // internal callback function
);
// return with appropriate code if PPI driver fails to open
if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
ADI_DEV_CMD_VALUE_PAIR PPI_config [] = { // table of PPI driver configuration values
{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG, (void *)pADV717x->PPIFrameLines },// Frame line count
{ ADI_PPI_CMD_SET_CONTROL_REG, (void *)pADV717x->PPIControl },// PPI Control Register
{ ADI_DEV_CMD_END, NULL },
};
Result = adi_dev_Control( pADV717x->ppiHandle, ADI_DEV_CMD_TABLE, (void*)PPI_config );
return (Result);
}
/*********************************************************************
*
* Function: PPI_Close
*
* Description: Closes the PPI device used for ADV717x video dataflow
*
*********************************************************************/
static u32 PPI_Close(
ADI_DEV_PDD_HANDLE PDDHandle // Physical Device Driver Handle
) {
// default return code
u32 Result = ADI_DEV_RESULT_SUCCESS;
// Pointer to the device driver instance
ADI_ADV717x *pADV717x = (ADI_ADV717x *)PDDHandle;
// Check if any PPI device is open
// if so, close the present PPI device in use
if (pADV717x->ppiHandle != NULL)
{
// close the present PPI device
if ((Result = adi_dev_Close(pADV717x->ppiHandle))!= ADI_DEV_RESULT_SUCCESS)
return (Result);
// Mark SPORT Handle as NULL indicating SPORT device is closed
pADV717x->ppiHandle = NULL;
}
return (Result);
}
/*********************************************************************
*
* Function: adi_pdd_Open
*
* Description: Opens the ADV717x device for use
*
*********************************************************************/
static u32 adi_pdd_Open( // Open a device
ADI_DEV_MANAGER_HANDLE ManagerHandle, // device manager handle
u32 DeviceNumber, // device number
ADI_DEV_DEVICE_HANDLE DMHandle, // device handle
ADI_DEV_PDD_HANDLE *pPDDHandle, // pointer to PDD handle location
ADI_DEV_DIRECTION Direction, // data direction
void *pEnterCriticalArg, // enter critical region parameter
ADI_DMA_MANAGER_HANDLE DMAHandle, // handle to the DMA manager
ADI_DCB_HANDLE DCBHandle, // callback handle
ADI_DCB_CALLBACK_FN DMCallback // device manager callback function
) {
u32 Result; // return code
ADI_ADV717x *pADV717x; // pointer to the ADV717x device we're working on
void *pExitCriticalArg; // exit critical region parameter
// Check for a valid device number
#ifdef ADI_DEV_DEBUG
if (DeviceNumber >= ADI_ADV717x_NUM_DEVICES) return (ADI_DEV_RESULT_BAD_DEVICE_NUMBER);
#endif
/********************************
Configure ADV717x device instance
********************************/
// assign the pointer to the device instance
pADV717x = &Device[DeviceNumber];
// and store the Manager handle
pADV717x->ManagerHandle = ManagerHandle;
// and store the Device Manager handle
pADV717x->DMHandle = DMHandle;
// and store the DMA Manager handle
pADV717x->DMAHandle = DMAHandle;
// and store the DCallback Manager handle
pADV717x->DCBHandle = DCBHandle;
// and callback function
pADV717x->DMCallback = DMCallback;
// insure the device the client wants is available
Result = ADI_DEV_RESULT_DEVICE_IN_USE;
// Check that this device instance is not already in use.
// If not, assign flag to indicate that it is now.
pExitCriticalArg = adi_int_EnterCriticalRegion(pEnterCriticalArg);
if (pADV717x->adv717x_semaphores.InUseFlag == FALSE) {
pADV717x->adv717x_semaphores.InUseFlag = TRUE;
Result = ADI_DEV_RESULT_SUCCESS;
}
adi_int_ExitCriticalRegion(pExitCriticalArg);
if (Result != ADI_DEV_RESULT_SUCCESS) return (Result);
// save the physical device handle in the client supplied location
*pPDDHandle = (ADI_DEV_PDD_HANDLE *)pADV717x;
// return after successful completion
return(Result);
}
/*********************************************************************
*
* Function: adi_pdd_Close
*
* Description: Closes down a PPI & twi device
*
*********************************************************************/
static u32 adi_pdd_Close( // Closes a device
ADI_DEV_PDD_HANDLE PDDHandle // PDD handle
) {
// default return code
u32 Result = ADI_DEV_RESULT_SUCCESS;
// Pointer to the device driver instance
ADI_ADV717x *pADV717x = (ADI_ADV717x *)PDDHandle;
// check for errors if required
#if defined(ADI_DEV_DEBUG)
if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// Close the present PPI device being used
Result = PPI_Close(PDDHandle);
// mark the device as closed
pADV717x->adv717x_semaphores.InUseFlag = FALSE;
return(Result);
}
/*********************************************************************
*
* Function: adi_pdd_Read
*
* Description: Never called as PPI uses DMA & only used to send data
*
*********************************************************************/
static u32 adi_pdd_Read( // Reads data or queues an inbound buffer to a device
ADI_DEV_PDD_HANDLE PDDHandle, // PDD handle
ADI_DEV_BUFFER_TYPE BufferType, // buffer type
ADI_DEV_BUFFER *pBuffer // pointer to buffer
) {
// No read operation for ADV717x
return(ADI_ADV717x_RESULT_CMD_NOT_SUPPORTED);
}
/*********************************************************************
*
* Function: adi_pdd_SequentialIO
*
* Description: Function not supported by this driver
*
*********************************************************************/
static u32 adi_pdd_SequentialIO( // Reads data or queues an inbound buffer to a device
ADI_DEV_PDD_HANDLE PDDHandle, // PDD handle
ADI_DEV_BUFFER_TYPE BufferType, // buffer type
ADI_DEV_BUFFER *pBuffer // pointer to buffer
) {
// Function not supported
return(ADI_ADV717x_RESULT_CMD_NOT_SUPPORTED);
}
/*********************************************************************
*
* Function: adi_pdd_Write
*
* Description: Write only to PPI driver (Video data)
*
*********************************************************************/
static u32 adi_pdd_Write( // Writes data or queues an outbound buffer to a device
ADI_DEV_PDD_HANDLE PDDHandle, // PDD handle
ADI_DEV_BUFFER_TYPE BufferType, // buffer type
ADI_DEV_BUFFER *pBuffer // pointer to buffer
) {
// Pointer to the device driver instance
ADI_ADV717x *pADV717x = (ADI_ADV717x *)PDDHandle;
#if defined(ADI_DEV_DEBUG)
// check for errors if required
u32 Result = ADI_DEV_RESULT_SUCCESS;
if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// pass the request on to PPI
return(adi_dev_Write (pADV717x->ppiHandle, BufferType, pBuffer));
}
/*********************************************************************
*
* Function: adi_pdd_Control
*
* Description:
*
*********************************************************************/
static u32 adi_pdd_Control( // Sets or senses a device specific parameter
ADI_DEV_PDD_HANDLE PDDHandle, // PDD handle
u32 Command, // command ID
void *Value // command specific value
) {
ADI_ADV717x *pADV717x; // pointer to the device we're working on
u32 Result; // return value
u32 u32Value; // u32 type to avoid casts/warnings etc.
u8 u8Value; // u8 type to avoid casts/warnings etc.
u16 SCFRvalue[4]; // array to hold subcarrier frequency value
// value to be passed to device access service to read/write AD717x SCFR
ADI_DEV_ACCESS_REGISTER_BLOCK accessSCFR;
// value to be passed to device access service reset ADV717x timing registers
ADI_DEV_ACCESS_REGISTER_FIELD ResetTimingReg;
// Structure passed to device access service
ADI_DEVICE_ACCESS_REGISTERS access_device;
// Pointer to the device driver instance
pADV717x = (ADI_ADV717x *)PDDHandle;
// assign 8, 16 and 32 bit values for the Value argument
u32Value = (u32) Value;
u8Value = (u8) u32Value;
// check for errors if required
#if defined(ADI_DEV_DEBUG)
if ((Result = ValidatePDDHandle(PDDHandle)) != ADI_DEV_RESULT_SUCCESS) return (Result);
#endif
// assume we're going to be successful
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -