📄 eeprom_test.c
字号:
/***********************************************************************
* $Workfile: eeprom_test.c $
* $Revision: 1.1 $
* $Author: TilburyC $
* $Date: Oct 14 2004 17:52:36 $
*
* Project: LH79524 EEPROM test
*
* Description: This file contains the basic eeprom tests
*
* Local Includes:
*
* Revision History:
* $Log:: $
*
* Rev 1.1 Oct 14 2004 17:52:36 TilburyC
* Fixed problem with reading eeprom at 400kbpS
*
* Rev 1.0 Oct 13 2004 16:58:52 TilburyC
* Initial revision.
*
*
***********************************************************************
*
* Copyright (c) 2004 Sharp Microelectronics of the Americas
*
* All rights reserved
*
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "sdk79524_board.h"
#include "lh79524_int_driver.h"
#include "console.h"
#include "eeprom_i2c.h"
/*
Basic EEPROM tests
*/
INT_32 init_all(void);
INT_32 run_test1(void);
/**********************************************************************
*
* Function:
* main()
*
* Purpose:
* Main program entry point.
*
* Processing:
* Run all tests associated with the eeprom
*
* Parameters:
* None
*
* Outputs:
* None
*
* Returns:
* zero
*
* Notes:
* None
*
*********************************************************************/
int main(void)
{
/* initailize to low speed */
if(init_all() != _NO_ERROR)
{
print_strg("\r\nInit low speed failed");
return _ERROR;
}
/* init the random number generator */
srand(time(NULL));
run_test1();
return 0;
}
/**********************************************************************
*
* Function:
* init_all()
*
* Purpose:
* Initialize all interfaces used by this application.
*
* Processing:
* See below
*
* Parameters:
* None
*
* Outputs:
* I2C, VIC, and UART0 registers.
*
* Returns:
* If any of the init functions returns something other than
* _NO_ERROR then that status is returned as an error.
*
* Notes:
* None
*
*********************************************************************/
INT_32 init_all(void)
{
INT_32 status = 0;
/* take care to init interrupts first. This other interfaces depend
upon it. */
if((status = init_irq_interrupts()) != _NO_ERROR)
return status;
/* init the console */
if((status = init_console()) != _NO_ERROR)
return status;
/* init I2C interface and the eeprom */
if((status = init_eeprom()) != _NO_ERROR)
return status;
return _NO_ERROR;
}
/**********************************************************************
*
* Function:
* run_test1()
*
* Purpose:
* Write and read a single sector of EEPROM at 100kbpS. Compare
* the results of the read to what was written. If they match,
* then the test passes.
*
* Processing:
* See below
*
* Parameters:
* None
*
* Outputs:
* Contents of the EEPROM
*
* Returns:
* _NO_ERROR upon success, or _ERROR
*
* Notes:
* If there is data in the EEPROM at address 0x100, then that
* data will be destroyed.
*
*********************************************************************/
INT_32 run_test1(void)
{
FILE *fp;
CHAR fname[80];
CHAR tmp_buffer[64];
CHAR i2c_buffer[64];
UNS_32 index, count = 0;
INT_32 addr = 0;
INT_32 result = _NO_ERROR;
int i;
/* set the interface speed to low */
i2c_ioctl(I2C_BASE, I2C_IOCTL_SET_SPEED, 0);
print_strg("\r\n\r\n===================================="
"==================================");
// prompt for the file to load
print_strg("\r\nEnter the name of the file to read: ");
if(read_strg(fname, sizeof(fname)) == 0)
{
print_strg("\r\nabort read\r\n");
return 0;
}
//strcpy(fname, "c:\\autoexec.bat");
// open the file
if((fp = fopen(fname, "rb")) == NULL)
{
print_strg("\r\nCannot open the file: %s: ", fname);
perror("");
return 0;
}
// find the size of the file by reading it
print_strg("\r\n");
index = 0;
do
{
count = fread(tmp_buffer, 1, sizeof(tmp_buffer), fp);
index += count;
/* write the data to the eeprom */
if(write_eeprom_buffer(addr, tmp_buffer, count) != count)
{
print_strg("\r\nWrite failed");
result = _ERROR;
goto end_of_function;
}
for(i=0;i<100000;i++);
/* read the buffer back from the EEPROM */
if(read_eeprom_buffer(addr, i2c_buffer, count) != count)
{
print_strg("\r\nRead failed");
result = _ERROR;
goto end_of_function;
} else {
UNS_32* src_addr = (UNS_32*)&tmp_buffer[0];
UNS_32* des_addr = (UNS_32*)&i2c_buffer[0];
int i;
i = count/sizeof(UNS_32);
/* verify the buffer is correct */
while(i--)
{
if(*src_addr++ != *des_addr++)
{
print_strg("\r\nBuffer comparison has failed!");
result = _ERROR;
dump_buffer(i2c_buffer, count, addr);
dump_buffer(tmp_buffer, count, addr);
goto end_of_function;
}
}
dump_buffer(i2c_buffer, count, addr);
}
addr += count;
} while(!feof(fp) && (index < 4096));
/* handle test results and errors here */
end_of_function:
/* reset the statistics */
i2c_ioctl(I2C_BASE, I2C_IOCTL_RESET_STATS, 0);
fclose(fp);
// print results
print_strg("\r\nThere were %d bytes read...\r\n", index);
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -