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

📄 eeprom_test.c

📁 用于dm6467 开发平台的uboot源码
💻 C
字号:
/*
 *  Copyright 2007 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  I2C EEPROM Test
 *
 */

#include "stdio.h"
#include "davincihd_eeprom.h"

static Uint8 tx[130];
static Uint8 rx[130];

#define MAX_IMAGE_SIZE 16384
#define E_PASS 0
#define E_FAIL -1





/* ------------------------------------------------------------------------ *
 *                                                                          *
 *  eeprom_test( )                                                          *
 *      I2C EEPROM test, write then verify the contents of the first 4      *
 *      pages.                                                              *
 *                                                                          *
 * ------------------------------------------------------------------------ */
Int16 eeprom_test( )
{
    Int16 i;
    Int16 errors = 0;

    Uint16 page_size = EEPROM_PAGE_SIZE;

    Uint32 src, dst;

	Uint32 *p32;

	FILE	*fPtr;
	Int32	fileSize = 0;
	Int32   no_of_pages;  
	Int8	fileName[256];

	printf( "Starting I2CWriter.\r\n");

	// Read the file from host
	printf("Enter the File Name\n");
	scanf("%s", fileName);
	fflush(stdin);

	// Open an File from the hard drive
	fPtr = fopen(fileName, "rb");
	if(fPtr == NULL)
	{
		printf("File %s Open failed\n", fileName);
		return E_FAIL;
	}

	// Initialize the pointer
	fileSize = 0;

	// Read file size
	fseek(fPtr,0,SEEK_END);
	fileSize = ftell(fPtr);

	if(fileSize == 0)
	{
		printf("File read failed.. Closing APP\n");
		fclose (fPtr);
		return E_FAIL;
	}

	fseek(fPtr,0,SEEK_SET);

	no_of_pages = fileSize/page_size + 1;

	printf("Writing Data to I2C EEPROM\n");
	printf(" ... please be patient this takes a while, thanks\n");

    /* Write 1 page at a time */
    for ( i = 0 ; i < no_of_pages ; i++ )
    {
		p32 = (Uint32*)tx;
		fileSize = fread(p32,1,page_size,fPtr);
        dst = i * page_size;

        if ( DAVINCIHD_EEPROM_write( (Uint32)tx, dst, page_size ) )
            return 1;

        _wait( 25000 );
    }
	fseek(fPtr,0,SEEK_SET);

	/*Verifying read */
	for ( i = 0 ; i < no_of_pages ; i++ )
    {
		p32 = (Uint32*)tx;
		fileSize = fread(p32,1,page_size,fPtr);
        src = i * page_size;
        dst = ( Uint32 )&rx[0];
		tx[64] = '\0';

        if ( DAVINCIHD_EEPROM_read( src, dst, page_size ) )
            return 2;

        rx[64] = '\0'; 
        _wait( 25000 );
		if(strcmp(rx,tx)!= 0)
			printf("Files did not match \n");
    }

	printf("Files matched \n");

	fclose(fPtr);
    return errors;
}

⌨️ 快捷键说明

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