[zaptel-commits] kpfleming: branch kpfleming/battery_alarms r3898 - /team/kpfleming/battery_al...
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Thu Feb 28 07:40:15 CST 2008
Author: kpfleming
Date: Thu Feb 28 07:40:15 2008
New Revision: 3898
URL: http://svn.digium.com/view/zaptel?view=rev&rev=3898
Log:
make same alarm changes for wctdm24xxp
Modified:
team/kpfleming/battery_alarms/kernel/wctdm24xxp/base.c
team/kpfleming/battery_alarms/kernel/wctdm24xxp/wctdm24xxp.h
Modified: team/kpfleming/battery_alarms/kernel/wctdm24xxp/base.c
URL: http://svn.digium.com/view/zaptel/team/kpfleming/battery_alarms/kernel/wctdm24xxp/base.c?view=diff&rev=3898&r1=3897&r2=3898
==============================================================================
--- team/kpfleming/battery_alarms/kernel/wctdm24xxp/base.c (original)
+++ team/kpfleming/battery_alarms/kernel/wctdm24xxp/base.c Thu Feb 28 07:40:15 2008
@@ -263,6 +263,7 @@
static int fxovoltage = 0;
static int battdebounce = DEFAULT_BATT_DEBOUNCE;
+static int battalarm = DEFAULT_BATT_ALARM;
static int battthresh = DEFAULT_BATT_THRESH;
static int debug = 0;
static int robust = 0;
@@ -1332,64 +1333,66 @@
{
unsigned char res;
signed char b;
+ struct fxo *fxo = &wc->mods[card].fxo;
+
/* Try to track issues that plague slot one FXO's */
b = wc->cmdq[card].isrshadow[0]; /* Hook/Ring state */
b &= 0x9b;
- if (wc->mods[card].fxo.offhook) {
+ if (fxo->offhook) {
if (b != 0x9)
wctdm_setreg_intr(wc, card, 5, 0x9);
} else {
if (b != 0x8)
wctdm_setreg_intr(wc, card, 5, 0x8);
}
- if (!wc->mods[card].fxo.offhook) {
+ if (!fxo->offhook) {
if (fwringdetect) {
res = wc->cmdq[card].isrshadow[0] & 0x60;
- if (wc->mods[card].fxo.ringdebounce--) {
- if (res && (res != wc->mods[card].fxo.lastrdtx) && (wc->mods[card].fxo.battery == 1)) {
- if (!wc->mods[card].fxo.wasringing) {
- wc->mods[card].fxo.wasringing = 1;
+ if (fxo->ringdebounce--) {
+ if (res && (res != fxo->lastrdtx) && (fxo->battery == 1)) {
+ if (!fxo->wasringing) {
+ fxo->wasringing = 1;
if (debug)
printk("RING on %d/%d!\n", wc->span.spanno, card + 1);
zt_hooksig(&wc->chans[card], ZT_RXSIG_RING);
}
- wc->mods[card].fxo.lastrdtx = res;
- wc->mods[card].fxo.ringdebounce = 10;
+ fxo->lastrdtx = res;
+ fxo->ringdebounce = 10;
} else if (!res) {
- if ((wc->mods[card].fxo.ringdebounce == 0) && wc->mods[card].fxo.wasringing) {
- wc->mods[card].fxo.wasringing = 0;
+ if ((fxo->ringdebounce == 0) && fxo->wasringing) {
+ fxo->wasringing = 0;
if (debug)
printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
}
}
- } else if (res && (wc->mods[card].fxo.battery == 1)) {
- wc->mods[card].fxo.lastrdtx = res;
- wc->mods[card].fxo.ringdebounce = 10;
+ } else if (res && (fxo->battery == BATTERY_PRESENT)) {
+ fxo->lastrdtx = res;
+ fxo->ringdebounce = 10;
}
} else {
res = wc->cmdq[card].isrshadow[0];
- if ((res & 0x60) && (wc->mods[card].fxo.battery == 1)) {
- wc->mods[card].fxo.ringdebounce += (ZT_CHUNKSIZE * 16);
- if (wc->mods[card].fxo.ringdebounce >= ZT_CHUNKSIZE * ringdebounce) {
- if (!wc->mods[card].fxo.wasringing) {
- wc->mods[card].fxo.wasringing = 1;
+ if ((res & 0x60) && (fxo->battery == BATTERY_PRESENT)) {
+ fxo->ringdebounce += (ZT_CHUNKSIZE * 16);
+ if (fxo->ringdebounce >= ZT_CHUNKSIZE * ringdebounce) {
+ if (!fxo->wasringing) {
+ fxo->wasringing = 1;
zt_hooksig(&wc->chans[card], ZT_RXSIG_RING);
if (debug)
printk("RING on %d/%d!\n", wc->span.spanno, card + 1);
}
- wc->mods[card].fxo.ringdebounce = ZT_CHUNKSIZE * ringdebounce;
+ fxo->ringdebounce = ZT_CHUNKSIZE * ringdebounce;
}
} else {
- wc->mods[card].fxo.ringdebounce -= ZT_CHUNKSIZE * 4;
- if (wc->mods[card].fxo.ringdebounce <= 0) {
- if (wc->mods[card].fxo.wasringing) {
- wc->mods[card].fxo.wasringing = 0;
+ fxo->ringdebounce -= ZT_CHUNKSIZE * 4;
+ if (fxo->ringdebounce <= 0) {
+ if (fxo->wasringing) {
+ fxo->wasringing = 0;
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
if (debug)
printk("NO RING on %d/%d!\n", wc->span.spanno, card + 1);
}
- wc->mods[card].fxo.ringdebounce = 0;
+ fxo->ringdebounce = 0;
}
}
@@ -1400,20 +1403,20 @@
if (fxovoltage) {
if (!(wc->intcount % 100)) {
printk("Port %d: Voltage: %d Debounce %d\n", card + 1,
- b, wc->mods[card].fxo.battdebounce);
+ b, fxo->battdebounce);
}
}
if (abs(b) < battthresh) {
- wc->mods[card].fxo.nobatttimer++;
#if 0
- if (wc->mods[card].fxo.battery == 1)
- printk("Battery loss: %d (%d debounce)\n", b, wc->mods[card].fxo.battdebounce);
-#endif
- if (wc->mods[card].fxo.battery && !wc->mods[card].fxo.battdebounce) {
+ if (fxo->battery == BATTERY_PRESENT)
+ printk("Battery loss: %d (%d debounce)\n", b, fxo->battdebounce);
+#endif
+ if ((fxo->battery != BATTERY_LOST) &&
+ (fxo->battdebounce == 0)) {
if (debug & DEBUG_CARD)
printk("NO BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
- wc->mods[card].fxo.battery = 0;
+ fxo->battery = BATTERY_LOST;
#ifdef JAPAN
if ((!wc->ohdebounce) && wc->offhook) {
zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
@@ -1425,13 +1428,16 @@
}
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
- zt_alarm_channel(&wc->chans[card], ZT_ALARM_RED);
-#endif
- wc->mods[card].fxo.battdebounce = battdebounce;
- } else if (!wc->mods[card].fxo.battery)
- wc->mods[card].fxo.battdebounce = battdebounce;
+#endif
+ /* set the alarm timer, taking into account that part of its time
+ period has already passed while debouncing occurred */
+ fxo->battalarm = battalarm - battdebounce;
+ fxo->battdebounce = battdebounce;
+ } else if (fxo->battery == BATTERY_LOST)
+ fxo->battdebounce = battdebounce;
} else if (abs(b) > battthresh) {
- if ((wc->mods[card].fxo.battery < 1) && !wc->mods[card].fxo.battdebounce) {
+ if ((fxo->battery != BATTERY_PRESENT) &&
+ (fxo->battdebounce == 0)) {
if (debug & DEBUG_CARD)
printk("BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1,
(b < 0) ? "-" : "+");
@@ -1444,43 +1450,54 @@
}
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
- zt_alarm_channel(&wc->chans[card], ZT_ALARM_NONE);
-#endif
- wc->mods[card].fxo.battery = 1;
- wc->mods[card].fxo.nobatttimer = 0;
- wc->mods[card].fxo.battdebounce = battdebounce;
- } else if (wc->mods[card].fxo.battery == 1)
- wc->mods[card].fxo.battdebounce = battdebounce;
-
- if (wc->mods[card].fxo.lastpol >= 0) {
+#endif
+ fxo->battery = BATTERY_PRESENT;
+ /* set the alarm timer, taking into account that part of its time
+ period has already passed while debouncing occurred */
+ fxo->battalarm = battalarm - battdebounce;
+ fxo->battdebounce = battdebounce;
+ } else if (fxo->battery == BATTERY_PRESENT)
+ fxo->battdebounce = battdebounce;
+
+ if (fxo->lastpol >= 0) {
if (b < 0) {
- wc->mods[card].fxo.lastpol = -1;
- wc->mods[card].fxo.polaritydebounce = POLARITY_DEBOUNCE;
+ fxo->lastpol = -1;
+ fxo->polaritydebounce = POLARITY_DEBOUNCE;
}
}
- if (wc->mods[card].fxo.lastpol <= 0) {
+ if (fxo->lastpol <= 0) {
if (b > 0) {
- wc->mods[card].fxo.lastpol = 1;
- wc->mods[card].fxo.polaritydebounce = POLARITY_DEBOUNCE;
+ fxo->lastpol = 1;
+ fxo->polaritydebounce = POLARITY_DEBOUNCE;
}
}
} else {
/* It's something else... */
- wc->mods[card].fxo.battdebounce = battdebounce;
- }
- if (wc->mods[card].fxo.battdebounce)
- wc->mods[card].fxo.battdebounce--;
- if (wc->mods[card].fxo.polaritydebounce) {
- wc->mods[card].fxo.polaritydebounce--;
- if (wc->mods[card].fxo.polaritydebounce < 1) {
- if (wc->mods[card].fxo.lastpol != wc->mods[card].fxo.polarity) {
+ fxo->battdebounce = battdebounce;
+ }
+ if (fxo->battdebounce) {
+ fxo->battdebounce--;
+ }
+
+ if (fxo->battalarm) {
+ if (--fxo->battalarm == 0) {
+ /* the alarm timer has expired, so update the battery alarm state
+ for this channel */
+ zt_alarm_channel(&wc->chans[card], fxo->battery ? ZT_ALARM_NONE : ZT_ALARM_RED);
+ }
+ }
+
+ if (fxo->polaritydebounce) {
+ fxo->polaritydebounce--;
+ if (fxo->polaritydebounce < 1) {
+ if (fxo->lastpol != fxo->polarity) {
if (debug & DEBUG_CARD)
printk("%lu Polarity reversed (%d -> %d)\n", jiffies,
- wc->mods[card].fxo.polarity,
- wc->mods[card].fxo.lastpol);
- if (wc->mods[card].fxo.polarity)
+ fxo->polarity,
+ fxo->lastpol);
+ if (fxo->polarity)
zt_qevent_lock(&wc->chans[card], ZT_EVENT_POLARITY);
- wc->mods[card].fxo.polarity = wc->mods[card].fxo.lastpol;
+ fxo->polarity = fxo->lastpol;
}
}
}
@@ -2200,7 +2217,7 @@
printk("DEBUG fxotxgain:%i.%i fxorxgain:%i.%i\n", (wctdm_getreg(wc, card, 38)/16) ? -(wctdm_getreg(wc, card, 38) - 16) : wctdm_getreg(wc, card, 38), (wctdm_getreg(wc, card, 40)/16) ? -(wctdm_getreg(wc, card, 40) - 16) : wctdm_getreg(wc, card, 40), (wctdm_getreg(wc, card, 39)/16) ? -(wctdm_getreg(wc, card, 39) - 16): wctdm_getreg(wc, card, 39), (wctdm_getreg(wc, card, 41)/16)?-(wctdm_getreg(wc, card, 41) - 16) : wctdm_getreg(wc, card, 41));
/* battery state still unknown */
- wc->mods[card].fxo.battery = -1;
+ wc->mods[card].fxo.battery = BATTERY_UNKNOWN;
return 0;
@@ -4424,6 +4441,7 @@
module_param(fastringer, int, 0600);
module_param(fxshonormode, int, 0600);
module_param(battdebounce, int, 0600);
+module_param(battalarm, int, 0600);
module_param(battthresh, int, 0600);
module_param(alawoverride, int, 0600);
module_param(nativebridge, int, 0600);
@@ -4453,6 +4471,7 @@
MODULE_PARM(fastringer, "i");
MODULE_PARM(fxshonormode, "i");
MODULE_PARM(battdebounce, "i");
+MODULE_PARM(battalarm, "i");
MODULE_PARM(battthresh, "i");
MODULE_PARM(alawoverride, "i");
MODULE_PARM(nativebridge, "i");
Modified: team/kpfleming/battery_alarms/kernel/wctdm24xxp/wctdm24xxp.h
URL: http://svn.digium.com/view/zaptel/team/kpfleming/battery_alarms/kernel/wctdm24xxp/wctdm24xxp.h?view=diff&rev=3898&r1=3897&r2=3898
==============================================================================
--- team/kpfleming/battery_alarms/kernel/wctdm24xxp/wctdm24xxp.h (original)
+++ team/kpfleming/battery_alarms/kernel/wctdm24xxp/wctdm24xxp.h Thu Feb 28 07:40:15 2008
@@ -39,7 +39,8 @@
*/
#define DEFAULT_RING_DEBOUNCE 128
#define DEFAULT_BATT_DEBOUNCE 64 /* Battery debounce (in ms) */
-#define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
+#define DEFAULT_BATT_ALARM 1000 /* Battery alarm (in ms) */
+#define POLARITY_DEBOUNCE 64 /* Polarity debounce (in ms) */
#define DEFAULT_BATT_THRESH 3 /* Anything under this is "no battery" */
#define OHT_TIMER 6000 /* How long after RING to retain OHT */
@@ -171,6 +172,12 @@
struct cmdq {
unsigned int cmds[MAX_COMMANDS];
unsigned char isrshadow[ISR_COMMANDS];
+};
+
+enum battery_state {
+ BATTERY_UNKNOWN,
+ BATTERY_PRESENT,
+ BATTERY_LOST,
};
struct wctdm {
@@ -215,19 +222,19 @@
wait_queue_head_t regq;
/* FXO Stuff */
union {
- struct {
+ struct fxo {
int wasringing;
int lastrdtx;
int ringdebounce;
int offhook;
int battdebounce;
- int nobatttimer;
- int battery;
+ int battalarm;
+ enum battery_state battery;
int lastpol;
int polarity;
int polaritydebounce;
} fxo;
- struct {
+ struct fxs {
int oldrxhook;
int debouncehook;
int lastrxhook;
More information about the zaptel-commits
mailing list