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

📄 edid.c

📁 IT projecotr reference design.
💻 C
字号:
/****************************************************************************/
/*             TEXAS INSTRUMENTS PROPRIETARY INFORMATION                    */
/*                                                                          */
/*  (c) Copyright, Texas Instruments Incorporated, 2006.                    */
/*      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.   */
/****************************************************************************/

/****************************************************************************/
/* edid.c                                                                   */
/*                                                                          */
/* EDID interface.                                                          */
/*                                                                          */
/* Functions in this file assume a type 24C01 or 24C02 EEPROM.              */
/****************************************************************************/

#include <stddef.h>
#include <string.h>

#include "common.h"
#include "ddp2230_rtos_include.h"

#include "edid.h"

/****************************************************************************/
/* Declarations.                                                            */
/****************************************************************************/

#define PAGESIZE    8                        /* eeprom read/write page size */



/****************************************************************************/
/* Compare:                                                                 */
/*                                                                          */
/* Compare the content of the device with the content at *pFlash, typically */
/* from the flash configuration. Comparison begins with byte[0] and         */
/* compares 128 bytes. Results are stored at *pComp, and are the XOR of     */
/* device and reference values.                                             */
/****************************************************************************/

int08 edid_compare( uint16 devAddress, uint08 *pComp, uint08 *pFlash )
{
    uint32 SemID;
    uint32 bytecount;                                         /* byte count */
    uint08 buffer[ PAGESIZE ];                               /* temp buffer */
    uint08 eeAddress;                               /* EEPROM array address */
    uint08 bp; /* byte pointer */
    int08  cc;                                           /* completion code */

    I2C_GetSemaphoreID( EDID_I2C_PORT, &SemID );
    
    if( RTA_SUCCESS != ( cc = RTA_SemReserve( SemID, 100 )))
        return cc;

    for( eeAddress = 0; eeAddress < 128; eeAddress += PAGESIZE )
    {
        if( PASS != ( cc = I2C_MasterWriteRestartRead( EDID_I2C_PORT, 
                            devAddress, 1, &eeAddress, 0, PAGESIZE, 
                            buffer, 1000, &bytecount, &bytecount )))
        {
	        RTA_SemRelease( SemID );
	        return cc;
        }
        
        for( bp = 0; bp < PAGESIZE; bp++ )                       /* compare */
            *pComp++ = *pFlash++ ^ buffer[ bp ];
    }

	RTA_SemRelease( SemID );

    return PASS;
}



/****************************************************************************/
/* Read:                                                                    */
/*                                                                          */
/* Read from the device and store at *pData, The read begins at byte[0] and */
/* reads 128 bytes.                                                         */
/****************************************************************************/

int08 edid_read( uint16 devAddress, uint08 *pData )
{
    uint32 SemID;
    uint32 bytecount;                                         /* byte count */
    uint08 eeAddress;                               /* EEPROM array address */
    int08  cc;                                           /* completion code */

    I2C_GetSemaphoreID( EDID_I2C_PORT, &SemID );
    
    if( RTA_SUCCESS != ( cc = RTA_SemReserve( SemID, 100 )))
        return cc;

    for( eeAddress = 0; eeAddress < 128; eeAddress += PAGESIZE )
    {
        if( PASS != ( cc = I2C_MasterWriteRestartRead( EDID_I2C_PORT, 
                            devAddress, 1, &eeAddress, 0, PAGESIZE, 
                            pData, 1000, &bytecount, &bytecount )))
        {
	        RTA_SemRelease( SemID );
	        return cc;
        }
        
        pData += 8;
    }

	RTA_SemRelease( SemID );

    return PASS;
}



/****************************************************************************/
/* Write:                                                                   */
/*                                                                          */
/* Fetch from *pData and write to the device. The write begins at byte[0]   */
/* and writes 128 bytes.                                                    */
/*                                                                          */
/* Write acknowledge polling is performed via the write retries.            */
/****************************************************************************/

int08 edid_write( uint16 devAddress, uint08 *pFlash )
{
    uint32 SemID;
    uint32 bytecount;                                         /* byte count */
    uint08 eeAddress;                               /* EEPROM array address */
    uint08 buffer[ PAGESIZE + 1 ];                   /* address byte + data */
    int08  cc;                                           /* completion code */
    int08  tryCount;                                   /* i2c timeout retry */

    I2C_GetSemaphoreID( EDID_I2C_PORT, &SemID ); 
    
    if( RTA_SUCCESS != ( cc = RTA_SemReserve( SemID, 100 )))
        return cc;

    for( eeAddress = 0; eeAddress < 128; eeAddress += PAGESIZE )
    {
        buffer[0] = eeAddress;          /* starting address in EEPROM array */
        
        memcpy( buffer + 1, pFlash, PAGESIZE );      /* copy data to buffer */
        pFlash += PAGESIZE;                          /* bump source address */
        
        for( tryCount = 0; tryCount < 5; tryCount++ )
        {
            if( PASS == ( cc = I2C_MasterWrite( EDID_I2C_PORT, devAddress, 
                                    PAGESIZE + 1, buffer, 0, 20, &bytecount )))
            {
                break;                                           /* success */
            }
        }
        
        if( PASS != cc )                 /* if unsuccessful at end of tries */
            break;
    }

	RTA_SemRelease( SemID );
	
    return cc;
}

⌨️ 快捷键说明

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