原创 DSP5402读写SST39VF400A之C++源代码

2006-12-28 22:36 4354 8 8 分类: 处理器与DSP


FlashRomObj::FlashRomObj(void)
{
//  SREG->SWWSR = 0x3f09;
  SREG->SWWSR = 0x7f09;
//  SREG->SWCR = 0;
//  _delay_loop_(10);
  FlashRomInit();  
}


void FlashRomObj::FlashRomInit(void)
{
  MakerId = 0;
  DeviceId = 0;
  FlashReset();
  if (!FlashId()) return;
  FlashReset();
  ChipErase();
  FlashReset();
  FlashWrite(&FlashRom8000, 0x12);
  FlashReset();
  FlashWrite(&FlashRom8001, 0x34);
  FlashReset();
//return; 
  if ((FlashRom8000 & 0xff) == 0x12) {
//    FlashWrite(&FlashRomStart, 0xff55);
  __nop();
  __nop();
  }
  else {
  __nop();
  __nop();
//    FlashWrite(&FlashRomStart, 0xffaa);
  }
  if ((FlashRom8001 & 0xff) == 0x34) {
//    FlashWrite(&FlashRomStart, 0xff55);
  __nop();
  __nop();
  }
  else {
  __nop();
  __nop();
//    FlashWrite(&FlashRomStart, 0xffaa);
  }
  FlashReset();
}


void FlashRomObj::FlashReset(void)
{
  FlashRom5555 = 0xaa; 
  __nop();
  __nop();
  FlashRom2AAA = 0x55; 
  __nop();
  __nop();
  FlashRom5555 = 0xf0;
  FlashWait();
}


bool FlashRomObj::FlashId(void)
{
bool flag;
  FlashRom5555 = 0xaa; 
  __nop();
  __nop();
  FlashRom2AAA = 0x55; 
  __nop();
  __nop();
  FlashRom5555 = 0x90;
  FlashWait();
  MakerId = FlashRomMaker & 0xff;
  __nop();
  __nop();
  DeviceId = FlashRomDevice & 0xff;
  __nop();
  __nop();
  flag = (MakerId == 0xbf) && (DeviceId == 0x80);
  FlashReset();
  return flag;
}


void FlashRomObj::ChipErase(void)
{
  FlashRom5555 = 0xaa; 
  __nop();
  __nop();
  FlashRom2AAA = 0x55; 
  __nop();
  __nop();
  FlashRom5555 = 0x80;
  __nop();
  __nop();
  FlashRom5555 = 0xaa; 
  __nop();
  __nop();
  FlashRom2AAA = 0x55; 
  __nop();
  __nop();
  FlashRom5555 = 0x10;
  FlashWait();
}


void FlashRomObj::FlashWrite(unsigned int * address, unsigned int val)
{
  FlashRom5555 = 0xaa; 
  __nop();
  __nop();
  FlashRom2AAA = 0x55; 
  __nop();
  __nop();
  FlashRom5555 = 0xa0;
  __nop();
  __nop();
  *address = val;
  FlashWait();
}


void FlashRomObj::FlashWait(void)
{
unsigned int temp, val;
  __nop();
  __nop();
  val = FlashRomStart;
  do {
    temp = FlashRomStart;
    __nop();
    __nop();
  }
  while(((val ^ temp) & (1 << BIT7)) != 0);
}

文章评论0条评论)

登录后参与讨论
我要评论
0
8
关闭 站长推荐上一条 /2 下一条