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

传真(Fax)编程

开发平台:

C/C++

  1. /***************************************
  2. Program:     FlashManage
  3. Author:      Bryan Cai
  4. Date:        2006.12.12
  5. ***************************************/
  6. #include "includeH.h"
  7. void WriteFaxFrontPointerTable(void)
  8. {
  9. unsigned char ucFlashSttsOverflowCnt=0,ucFaxPointerLenCnt=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=gwFrontPointerAddress & 0xff;
  20.   ADDRESS_LATCH_INTO();
  21.   ADDRESS_VALUE=(gwFrontPointerAddress>>8) & 0XFF;
  22.   ADDRESS_LATCH_INTO();
  23.   FLASH_CON_PORT_OUT &=~ ALE;
  24.   DATA_PORT_OUT_INITIAL;
  25.   for (ucFaxPointerLenCnt=0;ucFaxPointerLenCnt<4;ucFaxPointerLenCnt++)
  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 ReadLastFaxFrontPointer(void)//find last fax front pointer
  39. {
  40. unsigned int wPageAddress=0, wBlockAddress=0,
  41.              wColumnAddress=0,wNextPageAddress=0,
  42.              wRearPntCnt=0;
  43. unsigned char ucRxIndex=0,
  44.               ucRxIndex3=0,ucRxIndex2=0,
  45.               ucRxIndex0=0,ucRxIndex1=0,
  46.               ucGeneralCnt=0,ucFaxRearLenCnt;
  47.   for (wBlockAddress=cFaxFrontPointerTableStartBlockNum;
  48.      wBlockAddress<=cFaxFrontPointerTableOverBlockNum;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 (ucFaxRearLenCnt=0;ucFaxRearLenCnt<4;ucFaxRearLenCnt++)
  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.     
  89.     ucRxIndex3=ucRxIndex-4;
  90.             ucRxIndex2=ucRxIndex-3;
  91.             ucRxIndex1=ucRxIndex-2;
  92.             ucRxIndex0=ucRxIndex-1;
  93.     if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  94.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  95.      {
  96.      break;  //next front   
  97.      }//if
  98.   if (ucGeneralCnt<4)
  99.  wColumnAddress+=512;
  100.           else
  101.  wColumnAddress+=16;
  102.   }//for read next front pointer
  103.    
  104.     if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  105.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  106.      {break;}
  107.   }//for next page
  108.     
  109.     if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  110.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  111.      {break;}
  112. }//for next block
  113. gwFrontPointerAddress=wPageAddress; //for write Fax front pointer
  114.   gwColumnAddress=wColumnAddress; //read next front pointer address, for write next front pointer
  115.   if (wRearPntCnt>1)
  116.   {
  117.     ucRxIndex1=ucRxIndex-8;
  118.     ucRxIndex0=ucRxIndex-7;
  119.     wPageAddress=aucUartRxBuf[ucRxIndex0];
  120.     gwPageAddress=(wPageAddress<<8) | aucUartRxBuf[ucRxIndex1]; 
  121.   }
  122.   else
  123.     gwPageAddress=cstFaxContentStartPage-1;//2559;//1279;//read data start address(1280)
  124. }