[zaptel-commits] mogorman: trunk r1505 - /trunk/ztcodec_dte.c

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Mon Oct 16 09:49:50 MST 2006


Author: mogorman
Date: Mon Oct 16 11:49:49 2006
New Revision: 1505

URL: http://svn.digium.com/view/zaptel?rev=1505&view=rev
Log:
bringing trunk up to date.

Modified:
    trunk/ztcodec_dte.c

Modified: trunk/ztcodec_dte.c
URL: http://svn.digium.com/view/zaptel/trunk/ztcodec_dte.c?rev=1505&r1=1504&r2=1505&view=diff
==============================================================================
--- trunk/ztcodec_dte.c (original)
+++ trunk/ztcodec_dte.c Mon Oct 16 11:49:49 2006
@@ -58,7 +58,7 @@
 #define NUM_CARDS 24
 #define NUM_EC	  4
 
-#define NUM_CHANNELS 96
+#define NUM_CHANNELS 97
 
 #define DTE_FORMAT_ULAW   0x00
 #define DTE_FORMAT_G723_1 0x04
@@ -79,7 +79,7 @@
 #define ACK_SPACE 20
 
 #define MAX_COMMANDS (NUM_CHANNELS + ACK_SPACE)
-#define COMMAND_LEN 300		/* 274 for 30msec ulaw, 194 for 20mec ulaw */
+#define COMMAND_LEN 1500		/* 1432 for boot, 274 for 30msec ulaw, 194 for 20mec ulaw */
 
 #define ERING_SIZE (NUM_CHANNELS * 2)		/* Maximum ring size */
 
@@ -187,20 +187,23 @@
 
 #define zt_send_cmd(wc, command, length, hex) \
 	({ \
-		if ( (((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx) && debug ) \
-			printk("wcdte error: cmdq is full.\n"); \
-		else { \
-			unsigned char fifo[COMMAND_LEN] = command; \
-			wc->cmdq[wc->cmdq_wndx].cmdlen = length; \
-			for (i = 0; i < length; i++) \
-				wc->cmdq[wc->cmdq_wndx].cmd[i] = fifo[i]; \
-			wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS; \
-		} \
-		transmit_demand(wc); \
 		do { \
-			if (wcdte_waitfor_csmencaps(wc)) \
-				return(1); \
-		} while (wc->last_rcommand != hex); \
+			if ( (((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx) && debug ) \
+				printk("wcdte error: cmdq is full.\n"); \
+			else { \
+				unsigned char fifo[COMMAND_LEN] = command; \
+				wc->cmdq[wc->cmdq_wndx].cmdlen = length; \
+				for (i = 0; i < length; i++) \
+					wc->cmdq[wc->cmdq_wndx].cmd[i] = fifo[i]; \
+				wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS; \
+			} \
+			transmit_demand(wc); \
+			do { \
+				ret = wcdte_waitfor_csmencaps(wc); \
+				if (ret == 1) \
+					return(1); \
+			} while ((wc->last_rcommand != hex) && (ret != 2)); \
+		} while (ret == 2); \
 	})
 
 
@@ -295,7 +298,7 @@
 };
 
 
-static int numchannels = NUM_CHANNELS;
+static int numchannels = NUM_CHANNELS - 1;
 static struct zt_transcoder *uencode;
 static struct zt_transcoder *udecode;
 static struct dte_state *encoders;
@@ -909,7 +912,7 @@
 
 	
 	/* Configure watchdogs, access, etc */
-	wcdte_setctl(wc, 0x0030, 0x00080048);
+	wcdte_setctl(wc, 0x0030, 0x00280048);
 	wcdte_setctl(wc, 0x0078, 0x00000013 /* | (1 << 28) */);
 
 	reg = wcdte_getctl(wc, 0x00fc);
@@ -972,12 +975,23 @@
 
 static int wcdte_waitfor_csmencaps(struct wcdte *wc)
 {
-	if (wait_event_interruptible(wc->regq, wc->rcvflags != 0))
+	int ret;
+
+	ret = wait_event_interruptible_timeout(wc->regq, wc->rcvflags != 0, (1*HZ));
+
+	if (ret < 0)
 	{
 		if (debug)
-			printk("wcdte error: Wait interrupted, need to stop boot\n");
+			printk("wcdte error: Wait interrupted, need to stop boot (ret = %d)\n", ret);
 		return(1);
 	}
+	if (ret == 0)
+	{
+		if (debug)
+			printk("wcdte error: Waitfor CSMENCAPS ACK timed out (ret = %d)\n", ret);
+		return(2);
+	}
+
 	if (wc->rcvflags != RCV_CSMENCAPS)
 	{
 		printk("wcdte error: DTE processor failed to respond\n");
@@ -990,10 +1004,8 @@
 
 static int wcdte_boot_processor(struct wcdte *wc)	
 {
-	int i, byteloc, length, xmt_length, j, delay_count;
-	volatile unsigned char *writechunk;
-	int o2;
-	unsigned int reg;
+	int i, j, byteloc, last_byteloc, length, delay_count;
+	unsigned int reg, ret;
 
 #ifndef USE_TEST_HW
 	/* Set reset */
@@ -1021,57 +1033,48 @@
 	} while ((reg & 0xE0000000) != 0xE0000000);
 
 
+	/* Turn off booted LED */
+	wcdte_setctl(wc, 0x00A0, 0x04084000);
+
+	
+#endif
+
 	reg = wcdte_getctl(wc, 0x00fc);
 	if (debug)
 		printk("LINK STATUS: reg(0xfc) = %X\n", reg);
 
-	
-	/* Turn off booted LED */
-	wcdte_setctl(wc, 0x00A0, 0x04084000);
-
-	
-#endif
-
 	reg = wcdte_getctl(wc, 0x00A0);
 
-
+	last_byteloc;
+	byteloc = 0;
 	j = 0;
-	byteloc = 0;
 
 	do
 	{
-		writechunk = (volatile unsigned char *)(wc->writechunk);
-
-		writechunk += wc->tdbl * SFRAME_SIZE;
-
-		o2 = wc->tdbl * 4;
-		
-		do
-		{
-		} while ((wc->descripchunk[o2] & 0x80000000));
+		last_byteloc = byteloc;
 
 		length = (wcdte_firmware[byteloc] << 8) | wcdte_firmware[byteloc+1];
 		byteloc += 2;
-
-		xmt_length = length;
-		if (xmt_length < 64)
-			xmt_length = 64;
-	
-		wc->descripchunk[o2+1] = (wc->descripchunk[o2+1] & 0xFBFFF800) | xmt_length;
-
-		for(i = 0; i < length; i++)
-			writechunk[i] = wcdte_firmware[byteloc++];
-
-		wcdte_reinit_descriptor(wc, 1, wc->tdbl, "txchk");
-		wc->tdbl = (wc->tdbl + 1) % ERING_SIZE;
-
 		
-
-		if (wcdte_waitfor_csmencaps(wc))
+		if ( (((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx) && debug )
+			printk("wcdte error: cmdq is full.\n");
+		else
+		{
+			wc->cmdq[wc->cmdq_wndx].cmdlen = length;
+			for (i = 0; i < length; i++)
+				wc->cmdq[wc->cmdq_wndx].cmd[i] = wcdte_firmware[byteloc++];
+			wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS;
+		}
+		
+		transmit_demand(wc);
+
+		ret = wcdte_waitfor_csmencaps(wc);
+		if (ret == 1)
 			return(1);
-
+		else if (ret == 2)		/* Retransmit if dte processor times out */
+			byteloc = last_byteloc;
 		j++;
-		
+
 	} while (byteloc < sizeof(wcdte_firmware)-20);
 
 	/* Waitfor code to start */
@@ -1080,6 +1083,10 @@
 	
 	/* Turn on booted LED */
 	wcdte_setctl(wc, 0x00A0, 0x04080000);
+
+	if (debug)
+		printk("wcdte: Successfully booted DTE processor.\n");
+
 	return(0);
 }
 
@@ -1087,7 +1094,7 @@
 
 static int wcdte_setup_channels(struct wcdte *wc)	
 {
-	int i, j;
+	int i, j, ret;
 	unsigned int part1_id, part2_id;
 
 
@@ -1159,7 +1166,6 @@
 	struct wcdte *wc;
 	struct wcdte_desc *d = (struct wcdte_desc *)ent->driver_data;
 	int x;
-	int y;
 	static int initd_ifaces=0;
 	
 	if(initd_ifaces){
@@ -1188,6 +1194,8 @@
 			wc->pos = x;
 			wc->variety = d->name;
 
+			wc->tdbl = 0;
+			wc->rdbl = 0;
 			wc->rcvflags = 0;
 			wc->last_rcommand = 0;
 			wc->cmdq_wndx = 0;
@@ -1269,7 +1277,7 @@
 			/* Keep track of which device we are */
 			pci_set_drvdata(pdev, wc);
 
-			if (request_irq(pdev->irq, wcdte_interrupt, SA_SHIRQ, "wcdte24xxp", wc)) {
+			if (request_irq(pdev->irq, wcdte_interrupt, SA_SHIRQ, "tc400b", wc)) {
 				printk("wcdte error: Unable to request IRQ %d\n", pdev->irq);
 				if (wc->freeregion)
 					release_region(wc->iobase, 0xff);



More information about the zaptel-commits mailing list