ef8681.h
资源名称:de8681_w.zip [点击查看]
上传用户:sdttscl
上传日期:2010-01-04
资源大小:683k
文件大小:19k
源码类别:
Modem编程
开发平台:
C/C++
- //---------------------------------------------------------------------------------------------------
- // Project:- DE8681
- // Filename:- EF8681.H
- // Description:- EF8681 Header File.
- // 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.
- //---------------------------------------------------------------------------------------------------
- //////////////////////////////////////////////////
- /* Include additional Header files */
- //////////////////////////////////////////////////
- #include <pic.h>
- #include <string.h>
- #include <stdlib.h>
- #include "sci.h"
- #include "cbus.h"
- #include "chars.h"
- #include "delay.h"
- #include "atcmd.h"
- #include "hndshake.h"
- #include "dataxfer.h"
- #include "bert.h"
- #define BITDEF(reg,bit) ((unsigned)&(reg)*8+(bit))
- #ifdef EF8681_C
- void init_regs(void);
- void init_micro(void);
- void init_ports(void);
- void resmsgtopc(unsigned char);
- void init_sregs(unsigned char);
- void init_GPTs(void);
- void update_GPTs(void);
- void dial(void);
- void hook(unsigned char);
- void genmsgtopc(unsigned char);
- void ringdetection(void);
- void hexnum2scrn(unsigned int,unsigned char,unsigned char);
- void decnum2scrn(unsigned int,unsigned char,unsigned char);
- unsigned char dut_chksum(void);
- void testfunc1(void);
- #else
- extern void init_sregs(unsigned char);
- extern void dial(void);
- extern void hook(unsigned char);
- extern void init_GPTs(void);
- extern void update_GPTs(void);
- extern void genmsgtopc(unsigned char);
- extern void hexnum2scrn(unsigned int,unsigned char,unsigned char);
- extern void decnum2scrn(unsigned int,unsigned char,unsigned char);
- #endif
- //////////////////////////////////////////
- /* EF8681 CMX868 Shadow Registers */
- //////////////////////////////////////////
- static volatile unsigned int bank3 CMXGENCTRL @ 0x190; // 16 Bit General Control Reg (Least Sig. Byte @ 0x190)
- static volatile unsigned int bank3 CMXTXMODE @ 0x192; // 16 Bit Tx Mode Reg (Least Sig. Byte @ 0x192)
- static volatile unsigned int bank3 CMXRXMODE @ 0x194; // 16 Bit Rx Mode Reg (Least Sig. Byte @ 0x194)
- static volatile unsigned char bank3 CMXTXDATA @ 0x196; // 8 Bit Tx Data Reg
- static volatile unsigned char bank3 CMXTXDATAV14 @ 0x197; // 8 Bit V14 Tx Data Reg
- static volatile unsigned char bank3 CMXRXDATA @ 0x198; // 8 Bit Rx Data Reg
- static volatile unsigned int bank3 CMXSTAT @ 0x199; // 16 Bit Status Reg (Least Sig. Byte @ 0x199)
- static volatile unsigned int bank3 CMXPROG @ 0x19B; // 16 Bit Programming Reg (Least Sig. Byte @ 0x19B)
- static volatile unsigned int bank3 CMXTESTADDR @ 0x19D; // Reserved
- static volatile unsigned int bank3 CMXTESTWR @ 0x19F; // Reserved
- static volatile unsigned int bank3 CMXTESTRD @ 0x1A1; // Reserved
- //////////////////////////////////////////
- /* EF8681 GPT Registers */
- //////////////////////////////////////////
- static volatile unsigned char bank3 GPT1 @ 0x1A3;
- static volatile unsigned char bank3 GPT2 @ 0x1A4;
- static volatile unsigned char bank3 GPT3 @ 0x1A5;
- static volatile unsigned char bank3 GPT4 @ 0x1A6;
- static volatile unsigned char bank3 GPT5 @ 0x1A7;
- static volatile unsigned char bank3 GPT6 @ 0x1A8;
- static volatile unsigned char bank3 ESCTMR @ 0x1A9;
- static volatile unsigned char bank3 ESCPS @ 0x1AA;
- static volatile unsigned char bank3 PS10ms @ 0x1AB;
- static volatile unsigned char bank3 PS100ms @ 0x1AC;
- static volatile unsigned char bank3 PS1s @ 0x1AD;
- static volatile unsigned char bank3 POLLTMR @ 0x1AE;
- static volatile unsigned char bank3 RDTIMEOUT @ 0x1AF;
- static volatile unsigned char bank3 CDLOSTTMR @ 0x1B0;
- //////////////////////////////////////////
- /* EF8681 Status Registers */
- //////////////////////////////////////////
- static volatile unsigned char bank3 MODEMSTAT @ 0x1B2;
- static volatile unsigned char bank3 ATCMDSTAT @ 0x1B3;
- static volatile unsigned char bank3 XFERSTAT @ 0x1B4;
- //////////////////////////////////////////
- /* EF8681 array pointers */
- //////////////////////////////////////////
- static volatile unsigned char bank3 ATBUFPTR @ 0x1B5;
- static volatile unsigned char bank3 MSGBUFLDPTR @ 0x1B6;
- static volatile unsigned char bank3 MSGBUFRDPTR @ 0x1B7;
- static volatile unsigned char bank3 DATABUFLDPTR @ 0x1B8;
- static volatile unsigned char bank3 DATABUFRDPTR @ 0x1B9;
- //////////////////////////////////////////
- /* EF8681 Ring Detect Register */
- //////////////////////////////////////////
- static volatile unsigned char bank3 RDCNT @ 0x1BA;
- //////////////////////////////////////////
- /* EF8681 BERT Registers */
- //////////////////////////////////////////
- static volatile unsigned char bank3 BERTSTAT @ 0x1BB;
- static volatile unsigned char bank3 BERCNT @ 0x1BC;
- static volatile unsigned char bank3 BERTXBYTE @ 0x1BD;
- static volatile unsigned char bank3 BERTMR0ADJ @ 0x1BE;
- /////////////////////////////////////////
- /* EF8681 AT Command Buffer */
- //////////////////////////////////////////
- static volatile unsigned char bank3 ATBUF[48] @ 0x1C0;
- //////////////////////////////////////////////////
- /* EF8681 Status Register Bits */
- //////////////////////////////////////////////////
- /* Modem Status Register */
- static volatile bank3 bit EVMODE @ BITDEF(MODEMSTAT,0);
- static volatile bank3 bit ATCMDMODE @ BITDEF(MODEMSTAT,1); // AT Command Mode Flag
- static volatile bank3 bit DATAXFER @ BITDEF(MODEMSTAT,2); // Data Transfer Flag
- static volatile bank3 bit FALLBACK @ BITDEF(MODEMSTAT,3); // Modulation Fallback Flag
- static volatile bank3 bit TESTFUNC1 @ BITDEF(MODEMSTAT,4); // Test Function One Flag
- static volatile bank3 bit TESTFUNC2 @ BITDEF(MODEMSTAT,5); // Test Function Two Flag
- static volatile bank3 bit KEYABORT @ BITDEF(MODEMSTAT,6); // Flag to indicate key pushed, used for aborting routines
- static volatile bank3 bit RDINPROG @ BITDEF(MODEMSTAT,7); // Flag to indicate ringing in progress
- /* AT Command Status Register */
- static volatile bank3 bit ACHAR @ BITDEF(ATCMDSTAT,0);
- static volatile bank3 bit ATCHAR @ BITDEF(ATCMDSTAT,1);
- static volatile bank3 bit REPCMD @ BITDEF(ATCMDSTAT,2);
- static volatile bank3 bit INTERPRET @ BITDEF(ATCMDSTAT,3);
- static volatile bank3 bit LOADCHAR @ BITDEF(ATCMDSTAT,4); // Flag set within Rx AT Command interrupt routine
- static volatile bank3 bit LED_OVERRIDE @ BITDEF(ATCMDSTAT,5);
- /* BERT Status Register */
- static volatile bank3 bit BERTFLAG @ BITDEF(BERTSTAT,0);
- static volatile bank3 bit BERTXRDY @ BITDEF(BERTSTAT,1);
- static volatile bank3 bit BERRXDATACLR @ BITDEF(BERTSTAT,2);
- /* Data Transfer Status Register */
- static volatile bank3 bit ESCTMREXP @ BITDEF(XFERSTAT,0);
- static volatile bank3 bit ESC1CHAR @ BITDEF(XFERSTAT,1);
- static volatile bank3 bit ESC2CHAR @ BITDEF(XFERSTAT,2);
- static volatile bank3 bit CDLOST @ BITDEF(XFERSTAT,3);
- static volatile bank3 bit TX_WAITING @ BITDEF(XFERSTAT,4);
- //////////////////////////////////////////
- /* PIC16LF876 Port Definitions */
- //////////////////////////////////////////
- /* PORTA bits */
- static volatile bit TXDIND @ BITDEF(PORTA,3);
- static volatile bit DTRIND @ BITDEF(PORTA,2);
- static volatile bit RXDIND @ BITDEF(PORTA,1);
- static volatile bit DCDIND @ BITDEF(PORTA,0);
- static volatile bit BER_TXD @ BITDEF(PORTA,3);
- static volatile bit BER_TXDCLK @ BITDEF(PORTA,2);
- static volatile bit BER_RXD @ BITDEF(PORTA,1);
- static volatile bit BER_RXDCLK @ BITDEF(PORTA,0);
- /* PORTB bits */
- static volatile bit CTSN @ BITDEF(PORTB,7);
- static volatile bit RTSN @ BITDEF(PORTB,6);
- static volatile bit DTRN @ BITDEF(PORTB,4);
- static volatile bit DSRN @ BITDEF(PORTB,3);
- static volatile bit RIN @ BITDEF(PORTB,2);
- static volatile bit DCDN @ BITDEF(PORTB,1);
- static volatile bit PICIRQN @ BITDEF(PORTB,0);
- /* PORTC bits */
- static volatile bit PICRXDN @ BITDEF(PORTC,7);
- static volatile bit PICTXDN @ BITDEF(PORTC,6);
- static volatile bit PICCDATA @ BITDEF(PORTC,5);
- static volatile bit PICRDATA @ BITDEF(PORTC,4);
- static volatile bit PICSCLK @ BITDEF(PORTC,3);
- static volatile bit PICCSN @ BITDEF(PORTC,2);
- /* Port Configuration (direction 1 = Input, 0 = Output) */
- /* All unused pins are i/p's (RA4-5, RC0, RC1 and RB5) */
- #define CONFIGPA 0b00110000 // Port A I/O config
- #define CONFIGPB 0b01110001 // Port B I/O config
- // (PICIRQN, DTRN and RTSN i/p's, RIN, DSRN, DCDN and CTSN o/p's)
- #define CONFIGPC 0b10010011 // Port C I/O config
- // (Bits 4 and 7 i/p's, bits 2,3,5 and 6 o/p's)
- // (PICRDATA and PICRXDN i/p's, PICCSN, PICSCLK, PICCDATA and PICTXDN o/p's)
- #define CONFIGBERTPA 0b00101000 // Port A I/O config for BERT
- // (Bits 0,1,2 and 4 o/p's and Bit 3 is i/p)
- // (BER_TXDCLK, BER_RXD, BER_RXDCLK and CDN o/p's and BER_TXD is i/p)
- /* Initial Port Settings */
- #define INITPA 0b00000000 // Initial Port A Settings
- // (TXDIND, DCDIND, RXDIND LEDs turned off, DTRIND LED turned on)
- #define INITPB 0b10101100 // Initial Port B Settings
- // (Bits 2, 3, 5 and 7 set)
- // (RIN, DCDN, DSRN and CTSN set)
- #define INITPC 0b01001100 // Initial Port C Settings
- // (Bit 5 is clear, Bits 2,3 and 6 are set)
- // (PICCDATA clear, PICCSN, PICSCLK and PICTXDN set)
- //////////////////////////////////////////
- /* CMX868 Register Bits */
- //////////////////////////////////////////
- // General Control Register
- static volatile bank3 bit IRQNOP_EN @ BITDEF(CMXGENCTRL,6);
- static volatile bank3 bit RESET @ BITDEF(CMXGENCTRL,7);
- static volatile bank3 bit PWRUP @ BITDEF(CMXGENCTRL,8);
- static volatile bank3 bit RLYDRV_ON @ BITDEF(CMXGENCTRL,9);
- static volatile bank3 bit FIX_EQU @ BITDEF(CMXGENCTRL,10);
- static volatile bank3 bit LOOPBACK_EN @ BITDEF(CMXGENCTRL,11);
- static volatile bank3 bit XTAL @ BITDEF(CMXGENCTRL,12);
- // Rx Mode Register
- static volatile bank3 bit AUTO_EQU @ BITDEF(CMXRXMODE,8);
- static volatile bank3 bit RXUSART @ BITDEF(CMXRXMODE,5);
- // Status Register
- static volatile bank3 bit FSKOUT @ BITDEF(CMXSTAT,0);
- static volatile bank3 bit RXEVENPAR @ BITDEF(CMXSTAT,3);
- static volatile bank3 bit RXFERR @ BITDEF(CMXSTAT,4);
- static volatile bank3 bit RXOF @ BITDEF(CMXSTAT,5);
- static volatile bank3 bit DTMFDET @ BITDEF(CMXSTAT,5);
- static volatile bank3 bit RXRDY @ BITDEF(CMXSTAT,6);
- static volatile bank3 bit ANS2225DET @ BITDEF(CMXSTAT,6);
- static volatile bank3 bit T1DET @ BITDEF(CMXSTAT,6);
- static volatile bank3 bit ANS2100DET @ BITDEF(CMXSTAT,7);
- static volatile bank3 bit T2DET @ BITDEF(CMXSTAT,7);
- static volatile bank3 bit CONTA @ BITDEF(CMXSTAT,7);
- static volatile bank3 bit CONTB @ BITDEF(CMXSTAT,8);
- static volatile bank3 bit FSK0101 @ BITDEF(CMXSTAT,9);
- static volatile bank3 bit S1DET @ BITDEF(CMXSTAT,9);
- static volatile bank3 bit RXENERGYDET @ BITDEF(CMXSTAT,10);
- static volatile bank3 bit CPENERGYDET @ BITDEF(CMXSTAT,10);
- static volatile bank3 bit T1T2DET @ BITDEF(CMXSTAT,10);
- static volatile bank3 bit TXUF @ BITDEF(CMXSTAT,11);
- static volatile bank3 bit TXRDY @ BITDEF(CMXSTAT,12);
- static volatile bank3 bit PROGFLAG @ BITDEF(CMXSTAT,13);
- static volatile bank3 bit RDET @ BITDEF(CMXSTAT,14);
- static volatile bank3 bit IRQ @ BITDEF(CMXSTAT,15);
- //////////////////////////////////////////////////////////
- /* CMX868 Register Address Definitions */
- //////////////////////////////////////////////////////////
- #define CMXGENRESET 0x01
- #define CMXGENCTRL_ADDR 0xE0
- #define CMXTXMODE_ADDR 0xE1
- #define CMXRXMODE_ADDR 0xE2
- #define CMXTXDATA_ADDR 0xE3
- #define CMXTXDATAV14_ADDR 0xE4
- #define CMXRXDATA_ADDR 0xE5
- #define CMXSTAT_ADDR 0xE6
- #define CMXPROG_ADDR 0xE8
- #define CMXTESTADDR_ADDR 0xE9
- #define CMXTESTWR_ADDR 0xEA
- #define CMXTESTRD_ADDR 0xEB
- //////////////////////////////////////////
- /* CMX868 DTMF Definitions */
- //////////////////////////////////////////
- #define DTMF_D 0x00
- #define DTMF_1 0x01
- #define DTMF_2 0x02
- #define DTMF_3 0x03
- #define DTMF_4 0x04
- #define DTMF_5 0x05
- #define DTMF_6 0x06
- #define DTMF_7 0x07
- #define DTMF_8 0x08
- #define DTMF_9 0x09
- #define DTMF_0 0x0A
- #define DTMF_star 0x0B
- #define DTMF_hash 0x0C
- #define DTMF_A 0x0D
- #define DTMF_B 0x0E
- #define DTMF_C 0x0F
- //////////////////////////////////////////
- /* AT Command S-Registers */
- //////////////////////////////////////////
- #define sregmin 0x110
- #define numsregs 30
- #define SREGADDR(reg,offset) (reg + offset)
- static volatile unsigned char bank2 S0 @ SREGADDR(sregmin,0); // Automatic answer
- static volatile unsigned char bank2 S1 @ SREGADDR(sregmin,1); // Count incoming rings
- static volatile unsigned char bank2 S2 @ SREGADDR(sregmin,2); // Escape Sequence character value
- static volatile unsigned char bank2 S3 @ SREGADDR(sregmin,3); // Carriage return character
- static volatile unsigned char bank2 S4 @ SREGADDR(sregmin,4); // Line feed character
- static volatile unsigned char bank2 S5 @ SREGADDR(sregmin,5); // Backspace character
- static volatile unsigned char bank2 S6 @ SREGADDR(sregmin,6); // Wait time for blind dialling
- static volatile unsigned char bank2 S7 @ SREGADDR(sregmin,7); // Wait for carrier after dial
- static volatile unsigned char bank2 S8 @ SREGADDR(sregmin,8); // Pause Time for Comma Dial Modifier
- static volatile unsigned char bank2 S9 @ SREGADDR(sregmin,9); // Carrier Detect Response Time
- static volatile unsigned char bank2 S10 @ SREGADDR(sregmin,10); // Lost carrier to hang up delay
- static volatile unsigned char bank2 S11 @ SREGADDR(sregmin,11); // DTMF tone duration
- static volatile unsigned char bank2 S12 @ SREGADDR(sregmin,12); // Escape code guard time
- static volatile unsigned char bank2 S13 @ SREGADDR(sregmin,13); // Reserved
- static volatile unsigned char bank2 S14 @ SREGADDR(sregmin,14); // General bit mapped options
- static volatile unsigned char bank2 S15 @ SREGADDR(sregmin,15); // Reserved
- static volatile unsigned char bank2 S16 @ SREGADDR(sregmin,16); // Reserved
- static volatile unsigned char bank2 S17 @ SREGADDR(sregmin,17); // Reserved
- static volatile unsigned char bank2 S18 @ SREGADDR(sregmin,18); // General Purpose Timer (s)
- static volatile unsigned char bank2 S19 @ SREGADDR(sregmin,19); // General Purpose Timer (10ms)
- static volatile unsigned char bank2 S20 @ SREGADDR(sregmin,20); // Reserved
- static volatile unsigned char bank2 S21 @ SREGADDR(sregmin,21); // BERT Setup Register
- static volatile unsigned char bank2 S22 @ SREGADDR(sregmin,22); // Bit Mapped Register
- static volatile unsigned char bank2 S23 @ SREGADDR(sregmin,23); // Bit Mapped Register
- static volatile unsigned char bank2 S24 @ SREGADDR(sregmin,24); // Bit Mapped Register
- static volatile unsigned char bank2 S25 @ SREGADDR(sregmin,25); // Bit Mapped Register
- static volatile unsigned char bank2 S26 @ SREGADDR(sregmin,26); // Bit Mapped Register
- static volatile unsigned char bank2 S27 @ SREGADDR(sregmin,27); // Bit Mapped Register
- static volatile unsigned char bank2 S28 @ SREGADDR(sregmin,28); // Reserved
- static volatile unsigned char bank2 S29 @ SREGADDR(sregmin,29); // Reserved
- //////////////////////////////////////////
- /* DF8681 Telephone Number Buffer */
- //////////////////////////////////////////
- static volatile unsigned char bank2 TELNUM[16] @ 0x130;
- #define maxteldigits 16
- //////////////////////////////////////////
- /* DF8681 Message Buffer */
- //////////////////////////////////////////
- static volatile unsigned char bank2 MSGBUF[32] @ 0x150;
- #define msgbufwrap 31
- //////////////////////////////////////////
- /* DF8681 Data Buffer */
- //////////////////////////////////////////
- static volatile unsigned char bank2 DATABUF[16] @ 0x140;
- #define databufwrap 15
- #define databufpause 8
- //////////////////////////////////////////////////
- /* AT Command S-Register Bits */
- //////////////////////////////////////////////////
- /* S14 Register */
- static volatile bank2 bit ECHO @ BITDEF(S14,1); // Echo Command Characters (0=Disabled, 1=Enabled)
- static volatile bank2 bit RESOFF @ BITDEF(S14,2); // Result Code Display (0=Send, 1=Do Not Send)
- static volatile bank2 bit WORDRES @ BITDEF(S14,3); // Word or Number Responses (0=Number, 1=Word)
- static volatile bank2 bit HEXOP @ BITDEF(S14,4); // Decimal or Hex Responses (0=Decimal, 1=Hex)
- static volatile bank2 bit ANSORIG @ BITDEF(S14,7); // Answer/Originate Operation (0=Answer, 1= Originate)
- /* S21 Register */
- static volatile bank2 bit BERTEND @ BITDEF(S21,0); // BERT End (0=Rx End, 1=Tx End)
- static volatile bank2 bit BERTBAND @ BITDEF(S21,1); // BERT Operating Band (0=Low Band, 1=High Band)
- /* S24 Register */
- static volatile bank2 bit USER_XTAL @ BITDEF(S24,0); // User Xtal setting (0=12.2880MHz, 1=11.0592MHz)
- static volatile bank2 bit USER_FIX_EQU @ BITDEF(S24,1); // User Fixed Equaliser setting (0=Enabled, 1=Disabled)
- static volatile bank2 bit USER_AUTO_EQU @ BITDEF(S24,2); // User Auto Equaliser setting (0=Disabled, 1=Enabled)
- // Required Auto Equaliser setting is ignored during V22bis
- //////////////////////////////////////////////////
- /* S Register Definitions */
- //////////////////////////////////////////////////
- #define PROTB0 0b00000000 // Bits 4,5,6 and 7 contain info all other bits masked
- #define PROTB1 0b00010000
- #define PROTB2 0b00100000
- #define PROTB3 0b00110000
- #define PROTB4 0b01000000
- #define PROTB5 0b01010000
- #define PROTB6 0b01100000
- #define PROTB7 0b01110000
- #define PROTB8 0b10000000
- #define PROTB9 0b10010000
- #define X0CALLING 0b00000000 // Bits 5,6 and 7 contain info all other bits masked
- #define X1CALLING 0b10000000
- #define X2CALLING 0b10100000
- #define X3CALLING 0b11000000
- #define X4CALLING 0b11100000
- #define NOGUARD 0b00000000 // Bits 6 and 7 contain info all other bits masked
- #define GUARD550 0b11000000
- #define GUARD1800 0b10000000
- //////////////////////////////////////////////////
- /* General Definitions */
- //////////////////////////////////////////////////
- #define TRUE 1
- #define FALSE 0
- #define ON 1
- #define OFF 0
- #define NUL 0
- #define OK 0
- #define CONNECT 1
- #define RING 2
- #define NOCARRIER 3
- #define ERROR 4
- #define NODIALTONE 5
- #define BUSY 6
- #define CON2400 7
- #define CON1200 8
- #define CON600 9
- #define CON300 10
- #define CON120075 11
- #define CON751200 12
- #define CON1200150 13
- #define CON1501200 14
- #define NYI 15
- #define NORESULT 16
- #define idmsg 0
- #define prodmsg 1
- #define cmlukmsg 2
- #define cmlsgmsg 3
- #define mxcommsg 4
- #define cmlukemmsg 5
- #define cmlsgemmsg 6
- #define mxcomemmsg 7
- #define cmluktelmsg 8
- #define cmlukwwwmsg 9
- #define dutrevmsg 10