📄 dsp_flash.h
字号:
/*sp_flash.h*/
/*by lizw */
#ifndef DSP_FLASH_H
#define DSP_FLASH_H
int flash_read(int i,volatile unsigned char *p,int a) {
int m,n;
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
BYTE temp;
//BYTE ch;
//unsigned int kk_cmp;
temp=g_flag;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x03;
selectchip(g_flag);
m=(i/8)*2;
n=i%8;
*pdata=m;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x00;
selectchip(g_flag);
for(i=0;i<512;i++)
*(p+i)=*(pdata+n*0x1000+0x0200*a+i);
g_flag=temp;
selectchip(g_flag);
return 1;
}
////////////////////////////////////////////
void flash_copy(volatile unsigned char *p,int a){
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
int i;
BYTE temp;
temp=g_flag;
g_flag=g_flag&0xF8;
g_flag=g_flag|0x08;
selectchip(g_flag);
if(a>1)
pdata=pdata+0x2000;
a=a%2;
for(i=0;i<512;i++)
*(pdata+i+a*0x200+0x400)=*(p+i);
g_flag=temp;
selectchip(g_flag);
}
void move_data( int k ){
int i;
for(i=0;i<4;i++){
flash_read(k+8,p_flashbuf,i);
flash_copy(p_flashbuf,i);
}
}
int erase_sector(int i)
{
int m,n;
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
BYTE read,flag1,flag2;
BYTE temp;
temp=g_flag;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x03;
selectchip(g_flag);
m=(i/8)*2;
n=i%8;
*pdata=m;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x00;
selectchip(g_flag);
*(pdata+0x0555)=0xaa;
*(pdata+0x02aa)=0x55;
*(pdata+0x0555)=0x80;
*(pdata+0x0555)=0xaa;
*(pdata+0x02aa)=0x55;
///////////// ???????????????????????????
*pdata=0x30;
//my_delay(1);
read=*pdata;
flag1=read&0x80;
flag2=read&0x20;
while(flag1!=0x80)
{
if(flag2==0x20)
{
*pdata=0xf0;
return 0;
}
read=*pdata;
flag1=read&0x80;
flag2=read&0x20;
}
///////////////////////////////////////////////
return 1;
}
//////////////////////////////////////////////
int write_flash(volatile unsigned char *p,BYTE writedata ){
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
BYTE read;
BYTE flag1,flag2,flag3;
pdata=(volatile unsigned char*) 0x8555;
*pdata=0xaa;
pdata=(volatile unsigned char*) 0x82AA;
*pdata=0x55;
pdata=(volatile unsigned char*) 0x8555;
*pdata=0xa0;
//writedata=*(p+m); //接受数据
flag3=writedata&0x80;
pdata=p;
*pdata=writedata;
my_delay(1);
read=*pdata;
flag1=read&0x80;
flag2=read&0x20;
while(flag1!=flag3){
if(flag2==0x20){
*pdata=0xf0;
return 0;
}
read=*pdata;
flag1=read&0x80;
flag2=read&0x20;
}
return 1;
}
///////////////////////////////////////////
int write_one(int i,volatile unsigned char *p,int a){
int m,n,j;
int kk,kk1;
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
BYTE temp;
BYTE writedata,read;
BYTE flag1,flag2,flag3;
temp=g_flag;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x03;
selectchip(g_flag);
m=(i/8)*2;
n=i%8;
*pdata=m;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x00;
selectchip(g_flag);
kk=0;
for(m=0;m<512;m++){
g_flag=g_flag&0xF0;
g_flag=g_flag+0x00;
selectchip(g_flag);
kk1=write_flash((pdata+n*0x1000+0x0200*a+m), *(p+m));
if(kk1!=1)
kk1=1;
kk++;
}
if(kk<512)
error=2;
g_flag=temp;
selectchip(g_flag);
return 1;
}
///////////////////////////////////////////////////////////////
/*
*/
//////////////////////////////////////////////////////////////
void flash_write(int i,volatile unsigned char *p,int a) //i=0,1,2……,123.
{
int temp;
//chg_speed(0x07);
if(((i%8)==0)&&(a==0)){
temp=erase_sector(i+8);
if(temp==0)
temp=erase_sector(i+8);
}
write_one(i+8,p,a);
chg_speed(0x00);
}
////////////////////////////////////////////////////
////////////////////////////////////////////
void fac_reset(int a){
int i;
for(i=0;i<a;i=i+8){
erase_sector(i);
}
}
///////////////////////////////////////
int flash_read_cycle(int a){
int i;
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
BYTE temp;
temp=g_flag;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x03;
selectchip(g_flag);
*pdata=0;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x00;
selectchip(g_flag);
for(i=0;i<2;i++)
*(pInfo+i)=*(pdata+i);
for(i=0;i<16;i++)
*(pInfo+i+2)=(*(pdata+i+a*16+2))&0xff;
g_flag=temp;
selectchip(g_flag);
return 1;
}
int flash_write_cycle(int t_index,volatile unsigned char *p,int num){
int i;
volatile unsigned char *pdata=(volatile unsigned char*) 0x8000;
BYTE temp;
temp=g_flag;
g_flag=g_flag&0xF0;
g_flag=g_flag+0x03;
selectchip(g_flag);
*pdata=0;
if(*p!=0x01)
return 0;
if(t_index==0)
erase_sector(0);
// chg_speed(0x07);
g_flag=g_flag&0xF0;
g_flag=g_flag+0x00;
selectchip(g_flag);
if(t_index==0){
for(i=0;i<2;i++)
write_flash(pdata+i,*(p+i+1));
}
for(i=0;i<16*num;i++)
write_flash(pdata+512*t_index+i+2,*(p+4+i));
g_flag=temp;
selectchip(g_flag);
chg_speed(0x00);
return 1;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -