⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apite1.inc

📁 Sample driver code for Dallas DS26528 T1/E1 framer chip.
💻 INC
📖 第 1 页 / 共 2 页
字号:
/* 
 * Copyright 1997-2005 NComm, Inc.  All rights reserved.
 * 
 *
 *                     *** Important Notice ***
 * The software contained in this file may only be used within a 
 * valid license agreement between your company and NComm, Inc. 
 * The license agreement includes the definition of a PROJECT which 
 * defines the scope that this software can be used in.  Any use outside of
 * the definition of the PROJECT is prohibited without executing an additional 
 * agreement with NComm, Inc. Please refer to you license agreement for 
 * the definition of the PROJECT.
 *
 * Verification of your company's license agreement and copies of 
 * that agreement also may be obtained from:
 *
 * NComm, Inc.
 * 254 N Broadway
 * Suite 106
 * Salem, NH 03079
 * (603) 893-6186
 * sales@ncomm.com
 *
 */



#ifdef T1_DRIVER
#define MAX_TIMESLOTS MAX_T1_TIMESLOTS
#endif

#ifdef E1_DRIVER
#define MAX_TIMESLOTS MAX_E1_TIMESLOTS
#endif


/*
 * This file is common to all  T1 and E1 drivers.  It is included at the
 * end of the associated driver file.  You do NOT want to make changes in this
 * file as it will change ALL of your  T1 and E1 drivers.
 *
 */


/*------------------------------------------------------------------------*/
/* This is used until the app gets its callback hooked up
 */
static int _cbackstub(void *LnPtr, TE1DCLBK_FC fcode, ...)
{
	return(SUCCESS);
}

/*------------------------------------------------------------------------*/
/* This routine sets the state of the line to a known state during a
 * reset or unreset call.  
 * The T1 or E1 will be left transmiting an AIS.
 */
static int _te1SetDefaultState(STUFF *sptr)
{
int i;

	/* Set the default CLOCK */
	set_txclock(sptr, DEFAULT_TX_CLOCK);

	/* Process alarms */

	transmit_alarm(sptr, TMS_TXAIS, 1);
	sptr->tx_alm = TMS_TXAIS;

	transmit_alarm(sptr, TMS_TXRAI, 0);

	/* Turn off one second processing */
	onesec_init(sptr, 0);

	/* Process loopbacks */

	do_loopback(sptr, LOOP_REMSWITCH,   0, 0, 0);
	do_loopback(sptr, LOOP_PAYSWITCH,   0, 0, 0);
	do_loopback(sptr, LOOP_LOCSWITCH,   0, 0, 0);
	do_loopback(sptr, LOOP_FRMSWITCH,   0, 0, 0);

#ifdef T1_DRIVER
	do_loopback(sptr, LOOP_REMTXUPCODE, 0, 0, 0);
	do_loopback(sptr, LOOP_REMTXDNCODE, 0, 0, 0);
#endif

	set_side(sptr, USR_SIDE);

	/* set all timeslots to clear channel */
	for(i = 0;i < MAX_TIMESLOTS; i++) {
		signal_clear(sptr, i, 1);
	}

#ifdef T1_DRIVER
	/* shut down boc codes */
	sptr->boctx.active = 0;
	sptr->boctx.boc = 0xff;
	send_fdl_boc(sptr);

	/* shut down FDL packets */
	send_fdl_packet(sptr, 2);

	/* turn on counting excessive zeros */
	exz_init(sptr, 1);

	/* turn off the cmas channel */
	cmas_init(sptr, 0);
#endif

#ifdef E1_DRIVER
	tx_sabyte(sptr, E1SABYTE4, 0xff);
	tx_sabyte(sptr, E1SABYTE5, 0xff);
	tx_sabyte(sptr, E1SABYTE6, 0xff);
	tx_sabyte(sptr, E1SABYTE7, 0xff);
	tx_sabyte(sptr, E1SABYTE8, 0xff);
	tx_sibits(sptr, 0x01);
	tx_xbits(sptr,  0x01);
#endif

	return(1);
}

/*------------------------------------------------------------------------*/
/* Tears down the line and leave it setup per the confiuration shown
 * in the sptr structure.
 */
static int _te1DeviceTearDown(STUFF *sptr)
{
int retval = 1;
GDEVICE *d;

	retval = _te1UNReset(sptr);

	if(!retval)
		goto bagout;

	retval = _te1SetDefaultState(sptr);

	if(!retval)
		goto bagout;

#ifdef NEEDS_EXTERNAL_LIU
	retval = TE1LIU_CTRL(sptr->LIUptr, TE1LIUDCTRL_UNRESET, sptr->cfg);

	if(!retval)
		goto bagout;
#endif

	d = sptr->d;

        drvMemset(sptr, 0, sizeof(STUFF));
	
	retval = NCID_GDEVICEUNMAP(d);

bagout:
	return(retval);
}

/*------------------------------------------------------------------------*/
/* _te1StuffMap fills out the standard information in the 
 * stuff structure and calls the routine _te1_set_chip_stuff for
 * the chip specific stuff information 
 */

static STUFF *_te1StuffMap(GDEVICE *d, int line, int subchannel, void *lnPtr)
{
STUFF *sptr = (STUFF *)0;


	if(!_te1_valid_channel(d, subchannel))
		return(NULL);

	sptr = _te1_get_stuff(d, subchannel);

	if(sptr->init)
		return(0);

        drvMemset(sptr, 0, sizeof(STUFF));

        sptr->line = line;
        sptr->d = d;

        sptr->cback = _cbackstub;
        sptr->lnPtr = lnPtr;
        sptr->subc = subchannel;
        sptr->init = 1;

	_te1_set_chip_stuff(sptr);

	return(sptr);
}


/*------------------------------------------------------------------------*/
/* Bind the line to a device
 * This routine performs:
 * DeviceMap = selects a device structure to use
 * Validate = validates that the configuration is acceptable
 * LIU = Interfaces to an LIU if necessary
 * StuffMap = fills out the necessary areas in the STUFF area
 * Reset = performs the reset functions on the device
 */
static int _te1DeviceSetup(int line, void *baseadr, int subchannel,
	TE1_CONFIG *cfgptr, void *lnPtr, void **refptr)
{
int retval = 1;
STUFF *sptr = (STUFF *)0;
GDEVICE *d;

	d = NCID_GDEVICEMAP(baseadr);

	if(d == NULL)
		return (0);

	sptr = _te1StuffMap(d, line, subchannel, lnPtr);

	if(sptr == NULL) 
		goto bagout;

#ifdef NEEDS_EXTERNAL_LIU
	retval = TE1LIU_CTRL(NULL, TE1LIUDCTRL_RESET, line,
		LIU_MODADDR(baseadr),
		LIU_MODSUBC(subchannel), cfgptr,
		sptr, &(sptr->LIUptr));

	if(!retval)
		goto bagout;
#endif

	drvMemcpy(&sptr->cfg, cfgptr, sizeof(sptr->cfg));

	retval = _te1Reset(sptr);

	if(!retval)
		goto bagout;
		
#ifdef NEEDS_EXTERNAL_LIU
	retval = TE1LIU_CTRL(sptr->LIUptr, TE1LIUDCTRL_ALARMTX, TMS_TXAIS, 0);

	if(!retval)
		goto bagout;
#endif

	retval = _te1SetDefaultState(sptr);

	if(!retval)
		goto bagout;

	*refptr = sptr;

	return(1);

bagout:
	if(sptr != NULL)
		_te1DeviceTearDown(sptr);

	return (0);
}

/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------ A P I -----------------------------------*/
/*------------------------------ A P I -----------------------------------*/
/*------------------------------ A P I -----------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------*/
int TE1_CTRLENTRY(void *refPtr, TE1DCTRL_FC fcode, ...)
{
int retval = 0;
STUFF *sptr = (STUFF *)refPtr;
va_list alist;

	/* Assure Reset is/was called
	 */
	if ((fcode != TE1DCTRL_RESET) && (refPtr == NULL)) {
		return(ERR_FAILURE);
	}

	va_start (alist, fcode);

	switch (fcode) {
	case TE1DCTRL_RESET:
		/* called before OS is running. Must put the line into
		 * a known state and setup framer to transmit AIS
		 */

		{int line;
		 void *baseadr;
		 int subchannel;
		 TE1_CONFIG *cfgptr;
		 void *lnPtr;
		 void **refptr;

			line = va_arg(alist, int);
			baseadr = va_arg(alist, void *);
			subchannel = va_arg(alist, int);
			cfgptr = va_arg(alist, TE1_CONFIG *);
			lnPtr = va_arg(alist, void *);
			refptr = va_arg(alist, void **);

#ifdef T1_DRIVER
			if (cfgptr->t1e1 != NCIT1)
				break;
#endif
#ifdef E1_DRIVER
			if (cfgptr->t1e1 != NCIE1)
				break;
#endif

			retval = _te1DeviceSetup(line, baseadr, subchannel,
				cfgptr, lnPtr, refptr);

			if(!retval) 
				break;

	   	}
		break;

	case TE1DCTRL_UNRESET:
		{TE1_CONFIG *cfgptr;
			cfgptr = va_arg(alist, TE1_CONFIG *);

#ifdef T1_DRIVER
			if (cfgptr->t1e1 != NCIT1)
				break;
#endif
#ifdef E1_DRIVER
			if (cfgptr->t1e1 != NCIE1)
				break;
#endif

			drvMemcpy(&sptr->cfg, cfgptr, sizeof(sptr->cfg));

			retval = _te1DeviceTearDown(sptr);
		}
		break;

	case TE1DCTRL_CALLBACK:
		{void *vptr;
			vptr = va_arg(alist, void *);

			sptr->cback = vptr;
			retval = 1;
		}
		break;

	case TE1DCTRL_UTILINIT:
		{int set_clear;
			set_clear = va_arg(alist, int);

			if((retval = utility_init(sptr, set_clear)))
				sptr->utility_init = set_clear;
		}
		break;

	case TE1DCTRL_SETSIDE:	/* set NET_SIDE or USR_SIDE */
		{int side;
			side = va_arg(alist, int);
	
			if((retval = set_side(sptr, side)))
				sptr->side = side;
		}
		break;

	case TE1DCTRL_OSTIC:
		{int ticker;
			ticker = va_arg(alist, int);

			retval = process_OSTick(sptr, ticker);
		}
		break;

	case TE1DCTRL_DEVICE:
		/* This comes directly from the APP-level.  This is a
		 * catch-all fcode that permits framer-chip customization
		 * above and beyond that required by the NCI Package.
		 * Therefore, this call comes directly from the line-level...
		 * there is a matching fcode for the CTRL call.  Thus, the app
		 * does not have to (nor should it!) make calls directly
		 * into the driver, as that would be architecturally incorrect.
		 */

		{unsigned long uparam1;
		 unsigned long uparam2;
		 unsigned long uparam3;
		 unsigned long uparam4;

			uparam1 = va_arg (alist, unsigned long);
			uparam2 = va_arg (alist, unsigned long);
			uparam3 = va_arg (alist, unsigned long);
			uparam4 = va_arg (alist, unsigned long);

			retval = CUSTOM_CTRL(sptr,
				uparam1, uparam2, uparam3, uparam4);

		}
		break;

	case TE1DCTRL_TXCLOCK:	/* set the transmit clock */
		{CLOCK_TYPE txclk;
			txclk = va_arg(alist, CLOCK_TYPE);

			if((retval = set_txclock(sptr, txclk)))
				sptr->txclk = txclk;
		}
		break;

	case TE1DCTRL_ONESEC:
		{int set_clear;
			set_clear = va_arg(alist, int);

			if((retval = onesec_init(sptr,set_clear)))
				sptr->onesec_init = set_clear;
		}
		break;

	case TE1DCTRL_SIGNLINIT:
		{int set_clear;
			set_clear = va_arg(alist, int);

			if((retval = signal_init(sptr, set_clear)))
				sptr->signal_init = set_clear;
		}
		break;

	case TE1DCTRL_SIGNLCLEAR:
		{int ts;
			ts = va_arg(alist, int);

			signal_idle(sptr, ts, -1, 0);
			signal_rbcas(sptr, ts, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -