|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 cjsb37 于 2013-4-29 08:54 编辑
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二次写入"图例
* - 本贴最后修改时间:2008-5-5 23:12:22 修改者:hotpower
|
|
|
|