sst28sf040.c
资源名称:直接操作并行口.zip [点击查看]
上传用户:fsjiahua
上传日期:2013-03-07
资源大小:89k
文件大小:6k
源码类别:
并口编程
开发平台:
Visual C++
- #include <stdio.h>
- #include <windows.h>
- #include <time.h>
- #include <conio.h>
- #include "s3c4510.h"
- #include "sst28sf040.h"
- void Disable_Chip_Data_Protection(void)
- {
- access_bus(RS, 0x1823, 0, IP);
- read_rom(0x00001823); // read data from 0x1823
- access_bus(RS, 0x1820, 0, IP);
- read_rom(0x00001820); // read data from 0x1820
- access_bus(RS, 0x1822, 0, IP);
- read_rom(0x00001822); // read data from 0x1822
- access_bus(RS, 0x0418, 0, IP);
- read_rom(0x00000418); // read data from 0x0418
- access_bus(RS, 0x041b, 0, IP);
- read_rom(0x0000041B); // read data from 0x041B
- access_bus(RS, 0x0419, 0, IP);
- read_rom(0x00000419); // read data from 0x0419
- access_bus(RS, 0x041a, 0, IP);
- read_rom(0x0000041A); // read data from 0x041A
- access_bus(RS, 0x041a, 0, IP);
- }
- void Enable_Chip_Data_Protection()
- {
- access_bus(RS, 0x1823, 0, IP);
- read_rom(0x00001823); // read data from 0x1823
- access_bus(RS, 0x1820, 0, IP);
- read_rom(0x00001820); // read data from 0x1820
- access_bus(RS, 0x1822, 0, IP);
- read_rom(0x00001822); // read data from 0x1822
- access_bus(RS, 0x0418, 0, IP);
- read_rom(0x00000418); // read data from 0x0418
- access_bus(RS, 0x041b, 0, IP);
- read_rom(0x0000041B); // read data from 0x041B
- access_bus(RS, 0x0419, 0, IP);
- read_rom(0x00000419); // read data from 0x0419
- access_bus(RS, 0x040a, 0, IP);
- read_rom(0x0000040A); // read data from 0x040A
- access_bus(RS, 0x040a, 0, IP);
- }
- int Check_SST_28SF040(void)
- {
- BYTE SST_id1;
- BYTE SST_id2;
- int ReturnStatus;
- BYTE OriginalByte;
- OriginalByte = read_rom(0x00000000);/* save the original memory contents */
- write_rom(0x0000, RESET); /* reset tje 28SF040 chip first */
- write_rom(0x0000, READ_ID); /* issue the READ_ID command */
- SST_id1 = read_rom(0x00000000); /* get first ID byte */
- SST_id2 = read_rom(0x00000001); /* get second ID byte */
- if ((SST_id1 == SST_ID) && (SST_id2 == SST_28SF040))
- ReturnStatus = 0;
- else
- ReturnStatus = -1;
- write_rom(0x00000000, RESET); /* issue RESET command to 28SF040 */
- if (ReturnStatus ==-1) /* if not 28SF040, restore original contents */
- write_rom(0x00000000, OriginalByte);
- return(ReturnStatus);
- }
- void Check_Toggle_Ready(DWORD Dst)
- {
- unsigned char Loop = TRUE;
- unsigned char PreData;
- unsigned char CurrData;
- unsigned long TimeOut = 0;
- PreData = read_rom(Dst);
- PreData = PreData & 0x40;
- while ((TimeOut< 0x7FFFFFFF) && (Loop))
- {
- CurrData = read_rom(Dst);
- CurrData = CurrData & 0x40;
- if (PreData == CurrData)
- Loop = FALSE; /* ready to exit the while loop */
- PreData = CurrData;
- TimeOut++;
- }
- }
- int Read_28SF040(FILE* stream, DWORD Src,DWORD size)
- {
- int i,count;
- DWORD SrcReadAddress = Src;
- unsigned char cTemp;
- if( NULL == stream )
- return -1;
- fseek( stream,0,SEEK_SET );
- count = 0;
- for( i = 1; i <= (int)size; i++ )
- {
- cTemp = read_rom( SrcReadAddress++ );
- printf("%.2x ",cTemp);
- if( i%16 == 0 ) printf("n");
- fwrite((char*)&cTemp,sizeof(char),1,stream );
- }
- return 0;
- }
- int Write_28SF040(unsigned char *Src, DWORD Dst)
- {
- unsigned char *SourceBuf;
- DWORD DestBuf;
- int Index;
- int Count;
- unsigned char SourceByte;
- unsigned char Continue;
- Disable_Chip_Data_Protection();
- SourceBuf = Src;
- DestBuf = Dst;
- /************************************************************************************/
- /* ERASE OPERATION */
- /* */
- /************************************************************************************/
- write_rom(DestBuf, AUTO_PG_ERASE1); /* erase the page before programming */
- write_rom(DestBuf, AUTO_PG_ERASE2);
- Check_Toggle_Ready(Dst); /* wait for Toggle bit ready */
- Count = 0;
- Continue = TRUE;
- /* while ((Count < ROW_SIZE) && (Continue))
- {
- SourceByte = read_rom(DestBuf++);
- if (SourceByte == 0xFF)
- Count++;
- else
- Continue = FALSE;
- }
- if (!Continue)
- {
- Enable_Chip_Data_Protection();
- return (TRUE);
- }
- */
- /***********************************************************************************/
- /* PROGRAM OPERATION */
- /* */
- /***********************************************************************************/
- SourceBuf = Src;
- DestBuf = Dst;
- for (Index = 0; Index < ROW_SIZE; Index++)
- {
- SourceByte = *SourceBuf++;
- if (SourceByte != 0xFF) /* If the data is 0xFF, don,t program it*/
- {
- write_rom(DestBuf,AUTO_PGRM); /*issue AUTO PROGRAM command*/
- write_rom(DestBuf,SourceByte); /* program the data */
- //Check_Toggle_Ready(Dst); /* wait for Toggle bit ready */
- //ProgrammedByte = read_rom(DestBuf); /* read back the data pragrammed */
- //if (SourceByte != ProgrammedByte)
- //{
- // Continue = FALSE;
- // break;
- //}
- }
- DestBuf++;
- }
- Enable_Chip_Data_Protection();
- if (!Continue)
- return(TRUE); /* return with error */
- else
- return(FALSE); /* return with NO error */
- }