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

📄 ds26528e1.c

📁 Sample driver code for Dallas DS26528 T1/E1 framer chip.
💻 C
📖 第 1 页 / 共 3 页
字号:
static int tx_sabyte(STUFF *sptr, int sabyteN, int sabyte)
{
int retval = 1;
STANDARD_DECLARE;

	switch (sabyteN) {
	case E1SABYTE4:
		f->tsa4 = (unsigned char)BYTE_FLIP(sabyte);
		break;
	case E1SABYTE5:
		f->tsa5 = (unsigned char)BYTE_FLIP(sabyte);
		break;
	case E1SABYTE6:
		f->tsa6 = (unsigned char)BYTE_FLIP(sabyte);
		break;
	case E1SABYTE7:
		f->tsa7 = (unsigned char)BYTE_FLIP(sabyte);
		break;
	case E1SABYTE8:
		f->tsa8 = (unsigned char)BYTE_FLIP(sabyte);
		break;
	default:
		retval = 0;
		break;
	}

	return(retval);

}

/*------------------------------------------------------------------------*/
/* This routine transmits the Si (International) bits
 */
static int tx_sibits(STUFF *sptr, int sibits)
{
int retval = 1;
STANDARD_DECLARE;

	/* The Si bit position is consumed by the CRC */

	if(sptr->cfg.framing == FF_E1_CRC ||
	   sptr->cfg.framing == FF_E1_CRC_MF)
		return(0);

	f->tslc3_tsiaf = f->tsinaf = (sibits) ? 0xff : 0;

	return(retval);

}

/*------------------------------------------------------------------------*/
/* This routine transmits the extra (X) bits in a MF framed E1
 */
static int tx_xbits(STUFF *sptr, int xbits)
{
int retval = 1;
int bits;
long lval;
STANDARD_DECLARE;

	/* The X bits are only available with CAS signaling */

	if(sptr->cfg.framing == FF_E1_CRC ||
	   sptr->cfg.framing == FF_E1)
		return(0);

	lval = INTS_OFF();
	bits = f->ts[0] & 0xf4;	
	bits |= ((xbits & 0x03) | ((xbits & 0x04) << 1));
	f->ts[0] = bits;
	INTS_ON(lval);

	return(retval);
}

/*------------------------------------------------------------------------*/
/* This will poll alarms on the appriate line
 */
static int poll_alarm(STUFF *sptr, int alarm_type, int *valueptr)
{
int retval = 1;
int value = 0;
STANDARD_DECLARE;

	switch(alarm_type) {
	case TMS_RXLOS:

		value = (f->rrts1 & RRTS1_RLOS) ? 1 : 0;
		break;

	case TMS_RXOOF:

		value = (f->rrts1 & RRTS1_RLOF) ? 1 : 0;
		break;

	case TMS_RXAIS:
		value = (f->rrts1 & RRTS1_RAIS) ? 1 : 0;
		break;

	case TMS_RXRAI:
		value = (f->rrts1 & RRTS1_RRAI) ? 1 : 0;
		break;

	default:
		retval = 0;
		break;
	}

	*valueptr = value;
	return(retval);
}

/*------------------------------------------------------------------------*/
/* This routine will retreive the loop information
 */
static int poll_loop(STUFF *sptr, int loop_type, int *set_clear)
{
int retval = 1;
int value = 0;
LIU *l = sptr->e1s.myliu;
STANDARD_DECLARE;

	switch(loop_type) {
	case LOOP_REMSWITCH:
		/* Remote is when the the receive signal is looped back
		 * at the analog layer to the remote device.
		 * This is also known as line loopback
		 */  

		value = (f->rcr3 & RCR3_RLB) ? 1 : 0;

		break;

	case LOOP_LOCSWITCH:
		/* Local Loopback is when the voice channels are looped
		 * before the framer section.
		 */

		value = (l->lmcr & LMCR_LLB) ? 1 : 0;

		break;

	case LOOP_PAYSWITCH:
		/* Payload Loopback is when the framer receives the signal
		 * then, after the framer, the voice channels are re-sent out
		 * and the overhead is re-generated.
		 */

		value = (f->rcr3 & RCR3_PLB) ? 1 : 0;

		break;

	case LOOP_FRMSWITCH:	
		/* Framer Loopback is when the signal is set out of
		 * the framer and looped back to the framer but
		 * before it hits the LIU.  You will send and AIS while
		 * this happens.  The AIS is done by the chip and not the
		 * Upper layers.
		 */

		value = (f->rcr3 & RCR3_FLB) ? 1 : 0;

		break;

	default:
		retval = 0;
		break;
	}

	*set_clear = value;
	return(retval);
}

/*------------------------------------------------------------------------*/
/* This will retreive ALL 30 channels of signaling
 * It will fill the array of all_rxbits with all signaling channels
 * all_rxbits must be 32 ints long, but index 0 and 16 are not used
 * because they carry the framing channel and the CAS channel respecitively
 */
static int poll_allrxbits(STUFF *sptr, int *all_rxbits)
{
int retval = 1;
int val, all_bits, ts;
int *p;
STANDARD_DECLARE;

	/* note: Skip 0 which is TS 0 and TS 16 */
	p = all_rxbits;

	for (ts = 1; ts < MAX_E1_TIMESLOTS / 2; ts++) {
		all_bits = f->rs[ts];  /* this gets two time slots */

		val = flip_table[((all_bits & 0xf0) >> 4)];
		*(p + ts) = sptr->ds0[ts].rxbits = val;


		/* process the 2nd timeslot */
		val = flip_table[(all_bits & 0x0f)];
		*(p + ts + 15) = sptr->ds0[ts].rxbits = val;
		
	}

	return(retval);
}

/*------------------------------------------------------------------------*/
/* This routine will retreive the performance data
 */
static int get_pm(STUFF *sptr, E1_PERFINFO *pm)
{
int retval = 1;
STANDARD_DECLARE;

	pm->CVcount = (f->lcvcr1 << 8) | f->lcvcr2;
	pm->CRCcount = (f->pcvcr1 << 8) | f->pcvcr2;
	pm->EBITcount = (f->ebcr1 << 8) | f->ebcr2;
	pm->FAScount = (f->foscr1 << 8) | f->foscr2;

	return(retval);

}

/*------------------------------------------------------------------------*/
/* This will retreive the SA (National) bits on the line in nonCRC Framing
 */
static int poll_sabits(STUFF *sptr, int *sabits)
{
int retval = 1;
STANDARD_DECLARE;

	*sabits = f->rslc2_rnaf & 0x1f;

	return(retval);
}

/*------------------------------------------------------------------------*/
/* This will retreive the SA (National) bits on the line in CRC Framing
 */
static int poll_sabyte(STUFF *sptr, int sabyteN, int *sabyte)
{
int retval = 1;
STANDARD_DECLARE;
	
	switch (sabyteN) {
	case E1SABYTE4:
		*sabyte = (int)BYTE_FLIP(f->rsa4);	
		break;
	case E1SABYTE5:
		*sabyte = (int)BYTE_FLIP(f->rsa5);	
		break;
	case E1SABYTE6:
		*sabyte = (int)BYTE_FLIP(f->rsa6);	
		break;
	case E1SABYTE7:
		*sabyte = (int)BYTE_FLIP(f->rsa7);	
		break;
	case E1SABYTE8:
		*sabyte = (int)BYTE_FLIP(f->rsa8);	
		break;
	default:
		retval = 0;
		break;
	}

	return(retval);
}

/*------------------------------------------------------------------------*/
/* This will retreive the Si (International) bits on the line
 */
static int poll_sibits(STUFF *sptr, int *sibits)
{
int retval = 1;
STANDARD_DECLARE;

	/* The Si bit position is consumed by the CRC */

	if(sptr->cfg.framing == FF_E1_CRC ||
	   sptr->cfg.framing == FF_E1_CRC_MF)
		return(0);

	*sibits = (f->rslc2_rnaf & 0x80) ? 1 : 0;

	return(retval);
}

/*------------------------------------------------------------------------*/
/* This will retreive the X (Extra) bits on the line
 */
static int poll_xbits(STUFF *sptr, int *xbits)
{
int retval = 1;
int bits;
STANDARD_DECLARE;

	/* The X bits are only available with CAS signaling */

	if(sptr->cfg.framing == FF_E1_CRC ||
	   sptr->cfg.framing == FF_E1)
		return(0);

	bits = f->rs[0];
	*xbits = ((bits & 0x03) | (bits & 0x08) >> 1);

	return(retval);
}

/*------------------------------------------------------------------------*/
/* This will transmit on the appriate line 
 */
static int transmit_alarm(STUFF *sptr, int alarm_type, int set_clear)
{
int retval = 1;
STANDARD_DECLARE;

	switch(alarm_type) {
	case TMS_TXRAI:
		if(set_clear) {
			f->tsacr |= TSACR_RA;
		}
		else {
			f->tra = 0;
			f->tsacr &= ~TSACR_RA;
		}
		break;
	case TMS_TXAIS:
		if(set_clear) {
			f->tcr1 |= TCR1_TAIS;
		}
		else {
			f->tcr1 &= ~TCR1_TAIS;
		}
		break;

	default:
		retval = 0;
		break;
	}

	return(retval);
}

/*------------------------------------------------------------------------*/
/* Enable G.826 processing on the line 
 */
static int g826_init(STUFF *sptr, int set_clear)
{
int retval = 1;

	/* Nothing to de done here */
	return(retval);
}

/*------------------------------------------------------------------------*/
/* Enable one sec processing on the approriate line
 */
static int onesec_init(STUFF *sptr, int set_clear)
{
int retval = 1;
STANDARD_DECLARE;


	if(set_clear) {
		retval = hook_isr(sptr, set_clear, INTFLAG_ONESEC);
		if(!retval)
			return(0);
		f->rim4 |= RIM4_TIMER;
	}
	else {
		f->rim4 &= ~RIM4_TIMER;
		retval = hook_isr(sptr, set_clear, INTFLAG_ONESEC);
		if(!retval)
			return(0);
	}
	return(retval);
}

#if (MAX_GLOBAL_TICKERS	> 0)

/* -------------------------------------------------------------------------- */
/* The device has global tickers associated with it so,
 * the following routine is called by the global file for processing of
 * the global tickers
 */
static void E1GlobalTickerHandler(GDEVICE *d, int ticker)
{

	switch(ticker) {
	case 0:
		break;
	default:
		break;
	}
}


/*------------------------------------------------------------------------*/
/* This routine is called by global when the first time a ticker is
 * registered.  This routine makes the call back to the approprate TMS
 * to get the ticker hooked up.
 */
static void E1RegTicker(STUFF *sptr, void (*global_handler)(),
	int on_off, int ticker, int ms, void *handle)
{

	if(on_off)
		(*sptr->cback)(sptr->lnPtr, TE1DCLBK_HOOKOSTIC, ms, handle,
			global_handler, sptr->d, ticker);
		
	else
		(*sptr->cback)(sptr->lnPtr, TE1DCLBK_UNHOOKOSTIC, 
			*((unsigned long *)(handle)));
}

/*------------------------------------------------------------------------*/
/* This routine start a global ticker going
 */
static void start_global_ticker(STUFF *sptr, int ticker, int onoff)
{

	NCID_GHOOKTICKER(sptr->d, DRVR_IDX_E1, ticker, onoff,
		E1RegTicker, sptr, E1GlobalTickerHandler);
}

#endif	/* MAX_GLOBAL_TICKERS */

/*------------------------------------------------------------------------*/
/* This routine enables alarms 
 * Alarms:
 *         LOS OOF AIS RAI
 * If  MF, then Loss of MF alarm
 * If CRC, then Loss of CRC-4 framing
 */
static int alarm_init(STUFF *sptr, int set_clear)
{
int retval = 1;
STANDARD_DECLARE;

	/* Tell the app that the driver is doing Auto-RAI.  Off by default.
	 */
	(*sptr->cback)(sptr->lnPtr, TE1DCLBK_AUTORAI, 1);

	if(set_clear) {
		retval = hook_isr(sptr, set_clear, INTFLAG_ALM);
		if(!retval)
			return(0);

		f->rim1 |= RIM1_RRAIC | RIM1_RAISC | RIM1_RLOSC |
			RIM1_RLOFC | RIM1_RRAID | RIM1_RAISD |
			RIM1_RLOSD | RIM1_RLOFD;
		f->tcr2 |= TCR2_ARA;
	}
	else {
		f->rim1 |= ~(RIM1_RRAIC | RIM1_RAISC | RIM1_RLOSC |
			RIM1_RLOFC | RIM1_RRAID | RIM1_RAISD |
			RIM1_RLOSD | RIM1_RLOFD);

		retval = hook_isr(sptr, set_clear, INTFLAG_ALM);
		if(!retval)
			return(0);
	}
			
	return(retval);
}

/*------------------------------------------------------------------------*/
/* This routine sets up loopbacks of the indicated type
 */

static int do_loopback(STUFF *sptr, int looptype, int set_clear,
	int bits, int code)
{
int retval = 1;
LIU *l = sptr->e1s.myliu;
STANDARD_DECLARE;

	switch(looptype) {
	case LOOP_REMSWITCH:
		/* Remote is when the the receive signal is looped back
		 * at the analog layer to the remote device.
		 * This is also known as line loopback
		 */

		if(set_clear) {
			f->rcr3 |= RCR3_RLB;
		}
		else {
			f->rcr3 &= ~RCR3_RLB;
		}

		break;

	case LOOP_LOCSWITCH:
		/* Local Loopback is when the voice channels are looped
		 * before the framer section.
		 */
		if(set_clear) {
			l->lmcr |= LMCR_LLB;
		}
		else {
			l->lmcr &= ~LMCR_LLB;
		}

		break;

	case LOOP_PAYSWITCH:
		/* Payload Loopback is when the framer receives the signal
		 * then, after the framer, the voice channels are re-sent out
		 * and the overhead is re-generated.
		 */
		if(set_clear) {
			f->rcr3 |= RCR3_PLB;
		}
		else {
			f->rcr3 &= ~RCR3_PLB;
		}
		break;

	case LOOP_FRMSWITCH:	
		/* Framer Loopback is when the signal is set out of
		 * the framer and looped back to the framer but
		 * before it hits the LIU.  You will send and AIS while
		 * this happens.  The AIS is done by the chip and not the
		 * Upper layers.

⌨️ 快捷键说明

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