dataxfer.c
资源名称:de8681_w.rar [点击查看]
上传用户:lilishw
上传日期:2021-05-28
资源大小:1542k
文件大小:5k
源码类别:
Modem编程
开发平台:
Visual C++
- //---------------------------------------------------------------------------------------------------
- // Project:- DE8681
- // Filename:- DATAXFER.C
- // Description:- Data Transfer routines
- // Programmer:- D.T.F
- // Version:- 2.0
- // Created:- 28th February 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 DATAXFER_C
- #include "ef8681.h"
- void dataxfer(void)
- {
- DATABUFLDPTR = 0x00; // Initialise Data Buffer Load pointer
- DATABUFRDPTR = 0x00; // Initialise Data Buffer Read pointer
- ESCTMR = S12; // Start the Escape Timer
- ESCTMREXP = 0; // Clear Escape Timer Expired Flag
- ESC1CHAR = 0; // Clear 1st Escape Character Match Flag
- ESC2CHAR = 0; // Clear 2nd Escape Character Match Flag
- CMXGENCTRL &= 0xFF80; // Clear any previous irq settings
- CMXGENCTRL ^= 0x0049; // Enable IRQN output, Tx Rdy and Rx Rdy irq's
- wr16_cbus(CMXGENCTRL_ADDR,CMXGENCTRL); // Update CBUS register
- POLLTMR = 20; // Start 20ms timer used for Rx Energy polling
- do
- {
- if (MSGBUFLDPTR != MSGBUFRDPTR) TXIE=1; // Ensure Tx SCI Interrupt is enabled
- if (DATABUFRDPTR != DATABUFLDPTR)
- {
- if (TX_WAITING)
- {
- RCIE = 0; // Disable Rx USART interrupt to prevent adjustment to Data Buffer
- CMXTXDATA = DATABUF[DATABUFRDPTR++]; // Update shadow register
- wr_cbus(CMXTXDATA_ADDR,CMXTXDATA); // Tx contents of current Data buffer location
- DATABUFRDPTR &= databufwrap; // Wrap round buffer if necessary
- RCIE = 1; // Re-enable Rx USART interrupt
- TX_WAITING = 0;
- }
- }
- else
- {
- CTSN = 0; // Ensure CTSN is low to allow further characters
- }
- if (!PICIRQN || (POLLTMR == 0)) // If irq occurs or Rx energy polling timer expires
- {
- GIE = 0;
- CMXSTAT = rd16_cbus(CMXSTAT_ADDR); // Update Status shadow register and clear irq
- if (RXRDY)
- {
- MSGBUF[MSGBUFLDPTR++] = rd_cbus(CMXRXDATA_ADDR); // Load Message Buffer with Rx Data Reg contents
- MSGBUFLDPTR &= msgbufwrap; // Wrap round buffer if necessary
- }
- if (TXRDY || TXUF)
- {
- TX_WAITING = 1; // Set the Tx waiting flag to indicate CMX868 is waiting to tx
- }
- if (hangup() != 0) // If Carrier detect is clear for longer than S10
- {
- reset_cbus(); // Reset CMX868 into powersave, will cause board to go on-hook
- DCDIND = 0; // Turn off CD LED
- DCDN = 1; // Set DCDN line
- DATAXFER = 0; // Abort data transfer
- ATCMDMODE = 1; // Revert back to AT Command Mode
- }
- POLLTMR = 20; // Reload 20ms timer used for Rx Energy polling
- }
- GIE = 1;
- } while (!ATCMDMODE); // Continue to loop until AT command mode is required
- CMXGENCTRL &= 0xFF80; // Ensure IRQN enable, Tx and Rx Rdy irqs are cleared
- wr16_cbus(CMXGENCTRL_ADDR, CMXGENCTRL); // Update CBUS register
- }
- unsigned char hangup()
- {
- if (RXENERGYDET && RLYDRV_ON)
- {
- CDLOST = 0; // Clear Carrier Detect lost flag
- return(FALSE);
- }
- if (CDLOST)
- {
- if (CDLOSTTMR == 0) return (TRUE); // If Lost Carrier Detect timer has expired return true.
- }
- else
- {
- CDLOST = 1; // Set the Carrier Detect Lost Flag
- CDLOSTTMR = S10; // Load Lost Carrier timer (100ms increments)
- }
- return (FALSE);
- }