[zaptel-commits] kpfleming: branch kpfleming/battery_alarms r3897 - /team/kpfleming/battery_al...

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Thu Feb 28 07:29:07 CST 2008


Author: kpfleming
Date: Thu Feb 28 07:29:07 2008
New Revision: 3897

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3897
Log:
use a local variable to make the code easier to read (no functional change)

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=3897&r1=3896&r2=3897
==============================================================================
--- team/kpfleming/battery_alarms/kernel/wctdm.c (original)
+++ team/kpfleming/battery_alarms/kernel/wctdm.c Thu Feb 28 07:29:07 2008
@@ -310,7 +310,7 @@
 	spinlock_t lock;
 
 	union {
-		struct {
+		struct fxo {
 #ifdef AUDIO_RINGCHECK
 			unsigned int pegtimer;
 			int pegcount;
@@ -329,7 +329,7 @@
 		        int polarity;
 		        int polaritydebounce;
 		} fxo;
-		struct {
+		struct fxs {
 			int oldrxhook;
 			int debouncehook;
 			int lastrxhook;
@@ -847,6 +847,8 @@
 #endif	
 	signed char b;
 	int poopy = 0;
+	struct fxo *fxo = &wc->mod[card].fxo;
+
 	/* Try to track issues that plague slot one FXO's */
 	b = wc->reg0shadow[card];
 	if ((b & 0x2) || !(b & 0x8)) {
@@ -856,7 +858,7 @@
 		poopy++;
 	}
 	b &= 0x9b;
-	if (wc->mod[card].fxo.offhook) {
+	if (fxo->offhook) {
 		if (b != 0x9)
 			wctdm_setreg(wc, card, 5, 0x9);
 	} else {
@@ -866,55 +868,55 @@
 	if (poopy)
 		return;
 #ifndef AUDIO_RINGCHECK
-	if (!wc->mod[card].fxo.offhook) {
+	if (!fxo->offhook) {
 		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 == BATTERY_PRESENT)) {
-					if (!wc->mod[card].fxo.wasringing) {
-						wc->mod[card].fxo.wasringing = 1;
+			if (fxo->ringdebounce--) {
+				if (res && (res != fxo->lastrdtx) &&
+				    (fxo->battery == BATTERY_PRESENT)) {
+					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->mod[card].fxo.lastrdtx = res;
-					wc->mod[card].fxo.ringdebounce = 10;
+					fxo->lastrdtx = res;
+					fxo->ringdebounce = 10;
 				} else if (!res) {
-					if ((wc->mod[card].fxo.ringdebounce == 0) && wc->mod[card].fxo.wasringing) {
-						wc->mod[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->mod[card].fxo.battery == BATTERY_PRESENT)) {
-				wc->mod[card].fxo.lastrdtx = res;
-				wc->mod[card].fxo.ringdebounce = 10;
+			} else if (res && (fxo->battery == BATTERY_PRESENT)) {
+				fxo->lastrdtx = res;
+				fxo->ringdebounce = 10;
 			}
 		} else {
 			res = wc->reg0shadow[card];
-			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) {
-						wc->mod[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->mod[card].fxo.ringdebounce = ZT_CHUNKSIZE * ringdebounce;
+					fxo->ringdebounce = ZT_CHUNKSIZE * ringdebounce;
 				}
 			} else {
-				wc->mod[card].fxo.ringdebounce -= ZT_CHUNKSIZE * 4;
-				if (wc->mod[card].fxo.ringdebounce <= 0) {
-					if (wc->mod[card].fxo.wasringing) {
-						wc->mod[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->mod[card].fxo.ringdebounce = 0;
+					fxo->ringdebounce = 0;
 				}
 			}
 		}
@@ -926,20 +928,20 @@
 		static int count = 0;
 		if (!(count++ % 100)) {
 			printk("Card %d: Voltage: %d  Debounce %d\n", card + 1, 
-			       b, wc->mod[card].fxo.battdebounce);
+			       b, fxo->battdebounce);
 		}
 	}
 #endif	
 	if (abs(b) < battthresh) {
 #if 0
-		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 != BATTERY_LOST) &&
-		    (wc->mod[card].fxo.battdebounce == 0)) {
+		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)
 				printk("NO BATTERY on %d/%d!\n", wc->span.spanno, card + 1);
-			wc->mod[card].fxo.battery = BATTERY_LOST;
+			fxo->battery = BATTERY_LOST;
 #ifdef	JAPAN
 			if ((!wc->ohdebounce) && wc->offhook) {
 				zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
@@ -953,15 +955,15 @@
 			zt_hooksig(&wc->chans[card], ZT_RXSIG_ONHOOK);
 			/* set the alarm timer, taking into account that part of its time
 			   period has already passed while debouncing occurred */
-			wc->mod[card].fxo.battalarm = battalarm - battdebounce;
-#endif
-			wc->mod[card].fxo.battdebounce = battdebounce;
-		} else if (wc->mod[card].fxo.battery == BATTERY_LOST) {
-			wc->mod[card].fxo.battdebounce = battdebounce;
+			fxo->battalarm = battalarm - battdebounce;
+#endif
+			fxo->battdebounce = battdebounce;
+		} else if (fxo->battery == BATTERY_LOST) {
+			fxo->battdebounce = battdebounce;
 		}
 	} else if (abs(b) > battthresh) {
-		if ((wc->mod[card].fxo.battery != BATTERY_PRESENT) &&
-		    (wc->mod[card].fxo.battdebounce == 0)) {
+		if ((fxo->battery != BATTERY_PRESENT) &&
+		    (fxo->battdebounce == 0)) {
 			if (debug)
 				printk("BATTERY on %d/%d (%s)!\n", wc->span.spanno, card + 1, 
 				       (b < 0) ? "-" : "+");			    
@@ -975,55 +977,55 @@
 #else
 			zt_hooksig(&wc->chans[card], ZT_RXSIG_OFFHOOK);
 #endif
-			wc->mod[card].fxo.battery = BATTERY_PRESENT;
-			wc->mod[card].fxo.battdebounce = battdebounce;
+			fxo->battery = BATTERY_PRESENT;
+			fxo->battdebounce = battdebounce;
 			/* set the alarm timer, taking into account that part of its time
 			   period has already passed while debouncing occurred */
-			wc->mod[card].fxo.battalarm = battalarm - battdebounce;
-		} else if (wc->mod[card].fxo.battery == BATTERY_PRESENT) {
-			wc->mod[card].fxo.battdebounce = battdebounce;
-		}
-
-		if (wc->mod[card].fxo.lastpol >= 0) {
+			fxo->battalarm = battalarm - battdebounce;
+		} else if (fxo->battery == BATTERY_PRESENT) {
+			fxo->battdebounce = battdebounce;
+		}
+
+		if (fxo->lastpol >= 0) {
 		    if (b < 0) {
-			wc->mod[card].fxo.lastpol = -1;
-			wc->mod[card].fxo.polaritydebounce = POLARITY_DEBOUNCE;
+			fxo->lastpol = -1;
+			fxo->polaritydebounce = POLARITY_DEBOUNCE;
 		    }
 		} 
-		if (wc->mod[card].fxo.lastpol <= 0) {
+		if (fxo->lastpol <= 0) {
 		    if (b > 0) {
-			wc->mod[card].fxo.lastpol = 1;
-			wc->mod[card].fxo.polaritydebounce = POLARITY_DEBOUNCE;
+			fxo->lastpol = 1;
+			fxo->polaritydebounce = POLARITY_DEBOUNCE;
 		    }
 		}
 	} else {
 		/* It's something else... */
-		wc->mod[card].fxo.battdebounce = battdebounce;
-	}
-
-	if (wc->mod[card].fxo.battdebounce) {
-		wc->mod[card].fxo.battdebounce--;
-	}
-
-	if (wc->mod[card].fxo.battalarm) {
-		if (--wc->mod[card].fxo.battalarm == 0) {
+		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], wc->mod[card].fxo.battery ? ZT_ALARM_NONE : ZT_ALARM_RED);
-		}
-	}
-
-	if (wc->mod[card].fxo.polaritydebounce) {
-	        wc->mod[card].fxo.polaritydebounce--;
-		if (wc->mod[card].fxo.polaritydebounce < 1) {
-		    if (wc->mod[card].fxo.lastpol != wc->mod[card].fxo.polarity) {
+			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)
 					printk("%lu Polarity reversed (%d -> %d)\n", jiffies, 
-				       wc->mod[card].fxo.polarity, 
-				       wc->mod[card].fxo.lastpol);
-				if (wc->mod[card].fxo.polarity)
+				       fxo->polarity, 
+				       fxo->lastpol);
+				if (fxo->polarity)
 				    zt_qevent_lock(&wc->chans[card], ZT_EVENT_POLARITY);
-				wc->mod[card].fxo.polarity = wc->mod[card].fxo.lastpol;
+				fxo->polarity = fxo->lastpol;
 		    }
 		}
 	}




More information about the zaptel-commits mailing list