From 1f48e488a3f0f7fe606e847ceb353812f8e503ad Mon Sep 17 00:00:00 2001 From: markster Date: Sat, 23 Feb 2002 19:15:44 +0000 Subject: Version 0.1.6 from FTP git-svn-id: http://svn.digium.com/svn/zaptel/trunk@61 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- wcfxo.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'wcfxo.c') diff --git a/wcfxo.c b/wcfxo.c index f000b31..b878467 100755 --- a/wcfxo.c +++ b/wcfxo.c @@ -37,6 +37,10 @@ #include #endif +/* RING detection fiddling */ +#define RING_INC 10 +#define RING_MAX 50 + #define WC_MAX_IFACES 128 #define WC_CNTL 0x00 @@ -92,6 +96,7 @@ struct wcfxo { int rreadpos; int ringdebounce; int battdebounce; + int nobatttimer; int allread; int regoffset; /* How far off our registers are from what we expect */ int alt; @@ -99,7 +104,6 @@ struct wcfxo { int reset; /* Up to 6 register can be written at a time */ struct reg regs[ZT_CHUNKSIZE]; - struct reg midregs[ZT_CHUNKSIZE]; struct reg oldregs[ZT_CHUNKSIZE]; /* Up to 32 registers of whatever we most recently read */ unsigned char readregs[32]; @@ -193,6 +197,12 @@ static inline void wcfxo_transmitprep(struct wcfxo *wc, unsigned char ints) wc->readpos = 0; wc->wregcount = 0; + for (x=0;xoldregs[x] = wc->regs[x]; + wc->regs[x].flags = FLAG_EMPTY; + } + } static inline void wcfxo_receiveprep(struct wcfxo *wc, unsigned char ints) @@ -229,12 +239,6 @@ static inline void wcfxo_receiveprep(struct wcfxo *wc, unsigned char ints) } wc->chan.readchunk[x] = ZT_LIN2MU(((short)(readchunk[(x << 1) + (1 - wc->alt)] >> 16))); } - for (x=0;xoldregs[x] = wc->midregs[x]; - wc->midregs[x] = wc->regs[x]; - wc->regs[x].flags = FLAG_EMPTY; - } if (wc->ignoreread) wc->ignoreread--; zt_receive(&wc->span); @@ -258,8 +262,8 @@ static void wcfxo_interrupt(int irq, void *dev_id, struct pt_regs *regs) return; if (ints & 0x0f) { - wcfxo_transmitprep(wc, ints); wcfxo_receiveprep(wc, ints); + wcfxo_transmitprep(wc, ints); } if (ints & 0x10) { @@ -301,11 +305,11 @@ static void wcfxo_interrupt(int irq, void *dev_id, struct pt_regs *regs) } } else { /* Ring detected... Increment our counter by a bunch */ - wc->ringdebounce += 5; - /* Max out at 200. */ - if (wc->ringdebounce > 200) - wc->ringdebounce = 200; - if (!wc->ring && (wc->ringdebounce >= 200)) { + wc->ringdebounce += RING_INC; + /* Max out at RING_MAX. */ + if (wc->ringdebounce > RING_MAX) + wc->ringdebounce = RING_MAX; + if (!wc->ring && (wc->ringdebounce >= RING_MAX)) { /* Trigger the ring */ #ifndef DEBUG_RING if (debug) @@ -319,6 +323,7 @@ static void wcfxo_interrupt(int irq, void *dev_id, struct pt_regs *regs) /* Check for BATTERY from register and debounce for 8 ms */ b = wc->readregs[0xc] & 0xf; if (!b) { + wc->nobatttimer++; #if 0 if (wc->battery) printk("Battery loss: %d (%d debounce)\n", b, wc->battdebounce); @@ -331,13 +336,23 @@ static void wcfxo_interrupt(int irq, void *dev_id, struct pt_regs *regs) wc->battdebounce = BATT_DEBOUNCE; } else if (!wc->battery) wc->battdebounce = BATT_DEBOUNCE; + if ((wc->nobatttimer > 1000) && + (!wc->span.alarms)) { + wc->span.alarms = ZT_ALARM_RED; + zt_alarm_notify(&wc->span); + } } else if (b == 0xf) { if (!wc->battery && !wc->battdebounce) { if (debug) printk("BATTERY!\n"); zt_hooksig(&wc->chan, ZT_RXSIG_OFFHOOK); wc->battery = 1; + wc->nobatttimer = 0; wc->battdebounce = BATT_DEBOUNCE; + if (wc->span.alarms) { + wc->span.alarms = 0; + zt_alarm_notify(&wc->span); + } } else if (wc->battery) wc->battdebounce = BATT_DEBOUNCE; } else { @@ -752,6 +767,9 @@ MODULE_PARM(debug, "i"); MODULE_PARM(monitor, "i"); MODULE_DESCRIPTION("Wildcard X100P Zaptel Driver"); MODULE_AUTHOR("Mark Spencer "); +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif module_init(wcfxo_init); module_exit(wcfxo_cleanup); -- cgit v1.2.3