各位大侠,我仿照别人的烧写程序改写了一个自己的hex文件烧写程序,DSP是DSP6713,Flash是AM29LV160D,程序是从hex文件中每次读取10行,对这10行进行处理主要是去掉空格和换行符等,然后将其烧写进FLASH,之后再读取10行,循环进行直到读完整个hex文件。现在的问题是:我的进行完第一次10行的读取烧写后,到第二次就会挂死在那里,始终没找到原因,希望大家帮忙看看这是怎么回事?
下面是程序代码:
——————————————————————————————————————————
#include "Sun6713_config.h"
#include <csl_chip.h>
#include <math.h>
#define Sourceaddr 0x90000000
Uint8 Tempdata[720];
Uint8 Tempdata2[740];
Uint16 Tempdata1;
unsigned short Data_to_write[120];
unsigned char Data_from_flash[1024];
char filename[128];
long codelength;
long datalength;
long lengthtemp;
unsigned int processaddr=Sourceaddr;
unsigned int counter=0;
/********************************************************************************/
volatile Uint16* FLASH_ADR1 = (volatile Uint16 *)(0x90000000+(0x555<<1));
volatile Uint16* FLASH_ADR2 = (volatile Uint16 *)(0x90000000+(0x2AA<<1));
#define Pass_Flag 0
#define Fail_Flag 1
#define FLASH_UL1 0x012a;//0xAA
#define FLASH_UL2 0x0095;//0x55
#define FLASH_UL3 0x0100;//0x80
#define FLASH_UL4 0x012a;//0xAA
#define FLASH_UL5 0x0095;//0x55
#define FLASH_SECTOR_UL6 0x30
#define FLASH_CHIP_UL6 0x0010;//0x10
#define FLASH_PROGRAM 0x0120;//0xA0
#define SECTOR_SIZE 0x8000
#define BLOCK_SIZE 0x8000
#define CHIP_SIZE 0x40000
void flash_chip_erase()
{
*FLASH_ADR1=FLASH_UL1;//0xaa; (volatile Uint16*)
*FLASH_ADR2=FLASH_UL2;//0x55;(volatile Uint16*)
*FLASH_ADR1=FLASH_UL3;//0x80;(volatile Uint16*)
*FLASH_ADR1=FLASH_UL4;//0xaa;(volatile Uint16*)
*FLASH_ADR2=FLASH_UL5;//0x55;(volatile Uint16*)
*FLASH_ADR1=FLASH_CHIP_UL6;//0x10; (volatile Uint16*)
}
int Write_Flash_Word(Uint16 *data,Uint16 *address)
{
*(volatile Uint16 *)FLASH_ADR1=FLASH_UL1;//0xaa;
*(volatile Uint16 *)FLASH_ADR2=FLASH_UL2;//0x55;
*(volatile Uint16 *)FLASH_ADR1=FLASH_PROGRAM;//0xa0;
(*address)=*data;
//return(Toggle_Bit_Check(address));
return Pass_Flag;
}
int Read_Flash_Word(Uint16 *data,Uint16 *address)
{
*(volatile Uint16 *)FLASH_ADR1=FLASH_UL1;//0xaa;
*(volatile Uint16 *)FLASH_ADR2=FLASH_UL2;//0x55;
*(volatile Uint16 *)FLASH_ADR1=0x01b0;//0xf0;
*data=(*address);
//return(Toggle_Bit_Check(address));
return Pass_Flag;
}
void Write_Flash(Uint16 Data_to_write[],Uint16 *write_address)
{
int j;
for(j=0;j<120;j++)
Write_Flash_Word(&Data_to_write[j],write_address++);
}
/********************************************************************************/
main()
{
/*******************************************************/
/*** hex文件下载到Flash ***/
FILE *stream;
long int datalength1;
long codelength1;
int i,k;
int Conditionback=1;
/* Initialize DEC6713 board. */
DSP6713_Init();
puts("Please Input your file\n");
scanf("%s",filename);
flash_chip_erase();
puts(" erasing the Flash\n");
stream=fopen(filename,"rb");
fseek(stream,0,SEEK_END); /* the end address of the file */
codelength1 = (long)ftell(stream);
fseek(stream,0,SEEK_SET); /* the start address of the file */
datalength1 = (long)ftell(stream);
codelength = codelength1-datalength1;/* calculate the length of the file */
if(stream != NULL)
{
while(Conditionback)
{
if(codelength>740)
{
datalength = 740;
codelength -= 740;
lengthtemp = 740;
}
else
{
datalength = codelength;
lengthtemp = codelength;
Conditionback = 0;
}
fread(Tempdata2,sizeof(unsigned char),datalength,stream);
/************************/
/************************/
if(datalength<740)
{
for(i=datalength;i<740;i++)
{
Tempdata2='F';
}
}
/************************/
/************************/
for(k=0;k<10;k++)
{
for(i=0;i<72;i++)
{
Tempdata[72*k+i]=Tempdata2[74*k+i];
}
}
/************************/
/************************/
for(i=0;i<720;i++)
{
switch(Tempdata)
{
case'0':Tempdata=0x00;break;
case'1':Tempdata=0x01;break;
case'2':Tempdata=0x02;break;
case'3':Tempdata=0x03;break;
case'4':Tempdata=0x04;break;
case'5':Tempdata=0x05;break;
case'6':Tempdata=0x06;break;
case'7':Tempdata=0x07;break;
case'8':Tempdata=0x08;break;
case'9':Tempdata=0x09;break;
case'A':Tempdata=0x0A;break;
case'B':Tempdata=0x0B;break;
case'C':Tempdata=0x0C;break;
case'D':Tempdata=0x0D;break;
case'E':Tempdata=0x0E;break;
case'F':Tempdata=0x0F;break;
default:break;
}
}
for(i=0;i<120;i++)
{
Data_to_write=(Tempdata[i*6]<<12)|(Tempdata[i*6+1]<<8)|(Tempdata[i*6+3]<<4)|Tempdata[i*6+4];
}
Write_Flash(Data_to_write,(Uint16 *)processaddr);
processaddr += 120;
printf("%s,%d\n","Writing FLASH is in progress",counter++);
}
fclose(stream);
*(unsigned char *)Sourceaddr = 0xF0;
puts(" End of writting the Flash\n");
puts(" Now Please reset your system\n");
}
else
puts("the file is empty\n");
}
/*******************************************************/
关键词:
DSP6713
flash