ViewData2Flash.c
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:4k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. /***************************************
  2. Program:     View Data access into Flash
  3. Author:      Bryan Cai
  4. Date:        2007.04.11
  5. ***************************************/
  6. #include "includeH.h"
  7. void WriteViewData(void)
  8. {
  9. unsigned char ucFlashSttsOverflowCnt=0,ucFaxPropertyLenCnt=0,
  10.               ucRxIndex=0;
  11.   COMMAND_VAL=cFlashWriteCmd;
  12.   COMMAND_LATCH_INTO();
  13. //ADDRESS
  14.   
  15.   ADDRESS_VALUE=gwColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
  16.   ADDRESS_LATCH_INTO();
  17.   ADDRESS_VALUE=(gwColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
  18.   ADDRESS_LATCH_INTO();
  19.   ADDRESS_VALUE=gwFaxPropertyAddress & 0xff;//gwFaxPropertyAddress is equal gwFaxRearPointerAddress
  20.   ADDRESS_LATCH_INTO();
  21.   ADDRESS_VALUE=(gwFaxPropertyAddress>>8) & 0XFF;
  22.   ADDRESS_LATCH_INTO();
  23.   FLASH_CON_PORT_OUT &=~ ALE;
  24.   DATA_PORT_OUT_INITIAL;
  25.   for (ucFaxPropertyLenCnt=0;ucFaxPropertyLenCnt<8;ucFaxPropertyLenCnt++)
  26.   {
  27.   FLASH_CON_PORT_OUT&=~WE;
  28.     DATA_PORT_OUT=aucUartRxBuf[ucRxIndex++];
  29.     FLASH_CON_PORT_OUT |= WE;
  30.   }
  31.   COMMAND_VAL=cFlashWriteInitiateCmd; //10H INITIATES PROGRAM
  32.   COMMAND_LATCH_INTO();
  33.   READ_STATUS();
  34.   ucFlashSttsOverflowCnt=0;
  35.   if(FLASH_STATUS==1&&(ucFlashSttsOverflowCnt++)<2)
  36.   {;}
  37. }
  38. void ReadLastViewData(void)//find last fax property recorder
  39. {
  40. unsigned int wPageAddress=0, wBlockAddress=0,
  41.              wColumnAddress=0,wNextPageAddress=0,
  42.              wRearPntCnt=0;
  43. unsigned char ucRxIndex=0,
  44.               ucGeneralCnt=0,ucFaxPropertyLenCnt,
  45.               ucRxIndex3=0,ucRxIndex2=0,
  46.               ucRxIndex0=0,ucRxIndex1=0;
  47.   for (wBlockAddress=cstViewDataAreaStartPage;
  48.      wBlockAddress<=cstViewDataAreaEndPage;wBlockAddress++)
  49. {
  50. for (wPageAddress=(wBlockAddress<<6);wPageAddress<((wBlockAddress<<6)+64);wPageAddress++)
  51. {
  52.       do{
  53.     wNextPageAddress=wPageAddress+64;
  54.     wPageAddress=CalNextPageAddress(wPageAddress);
  55.       }while(wNextPageAddress==wPageAddress);
  56.       
  57.       wColumnAddress=0;
  58.       ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  59.       ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  60.       
  61.       for (ucGeneralCnt=0;ucGeneralCnt<8;ucGeneralCnt++)
  62.       {
  63. //COMMAND
  64.   COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
  65.   COMMAND_LATCH_INTO();
  66. //ADDRESS
  67.   ADDRESS_VALUE=wColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
  68.   ADDRESS_LATCH_INTO();
  69.   ADDRESS_VALUE=(wColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
  70.   ADDRESS_LATCH_INTO();
  71.   ADDRESS_VALUE=ROW_ADDRESS_LOW;
  72.   ADDRESS_LATCH_INTO();
  73.   ADDRESS_VALUE=ROW_ADDRESS_HIGH;
  74.   ADDRESS_LATCH_INTO();
  75.   FLASH_CON_PORT_OUT &=~ ALE;
  76.   COMMAND_VAL=0X30;
  77.   COMMAND_LATCH_INTO();
  78.   //ATcmdDelay();
  79.   while((FLASH_CON_PORT_IN & RB)==0);
  80.   DATA_PORT_IN_INITIAL;
  81.   for (ucFaxPropertyLenCnt=0;ucFaxPropertyLenCnt<8;ucFaxPropertyLenCnt++)
  82.   {
  83.     FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  84.     aucUartRxBuf[ucRxIndex++]=DATA_PORT_IN;
  85.     FLASH_CON_PORT_OUT |= RE;
  86.   }
  87.   wRearPntCnt++;
  88.   ucRxIndex3=ucRxIndex-4;
  89.       ucRxIndex2=ucRxIndex-3;
  90.       ucRxIndex1=ucRxIndex-2;
  91.       ucRxIndex0=ucRxIndex-1;
  92.     if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  93.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  94.      {
  95.      break;  //next rear   
  96.      }//if
  97.   if (ucGeneralCnt<4)
  98.  wColumnAddress+=512;
  99.           else
  100.  wColumnAddress+=16;
  101.   }//for read next rear pointer
  102.   
  103.   //ucRxIndex3=gucUartRxCnt-4;
  104.     //ucRxIndex2=gucUartRxCnt-3;
  105.     //ucRxIndex1=gucUartRxCnt-2;
  106.     //ucRxIndex0=gucUartRxCnt-1;
  107.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  108.      0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  109.     {break;}
  110.   }//for next page
  111.   //ucRxIndex3=gucUartRxCnt-4;
  112.     //ucRxIndex2=gucUartRxCnt-3;
  113.     //ucRxIndex1=gucUartRxCnt-2;
  114.     //ucRxIndex0=gucUartRxCnt-1;
  115.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  116.      0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  117.     {break;}
  118. }//for next block
  119. gwFaxPropertyAddress=wPageAddress; //for write Fax property record //gwFaxPropertyAddress is equal gwFaxRearPointerAddress
  120.   gwColumnAddress=wColumnAddress; //
  121. }