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

传真(Fax)编程

开发平台:

C/C++

  1. /***************************************
  2. Program:     FlashManage
  3. Author:      Bryan Cai
  4. Date:        2006.12.07
  5. ***************************************/
  6. #include "includeH.h"
  7. //unsigned int  gwGeneralPageAddress=0;//=960;
  8. void Write16Bytes2FlashMemoryArea(void)
  9. {
  10. unsigned char ucFlashSttsOverflowCnt=0,ucFaxGeneralLenCnt=0,
  11.               ucRxIndex=0;
  12.               
  13.   COMMAND_VAL=cFlashWriteCmd;
  14.   COMMAND_LATCH_INTO();
  15. //ADDRESS
  16.   
  17.   ADDRESS_VALUE=gwColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
  18.   ADDRESS_LATCH_INTO();
  19.   ADDRESS_VALUE=(gwColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
  20.   ADDRESS_LATCH_INTO();
  21.   ADDRESS_VALUE=gwGeneralPageAddress & 0xff;
  22.   ADDRESS_LATCH_INTO();
  23.   ADDRESS_VALUE=(gwGeneralPageAddress>>8) & 0XFF;
  24.   ADDRESS_LATCH_INTO();
  25.   FLASH_CON_PORT_OUT &=~ ALE;
  26.   DATA_PORT_OUT_INITIAL;
  27.   for (ucFaxGeneralLenCnt=0;ucFaxGeneralLenCnt<16;ucFaxGeneralLenCnt++)
  28.   {
  29.   FLASH_CON_PORT_OUT&=~WE;
  30.     DATA_PORT_OUT=aucUartRxBuf[ucRxIndex++];
  31.     FLASH_CON_PORT_OUT |= WE;
  32.   }
  33.   COMMAND_VAL=cFlashWriteInitiateCmd; //10H INITIATES PROGRAM
  34.   COMMAND_LATCH_INTO();
  35.   READ_STATUS();
  36.   ucFlashSttsOverflowCnt=0;
  37.   if(FLASH_STATUS==1&&(ucFlashSttsOverflowCnt++)<2)
  38.   {;}
  39. }
  40. void ReadLast16BytesFromFlashMemoryArea(unsigned char ucAreaStartBlockAddress, unsigned char ucAreaOverBlockAddress)//read last fax General pointer
  41. {
  42. unsigned int wPageAddress=0, wBlockAddress=0,
  43.              wColumnAddress=0,wNextPageAddress=0,
  44.              wGeneralPntCnt=0;
  45. unsigned char ucRxIndex=0,
  46.               ucRxIndex3=0,ucRxIndex2=0,
  47.               ucRxIndex0=0,ucRxIndex1=0,
  48.               ucGeneralCnt=0,ucFaxGeneralLenCnt;
  49.   //for (wBlockAddress=cFaxRearPointerTableStartBlockNum;
  50.      //wBlockAddress<=cFaxRearPointerTableOverBlockNum;wBlockAddress++)
  51. for (wBlockAddress=ucAreaStartBlockAddress;
  52.      wBlockAddress<=ucAreaOverBlockAddress;wBlockAddress++)
  53. {
  54. for (wPageAddress=(wBlockAddress<<6);wPageAddress<((wBlockAddress<<6)+64);wPageAddress++)//one block
  55. {
  56.       do{
  57.     wNextPageAddress=wPageAddress+64;
  58.     wPageAddress=CalNextPageAddress(wPageAddress);
  59.       }while(wNextPageAddress==wPageAddress);
  60.       
  61.       wColumnAddress=0;
  62.       ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  63.       ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
  64.       
  65.       for (ucGeneralCnt=0;ucGeneralCnt<8;ucGeneralCnt++)
  66.       {
  67. //COMMAND
  68.   COMMAND_VAL=0x00; //#0X00 //00H READ1 0-2111BYTE
  69.   COMMAND_LATCH_INTO();
  70. //ADDRESS
  71.   ADDRESS_VALUE=wColumnAddress & 0xff;//COLUMN_ADDRESS_LOW;
  72.   ADDRESS_LATCH_INTO();
  73.   ADDRESS_VALUE=(wColumnAddress>>8) & 0XFF;//COLUMN_ADDRESS_HIGH;
  74.   ADDRESS_LATCH_INTO();
  75.   ADDRESS_VALUE=ROW_ADDRESS_LOW;
  76.   ADDRESS_LATCH_INTO();
  77.   ADDRESS_VALUE=ROW_ADDRESS_HIGH;
  78.   ADDRESS_LATCH_INTO();
  79.   FLASH_CON_PORT_OUT &=~ ALE;
  80.   COMMAND_VAL=0X30;
  81.   COMMAND_LATCH_INTO();
  82.   //ATcmdDelay();
  83.   while((FLASH_CON_PORT_IN & RB)==0);
  84.   DATA_PORT_IN_INITIAL;
  85.   for (ucFaxGeneralLenCnt=0;ucFaxGeneralLenCnt<16;ucFaxGeneralLenCnt++)
  86.   {
  87.     FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
  88.     aucUartRxBuf[ucRxIndex++]=DATA_PORT_IN;
  89.     FLASH_CON_PORT_OUT |= RE;
  90.   }
  91.   wGeneralPntCnt++;
  92.   
  93.   ucRxIndex3=ucRxIndex-4;
  94.           ucRxIndex2=ucRxIndex-3;
  95.           ucRxIndex1=ucRxIndex-2;
  96.           ucRxIndex0=ucRxIndex-1;
  97.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  98.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  99.      {
  100.      gucUartRxCnt = ucRxIndex-32;
  101.      break;  //next General   
  102.      }//if
  103.   if (ucGeneralCnt<4)
  104.  wColumnAddress+=512;
  105.           else
  106.  wColumnAddress+=16;
  107.   }//for read next General pointer
  108.   
  109.   
  110.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  111.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  112.      {break;}
  113.   }//for next page
  114.   
  115.   
  116.   if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
  117.        0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
  118.      {break;}
  119. }//for next block
  120. gwGeneralPageAddress=wPageAddress; //for write Fax General pointer
  121.   gwColumnAddress=wColumnAddress; //for find blank page
  122.   if (ucAreaOverBlockAddress>10)
  123.   {
  124.   if (wGeneralPntCnt>1)
  125.   {
  126.     ucRxIndex1=ucRxIndex-32;
  127.     ucRxIndex0=ucRxIndex-31;
  128.     wPageAddress=aucUartRxBuf[ucRxIndex0];
  129.     gwPageAddress=(wPageAddress<<8) | aucUartRxBuf[ucRxIndex1];
  130.     gucGeneralStatus |= bitReadFlashMemoryOK; 
  131.   }
  132.   else
  133.     {
  134.      gwPageAddress=cstFaxContentStartPage-1;//2559;//1279;//write the data start address
  135.      gucGeneralStatus &= ~bitReadFlashMemoryOK;
  136.     }
  137.   }
  138. }