📄 adi_adv717x.c
字号:
/*****************************************************************************
Copyright (c) 2005 Analog Devices. All Rights Reserved.
This software is proprietary and confidential. By using this software you agree
to the terms of the associated Analog Devices License Agreement.
******************************************************************************
$File: adi_adv717x.c $
$Revision: 1.5 $
$Date: 2006/09/11 05:51:00 $
Project: ADV717x video encoder device driver
Title: ADV717x driver source code
Author(s): bmk
Revised by: bmk
Description:
This is the driver source code for the ADV717x Video Encoder. It is layered
on top of the PPI and TWI device drivers, which are configured for
the specific use of selected ADV717x peripheral.
References:
Note:
This driver supports BF533,BF537,BF561 and
can be used for ADV7170,ADV7171,ADV7174,ADV7179
******************************************************************************
Modification History:
====================
$Log: adi_adv717x.c,v $
Revision 1.5 2006/09/11 05:51:00 bmk
Fixed adi_dev_Close bug
*****************************************************************************/
#include <drivers/adi_dev.h> // device manager includes
#include <services/services.h> // system services
#include <drivers/deviceaccess/adi_device_access.h> // adi_device_access driver includes
#include <drivers/ppi/adi_ppi.h> // ppi includes
#include <drivers/encoder/adi_adv717x.h> // ADV717x driver includes
/*********************************************************************
Enumerations and defines
*********************************************************************/
/*********************************************************************
Check to insure that one of the ADV7170/ADV7171/ADV7174/ADV7179
video encoders are built but not the ADV717x driver by itself.
*********************************************************************/
#ifndef ADI_ADV7170_DEVICE
#ifndef ADI_ADV7171_DEVICE
#ifndef ADI_ADV7174_DEVICE
#ifndef ADI_ADV7179_DEVICE
#error "*** ERROR: Must build either adi_adv7170.c or adi_adv7171.c or adi_adv7174.c or adi_adv7179.c, not adi_adv717x.c ***"
#endif
#endif
#endif
#endif
#define ADI_ADV717x_NUM_DEVICES (sizeof(Device)/sizeof(ADI_ADV717x)) // number of ADV717x devices in the system
#if defined(ADI_ADV7171_DEVICE) || defined (ADI_ADV7179_DEVICE)
#define ADV717x_FINAL_REG_ADDRESS 0x19 // Address of the last register in ADV7171/ADV7179
#elif defined(ADI_ADV7170_DEVICE) || defined (ADI_ADV7174_DEVICE)
#define ADV717x_FINAL_REG_ADDRESS 0x2F // Address of the last register in ADV7170/ADV7174
#endif
typedef struct ADV717x_SEMAPHORES {
unsigned char TripleFrameSync :1; // flag to indicate whether Triple Frame Sync for PPI is set or not
unsigned char FSCount :2; // Frame Sync Count
unsigned char ADV717x_mode :1; // indicates ADV717x in non-standard (1) or standard (0) mode
unsigned char NTSC_PALflag :1; // flag to indicate ADV717x in NTSC(0) or PAL(1) mode (only in standard video mode)
unsigned char dataflow :1; // Video dataflow on(1) or off(0)
unsigned char InUseFlag :1; // flag to indicate whether an instance is in use or not
} ADV717x_SEMAPHORES;
// Structure to contain data for an instance of the ADV717x device driver
typedef struct {
ADI_DEV_MANAGER_HANDLE ManagerHandle; // Manager Handle
ADI_DEV_DEVICE_HANDLE DMHandle; // Handle of Device Manager instance
ADI_DMA_MANAGER_HANDLE DMAHandle; // handle to the DMA manager
ADI_DCB_HANDLE DCBHandle; // callback handle
ADI_DCB_CALLBACK_FN DMCallback; // the callback function supplied by the Device Manager
ADI_DEV_PDD_HANDLE ppiHandle; // Handle to the underlying PPI device driver
ADI_PPI_FS_TMR *PPI_FS1_TMR; // PPI Frame Sync 1 timer configuration (only for non-standard video mode)
ADI_PPI_FS_TMR *PPI_FS2_TMR; // PPI Frame Sync 2 timer configuration (only for non-standard video mode)
ADI_DEV_CMD_VALUE_PAIR *twiConfigTable; // TWI Configuration Table specific to the application
u32 ppiDeviceNumber; // PPI Device number used for ADV717x video dataflow
u16 PPIControl; // PPI Control register value
u32 PPIFrameLines; // Number of PPI lines per frame
u32 twiDeviceNumber; // TWI Device number used for ADV717x video dataflow
u32 twiDeviceAddress; // TWI address of the ADV717x device
ADV717x_SEMAPHORES adv717x_semaphores; // ADV717x locally used semaphores
} ADI_ADV717x;
// The initial values for the device instance
static ADI_ADV717x Device[] = {
{
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
0, // PPI 0 used by default
#if defined (__ADSPBF561__)
0x0186, // by default, PPI is configured as output with ITU 656 standard data & DMA32 enabled
#else // for BF533 & BF537
0x0086, // by default, PPI is configured as output with ITU 656 standard data
#endif
525, // NTSC as default
0, // TWI 0 as default
#if defined (ADI_ADV7170_DEVICE)
0x6A, // AD7170 device twi address
#elif defined (ADI_ADV7171_DEVICE)
0x2A, // AD7171 device twi address
#elif defined (ADI_ADV7174_DEVICE)
0x6A, // AD7174 device twi address
#elif defined (ADI_ADV7179_DEVICE)
0x2A, // AD7179 device twi address
#endif
0, // default as timing values not yet configured
},
};
/*********************************************************************
Static functions
*********************************************************************/
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
);
static u32 adi_pdd_Close( // Closes a device
ADI_DEV_PDD_HANDLE PDDHandle // PDD handle
);
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
);
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
);
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
);
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
);
// the callback function passed to the PPI driver
static void ppiCallbackFunction(
void* DeviceHandle,
u32 Event,
void* pArg
);
// 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
);
// PPI open function
static u32 PPI_Open(
ADI_DEV_PDD_HANDLE PDDHandle // pointer to PDD handle location
);
// PPI Close function
static u32 PPI_Close(
ADI_DEV_PDD_HANDLE PDDHandle // Physical Device Driver Handle
);
/*********************************************************************
Debug Mode functions (debug build only)
*********************************************************************/
#if defined(ADI_DEV_DEBUG)
// Validate PDD handle
static int ValidatePDDHandle(
ADI_DEV_PDD_HANDLE PDDHandle
);
#endif
/*********************************************************************
Global Registers
*********************************************************************/
/*********************************************************************
Table for Register Field Error check and Register field access
Table structure - 'Count' of Register addresses containing individual fields
Register address containing individual fields,
Register field locations in the corresponding register,
Reserved bit locations in the corresponding register
Register field location - Bit indicating start of new field in a register will be 1
Reserved bit locations will be 1
*********************************************************************/
// ADV717x register address to perform Register Field Error check and Register field access
static u16 adv717xRegAddr1[] = { ADV717x_MR0, ADV717x_MR1, ADV717x_MR2,
ADV717x_MR3, ADV717x_MR4, ADV717x_TMR0,
ADV717x_TMR1, ADV717x_CGMS_WSS0, ADV717x_CGMS_WSS1,
ADV717x_TTX_REQ };
// Register Field start locations corresponding to the entries in adv717xRegAddr1 (Reserved Bit locations marked as 1)
static u16 adv717xRegField[] = { 0x25, 0xFB, 0xFB,
0xFF, 0xFF, 0xDB,
0x55, 0xF1, 0x41,
0x11 };
static ADI_DEVICE_ACCESS_REGISTER_FIELD RegisterField[] = {
sizeof(adv717xRegAddr1)/2, // 'Count' of Register addresses containing individual fields
adv717xRegAddr1, // array of ADV717x register addresses containing individual fields
adv717xRegField, // array of register field locations in the corresponding registers
};
/*********************************************************************
Table to configure the reserved bits in the device to its recommended values
Table structure - 'Count' of Register addresses containing Reserved Locations
Register address containing Reserved Locations
Recommended value for the Reserved Locations
*********************************************************************/
#if defined(ADI_ADV7170_DEVICE) || defined (ADI_ADV7171_DEVICE)
// ADV7170/ADV7171 Register address containing Reserved Locations
static u16 adv717xRegAddr2[] = { ADV717x_MR2, ADV717x_MR3, ADV717x_MR4 };
// ADV7170/ADV7171 register Reserved Bit locations corresponding to the entries in adv717xRegAddr1
static u16 adv717xReservedBits[] = { 0x80, 0x03, 0x80 };
// Recommended values for the Reserved Bit locations corresponding to the entries in adv717xRegAddr2
static u16 adv717xReservedValues[] = { 0x00, 0x00, 0x00 };
#elif defined(ADI_ADV7174_DEVICE) || defined (ADI_ADV7179_DEVICE)
// ADV7174/ADV7179 Register address containing Reserved Locations
static u16 adv717xRegAddr2[] = { ADV717x_MR1, ADV717x_MR2, ADV717x_MR3,
ADV717x_MR4, ADV717x_TMR0 };
// ADV7174/ADV7179 register Reserved Bit locations corresponding to the entries in adv717xRegAddr1
static u16 adv717xReservedBits[] = { 0x10, 0x80, 0x03,
0x80, 0x40 };
// Recommended values for the Reserved Bit locations corresponding to the entries in adv717xRegAddr2
static u16 adv717xReservedValues[] = { 0x10, 0x00, 0x00,
0x00, 0x00 };
#endif
static ADI_DEVICE_ACCESS_RESERVED_VALUES ReservedValues[] = {
sizeof(adv717xRegAddr2)/2, // 'Count' of Register addresses containing Reserved Locations
adv717xRegAddr2, // array of ADV717x Register address containing Reserved Locations
adv717xReservedBits, // array of reserved bit locations in the corresponding register
adv717xReservedValues, // array of Recommended values for the Reserved Bit locations
};
/*********************************************************************
Table for ADV717x Register Error check for invalid & read-only register(s) access
Structure - 'Count' of invalid Register addresses in ADV717x
Invalid Register addresses in ADV717x
'Count' of Read-only Register addresses in ADV717x
Read-only Register addresses in ADV717x
*********************************************************************/
// array of read-only registers addresses in ADV717x.
// No Read-only registers available in ADV717x
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -