[svn-commits] sruffell: branch linux/sruffell/wctdm24xxp-updates r10134 - /linux/team/sruff...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 12 19:36:40 CDT 2011


Author: sruffell
Date: Fri Aug 12 19:36:37 2011
New Revision: 10134

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=10134
Log:
wctdm24xxp: Use interval for debouncing FXO battery.

Allows the driver the option of not calling the misc function for every
frame.  Preparation for moving this processing out of the interrupt
handler.  This also introduces a state machine for the various battery
states to make the code easier to read.

Signed-off-by: Shaun Ruffell <sruffell at digium.com>

Modified:
    linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/base.c
    linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/wctdm24xxp.h

Modified: linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/base.c?view=diff&rev=10134&r1=10133&r2=10134
==============================================================================
--- linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/base.c (original)
+++ linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/base.c Fri Aug 12 19:36:37 2011
@@ -1956,13 +1956,141 @@
 	}
 }
 
+#define MS_PER_CHECK_HOOK 1
+
+static void
+wctdm_check_battery_lost(struct wctdm *wc, struct wctdm_module *const mod)
+{
+	struct fxo *const fxo = &mod->mod.fxo;
+
+	/* possible existing states:
+	   battery lost, no debounce timer
+	   battery lost, debounce timer (going to battery present)
+	   battery present or unknown, no debounce timer
+	   battery present or unknown, debounce timer (going to battery lost)
+	*/
+	switch (fxo->battery_state) {
+	case BATTERY_DEBOUNCING_PRESENT:
+		/* we were going to BATTERY_PRESENT, but
+		 * battery was lost again. */
+		fxo->battery_state = BATTERY_LOST;
+		break;
+	case BATTERY_UNKNOWN:
+		mod_hooksig(wc, mod, DAHDI_RXSIG_ONHOOK);
+	case BATTERY_DEBOUNCING_PRESENT_ALARM: /* intentional drop through */
+	case BATTERY_PRESENT:
+		fxo->battery_state = BATTERY_DEBOUNCING_LOST;
+		fxo->battdebounce_timer = wc->framecount + battdebounce;
+		break;
+	case BATTERY_DEBOUNCING_LOST:
+		if (time_after(wc->framecount, fxo->battdebounce_timer)) {
+			if (debug) {
+				dev_info(&wc->vb.pdev->dev,
+					 "NO BATTERY on %d/%d!\n",
+					 wc->aspan->span.spanno,
+					 mod->card + 1);
+			}
+#ifdef	JAPAN
+			if (!wc->ohdebounce && wc->offhook) {
+				dahdi_hooksig(wc->aspan->chans[card],
+					      DAHDI_RXSIG_ONHOOK);
+				if (debug) {
+					dev_info(&wc->vb.pdev->dev,
+						 "Signalled On Hook\n");
+				}
+#ifdef	ZERO_BATT_RING
+				wc->onhook++;
+#endif
+			}
+#else
+			mod_hooksig(wc, mod, DAHDI_RXSIG_ONHOOK);
+#endif
+			/* set the alarm timer, taking into account that part
+			 * of its time period has already passed while
+			 * debouncing occurred */
+			fxo->battery_state = BATTERY_DEBOUNCING_LOST_ALARM;
+			fxo->battdebounce_timer = wc->framecount +
+						   battalarm - battdebounce;
+		}
+		break;
+	case BATTERY_DEBOUNCING_LOST_ALARM:
+		if (time_after(wc->framecount, fxo->battdebounce_timer)) {
+			fxo->battery_state = BATTERY_LOST;
+			dahdi_alarm_channel(get_dahdi_chan(wc, mod),
+					    DAHDI_ALARM_RED);
+		}
+		break;
+	case BATTERY_LOST:
+		break;
+	}
+}
+
+static void
+wctdm_check_battery_present(struct wctdm *wc, struct wctdm_module *const mod)
+{
+	struct fxo *const fxo = &mod->mod.fxo;
+
+	switch (fxo->battery_state) {
+	case BATTERY_DEBOUNCING_PRESENT:
+		if (time_after(jiffies, fxo->battdebounce_timer)) {
+			if (debug) {
+				dev_info(&wc->vb.pdev->dev,
+					 "BATTERY on %d/%d (%s)!\n",
+					 wc->aspan->span.spanno, mod->card + 1,
+					 (fxo->line_voltage_status < 0) ?
+						"-" : "+");
+			}
+#ifdef	ZERO_BATT_RING
+			if (wc->onhook) {
+				wc->onhook = 0;
+				dahdi_hooksig(wc->aspan->chans[card],
+					      DAHDI_RXSIG_OFFHOOK);
+				if (debug) {
+					dev_info(&wc->vb.pdev->dev,
+						 "Signalled Off Hook\n");
+				}
+			}
+#else
+			mod_hooksig(wc, mod, DAHDI_RXSIG_OFFHOOK);
+#endif
+			/* set the alarm timer, taking into account that part
+			 * of its time period has already passed while
+			 * debouncing occurred */
+			fxo->battery_state = BATTERY_DEBOUNCING_PRESENT_ALARM;
+			fxo->battdebounce_timer = jiffies +
+				msecs_to_jiffies(battalarm - battdebounce);
+		}
+		break;
+	case BATTERY_DEBOUNCING_PRESENT_ALARM:
+		if (time_after(jiffies, fxo->battdebounce_timer)) {
+			fxo->battery_state = BATTERY_PRESENT;
+			dahdi_alarm_channel(get_dahdi_chan(wc, mod),
+					    DAHDI_ALARM_NONE);
+		}
+		break;
+	case BATTERY_PRESENT:
+		break;
+	case BATTERY_DEBOUNCING_LOST:
+		/* we were going to BATTERY_LOST, but battery appeared again,
+		 * so clear the debounce timer */
+		fxo->battery_state = BATTERY_PRESENT;
+		break;
+	case BATTERY_UNKNOWN:
+		mod_hooksig(wc, mod, DAHDI_RXSIG_OFFHOOK);
+	case BATTERY_LOST: /* intentional drop through */
+	case BATTERY_DEBOUNCING_LOST_ALARM:
+		fxo->battery_state = BATTERY_DEBOUNCING_PRESENT;
+		fxo->battdebounce_timer = jiffies +
+						msecs_to_jiffies(battdebounce);
+		break;
+	}
+}
+
 static void
 wctdm_voicedaa_check_hook(struct wctdm *wc, struct wctdm_module *const mod)
 {
-#define MS_PER_CHECK_HOOK 1
-
 	signed char b;
-	unsigned int abs_voltage;
+	u8 abs_voltage;
 	struct fxo *const fxo = &mod->mod.fxo;
 
 	/* Try to track issues that plague slot one FXO's */
@@ -1978,15 +2106,14 @@
 		wctdm_fxo_ring_detect(wc, mod);
 	}
 
-	b = fxo->line_voltage_status;
-	abs_voltage = abs(b);
+	abs_voltage = abs(fxo->line_voltage_status);
 
 	if (fxovoltage && time_after(wc->framecount, fxo->display_fxovoltage)) {
 		/* Every 100 ms */
 		fxo->display_fxovoltage = wc->framecount + 100;
 		dev_info(&wc->vb.pdev->dev,
-			 "Port %d: Voltage: %d  Debounce %d\n",
-			 mod->card + 1, b, fxo->battdebounce);
+			 "Port %d: Voltage: %d\n",
+			 mod->card + 1, fxo->line_voltage_status);
 	}
 
 	if (unlikely(DAHDI_RXSIG_INITIAL == get_dahdi_chan(wc, mod)->rxhooksig)) {
@@ -2001,122 +2128,28 @@
 		 * to force us to report it again via dahdi_hooksig.
 		 *
 		 */
-		fxo->battery = BATTERY_UNKNOWN;
+		fxo->battery_state = BATTERY_UNKNOWN;
 	}
 
 	if (abs_voltage < battthresh) {
-		/* possible existing states:
-		   battery lost, no debounce timer
-		   battery lost, debounce timer (going to battery present)
-		   battery present or unknown, no debounce timer
-		   battery present or unknown, debounce timer (going to battery lost)
-		*/
-
 		fxo->lastpol = fxo->polarity;
 		fxo->polaritydebounce = 0;
 
-		if (fxo->battery == BATTERY_LOST) {
-			if (fxo->battdebounce) {
-				/* we were going to BATTERY_PRESENT, but battery was lost again,
-				   so clear the debounce timer */
-				fxo->battdebounce = 0;
-			}
-		} else {
-			if (fxo->battdebounce) {
-				/* going to BATTERY_LOST, see if we are there yet */
-				if (--fxo->battdebounce == 0) {
-					fxo->battery = BATTERY_LOST;
-					if (debug)
-						dev_info(&wc->vb.pdev->dev, "NO BATTERY on %d/%d!\n", wc->aspan->span.spanno, mod->card + 1);
-#ifdef	JAPAN
-					if (!wc->ohdebounce && wc->offhook) {
-						dahdi_hooksig(wc->aspan->chans[card], DAHDI_RXSIG_ONHOOK);
-						if (debug)
-							dev_info(&wc->vb.pdev->dev, "Signalled On Hook\n");
-#ifdef	ZERO_BATT_RING
-						wc->onhook++;
-#endif
-					}
-#else
-					mod_hooksig(wc, mod, DAHDI_RXSIG_ONHOOK);
-					/* set the alarm timer, taking into account that part of its time
-					   period has already passed while debouncing occurred */
-					fxo->battalarm = (battalarm - battdebounce) / MS_PER_CHECK_HOOK;
-#endif
-				}
-			} else {
-				/* start the debounce timer to verify that battery has been lost */
-				fxo->battdebounce = battdebounce / MS_PER_CHECK_HOOK;
-			}
-		}
+		wctdm_check_battery_lost(wc, mod);
 	} else {
-		/* possible existing states:
-		   battery lost or unknown, no debounce timer
-		   battery lost or unknown, debounce timer (going to battery present)
-		   battery present, no debounce timer
-		   battery present, debounce timer (going to battery lost)
-		*/
-
-		if (fxo->battery == BATTERY_PRESENT) {
-			if (fxo->battdebounce) {
-				/* we were going to BATTERY_LOST, but battery appeared again,
-				   so clear the debounce timer */
-				fxo->battdebounce = 0;
-			}
-		} else {
-			if (fxo->battdebounce) {
-				/* going to BATTERY_PRESENT, see if we are there yet */
-				if (--fxo->battdebounce == 0) {
-					fxo->battery = BATTERY_PRESENT;
-					if (debug) {
-						dev_info(&wc->vb.pdev->dev,
-							 "BATTERY on %d/%d (%s)!\n",
-							 wc->aspan->span.spanno,
-							 mod->card + 1,
-							 (b < 0) ? "-" : "+");
-					}
-#ifdef	ZERO_BATT_RING
-					if (wc->onhook) {
-						wc->onhook = 0;
-						mod_hooksig(wc, mod, DAHDI_RXSIG_OFFHOOK);
-						if (debug)
-							dev_info(&wc->vb.pdev->dev, "Signalled Off Hook\n");
-					}
-#else
-					mod_hooksig(wc, mod, DAHDI_RXSIG_OFFHOOK);
-#endif
-					/* set the alarm timer, taking into account that part of its time
-					   period has already passed while debouncing occurred */
-					fxo->battalarm = (battalarm - battdebounce) / MS_PER_CHECK_HOOK;
-				}
-			} else {
-				/* start the debounce timer to verify that battery has appeared */
-				fxo->battdebounce = battdebounce / MS_PER_CHECK_HOOK;
-			}
-		}
+		wctdm_check_battery_present(wc, mod);
 
 		if (fxo->lastpol >= 0) {
-			if (b < 0) {
+			if (fxo->line_voltage_status < 0) {
 				fxo->lastpol = -1;
 				fxo->polaritydebounce = POLARITY_DEBOUNCE / MS_PER_CHECK_HOOK;
 			}
 		} 
 		if (fxo->lastpol <= 0) {
-			if (b > 0) {
+			if (fxo->line_voltage_status > 0) {
 				fxo->lastpol = 1;
 				fxo->polaritydebounce = POLARITY_DEBOUNCE / MS_PER_CHECK_HOOK;
 			}
-		}
-	}
-
-	if (fxo->battalarm) {
-		if (--fxo->battalarm == 0) {
-			/* the alarm timer has expired, so update the battery alarm state
-			   for this channel */
-			dahdi_alarm_channel(get_dahdi_chan(wc, mod),
-					    (fxo->battery == BATTERY_LOST) ?
-						DAHDI_ALARM_RED :
-						DAHDI_ALARM_NONE);
 		}
 	}
 
@@ -2140,12 +2173,12 @@
 		* where the voltage is over the neon limit but
 		* does not vary greatly from the last reading
 		*/
-		if (fxo->battery == 1 &&
+		if (fxo->battery_state == BATTERY_PRESENT &&
 				  abs_voltage > neonmwi_level &&
 				  (0 == fxo->neonmwi_last_voltage ||
-				  (b >= fxo->neonmwi_last_voltage - neonmwi_envelope &&
-				  b <= fxo->neonmwi_last_voltage + neonmwi_envelope ))) {
-			fxo->neonmwi_last_voltage = b;
+				  (fxo->line_voltage_status >= fxo->neonmwi_last_voltage - neonmwi_envelope &&
+				  fxo->line_voltage_status <= fxo->neonmwi_last_voltage + neonmwi_envelope ))) {
+			fxo->neonmwi_last_voltage = fxo->line_voltage_status;
 			if (NEONMWI_ON_DEBOUNCE == fxo->neonmwi_debounce) {
 				fxo->neonmwi_offcounter = neonmwi_offlimit_cycles;
 				if (0 == fxo->neonmwi_state) {

Modified: linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/wctdm24xxp.h?view=diff&rev=10134&r1=10133&r2=10134
==============================================================================
--- linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/wctdm24xxp.h (original)
+++ linux/team/sruffell/wctdm24xxp-updates/drivers/dahdi/wctdm24xxp/wctdm24xxp.h Fri Aug 12 19:36:37 2011
@@ -105,7 +105,11 @@
 
 enum battery_state {
 	BATTERY_UNKNOWN = 0,
+	BATTERY_DEBOUNCING_PRESENT,
+	BATTERY_DEBOUNCING_PRESENT_ALARM,
 	BATTERY_PRESENT,
+	BATTERY_DEBOUNCING_LOST,
+	BATTERY_DEBOUNCING_LOST_ALARM,
 	BATTERY_LOST,
 };
 
@@ -159,9 +163,6 @@
 	u8 hook_ring_shadow;
 	s8 line_voltage_status;
 	int offhook;
-	int battdebounce;
-	int battalarm;
-	enum battery_state battery;
 	int lastpol;
 	int polarity;
 	int polaritydebounce;
@@ -171,6 +172,7 @@
 	unsigned int neonmwi_offcounter;
 	unsigned long display_fxovoltage;
 	unsigned long ringdebounce_timer;
+	unsigned long battdebounce_timer;
 };
 
 struct fxs {




More information about the svn-commits mailing list