DSP串行FLASH(AT45DB642)的源代码
#include"serprt30.h"
#include"math.h"
//'注释:
//'DB45BUSY = CLKR0;
//'DB45CS = CLKX0;
//'DB45SCLK = FSX0;
//'SI = DX0; //'输出
//'SO = FSR0;//'输入
//'DB45OE = DR0;
volatile SERIAL_PORT_REG *slpt = SERIAL_PORT_ADDR(0);
extern unsigned int shu_cai_flag;
/* //'串口控制寄存器
spo->gcontrol = 0x04;//'串行口总体控制寄存器
spo->s_x_control = 0x666;//'串行口发送控制寄存器
spo->s_r_control = 0x020;//'串行口接首控制寄存器
*/
extern int nCurRotorNum_new;
extern int flash_write_buf[0x4000];
void busy_wait()
{
unsigned int busy_bit;
busy_bit = read_status();
while((busy_bit&0x80) != 0x80)
busy_bit = read_status(); //'信号忙则等
}
unsigned int read_status()
{
unsigned int i,statusBuffer=0;
unsigned int statusComand;
statusComand = 0x57;
//'串口选择模式0
wait_busy:
if( slpt->s_r_control_bit.clkdati == 0)
goto wait_busy; //' DB45BUSY
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
delay_new(10);
slpt->s_x_control_bit.clkdato = 0; //' DB45CS
delay_new(10);
for(i=0;i<17;i++)
{
if(i<8)
{
if((statusComand&0x80) == 0x80)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
statusComand = statusComand<<1;
}
else if(i>8)
{
statusBuffer<<=1;
if(slpt->s_r_control_bit.fsdatin == 1) //' SO
statusBuffer++;
}
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(2);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
delay_new(5);
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
return(statusBuffer);
}
void read_mainMemoryPage(unsigned int pageAddr, unsigned int byteAddr,unsigned int wordLong)
{
unsigned int i,j;
unsigned int readPageComand = 0x52;
int *pBuffer;
int tempData = 0;
pBuffer = flash_write_buf;
busy_wait();
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
slpt->s_x_control_bit.clkdato = 0; //' DB45CS
for(i=0;i<65;i++)
{
if(i<8)
{
if((readPageComand&0x80) == 0x80)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
readPageComand <<= 1;
}
if((i>=8)&&(i<21))
{
if((pageAddr&0x1000) == 0x1000)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
pageAddr <<= 1;
}
if((i>=21)&&(i<32))
{
if((byteAddr&0x400) == 0x400)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
byteAddr <<= 1;
}
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(1);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
for(i=0;i<WORDLONG;I++) if(slpt- <<="1;" *pBuffer="0;" { for(j="0;j<32;j++)">s_r_control_bit.fsdatin == 1)
*pBuffer = *pBuffer + 1; //' SO
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(4);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
pBuffer++;
}
delay_new(5);
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
}
void write_mainMemoryPage(unsigned int pageAddr,unsigned int byteAddr,unsigned int wordLong)
{
unsigned int i,j;
unsigned int writePageComand = 0x53; // 'main->buffer1
int *pBuffer,temp;
pBuffer = flash_write_buf;
temp = pageAddr;
busy_wait();
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
slpt->s_x_control_bit.clkdato = 0; //' DB45CS
for(i=0;i<32;i++)
{
if(i<8)
{
if((writePageComand&0x80) == 0x80)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
writePageComand <<= 1;
}
if((i>=8)&&(i<21))
{
if((pageAddr&0x1000) == 0x1000)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
pageAddr <<= 1;
}
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(2);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
pageAddr = temp;
writePageComand = 0x82;
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
busy_wait();
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
slpt->s_x_control_bit.clkdato = 0; //' DB45CS
for(i=0;i<32;i++)
{
if(i<8)
{
if((writePageComand&0x80) == 0x80)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
writePageComand <<= 1;
}
if((i>=8)&&(i<21))
{
if((pageAddr&0x1000) == 0x1000)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
pageAddr <<= 1;
}
if(i>=21)
{
if((byteAddr&0x400) == 0x400)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
byteAddr <<= 1;
}
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(2);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
for(i=0;i<WORDLONG;I++) { for(j="0;j<32;j++)" slpt- 0x80000000) if((temp&0x80000000)="=" temp="*pBuffer;">s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
temp <<= 1;
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(3);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
pBuffer++;
}
delay_new(5);
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
}
void erase_mainMemoryPage(int pageAddr,int comandFlag)
{
unsigned int i,j = 1,k;
unsigned int erasePageComand ; //'也擦出
unsigned int buf1,buf2;
if(comandFlag == 0)
{
erasePageComand = 0x81;
}
if(comandFlag == 1)
{
erasePageComand = 0x50;
}
if(comandFlag == 2)
{
erasePageComand = 0x50;
j = 1024;
}
buf1 = erasePageComand;
buf2 = pageAddr;
for(k=0;k<J;K++,BUF2=BUF2+8) { slpt- busy_wait(); pageAddr="buf2;" erasePageComand="buf1;">s_x_control_bit.clkdato = 1; //' DB45CS
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
slpt->s_x_control_bit.clkdato = 0; //' DB45CS
for(i=0;i<32;i++)
{
if(i<8)
{
if((erasePageComand&0x80) == 0x80)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
erasePageComand <<= 1;
}
if((i>=8)&&(i<21))
{
if((pageAddr&0x1000) == 0x1000)
slpt->s_x_control_bit.ddatout = 1; //' SI
else
slpt->s_x_control_bit.ddatout = 0; //' SI
pageAddr <<= 1;
}
slpt->s_x_control_bit.fsdatout = 1; //' DB45CLK
delay_new(2);
slpt->s_x_control_bit.fsdatout = 0; //' DB45CLK
}
delay_new(5);
slpt->s_x_control_bit.clkdato = 1; //' DB45CS
}
busy_wait();