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

📄 te8200pf.c

📁 IT projecotr reference design.
💻 C
字号:
/*************************************************************************
** TEXAS INSTRUMENTS PROPRIETARY INFORMATION
**
**  (c) Copyright, Texas Instruments Incorporated, 2005-2007.
**      All Rights Reserved.
**
**  Property of Texas Instruments Incorporated. Restricted Rights -
**  Use, duplication, or disclosure is subject to restrictions set
**  forth in TI's program license agreement and associated documentation.
**************************************************************************/
/* This code was written from the TE8200PF spec */

#include "common.h"
#include "rta_pub.h"
#include "rta_tsk.h"
#include "rta_sem.h"
#include "tmr.h"
#include "i2c.h"
#include "te8200pf.h"

/* Register defines */

#define PORT_SELECT          0x00
#define PC_INPUT_POL        0x01
#define IN_TYPE_DETECT_1    0x02
#define IN_TYPE_DETECT_2    0x03
#define SYNCSEP_ADJ_1        0x04
#define SYNCSEP_ADJ_2        0x05
#define HSYNC_MASK_1        0x06
#define HSYNC_MASK_2        0x07
#define VSYNC_MASK_1        0x08
#define VSYNC_MASK_2        0x09   
#define VSYNC_MASK_3        0x0A   
#define PROG_GATE_1            0x0B
#define PROG_GATE_2            0x0C
#define STDBY_ETC            0x0D

#define HSYNC_WIDTH_CTS_1   0x1c
#define HSYNC_WIDTH_CTS_2   0x1d
#define OUTPUT_CONT         0x1e
#define INTERLACE           0x1f
#define BGP_CTRL_1          0x20
#define BGP_CTRL_2          0x21
#define BLANKING_PULSE      0x22

I2CPORT sync_i2c_port;
uint08  sync_i2c_addr;
uint32 sync_i2c_sem;

BOOL configuredForSOG = TRUE;

//=================================================================================================
const uint08 SYNC_InitDataCommon[] = {        // common init data for TEP8200PF
    PORT_SELECT,        0x02,        // Video1, TVideo1
    PC_INPUT_POL,       0xCC,        // Set Polarity check times to TVPA = Tclk * 2^18
    IN_TYPE_DETECT_1,   0x18,        // Auto sync type detect on primary
    IN_TYPE_DETECT_2,   0x00,        // Auto sync type detect on background channel
    SYNCSEP_ADJ_1,      0x15,        // Medium Threshold values for primary
    SYNCSEP_ADJ_2,      0x55,        // Medium Threshold values for video in

//-----------------------------------------------
    0xFF, 0xFF,        // End mark
};

//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_I2CMasterWrite
//
//@Description :: TE8200PF I2C Write
//
//@Parameter   ::
//    uint08 *pI2cCmdData        :    pointer to I2C command data
//
//@Return      :: int08: PASS/FAIL
//-----------------------------------------------------------------------------
int08 SYNC_i2c_MasterWrite( I2CPORT  Port, uint16  DeviceAddress,  uint32  NumOfBytes,  
                                uint08 *  WriteBuffer, uint32  ByteDelay, uint32  Timeout,  
                                uint32 *  BytesWritten )
{
    int08 RetVal = PASS;

    // Reserve I2C Semaphore
    if (RTA_SemReserve(sync_i2c_sem, TMR_ConvertMSToTicks(1000)) != RTA_SUCCESS) {
        return FAIL;
    }
        
    RetVal = I2C_MasterWrite(Port,
                            DeviceAddress,
                            NumOfBytes,                /* num write bytes */
                            WriteBuffer,
                            ByteDelay,                /* byte delay */
                            Timeout,            /* timeout */
                            BytesWritten);

    // Release I2C Semaphore
    RTA_SemRelease(sync_i2c_sem);

    return RetVal;
}

int08 SYNC_i2c_MasterWriteRestartRead  (  I2CPORT Port, uint16  DeviceAddress,  uint32  NumOfWrtBytes,  
                                    uint08 * WriteBuffer, uint32  ByteDelay, uint32  NumOfRdBytes,  
                                    uint08 * ReadBuffer,  uint32  Timeout,  uint32 *  BytesWritten,  
                                    uint32 *  BytesRead )  
 {
     int08 RetVal = PASS;
    
    
        // Reserve I2C Semaphore
    if (RTA_SemReserve(sync_i2c_sem, TMR_ConvertMSToTicks(1000)) != RTA_SUCCESS) {
        return FAIL;
    }
    
        
    RetVal = I2C_MasterWriteRestartRead(Port,
                            DeviceAddress,
                            NumOfWrtBytes,                /* num write bytes */
                            WriteBuffer,
                            ByteDelay,                /* byte delay */
                            NumOfRdBytes,
                            ReadBuffer,
                            Timeout,            /* timeout */
                            BytesWritten,
                            BytesRead);
    
    
    // Release I2C Semaphore
    RTA_SemRelease(sync_i2c_sem);
    
    return RetVal;
 
 
 }






//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_I2CMasterWriteCmds
//
//@Description :: TE8200PF Video Decoder uCode downloading
//
//@Parameter   ::
//    uint08 *pI2cCmdData        :    pointer to I2C command data
//
//@Return      :: int08: PASS/FAIL
//-----------------------------------------------------------------------------
int08 SYNC_I2CMasterWriteCmds(  uint08 *pI2cCmdData)
{
    int08 RetVal = PASS;
    uint32 numWritten;

    while (RetVal == PASS && *pI2cCmdData != 0xFF) {
        RetVal = SYNC_i2c_MasterWrite(sync_i2c_port,
                        (uint16) sync_i2c_addr,
                        2,                /* num write bytes */
                        (uint08 *) pI2cCmdData,
                        0,                /* byte delay */
                        1000,            /* timeout */
                        &numWritten);
        pI2cCmdData += 2;    // point to next command
    }
    
    return RetVal;
}


//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_IsSignalPresent
//
//@Description :: TE8200PF Sync Seperator Check if Signal present
//
//@Parameter   ::
//    uint08 sync_i2c_addr    :    I2C Device Address
//    BOOL *signal            :    Signal present status
//
//@Return      :: int08: PASS/FAIL
//                 uint08 type 0 = no syncs
//                             1 = separate H&V
//                             2, 3 = sync on green
//-----------------------------------------------------------------------------
int08 SYNC_GetSyncType(uint08* type )
{
    int08 RetVal;
    uint08 WorkUint08[2];
    uint32 numWritten, numRead;
    

    WorkUint08[0] = IN_TYPE_DETECT_1;
    WorkUint08[1] = 0;
    
    RetVal = SYNC_i2c_MasterWriteRestartRead(sync_i2c_port,
                                    (uint16)sync_i2c_addr,
                                    1,                    /* num write bytes */
                                    WorkUint08,            /* write buffer */
                                    0,                    /* write delay */
                                    1,                    /* num read bytes */
                                    &(WorkUint08[1]),    /* Read data buffer */
                                    1000,                /* timeout (ms) */
                                    &numWritten,
                                    &numRead);
    
    if (RetVal == PASS) 
    {        
        // BIT0&1 determine sync type
        *type = (uint08)(WorkUint08[1] & (uint08)0x03);
    }
    

    return RetVal;
}

//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_GetConfiguredPort
//
//@Description :: TE8200PF Sync Seperator Check if Separate H&V present
//
//@Parameter   ::
//    uint08 sync_i2c_addr    :    I2C Device Address
//    BOOL *signal            :    Signal present status
//
//@Return      :: int08: 0 = Sync on Green
//                       1 = Separate H&V
//
//-----------------------------------------------------------------------------
int08 SYNC_GetConfiguredPort( void )
{
    return configuredForSOG;
}

//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_ConfigureForSeparateHV
//
//@Description :: TE8200PF Sync Seperator Check if Separate H&V present
//
//@Parameter   ::
//    uint08 sync_i2c_addr    :    I2C Device Address
//    BOOL *signal            :    Signal present status
//
//@Return      :: int08: PASS/FAIL
//-----------------------------------------------------------------------------
int08 SYNC_ConfigureForSeparateHV( void )
{
    int08 RetVal;
    uint08 WorkUint08[2];
    uint32 numWritten;
    
    WorkUint08[0] = PORT_SELECT;
    WorkUint08[1] = 0x0; /* look for separate H&V -- Hin1 Vin1 Gin1 */

    RetVal = SYNC_i2c_MasterWrite(  sync_i2c_port,
                                    (uint16)sync_i2c_addr,
                                    2,                    /* num write bytes */
                                    WorkUint08,            /* write buffer */
                                    0,                    /* write delay */
                                    1000,                /* timeout (ms) */
                                    &numWritten );
    if( RetVal == PASS )
        configuredForSOG = FALSE;
        
    return RetVal;
}

//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_ConfigureForSOG
//
//@Description :: TE8200PF Sync Seperator Check if Sync on Green present
//
//@Parameter   ::
//    uint08 sync_i2c_addr    :    I2C Device Address
//    BOOL *signal            :    Signal present status
//
//@Return      :: int08: PASS/FAIL
//-----------------------------------------------------------------------------
int08 SYNC_ConfigureForSOG( void )
{
    int08 RetVal;
    uint08 WorkUint08[2];
    uint32 numWritten;
    
    WorkUint08[0] = PORT_SELECT;
    WorkUint08[1] = 0x2; /* look for SOG -- Video1 TVideo1 */

    RetVal = SYNC_i2c_MasterWrite(  sync_i2c_port,
                                    (uint16)sync_i2c_addr,
                                    2,                    /* num write bytes */
                                    WorkUint08,            /* write buffer */
                                    0,                    /* write delay */
                                    1000,                /* timeout (ms) */
                                    &numWritten );
    if( RetVal == PASS )
        configuredForSOG = TRUE;
        
    return RetVal;
}

//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_SearchSignal
//
//@Description :: TE8200PF Sync Seperator Check if Signal present
//
//@Parameter   ::
//    uint08 sync_i2c_addr    :    I2C Device Address
//    BOOL *signal            :    Signal present status
//
//@Return      :: int08: PASS/FAIL
//               detectedSignalType 0 = no syncs detected
//                                  1 = vert and horiz sync detected
//                                  2 = sync on green detected
//-----------------------------------------------------------------------------
int08 SYNC_SearchSignal(uint08* detectedSignalType )
{
    int08 RetVal;
    uint08 WorkUint08[2];
    uint32 numWritten, numRead;
    
    *detectedSignalType = 0;

    /* search first for separate H&V syncs */
    RetVal = SYNC_ConfigureForSeparateHV();
    
    if( RetVal != PASS )
        return RetVal;

    RTA_TaskDelay(TMR_ConvertMSToTicks( 400 ));

    WorkUint08[0] = IN_TYPE_DETECT_1;
    WorkUint08[1] = 0;
    
    RetVal = SYNC_i2c_MasterWriteRestartRead(sync_i2c_port,
                                    (uint16)sync_i2c_addr,
                                    1,                    /* num write bytes */
                                    WorkUint08,            /* write buffer */
                                    0,                    /* write delay */
                                    1,                    /* num read bytes */
                                    &(WorkUint08[1]),    /* Read data buffer */
                                    1000,                /* timeout (ms) */
                                    &numWritten,
                                    &numRead);
    if( RetVal != PASS )
        return RetVal;

    if( (WorkUint08[1] & 0x3) == 1 ) /* PC syncs */
    {
        *detectedSignalType = 1;  /* vertical and horizontal syncs detected */
        return PASS;
    }
    
    
    /* search for Sync on Green */
    RetVal = SYNC_ConfigureForSOG();
    
    if( RetVal != PASS )
        return RetVal;

    RTA_TaskDelay(TMR_ConvertMSToTicks( 400 ));

    WorkUint08[0] = IN_TYPE_DETECT_1;
    WorkUint08[1] = 0;
    
    RetVal = SYNC_i2c_MasterWriteRestartRead(sync_i2c_port,
                                    (uint16)sync_i2c_addr,
                                    1,                    /* num write bytes */
                                    WorkUint08,            /* write buffer */
                                    0,                    /* write delay */
                                    1,                    /* num read bytes */
                                    &(WorkUint08[1]),    /* Read data buffer */
                                    1000,                /* timeout (ms) */
                                    &numWritten,
                                    &numRead);
    if( RetVal != PASS )
        return RetVal;

    if( (WorkUint08[1] & 0x3) == 2 ) /* SOG syncs */
    {
        *detectedSignalType = 2;  /* SOG detected */
        return PASS;
    }

    return PASS;
}

//-----------------------------------------------------------------------------
//@RoutineName :: SYNC_Init
//
//@Description :: TE8200PF Sync Seperator initializations (almost the same as SYNC_InitCommon)
//
//@Parameter   ::
//    uint08 sync_i2c_addr    :    I2C Device Address
//  I2CPORT i2cport            :    I2C Port 0/1
//
//@Return      :: int08: PASS/FAIL
//-----------------------------------------------------------------------------
int08 SYNC_Init( uint08 synci2caddr, I2CPORT i2cport )
{
    int08 RetVal = PASS;
    
    sync_i2c_port = i2cport;
    sync_i2c_addr = synci2caddr;
    I2C_GetSemaphoreID( sync_i2c_port, &sync_i2c_sem );
    
    RetVal = SYNC_I2CMasterWriteCmds((uint08 *) &(SYNC_InitDataCommon[0]));
    
    return RetVal;
}

⌨️ 快捷键说明

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