[zaptel-commits] tzafrir: trunk r1381 - in /trunk/xpp: card_fxo.c card_fxo.h init_data_4_20.cmd

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Sat Sep 2 14:36:25 MST 2006


Author: tzafrir
Date: Sat Sep  2 16:36:25 2006
New Revision: 1381

URL: http://svn.digium.com/view/zaptel?rev=1381&view=rev
Log:
Fix problems with battery voltage fluctuations:
- Use a higher voltage.
- Add a software debounce counter.

Modified:
    trunk/xpp/card_fxo.c
    trunk/xpp/card_fxo.h
    trunk/xpp/init_data_4_20.cmd

Modified: trunk/xpp/card_fxo.c
URL: http://svn.digium.com/view/zaptel/trunk/xpp/card_fxo.c?rev=1381&r1=1380&r2=1381&view=diff
==============================================================================
--- trunk/xpp/card_fxo.c (original)
+++ trunk/xpp/card_fxo.c Sat Sep  2 16:36:25 2006
@@ -51,6 +51,9 @@
 #define	NUM_LEDS		1
 #define	DELAY_UNTIL_DIALTONE	3000
 
+#define	BAT_THRESHOLD		3
+#define	BAT_DEBOUNCE		3	/* compensate for battery voltage fluctuation (in poll_battery_interval's) */
+
 /*---------------- FXO Protocol Commands ----------------------------------*/
 
 static /* 0x0F */ DECLARE_CMD(FXO, CHAN_ENABLE, xpp_line_t lines, bool on);
@@ -83,6 +86,7 @@
 	slic_reply_t			requested_reply;
 	slic_reply_t			last_reply;
 	xpp_line_t			battery;
+	ushort				battery_debounce[CHANNELS_PERXPD];
 	xpp_line_t			ledstate[NUM_LEDS];	/* 0 - OFF, 1 - ON */
 	xpp_line_t			ledcontrol[NUM_LEDS];	/* 0 - OFF, 1 - ON */
 	int				blinking[NUM_LEDS][CHANNELS_PERXPD];
@@ -699,22 +703,28 @@
 	priv = xpd->priv;
 	BUG_ON(!priv);
 	if(!info->indirect && info->reg_num == DAA_VBAT_REGISTER) {
-		xpp_line_t	last_batt_on = priv->battery;
-		xpp_line_t	changed_lines;
-		signed char	bat = info->data_low;
+		byte		bat = abs((signed char)info->data_low);
 		int		i;
 
-		if(abs(bat) < BAT_THRESHOLD) {
-			priv->battery &= ~lines;
-			// DBG("%s/%s: BATTERY OFF (%04X) = %d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
-		} else {
-			priv->battery |= lines;
-			// DBG("%s/%s: BATTERY ON (%04X) = %d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
-		}
-		changed_lines = last_batt_on ^ priv->battery;
 		for_each_line(xpd, i) {
-			if(IS_SET(changed_lines, i)) {
-				update_line_status(xpd, i, IS_SET(priv->battery, i));
+			if(!IS_SET(lines, i))
+				continue;
+			if(bat < BAT_THRESHOLD) {
+				/*
+				 * Check for battery voltage fluctuations
+				 */
+				if(IS_SET(priv->battery, i) && priv->battery_debounce[i]++ > BAT_DEBOUNCE) {
+					DBG("%s/%s: BATTERY OFF (%04X) voltage=%d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
+					priv->battery &= ~lines;
+					update_line_status(xpd, i, 0);
+				}
+			} else {
+				priv->battery_debounce[i] = 0;
+				if(!IS_SET(priv->battery, i)) {
+					DBG("%s/%s: BATTERY ON (%04X) voltage=%d\n", xpd->xbus->busname, xpd->xpdname, lines, bat);
+					priv->battery |= lines;
+					update_line_status(xpd, i, 1);
+				}
 			}
 		}
 	}
@@ -824,38 +834,42 @@
 	len += sprintf(page + len, "\t%-17s: ", "Channel");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%d ", i % 10);
+			len += sprintf(page + len, "%2d ", i % 10);
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "ledstate");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%d ", IS_SET(priv->ledstate[LED_GREEN], i));
+			len += sprintf(page + len, "%2d ", IS_SET(priv->ledstate[LED_GREEN], i));
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "ledcontrol");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%d ", IS_SET(priv->ledcontrol[LED_GREEN], i));
+			len += sprintf(page + len, "%2d ", IS_SET(priv->ledcontrol[LED_GREEN], i));
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "blinking");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%d ", IS_BLINKING(priv,i,LED_GREEN));
+			len += sprintf(page + len, "%2d ", IS_BLINKING(priv,i,LED_GREEN));
 	}
 #ifdef	SOFT_RING
 	len += sprintf(page + len, "\n\t%-17s: ", "ring_thresh");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%d ", priv->ring_thresh[i]);
+			len += sprintf(page + len, "%2d ", priv->ring_thresh[i]);
 	}
 	len += sprintf(page + len, "\n\t%-17s: ", "noring_thresh");
 	for_each_line(xpd, i) {
 		if(!IS_SET(xpd->digital_outputs, i) && !IS_SET(xpd->digital_inputs, i))
-			len += sprintf(page + len, "%d ", priv->noring_thresh[i]);
+			len += sprintf(page + len, "%2d ", priv->noring_thresh[i]);
 	}
 #endif
 	len += sprintf(page + len, "\n\t%-17s: ", "battery");
 	for_each_line(xpd, i) {
-		len += sprintf(page + len, "%d ", IS_SET(priv->battery, i));
+		len += sprintf(page + len, "%2d ", IS_SET(priv->battery, i));
+	}
+	len += sprintf(page + len, "\n\t%-17s: ", "battery_debounce");
+	for_each_line(xpd, i) {
+		len += sprintf(page + len, "%2d ", priv->battery_debounce[i]);
 	}
 	len += sprintf(page + len, "\n");
 	spin_unlock_irqrestore(&xpd->lock, flags);

Modified: trunk/xpp/card_fxo.h
URL: http://svn.digium.com/view/zaptel/trunk/xpp/card_fxo.h?rev=1381&r1=1380&r2=1381&view=diff
==============================================================================
--- trunk/xpp/card_fxo.h (original)
+++ trunk/xpp/card_fxo.h Sat Sep  2 16:36:25 2006
@@ -56,6 +56,5 @@
 	);
 
 #define	DAA_VBAT_REGISTER	29
-#define	BAT_THRESHOLD		3
 
 #endif	/* CARD_FXO_H */

Modified: trunk/xpp/init_data_4_20.cmd
URL: http://svn.digium.com/view/zaptel/trunk/xpp/init_data_4_20.cmd?rev=1381&r1=1380&r2=1381&view=diff
==============================================================================
--- trunk/xpp/init_data_4_20.cmd (original)
+++ trunk/xpp/init_data_4_20.cmd Sat Sep  2 16:36:25 2006
@@ -58,3 +58,7 @@
 
 ; ----------- DAA ONHOOK --------------------
 FF FF 00 00	WD	05	08
+
+; Set tip to ring voltage to 3.5 volts while off-hook
+; instead of default of 3.1
+FF FF 00 00	WD	1A	C0



More information about the zaptel-commits mailing list