原创 DSP2812读写SST39VF800A之C++程序源码

2008-5-5 23:14 4392 8 8 分类: 处理器与DSP
hotpower 发表于 2008-5-5 23:11 DSP 技术 ←返回版面 按此察看该网友的资料 按此把文章加入收藏夹 按此编辑本帖

楼主: DSP2812读写SST39VF800A之C++程序源码


/*-----------------------------------------------------
    DSP2812读写SST39VF800A之C++程序源码
本演示程序在Study-2812增强版上通过运行测试

菜农HotPower@126.com  2008.5.5  于西安大雁塔菜地
------------------------------------------------------*/
#include "flash.h"

FlashObj::FlashObj(void)
{
  Init();   
  Test();
}

void FlashObj::Init(void)
{
  Active = false;
  Busy = false;
  MakerId = 0;
  DeviceId = 0;
  FlashReset();
  ReadId();
  Test();
}

void FlashObj::FlashReset(void)
{
  Busy = true;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0xf0;
  Wait(FLASH[0x5555]);
  Busy = false;
}

void FlashObj::ReadId(void)
{
  Busy = true;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0x90;
  Wait(FLASH[0x5555]);
  MakerId = FLASH[0x0000] & 0xff;
  DeviceId = FLASH[0x0001] & 0xff;
//SST39VF800A MakerId="0xBF" DeviceId="0x81"
  Active = (MakerId == 0xBF) && (DeviceId == 0x81);
  FlashReset();
  Busy = false;
}

void FlashObj::ChipErase(void)
{
  Busy = true;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0x80;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0x10;
  Wait(FLASH[0x5555]);
  Busy = false;
}

void FlashObj::SectorErase(unsigned int SectorNum)
{
  Busy = true;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0x80;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[SectorSize * SectorNum] = 0x30;
  Wait(FLASH[0x5555]);
  Busy = false;
}

void FlashObj::BlockErase(unsigned int BlockNum)
{
  Busy = true;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0x80;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[BlockSize * BlockNum] = 0x50;
  Wait(FLASH[0x5555]);
  Busy = false;
}

void FlashObj::Write(unsigned int & address, unsigned int val)
{
  Busy = true;
  FLASH[0x5555] = 0xaa;  
  FLASH[0x2AAA] = 0x55;  
  FLASH[0x5555] = 0xa0;
  address = val;
  Wait(address);
  Busy = false;
}

void FlashObj::Wait(unsigned int & address)
{
unsigned int temp, val;
  Busy = true;
  do
  {
    _delay_loop_(1);
    val = address;
    _delay_loop_(1);
    temp = address;
  }
  while(((val ^ temp) & BIT6) != 0);
  Busy = false;
}

void FlashObj::Test(void)
{
  Busy = true;
  if (Active)//SST39VF800A测试正常
  {
    FlashReset();
    ChipErase();
    FlashReset();
    Write(FLASH[0x0000], 0x1234);
    Write(FLASH[0x5555], 0x1234);
    Write(FLASH[0x2aaa], 0xabcd);
    FlashReset();
    SectorErase(0);
    FlashReset();
    Write(FLASH[0x0000], 0x8888);
    FlashReset();
    BlockErase(0);
    Write(FLASH[0x0000], 0x6666);
    FlashReset();
  }
  Busy = false;
}

下图是在SST39VF800A上实现的"FLASH二次写入"图例



2007620232653915.gif

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
8
关闭 站长推荐上一条 /3 下一条