📄 spirom_test.c
字号:
/*
* Copyright 2007 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* SPI ROM test
*
*/
#include "davincihd.h"
#include "spirom.h"
#include "stdio.h"
static Uint8 tx[64];
static Uint8 rx[64];
#define MAX_IMAGE_SIZE 16384
#define E_PASS 0
#define E_FAIL -1
/* ------------------------------------------------------------------------ *
* *
* spirom_test( ) *
* SPI ROM test, write then verify the contents of the first 4 pages *
* *
* ------------------------------------------------------------------------ */
Int16 spirom_test( )
{
Int16 i;
Uint8* p8;
Uint16 page_size = spirom_PAGESIZE;
FILE *fPtr;
Int32 fileSize = 0;
Int32 no_of_pages;
Int8 fileName[256];
/* Initialize the SPI interface */
spirom_init( );
printf( "Starting SPIWriter.\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/spirom_PAGESIZE + 1;
printf("Writing Data to SPI 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++ )
{
p8 = (Uint8*) tx;
fileSize = fread(p8,1,spirom_PAGESIZE,fPtr);
spirom_write( ( Uint32 )tx, i * spirom_PAGESIZE, spirom_PAGESIZE );
}
fseek(fPtr,0,SEEK_SET);
for ( i = 0 ; i < no_of_pages ; i++ )
{
fileSize = fread(tx,1,spirom_PAGESIZE,fPtr);
tx[32] = '\0';
spirom_read( i * spirom_PAGESIZE, (Uint32)rx, page_size );
rx[32] = '\0';
if(strcmp(rx,tx)!= 0)
printf("Files did not match \n");
}
printf("Files matched \n");
fclose(fPtr);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -