⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flashpgmfunc.~pas

📁 LOM-ARM7的Flash烧写的windows版程序
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:

	//very time we write 2 byte
	tmp_ptr := src;
  j:=0;
	while( size <> break_point ) do
  begin
		//read from bin file
		tmp := (word(ord(tmp_ptr[j+1])) shl 8)+ord(tmp_ptr[j]);//tmp_ptr^;
		j:=j+2;
    sst_write_word( addr, tmp );
	
    //prepare for next write
    size := size - 2;
    addr := addr + 2;

    //count the program percent
    if( size < percent * ( 100 - i ) ) then
    begin
		  if(i=0) then
        Form1.Memo1.Lines.Add(concat('finished programing '+inttostr(i),saved_size_str) )
      else
        Form1.Memo1.Lines[Form1.Memo1.Lines.Count-1]:=concat('finished programing '+inttostr(i),saved_size_str);
		  i:=i+1;
    end;
	end;
	
	if( size = 0 ) then
  begin
    Result:=0;
		Exit;
  end;
	
	//write the last byte
	ch := PChar(tmp_ptr)^;
	tmp := sst_read_word( addr );
	tmp := tmp and ord(ch);
	
	sst_write_word( addr, tmp );

	Result:=0;

end;

{ ----------------------------------------------------------------	
 * brief : 	save the flash data to the bin file
 * author:	guojian
 * param:	dst------point to the buffer
 			addr-----the first read address(0x0~0x1fffff)
 			size-----read size
 * retval:	0----------succeed
 			-1---------error
 * modify history:	
if you change the function please give the discription
----------------------------------------------------------------- }
function flash_read( dst:pchar; addr,size:longword ):integer;
var
	break_point:integer;
	tmp:word;
	//unsigned short  *tmp_ptr;
  tmp_ptr:pchar;
	i,j:integer;
	percent:integer;
  saved_size_str:string;
begin
  i:=0;
  saved_size_str:='% of '+inttostr(size)+' bytes';
  percent:= trunc(size/100);
	//write first byte if addr is odd
	if( addr mod 2<>0 ) then
  begin
	    tmp := sst_read_word( addr - 1 );
	    dst^ := char(tmp shr 8);
	    dst:=dst+1;
	    size:=size-1;
	    addr:=addr+1;
	end;
	
	//if read size is odd
	if( size mod 2 <>0) then
	    break_point := 1
	else
	    break_point := 0;
	
	//very time we read 2 byte
	tmp_ptr := dst;
  j:=0;
	while( size <> break_point ) do
  begin
		//read from flash
		tmp := sst_read_word( addr );
    tmp_ptr[j] := chr(tmp);
		tmp_ptr[j+1] := chr(tmp shr 8);
	  j:=j+2;

    //prepare for next write
    size := size - 2;
    addr := addr + 2;

    //count the read percent
    if( size < percent * ( 100 - i ) ) then
    begin
      if(i=0) then
        Form1.Memo1.Lines.Add(concat('finished programing '+inttostr(i),saved_size_str) )
      else
        Form1.Memo1.Lines[Form1.Memo1.Lines.Count-1]:=concat('finished reading '+inttostr(i),saved_size_str);
      i:=i+1;
    end;
	end;
	
	if( size = 0 ) then
  begin
    Result:=0;
    Exit;
  end;

	//read the last byte
	tmp := sst_read_word( addr );
	PByte(tmp_ptr)^ := tmp and $ff;

	Result:=0;

end;

{ ----------------------------------------------------------------	
 * brief : 	verify the program procedure
 * author:	guojian
 * param:	src------point to the verified data
 			addr-----the first write address(0x0~0x1fffff)
 			size-----verifed size
 * retval:	0----------succeed
 			-1---------error
 * modify history:	
if you change the function please give the discription
----------------------------------------------------------------- }
function flash_verify( src:pchar; addr,size:longword ):integer;
var
  break_point:integer;
	tmp:word;
  tmp_ptr:pchar;
	ch:char;
	i,j:integer;
	percent:integer;
  saved_size_str:string;
begin
  i:=0;
  saved_size_str:='% of '+inttostr(size)+' bytes';
  percent:= trunc(size/100);
	//verify first byte if addr is odd
	if( addr mod 2<>0 ) then
  begin
	    tmp := sst_read_word( addr - 1 );
	    ch  := src^;
	    src:=src+1;
	    
	    //equal means program right
	    if( (tmp shr 8) <> ord(ch) ) then
      begin
        Result:=-1;
        Exit;
      end;
	    size:=size-1;
	    addr:=addr+1;
	end;
	
	//if read size is odd
	if( size mod 2 <>0) then
	    break_point := 1
	else
	    break_point := 0;
	
	//very time we verify 2 byte
	tmp_ptr := src;
  j:=0;
	while( size <> break_point ) do
  begin
		//read from bin file
		tmp := (word(ord(tmp_ptr[j+1])) shl 8)+ord(tmp_ptr[j]);//tmp_ptr^;
		j:=j+2;
	    
    if( sst_read_word( addr ) <> tmp ) then
    begin
      Result:=-1;
      Exit;
    end;
	
    //prepare for next write
    size := size - 2;
    addr := addr + 2;

    //count the verify percent
    if( size < percent * ( 100 - i ) ) then
    begin
		  if(i=0) then
        Form1.Memo1.Lines.Add(concat('finished verifying '+inttostr(i),saved_size_str))
      else
        Form1.Memo1.Lines[Form1.Memo1.Lines.Count-1]:=concat('finished verifying '+inttostr(i),saved_size_str);
      i:=i+1;
    end;
	end;

	if( size = 0 ) then
  begin
    Result:=0;
    Exit;
  end;
	
	//verify the last byte
	ch := PChar(tmp_ptr )^;
	tmp := sst_read_word( addr );
	tmp :=tmp and $ff;
	
	if( tmp <> ord(ch) )  then
	begin
	  Result:=-1;
	  Exit;
	end;

  Form1.Memo1.Lines.Add( '----------------------------------' );
	Result:= 0;

end;

{ ----------------------------------------------------------------	
 * brief : 	erase sectors
 * author:	guojian
 * param:	none
 * retval:	none
 * modify history:	
	2003-12-3		Guo Jian 		first version
----------------------------------------------------------------- }
procedure erase_sectors(sector_addr, sector_count:longword);
var
    i:integer;
begin
    //health check
    if( sector_addr > 512 ) then
    begin
        Form1.Memo1.Lines.Add('bad sector number' );
        Form1.Memo1.Lines.Add( '----------------------------------' );
        Exit;
    end;
    
    //change sector num to address
    sector_addr := sector_addr * 4096;
    
    //check overflow
    if( ( sector_addr + sector_count * 4096 ) > FLASH_SIZE ) then
    begin
        Form1.Memo1.Lines.Add('erase the space out of the flash');
        Form1.Memo1.Lines.Add( '----------------------------------' );
        Exit;
    end;
    
    //erase
    for  i := 0 to sector_count-1 do
      sst_erase_one_sector( sector_addr + i*4096 );
      
    Form1.Memo1.Lines.Add('sector erase ok!');
    Form1.Memo1.Lines.Add( '----------------------------------' );

end;

{ ----------------------------------------------------------------	
 * brief : 	erase blocks
 * author:	guojian
 * param:	none
 * retval:	none
 * modify history:	
	2003-12-3		Guo Jian 		first version
----------------------------------------------------------------- }
procedure erase_blocks(block_addr, block_count:longword);
var
    i:integer;
begin
    //printf( "please input the first erased block num( 0~511 )\n" );
    //printf( "please input the erased block count\n" );

    //health check
    if( block_addr > 32) then
    begin
        Form1.Memo1.Lines.Add('bad block number' );
        Form1.Memo1.Lines.Add( '----------------------------------' );
        Exit;
    end;
    
    //change block num to address
    block_addr := block_addr * 64 * 1024;
    
    //check overflow
    if( ( block_addr + block_count * 64 * 1024 ) > FLASH_SIZE ) then
    begin
        Form1.Memo1.Lines.Add('erase the space out of the flash' );
        Form1.Memo1.Lines.Add( '----------------------------------' );
        Exit;
    end;
    
    //erase
    for  i := 0 to block_count-1 do
        sst_erase_one_block( block_addr + i* 64 * 1024 );

    Form1.Memo1.Lines.Add('block erase ok!');
    Form1.Memo1.Lines.Add( '----------------------------------' );

end;

{ ----------------------------------------------------------------
 * brief : 	main entry function
 * author:	guojian
 * param:	none
 * retval:	none
 * modify history:
	2003-12-3		Guo Jian 		first version
----------------------------------------------------------------- }
//int main( int argc, char **argv )
var BH:array[0..15]of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
function ToHexChar(data:smallint):string;
var s:string;
begin
  s:='000H';
  s[3]:=BH[data mod 16]; data:=data div 16;
  s[2]:=BH[data mod 16]; data:=data div 16;
  s[1]:=BH[data mod 16];
  ToHexChar:=s;
end;
function connect_device:integer;
begin
	// find a valid parallel port
  lpt_address := test_port();
	if( lpt_address= -1 ) then
  begin
		Form1.Memo1.Lines.Add( 'can not find the parallel' );
    Form1.Memo1.Lines.Add( '----------------------------------' );
    Result:=1;
		Exit;
	end;
	Form1.Memo1.Lines.Add( 'LPT is at '+ToHexChar(lpt_address) );
	
	//check the cpu id
	reset_jtag();
	test_logic_reset();
	if( id_command = -1 )then
  begin
		Form1.Memo1.Lines.Add( 'wrong cpu id' );
    Form1.Memo1.Lines.Add( '----------------------------------' );
    Result:=2;
		Exit;
	end;
	
	//check flash id
	extest();		//select boundary scan register.
	if( sst_check_id =  -1 )  then
  begin
   	  Form1.Memo1.Lines.Add( 'SST39VF160 Chip Not Founded!!' );
	    Form1.Memo1.Lines.Add( '----------------------------------' );
      Result:=3;
      Exit;
	end
  else
	    Form1.Memo1.Lines.Add( 'SST39VF160 Chip Founded!!' );

  Form1.Memo1.Lines.Add( '----------------------------------' );
  Result:=0;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -