DTEcmdProcess.c
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:10k
- /************************************************
- Description:
- process Dte Command
- Input:
- none
- Output:
- none
- Update:
- 2007.03.20 Bryan add some function
- 2007.1.25 Bryan function header create
- ************************************************/
- #include "includeH.h"
- void DteGetModemBus(void)
- {
- MODEM_BUS_CON_PORT |= MODEM_BUS_2_MCU;
- MODEM_BUS_CON_PORT &= ~MODEM_BUS_2_PC;
- gucViewStaticStatus &= ~bitViewReceiving;
- gucViewStaticStatus |= bitViewSending;
- ViewCommunicationTX(0x01);
-
- }
- //*************************************************************************
- void DteReturnModemBus(void)
- {
- unsigned int wGeneralCount = 0;
- unsigned int wOKcount=0;
- unsigned int wNotOKcount=0;
- unsigned char ucRxIndex1=0;
- unsigned char ucRxIndex0=0;
-
- MODEM_BUS_CON_PORT |= MODEM_BUS_2_PC;
- MODEM_BUS_CON_PORT &= ~MODEM_BUS_2_MCU;
- while (1)
- {
- ATcmdDelay();
- SendATcmd();
- ATcmdDelay();
- ATcmdDelay();
-
- while (wGeneralCount++<0xffff)
- {
- ucRxIndex1=gucUartRxCnt-3;
- ucRxIndex0=gucUartRxCnt-2;
- if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
- {wOKcount++;break;}
- if (wGeneralCount==0xffff)
- {
- //wGeneralCount=0;
- wNotOKcount++;
- SendATcmdModemSoftReset();
- ATcmdDelay();
- ATcmdDelay();
- }//if
- }//while
- ucRxIndex1=gucUartRxCnt-3;
- ucRxIndex0=gucUartRxCnt-2;
- if ((0x0d==aucUartRxBuf[ucRxIndex0])&&(0x4B==aucUartRxBuf[ucRxIndex1]))
- {wOKcount++;break;}
- }//while
- _NOP();
- gucViewStaticStatus |= bitViewReceiving;
- gucViewStaticStatus &= ~bitViewSending;
- ViewCommunicationTX(0x01);
- }
- //*************************************************************************
- void DteGetFaxList(void)
- {
- 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;
-
- SOFTUART_PORT_DIRECTION |= bitSOFTUARTTX;//set SOFTUARTTX open SoftUart TX
- for (wBlockAddress=cstFaxPropertyTableStartBlockNum;
- wBlockAddress<=cstFaxPropertyTableOverBlockNum;wBlockAddress++)
- {
- //1 block==64pages
- 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;
-
- //if a block no erase, one page can write 8 tiems(00 512 1024 1536 2048 2064 2080 2096)
- //So 8 times shall be readed within one page.
- 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<16;ucFaxPropertyLenCnt++)
- {
- FLASH_CON_PORT_OUT &=~ RE; //RE IS LOW,ENABLE READ DATA
- SoftUartTxOneFrame(DATA_PORT_IN);//add at Jan. 25, 2007
- 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 property 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
- /*
- //send the 16 FaxProperty to PC (16*16=256bytes)
- ucRxIndex=0;
- for (wGeneralCnt=0;wGeneralCnt<256;wGeneralCnt++)//
- {
- SoftUartTxOneFrame(aucUartRxBuf[ucRxIndex++]);
- ucRxIndex3=ucRxIndex+3;
- ucRxIndex2=ucRxIndex+2;
- ucRxIndex1=ucRxIndex+1;
- ucRxIndex0=ucRxIndex+0;
- if (0xff == aucUartRxBuf[ucRxIndex0] && 0xff == aucUartRxBuf[ucRxIndex1] &&
- 0xff == aucUartRxBuf[ucRxIndex2] && 0xff == aucUartRxBuf[ucRxIndex3])
- break;
- }
- */
- //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
- gwGeneralPageAddress=wPageAddress; //for write Fax property record
- gwColumnAddress=wColumnAddress; //for write Fax property record
- SOFTUART_PORT_DIRECTION &= ~bitSOFTUARTTX;//off the SoftUart
- }
- //*************************************************************************
- void DteGetOneFax(unsigned int wEveryFaxHead, unsigned int wEveryFaxRear)
- {
- unsigned char ucFlashColumnAddCnt=0;
-
- //unsigned char ucRxIndex=0;
- //unsigned char ucBlockCnt=0;
- unsigned int
- wNextPageAddress=0,wPageAddress=0,
- wGeneralCnt=0;
- //MODEM_BUS_CON_PORT |= SOFT_UART_2_PC;
- //SOFTUART_PORT_DIRECTION |= SOFT_UART_2_PC;
- SOFTUART_PORT_DIRECTION |= bitSOFTUARTTX;
- if (wEveryFaxHead<wEveryFaxRear)//(wEveryFaxHead!=wEveryFaxRear)//
- {
-
- for (wPageAddress=wEveryFaxHead;wPageAddress<=wEveryFaxRear;)//
- {
-
- ROW_ADDRESS_LOW = wPageAddress & 0xff;
- ROW_ADDRESS_HIGH = (wPageAddress>>8) & 0xff;
- for (ucFlashColumnAddCnt = 0;ucFlashColumnAddCnt < 8;ucFlashColumnAddCnt++)//8*256=2048
- {
- //8 * 256 == 2048 Bytes 2^4*2^8 12bit column address HighColumnAddr:0~8
- //total 8*256B+64B=2K+64B
- COLUMN_ADDRESS_HIGH=ucFlashColumnAddCnt;
- READ_256_BYTE();//read 256 Byte to aucUartRxBuf[256]
- for (wGeneralCnt=0;wGeneralCnt<256;wGeneralCnt++)//
- {
- SoftUartTxOneFrame(aucUartRxBuf[wGeneralCnt]);
- if (aucUartRxBuf[wGeneralCnt-1] == 0xfb && aucUartRxBuf[wGeneralCnt-2] == 0x13 && aucUartRxBuf[wGeneralCnt-3] == 0xff)
- {_NOP();break;}
- }//third for
- if (aucUartRxBuf[wGeneralCnt-1] == 0xfb && aucUartRxBuf[wGeneralCnt-2] == 0x13 && aucUartRxBuf[wGeneralCnt-3] == 0xff)
- break;
- }//second for
-
- if (aucUartRxBuf[wGeneralCnt-1] == 0xfb && aucUartRxBuf[wGeneralCnt-2] == 0x13 && aucUartRxBuf[wGeneralCnt-3] == 0xff)//pageimage over
- {
- /*//Record the front pointer for Check new in DCE
- ATcmdDelay();// a bug of Dec.23,2006 FF 10 00 0E // receive data delay(if not, can't receive 0x10 0x03)
- if ((gwGeneralPageAddress>>6) > cstFaxFrontPointerTableOverBlockNum)
- {
- for (ucBlockCnt=0;ucBlockCnt<4;ucBlockCnt++)
- {
- wPageAddress=(cstFaxFrontPointerTableStartBlockNum+ucBlockCnt)<<6;
- ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
- ERASE_ONE_BLOCK();
- }
- gwGeneralPageAddress = cstFaxFrontPointerTableStartPage;
- gwColumnAddress=0;
- }
-
- //Record the front pointer for Check new in DCE
-
- ReadLastFaxFrontPointer();
- ucRxIndex=0; //write Fax Front Pointer
- aucUartRxBuf[ucRxIndex++]=wPageAddress & 0xff;
- aucUartRxBuf[ucRxIndex++]=(wPageAddress>>8) & 0xff;
- for (ucBlockCnt=0; ucBlockCnt<12; ucBlockCnt++)
- {
- aucUartRxBuf[ucRxIndex++]=0x55;
- }
- //WriteFaxFrontPointerTable();
- Write16Bytes2FlashMemoryArea();
- */
- wPageAddress++;
- if(wPageAddress==0)
- wPageAddress += cstFaxContentStartPage;//2560;//Mar. 1, 20007
- do{
- wNextPageAddress=wPageAddress+64;
- wPageAddress=CalNextPageAddress(wPageAddress);
- }while(wNextPageAddress==wPageAddress);
- //ReadLastFaxFrontPointer();//read next write fax front pointer addr //delete at Jan. 19, 2007
- continue;//break; a bug of Dec. 12,2006
- }
- wPageAddress++;
- if(wPageAddress==0)
- wPageAddress += cstFaxContentStartPage;//2560;//Mar. 1, 20007
- do{
- wNextPageAddress=wPageAddress+64;//wNextPageAddress=gwPageAddress+64;
- wPageAddress=CalNextPageAddress(wPageAddress);
- }while(wNextPageAddress==wPageAddress);
- }//third for ----> next page
-
- }//if wNewFaxHead<wNewFaxRear
- //MODEM_BUS_CON_PORT &= ~SOFT_UART_2_PC;
- //SOFTUART_PORT_DIRECTION &= ~SOFT_UART_2_PC;
- SOFTUART_PORT_DIRECTION &= ~bitSOFTUARTTX;
- }//DteGetOneFax function over
- /*
- void SetSystemTime(unsigned char ucYear, unsigned char ucMonth, unsigned char ucDate,
- unsigned char ucHour, unsigned char ucMinute, unsigned char ucSecond)
- {
- ;
- }
- */
- void DceResponsePc(void)
- {
- unsigned char ucRxIndex=0;
- for (ucRxIndex=0; ucRxIndex<8; ucRxIndex++)
- SoftUartTxOneFrame(aucUartRxBuf[ucRxIndex]);
- }