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

📄 ds26528.h

📁 Sample driver code for Dallas DS26528 T1/E1 framer chip.
💻 H
📖 第 1 页 / 共 4 页
字号:
 * It IS possible that this routine will be called a 2nd time if a device
 * is not mapped at all, then a new global reset will call this a 2nd time.
 * If the device is completely un-reset, this will get called also.
 */
static int _device_GlobalReset(GDEVICE *d)
{
int retval = 1;
unsigned int i;
DEVICE *dev = (DEVICE *)(d->BaseAdr);
unsigned char *ucp = (unsigned char *)dev;
FRAMER *f = (FRAMER *)(&dev->te1[0]);

	/* Reset the LIUs */

	f->glsrr = 0xff;
	f->glsrr = 0; 
	
	/* Reset the Framer */
	f->gfsrr = 0xff;
	f->gfsrr = 0; 

	f->gtcr1 = (RLOFLTS_SELECT) ? GTCR1_RLOFLTS : 0;

	f->gfcr = ((RCHBCS_SELECT) ? GFCR_RCBCS : 0) |
		((TCHBCS_SELECT) ? GFCR_TCBCS : 0) |
		((RFMSS_SELECT) ? GFCR_RFMSS : 0) |
		((RLOSSFS_SELECT) ? GFCR_RLOSSFS : 0) |
		(GFCR_BPCLK(BACKPLANE_CLOCK)) |
		(GFCR_IBOMS(INTERLEAVE_MODE));

	f->gtcr2 = ((TSSYNIO_SELECT) ? GTCR2_TSSYNIOSEL : 0) |
			((LOS_SELECT) ? GTCR2_LOSS : 0);

	f->gtccr = ((FREQUENCY_SELECT) ? GTCCR_FREQSEL : 0) |
		(GTCCR_MPS(MASTER_PERIOD)) |
		(GTCCR_BPREFSEL(BACKPLANE_REFERENCE)) |
		((BP_FREQUENCY_SELECT) ? GTCCR_BPFREQSEL : 0);

	/* Write the address space to 00h except global 0xF0 - 0xFF */

	for(i = 0; i < 0xF0; i++) 
		*ucp++ = 0;
	ucp += 16;
	for(i = 0; i < 4224; i++) 
		*ucp++ = 0;
	
	return(retval);
}


/* -------------------------------------------------------------------------- */
/* The global unreset should put the device in the unreset state.
 * This state is up to your platform.  By default, we will just call the
 * reset routine.
 */
static int _device_GlobalUNReset(GDEVICE *d)
{
int retval = 1;

	_device_GlobalReset(d);

	return(retval);
}

/* -------------------------------------------------------------------------- */
/* This routine hooks and unhooks the ISR for the chip.  It can be called from
 * any technology driver.  The first one here, will acutually be the
 * driver that hooks up the ISR via the technology CLBK API call.
 * The last one will cause the ISR to be un-hooked.
 */
void NCID_GHOOKISR(GDEVICE *d, NCID_TI ti, int onoff, 
	void (*fooptr)(), void *LnPtr, void *isr)
{

	if(onoff) {
		d->isr_cnt++;
		d->tech_handlers[ti] = isr;

		if(d->isr_cnt == 1) {
			(*fooptr)(LnPtr, d->device_isr, 1);
		} 
	}
	else {
		if(d->isr_cnt == 1) {
			(*fooptr)(LnPtr, d->device_isr, 0);
		} 

		d->isr_cnt--;
	}
}

#if (MAX_GLOBAL_TICKERS	> 0)
/* -------------------------------------------------------------------------- */
/* This routine translates the ticker into a number of ms required
 */
static int get_ms(int ticker)
{
int ms = 0;
	switch(ticker) {

	default:
		break;
	}
	return(ms);
}

/* -------------------------------------------------------------------------- */
/* This routine get called first on each global ticker before the technology
 * handlers get called
 */

static void GlobalTickerHandler(GDEVICE *d, int ticker)
{

	switch(ticker) {

	default:
		break;
	}

	return;
}


/* -------------------------------------------------------------------------- */
/* This is the OSTickerhandler common to all devices of this type.  
 * This routine will call the OSTicker service routines in each of 
 * the driver files 
 */
static void GlobalTickerProc(void *refptr, GDEVICE *d, int ticker)
{
int i;
void (**fooptr)();

	refptr = refptr;	/* trash compiler warning */

	fooptr = d->tickers[ticker].tickerHandler;

	GlobalTickerHandler(d, ticker);

	for(i = 0; i < DRVR_IDX_END; i++, fooptr++) {

		if(*fooptr != NULL)
		   (**fooptr)(d, ticker);
	}
}

/* -------------------------------------------------------------------------- */
/* This routine gets call by each technology driver to request starting 
 * and unstarting of a global OS Ticker.  
 * The variable "ticker" is the id number and has to
 * be in the range [0,MAX_NCI_TICKERS)
 * The first technology to request the global ticker will start the ticker
 * going.  The last technology to free the ticker will cause the ticker to
 * be freed.
 */
void NCID_GHOOKTICKER(GDEVICE *d, NCID_TI ti, int ticker, int onoff,
	void (*fooptr)(), void *LnPtr, void *tech_handler)
{
struct _tickers *p;
int ms;

	p = &d->tickers[ticker];
	ms = get_ms(ticker);

	if(onoff) {
		p->cnt++;
		p->tickerHandler[ti] = tech_handler;

		if(p->cnt == 1) {
			(*fooptr)(LnPtr, GlobalTickerProc, onoff, ticker, 
				ms, &p->handle);
		} 
	}
	else {
		if(p->cnt == 1) {
			(*fooptr)(LnPtr, GlobalTickerProc, onoff, ticker,
				ms, &p->handle);
			p->handle = NULL;
		} 

		p->cnt--;
	}
}
#endif 	/* MAX_GLOBAL_TICKERS */

/* -------------------------------------------------------------------------- */
/* This routine gets called before any of the technology handlers get called.
 * This is where you would read status registers that are done on a global
 * basis.
 */
static int GlobalISRHandler(GDEVICE *d)
{
int check_again = 0;


	return(check_again);
}

/* -------------------------------------------------------------------------- */
/* This is the interrupt handler common to all devices of this type.  
 * This routine will call the interrupt services routines in each of 
 * the driver files 
 */
static void _device_handler(int device)
{
GDEVICE *d = &gdevice[device];
int check_again;
int i;
int (*fooptr)();


	do {
		check_again = GlobalISRHandler(d);

		for(i = 0; i < DRVR_IDX_END; i++) {

			fooptr = d->tech_handlers[i];
		
			if(*fooptr != NULL)
				check_again |= (*fooptr)(d);
		}

	} while (EDGE_TRIG_INTRPT && check_again);

}


/* -------------------------------------------------------------------------- */
/* This is interrupt services routines per each device.
 * These routines call the main routine with an -1 of the device which
 * is interrupting.
 */

#if MAX_DEVICES > 0
static void _device0_handler(void)
{
        _device_handler(0);
}
#endif

#if MAX_DEVICES > 1
static void _device1_handler(void)
{
        _device_handler(1);
}
#endif

#if MAX_DEVICES > 2
static void _device2_handler(void)
{
        _device_handler(2);
}
#endif

#if MAX_DEVICES > 3
static void _device3_handler(void)
{
        _device_handler(3);
}
#endif

#if MAX_DEVICES > 4
static void _device4_handler(void)
{
        _device_handler(4);
}
#endif

#if MAX_DEVICES > 5
static void _device5_handler(void)
{
        _device_handler(5);
}
#endif

#if MAX_DEVICES > 6
static void _device6_handler(void)
{
        _device_handler(6);
}
#endif

#if MAX_DEVICES > 7
static void _device7_handler(void)
{
        _device_handler(7);
}
#endif

#if MAX_DEVICES > 8
static void _device8_handler(void)
{
        _device_handler(8);
}
#endif

#if MAX_DEVICES > 9
static void _device9_handler(void)
{
        _device_handler(9);
}
#endif

#if MAX_DEVICES > 10
static void _device10_handler(void)
{
        _device_handler(10);
}
#endif

#if MAX_DEVICES > 11
static void _device11_handler(void)
{
        _device_handler(11);
}
#endif

#if MAX_DEVICES > 12
static void _device12_handler(void)
{
        _device_handler(12);
}
#endif

#if MAX_DEVICES > 13
static void _device13_handler(void)
{
        _device_handler(13);
}
#endif

#if MAX_DEVICES > 14
static void _device14_handler(void)
{
        _device_handler(14);
}
#endif

#if MAX_DEVICES > 15
static void _device15_handler(void)
{
        _device_handler(15);
}
#endif

/*------------------------------------------------------------------------*/
/* This routine maps a line to a particular device and channel, and initializes
 * any data records required to manage interrupts for that particular line.
 * Returns NULL if errored, else returns a pointer to the device.
 * This routine gets call from all technology drivers
 */
GDEVICE *NCID_GDEVICEMAP(void *baseadr)
{
int i;
GDEVICE *d = &gdevice[0];

	/* if the first is uninitialized then nothing is initialized
	 */
	if (!gdevice_init) {
		gdevice_init = 1;

		drvMemset(d, 0, sizeof(gdevice));

		/* record info for when we hook interrupts during the INIT call
		 */
		gdevice[0].device_isr = _device0_handler;

#if MAX_DEVICES > 1
		gdevice[1].device_isr = _device1_handler;
#endif
#if MAX_DEVICES > 2
		gdevice[2].device_isr = _device2_handler;
#endif
#if MAX_DEVICES > 3
		gdevice[3].device_isr = _device3_handler;
#endif
#if MAX_DEVICES > 4
		gdevice[4].device_isr = _device4_handler;
#endif
#if MAX_DEVICES > 5
		gdevice[5].device_isr = _device5_handler;
#endif
#if MAX_DEVICES > 6
		gdevice[6].device_isr = _device6_handler;
#endif
#if MAX_DEVICES > 7
		gdevice[7].device_isr = _device7_handler;
#endif
#if MAX_DEVICES > 8
		gdevice[8].device_isr = _device8_handler;
#endif
#if MAX_DEVICES > 9
		gdevice[9].device_isr = _device9_handler;
#endif
#if MAX_DEVICES > 10
		gdevice[10].device_isr = _device10_handler;
#endif
#if MAX_DEVICES > 11
		gdevice[11].device_isr = _device11_handler;
#endif
#if MAX_DEVICES > 12
		gdevice[12].device_isr = _device12_handler;
#endif
#if MAX_DEVICES > 13
		gdevice[13].device_isr = _device13_handler;
#endif
#if MAX_DEVICES > 14
		gdevice[14].device_isr = _device14_handler;
#endif
#if MAX_DEVICES > 15
		gdevice[15].device_isr = _device15_handler;
#endif

		for (d = gdevice, i = 0; i < MAX_DEVICES; i++, d++) {
			d->id = i;
		}
	}


	/* First, See if device is already allocated
	 * This is done by the base address of the chip
	 */
	for (d = gdevice, i = 0; i < MAX_DEVICES; i++, d++) {

		if (d->init && (d->BaseAdr == baseadr)) {
			d->mapCnt++;
			return(d);
		}
	}

	/* OK, this is a new chip, find a location and allocate it 
	 */
	for (d = gdevice, i = 0; i < MAX_DEVICES; i++, d++) {
		/* init the device information
		 */
		if (!d->init) {
			d->init = 1;
			d->BaseAdr = baseadr;
			d->mapCnt++;
			return(d);
		}
	}

	/* No room at the inn, so return null 
	 */
	return(NULL);
}


/*------------------------------------------------------------------------*/
/* This routine performs the unmap function and marks the
 * entire device when all mapping has been cleared 
 * This routine gets call from all technology drivers
 */
int NCID_GDEVICEUNMAP(GDEVICE *d)
{

	if(d->mapCnt > 0)
		d->mapCnt--;

	if(d->mapCnt == 0) {
		d->init = 0;
		d->BaseAdr = NULL;
	}

	return(1);
}

/*------------------------------------------------------------------------*/
/* This routine performs the general reset duties, but nothing chip
 * specific.  It calls the routine _device_GlobalReset to perform
 * the chip specific duties.
 */

void NCID_GRESET(GDEVICE *d)
{

unsigned long lval;

	lval=INTS_OFF();
	if(!d->resetCnt) {

		_device_GlobalReset(d);

	}
	d->resetCnt++;
	INTS_ON(lval);
}

/*------------------------------------------------------------------------*/
/* This routine performs the general UNreset duties, but nothing chip
 * specific.  It calls the routine _device_GlobalUNReset to perform
 * the chip specific duties.
 */

void NCID_GUNRESET(GDEVICE *d)
{

unsigned long lval;

	lval=INTS_OFF();
	if(d->resetCnt == 1) {

		_device_GlobalUNReset(d);

	}
	d->resetCnt--;
	INTS_ON(lval);
}

#endif
#endif /* Build for Specific Driver */

⌨️ 快捷键说明

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