SST39VF160.c
资源名称:直接操作并行口.zip [点击查看]
上传用户:fsjiahua
上传日期:2013-03-07
资源大小:89k
文件大小:5k
源码类别:
并口编程
开发平台:
Visual C++
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #include <conio.h>
- #include "s3c4510.h"
- #include "sst39vf160.h"
- #include "sst28sf040.h"
- int Check_SST_39VF160(void) //历程和hy的一致,先不修改
- {
- WORD SST_id1;
- WORD SST_id2;
- int ReturnStatus;
- write_rom2( SST39_CMD_ADDRESS1, SST39_READ_ID1);
- write_rom2( SST39_CMD_ADDRESS2, SST39_READ_ID2);
- write_rom2( SST39_CMD_ADDRESS1, SST39_READ_ID3);
- access_bus2(HOLD, SST39_CMD_ADDRESS1, SST39_READ_ID2, IP);
- /* read_rom2(0x00000000);
- read_rom2(0x00000002);
- read_rom2(0x00000004);
- read_rom2(0x00000006);
- read_rom2(0x00000008);
- read_rom2(0x0000000a);
- read_rom2(0x0000000c);
- read_rom2(0x0000000e);
- read_rom2(0x00000010);
- read_rom2(0x00000012);
- read_rom2(0x00000014);
- read_rom2(0x00000016);
- read_rom2(0x00000018);
- */
- SST_id1 = read_rom2(0x00000000);
- SST_id2 = read_rom2(0x00000002);
- if ((SST_id1 == HY29_ID) && (SST_id2 == SST_39VF160))
- ReturnStatus = 0;
- else
- ReturnStatus = -1;
- write_rom2( SST39_CMD_ADDRESS1, SST39_READ_ID1);
- write_rom2( SST39_CMD_ADDRESS2, SST39_READ_ID2); // exit get id
- write_rom2( SST39_CMD_ADDRESS1, SST39_EXIT_READ_ID);
- return(ReturnStatus);
- }
- int Read_39VF160(FILE* stream, DWORD Src,DWORD size)
- {
- int i,count;
- DWORD SrcReadAddress = Src;
- WORD wTemp; // 16 bit access
- if( NULL == stream )
- return -1;
- fseek( stream,0,SEEK_SET );
- count = 0;
- for( i = 1; i <= (int)(size/sizeof(WORD)); i++ )
- {
- wTemp = read_rom2( SrcReadAddress++ );
- SrcReadAddress++ ;
- printf("%.4x ",wTemp);
- if( i%8 == 0 ) printf("n");
- fwrite((char*)&wTemp,sizeof(WORD),1,stream );
- }
- return 0;
- }
- int Write_39VF160(unsigned char *Src, DWORD Dst)
- {
- WORD *SourceBuf;
- DWORD DestBuf;
- DWORD DestSector;
- int Index;
- int Count;
- WORD SourceWord,Programmedword;
- unsigned char Continue;
- /************************************************************************************/
- /* ERASE OPERATION */
- /* */
- /************************************************************************************/
- DestSector = Dst;
- Sleep(30);
- if (DestSector==0x000 || DestSector == 0x4000 || DestSector== 0x6000 || DestSector== 0x4000 || DestSector== 0x8000 || DestSector&0x0000ffff ==0x0000)
- { write_rom2( SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE1);
- write_rom2( SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE2);
- write_rom2( SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE3);
- write_rom2( SST39_CMD_ADDRESS1, SST39_AUTO_PG_ERASE4);
- write_rom2( SST39_CMD_ADDRESS2, SST39_AUTO_PG_ERASE5);
- printf("Erasing the sector 0x%.8x ....",DestSector);
- write_rom2( DestSector, SST39_AUTO_PG_ERASE6);
- printf("on doing.n");
- SST39Check_Toggle_Ready(DestSector);
- printf("Erase Done.n");
- }
- Count=0;
- Continue = TRUE;
- /***********************************************************************************/
- /* PROGRAM OPERATION */
- /* */
- /***********************************************************************************/
- SourceBuf = (WORD *)Src;
- DestBuf = Dst;
- if ( DestBuf == 0 ) printf("write 0 Kbyte n");
- for (Index = 0; Index < 4096; Index++)
- {
- SourceWord = *SourceBuf++;
- if (SourceWord != 0xFFFF) // If the data is 0xFF, don,t program it/
- {
- write_rom2(SST39_CMD_ADDRESS1, SST39_AUTO_PGRM1);
- write_rom2(SST39_CMD_ADDRESS2, SST39_AUTO_PGRM2);
- write_rom2(SST39_CMD_ADDRESS1, SST39_AUTO_PGRM3);
- write_rom2(DestBuf,SourceWord); // program the data //
- Programmedword = SST39Check_Toggle_Ready(DestBuf);
- // wait for Toggle bit ready //
- // Programmedword = read_rom2(DestBuf); // read back the data pragrammed /
- // printf("addr: 0x%lx read data: 0x%x .n",DestBuf, Programmedword );
- if (SourceWord != Programmedword)
- {
- printf("data compare error 0x%x : 0x%x.n",SourceWord,Programmedword);
- Continue = FALSE;
- break;
- }
- }
- DestBuf++;
- DestBuf++;
- if ( DestBuf % 1024 == 0)
- printf("write %d Kbyte n", DestBuf/1024); //
- }
- if (!Continue)
- return(TRUE); /* return with error */
- else
- return(FALSE); /* return with NO error */
- }
- WORD SST39Check_Toggle_Ready(DWORD Dst)
- {
- unsigned char Loop = TRUE;
- WORD PreData;
- WORD CurrData;
- WORD ReturnData;
- unsigned long TimeOut = 0;
- PreData = read_rom2(Dst);
- access_bus2(HOLD, Dst, 0, IP);
- PreData = PreData & 0x4040;
- while ((TimeOut< 0x7FFFFFFF) && (Loop))
- {
- CurrData = read_rom2(Dst); //操作未完成时,d6会读一次翻转一次。
- ReturnData = CurrData;
- access_bus2(HOLD, Dst, 0, IP);
- // printf("data toggle 0x%x .n",CurrData);
- CurrData = CurrData & 0x4040;
- if (PreData == CurrData)
- Loop = FALSE; /* ready to exit the while loop */
- PreData = CurrData;
- TimeOut++;
- }
- return(ReturnData);
- }