chars.c
资源名称:de8681_w.zip [点击查看]
上传用户:sdttscl
上传日期:2010-01-04
资源大小:683k
文件大小:6k
源码类别:
Modem编程
开发平台:
C/C++
- //---------------------------------------------------------------------------------------------------
- // Project:- DE8681
- // Filename:- CHARS.C
- // Description:- Tx and Rx Character processing routines
- // Programmer:- D.T.F
- // Version:- 2.0
- // Created:- 28th November 2002
- // Last modified:-
- //---------------------------------------------------------------------------------------------------
- // (C) Consumer Microcircuits Ltd 2002
- //
- // This firmware was designed by:-
- // Consumer Microcircuits Ltd,
- // Langford, Maldon,
- // ESSEX
- // CM9 6WG.
- // in the UK for use with CML evaluation kits only and is based on UK originated technology.
- // Please contact
- // sales@cmlmicro.co.uk
- // +44 (0)1621 875500
- // for licensing details.
- //---------------------------------------------------------------------------------------------------
- #define CHARS_C
- #include "ef8681.h"
- void rx_atchars(void)
- {
- unsigned char tmprx;
- if (sci_getFERR())
- {
- sci_getByte(); // Read SCI receive register
- return; // Return
- }
- tmprx = sci_getByte(); // Read SCI receive register
- // Ignore all chars if the last AT command is still being processed
- // Exit if frame or overrun errors are experienced
- if (sci_checkOERR() || INTERPRET) return;
- // Set abort flag if key pushed during BERT or Test Functions
- if (BERTFLAG || TESTFUNC1 || TESTFUNC2)
- {
- KEYABORT = 1; // Set flag to indicate abort
- return;
- }
- // Set abort flag if key pushed during handshaking
- if (!ATCMDMODE && !DATAXFER) // During Handshaking
- {
- KEYABORT = 1; // Set flag to indicate abort
- return;
- }
- // Ignore chars outside the AT Command character set (echo all chars if required)
- if ((tmprx <= '9' && tmprx >= '0') || (tmprx <= 'Z' && tmprx >= 'A')
- || (tmprx <= 'z' && tmprx >= 'a') || tmprx == S3 || tmprx == S5
- || tmprx == '&' || tmprx == '@' || tmprx == '='
- || tmprx == '?' || tmprx == ',' || tmprx == '%' || tmprx == '*'
- || tmprx == '#' || tmprx == '/')
- {
- if (ATCHAR)
- {
- if (tmprx == S3)
- {
- ATBUF[ATBUFPTR] = NUL; // Null terminate command buffer string
- REPCMD=1; // Set repeat command flag
- ATCHAR=0; // Clear 'AT' char flag
- ACHAR=0; // Clear 'A' char flag
- INTERPRET=1; // Set Interpret flag
- CTSN=1; // Prevent any further chars
- }
- else if (tmprx == S5)
- {
- if (ATBUFPTR != 0) ATBUFPTR--; // Decrement AT Command Buffer Pointer
- }
- else
- {
- if (ATBUFPTR == 47) // If command buffer is full
- {
- ATBUF[ATBUFPTR] = NUL; // Null terminate command buffer string
- REPCMD=1; // Set repeat command flag
- ATCHAR=0; // Clear 'AT' char flag
- ACHAR=0; // Clear 'A' char flag
- INTERPRET=1; // Set Interpret flag
- CTSN=1; // Prevent any further chars
- }
- else
- {
- ATBUF[ATBUFPTR++] = tmprx; // Load current char into command buffer
- // Increment AT Command Buffer Pointer
- }
- }
- }
- else if (ACHAR)
- {
- if (tmprx == '/')
- {
- ACHAR=0; // Clear 'A' char flag
- INTERPRET=1; // Set Interpret flag
- CTSN=1; // Prevent any further chars
- }
- // If the current char is 'T' or 't' then set 'AT' char flag
- if (tmprx == 'T' || tmprx == 't') ATCHAR=1;
- }
- else
- {
- if (tmprx == 'A' || tmprx == 'a') ACHAR=1; // Set 'A' char flag
- }
- }
- if (ECHO) // Echo current rx char if required
- {
- MSGBUF[MSGBUFLDPTR++]=tmprx;
- MSGBUFLDPTR &= msgbufwrap; // Wrap round buffer if necessary
- if ((tmprx == S3) && WORDRES) // Check for CR char and word result enabled
- {
- MSGBUF[MSGBUFLDPTR++]= S4; // Insert additional LF
- MSGBUFLDPTR &= msgbufwrap; // Wrap round buffer if necessary
- }
- LOADCHAR=1; // Set load char flag
- }
- }
- void tx_chars(void)
- {
- if (TXIF)
- {
- if (!RTSN)
- {
- if (MSGBUFRDPTR != MSGBUFLDPTR)
- {
- TXREG = MSGBUF[MSGBUFRDPTR++];
- MSGBUFRDPTR &= msgbufwrap; // Wrap round buffer if necessary
- }
- else
- {
- TXIE=0; // Disable Tx interrupt
- }
- }
- }
- }
- void rx_datachars(void)
- {
- unsigned char tmprx;
- if (sci_getFERR())
- {
- sci_getByte(); // Read SCI receive register
- return; // Return
- }
- tmprx = sci_getByte(); // Read SCI receive register
- // Exit if frame or overrun errors are experienced
- if (sci_checkOERR()) return;
- DATABUF[DATABUFLDPTR++]=tmprx; // Load Data buffer at buffer location
- DATABUFLDPTR &= databufwrap; // Wrap round buffer if necessary
- if (((DATABUFLDPTR - DATABUFRDPTR) & databufwrap) >= databufpause)
- {
- CTSN=1; // Prevent any further chars
- }
- if (ESCTMR == 0) // If the Escape Timer has expired set the Flag
- {
- ESCTMREXP = 1;
- }
- ESCTMR = S12; // Reload the Escape Timer
- if (tmprx != S2)
- {
- ESCTMREXP = 0; // Clear Escape Timer Expired Flag
- ESC1CHAR = 0; // Clear 1st Escape Character Match Flag
- ESC2CHAR = 0; // Clear 2nd Escape Character Match Flag
- return;
- }
- if (!ESCTMREXP) return;
- if (!ESC1CHAR)
- {
- ESC1CHAR = 1; // Set 1st Escape Character Match Flag
- return;
- }
- if (!ESC2CHAR)
- {
- ESC2CHAR = 1; // Set 2nd Escape Character Match Flag
- return;
- }
- ATCMDMODE = 1; // Escape sequence received so revert back to AT command mode
- DATABUFLDPTR = 0x00; // Initialise Data Buffer Load pointer
- DATABUFRDPTR = 0x00; // Initialise Data Buffer Read pointer
- ESCTMREXP = 0; // Clear Escape Timer Expired Flag
- ESC1CHAR = 0; // Clear 1st Escape Character Match Flag
- ESC2CHAR = 0; // Clear 2nd Escape Character Match Flag
- CTSN=0; // Ensure we can accept new characters
- }