📄 testflash.c
字号:
#include <csl.h>
#include <csl_ebus.h>
#include <stdio.h>
#include <csl_pll.h>
//#include <csl_mcbsp.h>
//#include <csl_gpio.h>
//#include <csl_irq.h>
#include <csl_chip.h>
#define FLASH_ADDRS 0x8000
#define LENGTH 0x200
//#define DATALEN 11152
#define DATALEN 10984
unsigned int read_buf[128],write_buf[128];
unsigned int *flash_start;
PLL_Config pll_conf={PLL_MODE_MUL,20,0};
void waitfor(int tt);
void ebus_init();
void read_sector(unsigned int offset);
void read_sectorflag();
void read_productid();
void main()
{
unsigned int *flash_ptr =(unsigned int *)0x8000;
unsigned int * src_ptr;
unsigned int length;
unsigned int last_dataL;
unsigned int write_num;
unsigned int temp1;
unsigned int temp2;
unsigned int i,j;
int error=0;
FILE *f1;
CSL_init();
ebus_init();
PLL_config(&pll_conf);
flash_start =(unsigned int *)FLASH_ADDRS;
for(i=0;i<128;i++)
{
read_buf[i]=0x0000;
write_buf[i]=0x0000;
}
erase_flash();
read_sector(0);
// f1=fopen("f:\\modem5402\\modem1018.bin","rb+");
f1=fopen("f:\\modem5402\\demodem1018.bin","rb+");
// if(f1==NULL)
// puts("not open file");
write_num=DATALEN/128;
temp1=write_num*128;
temp2=DATALEN;
last_dataL=temp2-temp1;
for(i=0;i<write_num;i++)
{
fread(read_buf,1,128,f1);
src_ptr=read_buf;
program_flash(src_ptr, flash_ptr, 128);
for(j=0;j<128;j++)
{
write_buf[j]=0x0000;
}
flash_ptr=flash_ptr+128;
read_sector(i);
for(j=0;j<128;j++)
{
if(read_buf[j]!=write_buf[j])
{
error=1;
}
}
}
for(i=0;i<128;i++)
{
read_buf[i]=0xff;
}
fread(read_buf,1,last_dataL,f1);
src_ptr=read_buf;
program_flash(src_ptr, flash_ptr, 128);
read_sector(write_num);
for(j=0;j<128;j++)
{
if(read_buf[j]!=write_buf[j])
{
error=1;
}
}
for(i=0;i<126;i++)
{
read_buf[i]=0xff;
}
read_buf[126]=0x80;
read_buf[127]=0x00;
flash_ptr=(unsigned int *)0xff80;
src_ptr=read_buf;
program_flash(src_ptr, flash_ptr, 128);
read_sectorflag();
for(j=0;j<128;j++)
{
if(read_buf[j]!=write_buf[j])
{
error=1;
}
}
//}
for(i=0;i<10;i++)
read_sector(i);
fclose(f1);
}
/****************************************************************************/
/* erase_flash : Routine to erase entire FLASH memory AM29LV800 (1M bit/ */
/* 512k x 16bit) */
/* Inputs: */
/* flash_ptr: Address of the FLASH PEROM */
/* */
/****************************************************************************/
int erase_flash()
{
/* Control addresses are left shifted so that */
/* they appear correctly on the EMIF's EA[19:2] */
/* Byte address << 2 == Word Address */
int pass = TRUE;
int * ctrl_addr1 =(unsigned int *)(flash_start + 0x5555);
int * ctrl_addr2 =(unsigned int *)(flash_start + 0x2aaa);;
* ctrl_addr1 = 0x00aa; /* Erase sequence writes to addr1 and addr2 */
* ctrl_addr2 = 0x0055; /* with this data */
* ctrl_addr1 = 0x0080;
* ctrl_addr1 = 0x00aa;
* ctrl_addr2 = 0x0055;
* ctrl_addr1 = 0x0010;
// pass = poll_data(flash_ptr, (unsigned int) 0xff);
waitfor(200);
return pass;
}
/****************************************************************************/
/* program_flash: Routine to program FLASH AM29LV800 */
/* Inputs: */
/* flash_ptr : Address of the FLASH */
/* source_ptr : Address of the array containing the code to program */
/* length : Length to be programmed */
/* */
/****************************************************************************/
int program_flash(unsigned int * source_ptr, unsigned int * flash_ptr, int length)
{
unsigned int i,j;
int data;
int pass=TRUE;
unsigned int * ctrl_addr1 = (unsigned int *) (flash_start + 0x5555);
unsigned int * ctrl_addr2 = (unsigned int *) (flash_start + 0x2aaa);
for (i = 0; i < 1; i++)
{
* ctrl_addr1 = 0x00aa;
* ctrl_addr2 = 0x0055;
* ctrl_addr1 = 0x00a0;
for(j=0;j<length;j++)
{
data=* source_ptr++;
* flash_ptr++ = data;
}
}
// pass = poll_data(flash_ptr-1, data);
waitfor(20);
return pass;
}
int poll_data(unsigned int * prog_ptr, unsigned int prog_data)
{
int data;
int fail = FALSE;
do {
data = (unsigned int) * prog_ptr;
if (data != prog_data) /* is D7 != Data? */
{
fail = FALSE;
}
else
fail = TRUE; /*PASS */
} while (!fail);
return fail; /* FAIL*/
}
void read_sector(unsigned int offset)
{
unsigned int *source_ptr;
int i;
source_ptr=(unsigned int *)(0x8000+offset*128);
for(i=0;i<128;i++)
{
write_buf[i]=(*source_ptr++)&0x00ff;
}
}
void read_sectorflag()
{
unsigned int *source_ptr;
int i;
source_ptr=(unsigned int *)0xff80;
for(i=0;i<128;i++)
{
write_buf[i]=(*source_ptr++)&0x00ff;
}
}
void waitfor(int tt)
{
unsigned int t1,t2;
for(t1=0;t1<0x8000;t1++)
{
for(t2=0;t2<tt;t2++)
{
}
}
}
void ebus_init()
{
EBUS_Config ebus_conf={
0x7fff,
0xf800,
0x0000
};
EBUS_config(&ebus_conf);
}
/*
void read_productid()
{
int pass = TRUE;
unsigned int ManuID;
unsigned int DeviceID;
unsigned int * ctrl_addr1 =(unsigned int *)((long)flash_ptr + 0x5555);
unsigned int * ctrl_addr2 =(unsigned int *)((long)flash_ptr + 0x2aaa);
unsigned int *flash_ptr1=(unsigned int *)0x0000;
unsigned int *flash_ptr2=(unsigned int *)0x0001;
* ctrl_addr1 = 0x00aa;
* ctrl_addr2 = 0x0055;
* ctrl_addr1 = 0x0090;
waitfor(200);
ManuID=*
DeviceID=*
* ctrl_addr1 = 0x00aa;
* ctrl_addr2 = 0x0055;
* ctrl_addr1 = 0x00f0;
// pass = poll_data(flash_ptr, (unsigned int) 0xff);
waitfor(200);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -