[zaptel-commits] kpfleming: branch mogorman/zaptel-1.2-transcoder r1911 - /team/mogorman/zapte...

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Mon Jan 22 18:35:10 MST 2007


Author: kpfleming
Date: Mon Jan 22 19:35:09 2007
New Revision: 1911

URL: http://svn.digium.com/view/zaptel?view=rev&rev=1911
Log:
more code and comment cleanups

Modified:
    team/mogorman/zaptel-1.2-transcoder/wctc4xxb/base.c

Modified: team/mogorman/zaptel-1.2-transcoder/wctc4xxb/base.c
URL: http://svn.digium.com/view/zaptel/team/mogorman/zaptel-1.2-transcoder/wctc4xxb/base.c?view=diff&rev=1911&r1=1910&r2=1911
==============================================================================
--- team/mogorman/zaptel-1.2-transcoder/wctc4xxb/base.c (original)
+++ team/mogorman/zaptel-1.2-transcoder/wctc4xxb/base.c Mon Jan 22 19:35:09 2007
@@ -67,8 +67,6 @@
 
 #define WC_MAX_IFACES 128
 
-#define NUM_CARDS 24
-
 /* NUM_CHANNELS must be checked if new firmware (dte_firm.h) is used */
 #define NUM_CHANNELS 97
 
@@ -92,17 +90,21 @@
 #define MAX_COMMANDS (NUM_CHANNELS + ACK_SPACE)
 #define MAX_RCV_COMMANDS 16
 
-/* 1432 for boot, 274 for 30msec ulaw, 194 for 20mec ulaw */
+/* 1432 for boot, 274 for 30ms ulaw, 194 for 20ms ulaw */
 #define BOOT_CMD_LEN 1500
 #define OTHER_CMD_LEN 300
 
-#define MAX_COMMAND_LEN BOOT_CMD_LEN	/* Must be the larger of BOOT_CMD_LEN or OTHER_CMD_LEN */
+#if BOOT_CMD_LEN > OTHER_CMD_LEN
+#define MAX_COMMAND_LEN BOOT_CMD_LEN
+#else
+#define MAX_COMMAND_LEN OTHER_CMD_LEN
+#endif
 
 #define ERING_SIZE (NUM_CHANNELS / 2)		/* Maximum ring size */
 
 #define SFRAME_SIZE MAX_COMMAND_LEN
 
-#define PCI_WINDOW_SIZE ((2*  2 * ERING_SIZE * SFRAME_SIZE) + (2 * ERING_SIZE * 4))
+#define PCI_WINDOW_SIZE ((2 *  2 * ERING_SIZE * SFRAME_SIZE) + (2 * ERING_SIZE * 4))
 
 #define MDIO_SHIFT_CLK		0x10000
 #define MDIO_DATA_WRITE0 	0x00000
@@ -115,7 +117,6 @@
 #define RCV_RTP           2
 #define RCV_CSMENCAPS_ACK 3
 #define RCV_OTHER         99
-
 
 /* TDM Commands */
 #define CMD_MSG_TDM_SELECT_BUS_MODE_LEN 30
@@ -300,7 +301,6 @@
 	int freeregion;
 	int rdbl;
 	int tdbl;
-	int cards;
 	spinlock_t reglock;
 	wait_queue_head_t regq;
 	int rcvflags;
@@ -351,17 +351,17 @@
 static struct wcdte *ifaces[WC_MAX_IFACES];
 
 struct dte_state {
-	int encoder;	/* If we're an encoder */
+	int encoder;
 	struct wcdte *wc;
 
 	unsigned int timestamp;
 	unsigned int seqno;
 
-	unsigned int timeslot_in_num;		/* DTE chennel on which results we be received from */
-	unsigned int timeslot_out_num;		/* DTE channel to send data to */
-
-	unsigned int chan_in_num;		/* DTE chennel on which results we be received from */
-	unsigned int chan_out_num;		/* DTE channel to send data to */
+	unsigned int timeslot_in_num;
+	unsigned int timeslot_out_num;
+
+	unsigned int chan_in_num;
+	unsigned int chan_out_num;
 	
 	unsigned int packets_sent;
 	unsigned int packets_received;
@@ -444,9 +444,9 @@
 
 static inline void reinit_descriptor(struct wcdte *wc, int tx, int dbl, char *s)
 {
-	int o2 = 0;
-
-	o2 += dbl * 4;
+	int o2;
+
+	o2 = dbl * 4;
 
 	if (!tx)
 		o2 += ERING_SIZE * 4;
@@ -467,16 +467,15 @@
 	return val;
 }
 
-
 static inline int __transmit_demand(struct wcdte *wc)
 {
 	volatile unsigned char *writechunk;
-	int o2,i,j;
+	int o2, i, j;
 	unsigned int reg, xmt_length;
 
 	reg = getctl(wc, 0x0028) & 0x00700000;
 	
-	/* Already transmiting, no need to demand another */
+	/* Already transmitting, no need to demand another */
 	if (!((reg == 0) || (reg = 6)))
 		return 1;
 
@@ -485,7 +484,7 @@
 		return 1;
 
 	/* Nothing to transmit */
-	if (wc->cmdq[wc->cmdq_rndx].cmdlen == 0 )
+	if (!wc->cmdq[wc->cmdq_rndx].cmdlen)
 		return 1;
 
 	writechunk = (volatile unsigned char *)(wc->writechunk);
@@ -496,10 +495,8 @@
 		
 	do {} while ((le32_to_cpu(wc->descripchunk[o2]) & 0x80000000));
 
-	xmt_length = wc->cmdq[wc->cmdq_rndx].cmdlen;
-	if (xmt_length < 64)
-		xmt_length = 64;
-	
+	xmt_length = max(wc->cmdq[wc->cmdq_rndx].cmdlen, 64U);
+
 	wc->descripchunk[o2 + 1] = cpu_to_le32((le32_to_cpu(wc->descripchunk[o2 + 1]) & 0xFBFFF800) | xmt_length);
 				
 	for (i = 0; i < wc->cmdq[wc->cmdq_rndx].cmdlen; i++)
@@ -555,28 +552,29 @@
 	unsigned int timestamp_inc = 0;
 	int i = 0;
 	int res = 0;
-	unsigned int ipchksum, ndx;
+	unsigned int ipchksum;
 
 	switch(op) {
 	case ZT_TCOP_RESET:
 		down(&wc->chansem);
-		if (ztc->chan_built == 0) {
+		if (!ztc->chan_built) {
 			if (st->encoder)
 				create_channel(wc, zapfmt_to_dtefmt(zth->srcfmt), zapfmt_to_dtefmt(zth->dstfmt),
-						st->timeslot_in_num, st->timeslot_out_num, &(st->chan_in_num), &(st->chan_out_num));
+					       st->timeslot_in_num, st->timeslot_out_num, &(st->chan_in_num),
+					       &(st->chan_out_num));
 			else
 				create_channel(wc, zapfmt_to_dtefmt(zth->dstfmt), zapfmt_to_dtefmt(zth->srcfmt),
-						st->timeslot_out_num, st->timeslot_in_num, &(st->chan_out_num), &(st->chan_in_num));
+					       st->timeslot_out_num, st->timeslot_in_num, &(st->chan_out_num),
+					       &(st->chan_in_num));
 			/* Mark this channel as built */
 			ztc->chan_built = 1;
 			ztc->built_fmts = zth->dstfmt | zth->srcfmt;
 
 			/* Mark the channel complement (other half of encoder/decoder pair) as built */
-			ndx = st->timeslot_in_num/2;
 			if (st->encoder)
-				compl_ztc = &(wc->udecode->channels[ndx]);
+				compl_ztc = &(wc->udecode->channels[st->timeslot_in_num >> 1]);
 			else
-				compl_ztc = &(wc->uencode->channels[ndx]);
+				compl_ztc = &(wc->uencode->channels[st->timeslot_in_num >> 1]);
 			compl_ztc->chan_built = 1;
 			compl_ztc->built_fmts = zth->dstfmt | zth->srcfmt;
 			compl_st = compl_ztc->pvt;
@@ -587,12 +585,11 @@
 		break;
 	case ZT_TCOP_RELEASE:
 		down(&wc->chansem);
-		ndx = st->timeslot_in_num/2;
 			
 		if (st->encoder)
-			compl_ztc = &(wc->udecode->channels[ndx]);
+			compl_ztc = &(wc->udecode->channels[st->timeslot_in_num >> 1]);
 		else
-			compl_ztc = &(wc->uencode->channels[ndx]);
+			compl_ztc = &(wc->uencode->channels[st->timeslot_in_num >> 1]);
 
 		/* If the channel complement (other half of the encoder/decoder pair) is not being used... */
 		if ((compl_ztc->flags & ZT_TC_FLAG_BUSY) == 0) {
@@ -620,13 +617,12 @@
 	case ZT_TCOP_TRANSCODE:
 		if ((((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW)) &&
 		     ((zth->dstfmt == ZT_FORMAT_G729A  && zth->srclen >= G729_SAMPLES) ||
-		      (zth->dstfmt == ZT_FORMAT_G723_1  && zth->srclen >= G723_SAMPLES)))
-		    || ((zth->srcfmt == ZT_FORMAT_G729A) && (zth->srclen >= G729_BYTES))
-		    || ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_BYTES))) {
-			do
-			{
+		      (zth->dstfmt == ZT_FORMAT_G723_1  && zth->srclen >= G723_SAMPLES))) ||
+		    ((zth->srcfmt == ZT_FORMAT_G729A) && (zth->srclen >= G729_BYTES)) ||
+		    ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_BYTES))) {
+			do {
 				chars = (unsigned char *)(zth->srcdata + zth->srcoffset);
-					
+				
 				if ((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW))
 				{
 					if (zth->dstfmt == ZT_FORMAT_G729A) {
@@ -636,41 +632,38 @@
 						inbytes = G723_SAMPLES; 
 						timestamp_inc = G723_SAMPLES; 
 					}
-
-				} else if (zth->srcfmt == ZT_FORMAT_G729A)
-				{
+				} else if (zth->srcfmt == ZT_FORMAT_G729A) {
 					inbytes = G729_BYTES;
 					timestamp_inc = G729_SAMPLES;
-				} else if (zth->srcfmt == ZT_FORMAT_G723_1)
-				{
+				} else if (zth->srcfmt == ZT_FORMAT_G723_1) {
 					inbytes = G723_BYTES;
 					timestamp_inc = G723_SAMPLES;
 				}
 
 				zth->srclen -= inbytes;
-
+			
 				{
 					unsigned char fifo[OTHER_CMD_LEN] = CMD_MSG_IP_UDP_RTP(
-						 ((inbytes+40) >> 8)                 & 0xFF,
-						  (inbytes+40)                       & 0xFF,
-						   st->seqno                         & 0xFF,
-						   0x00,
-						   0x00,
+						((inbytes+40) >> 8)                 & 0xFF,
+						(inbytes+40)                       & 0xFF,
+						st->seqno                         & 0xFF,
+						0x00,
+						0x00,
 						(((st->timeslot_out_num) >> 8)+0x50) & 0xFF,
-						  (st->timeslot_out_num)             & 0xFF,
+						(st->timeslot_out_num)             & 0xFF,
 						(((st->timeslot_in_num) >> 8)+0x50)  & 0xFF,
-						  (st->timeslot_in_num)              & 0xFF,
-						 ((inbytes+20) >> 8)                 & 0xFF,
-						  (inbytes+20)                       & 0xFF,
-						   0x00,
-						   0x00,
-						   zapfmt_to_dtefmt(zth->srcfmt),					 
-						 ((st->seqno) >> 8)                  & 0xFF,
-						  (st->seqno)                        & 0xFF,
-						 ((st->timestamp) >> 24)             & 0xFF,
-						 ((st->timestamp) >> 16)             & 0xFF,
-	 					 ((st->timestamp) >> 8)              & 0xFF,
-						  (st->timestamp)                    & 0xFF);
+						(st->timeslot_in_num)              & 0xFF,
+						((inbytes+20) >> 8)                 & 0xFF,
+						(inbytes+20)                       & 0xFF,
+						0x00,
+						0x00,
+						zapfmt_to_dtefmt(zth->srcfmt),					 
+						((st->seqno) >> 8)                  & 0xFF,
+						(st->seqno)                        & 0xFF,
+						((st->timestamp) >> 24)             & 0xFF,
+						((st->timestamp) >> 16)             & 0xFF,
+						((st->timestamp) >> 8)              & 0xFF,
+						(st->timestamp)                    & 0xFF);
 
 					ipchksum = 0x9869 + (fifo[16] << 8) + fifo[17]
 						+ (fifo[18] << 8) + fifo[19];
@@ -704,15 +697,12 @@
 				}
 				st->packets_sent++;
 
-
-
 				zth->srcoffset += inbytes;
-
-
-			} while ((((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW)) && ((zth->dstfmt == ZT_FORMAT_G729A  && zth->srclen >= G729_SAMPLES) ||(zth->dstfmt == ZT_FORMAT_G723_1  && zth->srclen >= G723_SAMPLES)) )
-				|| ((zth->srcfmt == ZT_FORMAT_G729A) && (zth->srclen >= G729_BYTES))
-				|| ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_BYTES)) );
-
+			} while ((((zth->srcfmt == ZT_FORMAT_ULAW) || (zth->srcfmt == ZT_FORMAT_ALAW)) &&
+				  ((zth->dstfmt == ZT_FORMAT_G729A  && zth->srclen >= G729_SAMPLES) ||
+				   (zth->dstfmt == ZT_FORMAT_G723_1  && zth->srclen >= G723_SAMPLES))) ||
+				 ((zth->srcfmt == ZT_FORMAT_G729A) && (zth->srclen >= G729_BYTES)) ||
+				 ((zth->srcfmt == ZT_FORMAT_G723_1) && (zth->srclen >= G723_BYTES)));
 		} else {
 			zt_transcoder_alert(ztc);
 		}
@@ -1417,7 +1407,6 @@
 	spin_lock_init(&wc->reglock);
 	sema_init(&wc->chansem, 1);
 	sema_init(&wc->cmdqsem, 1);
-	wc->cards = NUM_CARDS;
 	wc->iobase = pci_resource_start(pdev, 0);
 	wc->dev = pdev;
 	wc->pos = x;



More information about the zaptel-commits mailing list