ViewData2Flash.c
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:4k
- /***************************************
- Program: View Data access into Flash
- Author: Bryan Cai
- Date: 2007.04.11
- ***************************************/
- #include "includeH.h"
- void WriteViewData(void)
- {
-
- unsigned char ucFlashSttsOverflowCnt=0,ucFaxPropertyLenCnt=0,
- ucRxIndex=0;
-
- COMMAND_VAL=cFlashWriteCmd;
- COMMAND_LATCH_INTO();
- //ADDRESS
-
- ADDRESS_VALUE=gwColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
- ADDRESS_LATCH_INTO();
-
- ADDRESS_VALUE=(gwColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
- ADDRESS_LATCH_INTO();
-
- ADDRESS_VALUE=gwFaxPropertyAddress & 0xff;//gwFaxPropertyAddress is equal gwFaxRearPointerAddress
- ADDRESS_LATCH_INTO();
-
- ADDRESS_VALUE=(gwFaxPropertyAddress>>8) & 0XFF;
- ADDRESS_LATCH_INTO();
- FLASH_CON_PORT_OUT &=~ ALE;
-
- DATA_PORT_OUT_INITIAL;
- for (ucFaxPropertyLenCnt=0;ucFaxPropertyLenCnt<8;ucFaxPropertyLenCnt++)
- {
- FLASH_CON_PORT_OUT&=~WE;
- DATA_PORT_OUT=aucUartRxBuf[ucRxIndex++];
- FLASH_CON_PORT_OUT |= WE;
- }
-
- COMMAND_VAL=cFlashWriteInitiateCmd; //10H INITIATES PROGRAM
- COMMAND_LATCH_INTO();
-
- READ_STATUS();
- ucFlashSttsOverflowCnt=0;
- if(FLASH_STATUS==1&&(ucFlashSttsOverflowCnt++)<2)
- {;}
- }
- void ReadLastViewData(void)//find last fax property recorder
- {
- unsigned int wPageAddress=0, wBlockAddress=0,
- wColumnAddress=0,wNextPageAddress=0,
- wRearPntCnt=0;
- unsigned char ucRxIndex=0,
- ucGeneralCnt=0,ucFaxPropertyLenCnt,
- ucRxIndex3=0,ucRxIndex2=0,
- ucRxIndex0=0,ucRxIndex1=0;
-
- for (wBlockAddress=cstViewDataAreaStartPage;
- wBlockAddress<=cstViewDataAreaEndPage;wBlockAddress++)
- {
-
- for (wPageAddress=(wBlockAddress<<6);wPageAddress<((wBlockAddress<<6)+64);wPageAddress++)
- {
- do{
- wNextPageAddress=wPageAddress+64;
- wPageAddress=CalNextPageAddress(wPageAddress);
- }while(wNextPageAddress==wPageAddress);
-
- wColumnAddress=0;
- ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
-
- for (ucGeneralCnt=0;ucGeneralCnt<8;ucGeneralCnt++)
- {
- //COMMAND
- COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
- COMMAND_LATCH_INTO();
- //ADDRESS
- ADDRESS_VALUE=wColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
- ADDRESS_LATCH_INTO();
-
- ADDRESS_VALUE=(wColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
- ADDRESS_LATCH_INTO();
-
- ADDRESS_VALUE=ROW_ADDRESS_LOW;
- ADDRESS_LATCH_INTO();
-
- ADDRESS_VALUE=ROW_ADDRESS_HIGH;
- ADDRESS_LATCH_INTO();
- FLASH_CON_PORT_OUT &=~ ALE;
-
- COMMAND_VAL=0X30;
- COMMAND_LATCH_INTO();
- //ATcmdDelay();
- while((FLASH_CON_PORT_IN & RB)==0);
- DATA_PORT_IN_INITIAL;
- for (ucFaxPropertyLenCnt=0;ucFaxPropertyLenCnt<8;ucFaxPropertyLenCnt++)
- {
- FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
- aucUartRxBuf[ucRxIndex++]=DATA_PORT_IN;
- FLASH_CON_PORT_OUT |= RE;
- }
- wRearPntCnt++;
- ucRxIndex3=ucRxIndex-4;
- ucRxIndex2=ucRxIndex-3;
- ucRxIndex1=ucRxIndex-2;
- ucRxIndex0=ucRxIndex-1;
- if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
- 0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
- {
- break; //next rear
- }//if
- if (ucGeneralCnt<4)
- wColumnAddress+=512;
- else
- wColumnAddress+=16;
- }//for read next rear pointer
-
- //ucRxIndex3=gucUartRxCnt-4;
- //ucRxIndex2=gucUartRxCnt-3;
- //ucRxIndex1=gucUartRxCnt-2;
- //ucRxIndex0=gucUartRxCnt-1;
- if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
- 0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
- {break;}
- }//for next page
- //ucRxIndex3=gucUartRxCnt-4;
- //ucRxIndex2=gucUartRxCnt-3;
- //ucRxIndex1=gucUartRxCnt-2;
- //ucRxIndex0=gucUartRxCnt-1;
- if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
- 0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
- {break;}
- }//for next block
- gwFaxPropertyAddress=wPageAddress; //for write Fax property record //gwFaxPropertyAddress is equal gwFaxRearPointerAddress
- gwColumnAddress=wColumnAddress; //
- }