📄 sst39vf160func.~pas
字号:
Unit SST39VF160Func;
Interface
function sst_check_id:integer;
procedure sst_write_word( addr:longword; data:longword );
function sst_read_word( addr:longword ):longword;
procedure sst_erase_one_block( addr:longword );
procedure sst_erase_one_sector( addr:longword );
procedure sst_erase_chip;
procedure sst_check_toggle_ready( addr:longword );
Implementation
Uses Unit1,S3C4510Func,FlashPGMFunc,Define;
{ ----------------------------------------------------------------
* brief : check the flash Manufacturer’s ID and Device ID
* author: dailzh
* param: none
* retval: -1--------different
0---------the same
* modify history:
if you change the function please give the discription
----------------------------------------------------------------- }
function sst_check_id:integer;
var
SST_id1:longword;
SST_id2:longword;
ReturnStatus:integer;
begin
//soft id entry
//first bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP );
//second bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP );
//third bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_READ_ID3, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_READ_ID3, IP );
//prepare to read
access_bus( HOLD, SST39_CMD_ADDRESS1, SST39_READ_ID2, IP );
//read from bus-----Manufacturer’s ID
access_bus( READ, $00000000, 0, IP );
SST_id1 := access_bus( READ, $00000000, 0 , RP );
//read from bus-----device ID
access_bus( READ, $00000001, 0, IP );
SST_id2 := access_bus( READ, $00000001, 0 , RP );
//compare to sst39lv160
if( SST_id1 = SST_ID) and (SST_id2 = SST_39VF160 ) then
ReturnStatus := 0
else
ReturnStatus := -1;
//soft id exit
//first bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_READ_ID1, IP );
//second bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_READ_ID2, IP );
//third bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_EXIT_READ_ID, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_EXIT_READ_ID, IP );
Result:=ReturnStatus;
end;
{ ----------------------------------------------------------------
* brief : write a word to the flash
* author: dailzh
* param: addr------must a even addr($0~$1ffffe)
data------the write word
* retval: none
* modify history:
2003-12-3 Guo Jian first version
----------------------------------------------------------------- }
procedure sst_write_word( addr:longword; data:longword );
begin
//first bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM1, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM1, IP );
//second bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PGRM2, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PGRM2, IP );
//third bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM3, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PGRM3, IP );
//forth bus write cycle
access_bus( WRITE, addr div 2, data, IP );
access_bus( SETUP, addr div 2, data, IP );
sst_check_toggle_ready( addr );
end;
{ ----------------------------------------------------------------
* brief : read a word on the flash
* author: dailzh
* param: addr------must a even addr($0~$1ffffe)
* retval: the word save on the flash
* modify history:
2003-12-3 Guo Jian first version
----------------------------------------------------------------- }
function sst_read_word( addr:longword ):longword;
var tmp:longword;
begin
access_bus(READ, addr div 2, 0, IP);
tmp := access_bus(READ, addr div 2, 0 , RP);
Result:= tmp;
end;
{ ----------------------------------------------------------------
* brief : erase one block
* author: dailzh
* param: addr------the erase block first address
* retval: none
* modify history:
2003-12-3 Guo Jian first version
----------------------------------------------------------------- }
procedure sst_erase_one_block( addr:longword );
begin
//first bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP );
//second bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP );
//third bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP );
//forth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP );
//fifth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP );
//sixth bus write cycle
access_bus( WRITE, addr, SST39_ERASE_BLOCK, IP );
access_bus( SETUP, addr, SST39_ERASE_BLOCK, IP );
sst_check_toggle_ready( addr );
end;
{ ----------------------------------------------------------------
* brief : erase one sector
* author: dailzh
* param: addr------the first address of the erased addr
* retval: none
* modify history:
2003-12-3 Guo Jian first version
----------------------------------------------------------------- }
procedure sst_erase_one_sector( addr:longword );
begin
//first bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP );
//second bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP );
//third bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP );
//forth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP );
//fifth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP );
//sixth bus write cycle
access_bus( WRITE, addr, SST39_ERASE_SECTOR, IP );
access_bus( SETUP, addr, SST39_ERASE_SECTOR, IP );
sst_check_toggle_ready( addr );
end;
{ ----------------------------------------------------------------
* brief : erase the whole flash
* author: dailzh
* param: none
* retval: none
* modify history:
2003-12-3 Guo Jian first version
----------------------------------------------------------------- }
procedure sst_erase_chip;
begin
//first bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1, IP );
//second bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2, IP );
//third bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3, IP );
//forth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4, IP );
//fifth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP );
access_bus( SETUP, SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5, IP );
//sixth bus write cycle
access_bus( WRITE, SST39_CMD_ADDRESS1, SST39_ERASE_CHIP, IP );
access_bus( SETUP, SST39_CMD_ADDRESS1, SST39_ERASE_CHIP, IP );
sst_check_toggle_ready( 0 );
Form1.Memo1.Lines.Add( 'erase ok' );
Form1.Memo1.Lines.Add( '----------------------------------' );
end;
{ ----------------------------------------------------------------
* brief : check the toggle bit to confirm the internal operation finished
* author: dailzh
* param: addr------flash address
* retval: the word save on the flash
* modify history:
2003-12-3 Guo Jian first version
----------------------------------------------------------------- }
procedure sst_check_toggle_ready( addr:longword );
var
pre_data:longword;
cur_data:longword;
time_out:longword;
begin
time_out:=0;
pre_data := sst_read_word( addr );
pre_data := pre_data and $4040;
while( time_out < $7FFFFFFF ) do
begin
//get the current data on the bus
cur_data := sst_read_word( addr );
cur_data := pre_data and $4040;
//if finished internal operation return
if( pre_data = cur_data ) then
Exit;
pre_data := cur_data;
time_out:=time_out+1;
end;
Form1.Memo1.Lines.Add( 'time out in check toggle\n' );
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -