[zaptel-commits] kpfleming: branch kpfleming/battery_alarms r3894 - in /team/kpfleming/battery...
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Thu Feb 28 07:07:46 CST 2008
Author: kpfleming
Date: Thu Feb 28 07:07:45 2008
New Revision: 3894
URL: http://svn.digium.com/view/zaptel?view=rev&rev=3894
Log:
make a branch to improve FXO port battery alarm generation code
Added:
team/kpfleming/battery_alarms/
- copied from r3893, branches/1.4/
Modified:
team/kpfleming/battery_alarms/kernel/wctdm.c
Modified: team/kpfleming/battery_alarms/kernel/wctdm.c
URL: http://svn.digium.com/view/zaptel/team/kpfleming/battery_alarms/kernel/wctdm.c?view=diff&rev=3894&r1=3893&r2=3894
==============================================================================
--- team/kpfleming/battery_alarms/kernel/wctdm.c (original)
+++ team/kpfleming/battery_alarms/kernel/wctdm.c Thu Feb 28 07:07:45 2008
@@ -251,10 +251,11 @@
/* the constants below control the 'debounce' periods enforced by the
check_hook routines; these routines are called once every 4 interrupts
- (the interrupt cycles around the four modules), so the periods are
- specified in _4 millisecond_ increments
+ (the interrupt cycles around the four modules), but each function is only performed
+ once every four cycles, so the periods are specified in _16 millisecond_ increments
*/
#define DEFAULT_BATT_DEBOUNCE 4 /* Battery debounce (64 ms) */
+#define DEFAULT_BATT_ALARM 62 /* Battery alarm debounce (992 ms) */
#define POLARITY_DEBOUNCE 4 /* Polarity debounce (64 ms) */
#define DEFAULT_BATT_THRESH 3 /* Anything under this is "no battery" */
@@ -283,6 +284,12 @@
PROSLIC_POWER_UNKNOWN = 0,
PROSLIC_POWER_ON,
PROSLIC_POWER_WARNED,
+};
+
+enum battery_state {
+ BATTERY_UNKNOWN,
+ BATTERY_PRESENT,
+ BATTERY_LOST,
};
struct wctdm {
@@ -316,8 +323,8 @@
int ringdebounce;
int offhook;
int battdebounce;
- int nobatttimer;
- int battery;
+ int battalarm;
+ enum battery_state battery;
int lastpol;
int polarity;
int polaritydebounce;
@@ -365,6 +372,7 @@
static void wctdm_release(struct wctdm *wc);
static int battdebounce = DEFAULT_BATT_DEBOUNCE;
+static int battalarm = DEFAULT_BATT_ALARM;
static int battthresh = DEFAULT_BATT_THRESH;
static int ringdebounce = DEFAULT_RING_DEBOUNCE;
static int fwringdetect = 0;
@@ -862,7 +870,8 @@
if (fwringdetect) {
res = wc->reg0shadow[card] & 0x60;
if (wc->mod[card].fxo.ringdebounce--) {
- if (res && (res != wc->mod[card].fxo.lastrdtx) && (wc->mod[card].fxo.battery == 1)) {
+ if (res && (res != wc->mod[card].fxo.lastrdtx) &&
+ (wc->mod[card].fxo.battery == BATTERY_PRESENT)) {
if (!wc->mod[card].fxo.wasringing) {
wc->mod[card].fxo.wasringing = 1;
if (debug)
@@ -879,13 +888,13 @@
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
}
}
- } else if (res && (wc->mod[card].fxo.battery == 1)) {
+ } else if (res && (wc->mod[card].fxo.battery == BATTERY_PRESENT)) {
wc->mod[card].fxo.lastrdtx = res;
wc->mod[card].fxo.ringdebounce = 10;
}
} else {
res = wc->reg0shadow[card];
- if ((res & 0x60) && (wc->mod[card].fxo.battery == 1)) {
+ if ((res & 0x60) && (wc->mod[card].fxo.battery == BATTERY_PRESENT)) {
wc->mod[card].fxo.ringdebounce += (ZT_CHUNKSIZE * 16);
if (wc->mod[card].fxo.ringdebounce >= ZT_CHUNKSIZE * ringdebounce) {
if (!wc->mod[card].fxo.wasringing) {
@@ -922,15 +931,15 @@
}
#endif
if (abs(b) < battthresh) {
- wc->mod[card].fxo.nobatttimer++;
#if 0
- if (wc->mod[card].fxo.battery == 1)
+ if (wc->mod[card].fxo.battery == BATTERY_PRESENT)
printk("Battery loss: %d (%d debounce)\n", b, wc->mod[card].fxo.battdebounce);
#endif
- if (wc->mod[card].fxo.battery && !wc->mod[card].fxo.battdebounce) {
+ if ((wc->mod[card].fxo.battery != BATTERY_LOST) &&
+ (wc->mod[card].fxo.battdebounce == 0)) {
if (debug)
printk("NO BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
- wc->mod[card].fxo.battery = 0;
+ wc->mod[card].fxo.battery = BATTERY_LOST;
#ifdef JAPAN
if ((!wc->ohdebounce) && wc->offhook) {
zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
@@ -942,13 +951,17 @@
}
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
- zt_alarm_channel(&wc->chans[card], ZT_ALARM_RED);
+// zt_alarm_channel(&wc->chans[card], ZT_ALARM_RED);
#endif
wc->mod[card].fxo.battdebounce = battdebounce;
- } else if (!wc->mod[card].fxo.battery)
+ wc->mod[card].fxo.battalarm = battalarm;
+ } else if (wc->mod[card].fxo.battery == BATTERY_LOST) {
wc->mod[card].fxo.battdebounce = battdebounce;
+ wc->mod[card].fxo.battalarm = battalarm;
+ }
} else if (abs(b) > battthresh) {
- if ((wc->mod[card].fxo.battery < 1) && !wc->mod[card].fxo.battdebounce) {
+ if ((wc->mod[card].fxo.battery != BATTERY_PRESENT) &&
+ !wc->mod[card].fxo.battdebounce) {
if (debug)
printk("BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1,
(b < 0) ? "-" : "+");
@@ -961,13 +974,15 @@
}
#else
zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
- zt_alarm_channel(&wc->chans[card], ZT_ALARM_NONE);
-#endif
- wc->mod[card].fxo.battery = 1;
- wc->mod[card].fxo.nobatttimer = 0;
+// zt_alarm_channel(&wc->chans[card], ZT_ALARM_NONE);
+#endif
+ wc->mod[card].fxo.battery = BATTERY_PRESENT;
wc->mod[card].fxo.battdebounce = battdebounce;
- } else if (wc->mod[card].fxo.battery == 1)
+ wc->mod[card].fxo.battalarm = battalarm;
+ } else if (wc->mod[card].fxo.battery == BATTERY_PRESENT) {
wc->mod[card].fxo.battdebounce = battdebounce;
+ wc->mod[card].fxo.battalarm = battalarm;
+ }
if (wc->mod[card].fxo.lastpol >= 0) {
if (b < 0) {
@@ -984,9 +999,17 @@
} else {
/* It's something else... */
wc->mod[card].fxo.battdebounce = battdebounce;
- }
- if (wc->mod[card].fxo.battdebounce)
+ wc->mod[card].fxo.battalarm = battalarm;
+ }
+
+ if (wc->mod[card].fxo.battdebounce) {
wc->mod[card].fxo.battdebounce--;
+ }
+
+ if (wc->mod[card].fxo.battalarm) {
+ wc->mod[card].fxo.battalarm--;
+ }
+
if (wc->mod[card].fxo.polaritydebounce) {
wc->mod[card].fxo.polaritydebounce--;
if (wc->mod[card].fxo.polaritydebounce < 1) {
@@ -1608,7 +1631,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->mod[card].fxo.battery = -1;
+ wc->mod[card].fxo.battery = BATTERY_UNKNOWN;
return 0;
@@ -2557,6 +2580,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(ringdebounce, int, 0600);
module_param(fwringdetect, int, 0600);
@@ -2579,6 +2603,7 @@
MODULE_PARM(fastringer, "i");
MODULE_PARM(fxshonormode, "i");
MODULE_PARM(battdebounce, "i");
+MODULE_PARM(battalarm, "i");
MODULE_PARM(battthresh, "i");
MODULE_PARM(ringdebounce, "i");
MODULE_PARM(fwringdetect, "i");
More information about the zaptel-commits
mailing list