[zaptel-commits] mogorman: trunk r1839 - in /trunk: ./ ztcodec_dte/

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Wed Jan 17 14:42:46 MST 2007


Author: mogorman
Date: Wed Jan 17 15:42:45 2007
New Revision: 1839

URL: http://svn.digium.com/view/zaptel?view=rev&rev=1839
Log:
move to better binary methods

Added:
    trunk/ztcodec_dte/
    trunk/ztcodec_dte/Kbuild   (with props)
    trunk/ztcodec_dte/Makefile   (with props)
    trunk/ztcodec_dte/base.c
      - copied, changed from r1833, trunk/ztcodec_dte.c
    trunk/ztcodec_dte/codec_test.c   (with props)
    trunk/ztcodec_dte/dte_firm.bin   (with props)
Removed:
    trunk/dte_firm.h
    trunk/ztcodec_dte.c
Modified:
    trunk/Makefile
    trunk/zaptel.h
    trunk/zttranscode.c

Modified: trunk/Makefile
URL: http://svn.digium.com/view/zaptel/trunk/Makefile?view=diff&rev=1839&r1=1838&r2=1839
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Wed Jan 17 15:42:45 2007
@@ -133,7 +133,7 @@
 ifeq ($(findstring xpp_usb,$(MENUSELECT_MODULES)),)
   BUILD_XPP:=yes
 endif
-MODULES:=pciradio tor2 torisa wcfxo wct1xxp wctdm wctdm24xxp wcte11xp wcusb zaptel ztd-eth ztd-loc ztdummy ztdynamic zttranscode ztcodec_dte
+MODULES:=pciradio tor2 torisa wcfxo wct1xxp wctdm wctdm24xxp wcte11xp wcusb zaptel ztd-eth ztd-loc ztdummy ztdynamic zttranscode
 MODULES:=$(filter-out $(MENUSELECT_MODULES),$(MODULES))
 
 MODULESO:=$(MODULES:%=%.o)
@@ -157,6 +157,10 @@
 obj-m+=wct4xxp/
 MODULES+=wct4xxp
 endif
+ifeq ($(findstring ztcodec_dte,$(MENUSELECT_MODULES)),)
+obj-m+=ztcodec_dte/
+MODULES+=ztcodec_dte
+endif
 
 # Set this to override hotplug firmware loading and revert to classic header
 #HOTPLUG_FIRMWARE=no
@@ -208,6 +212,9 @@
 
 wct4xxp/wct4xxp.o:
 	$(MAKE) -C wct4xxp KFLAGS="$(KFLAGS) -I.." CFLAGS="$(CFLAGS) -I.."
+
+ztcodec_dte/ztcodec_dte.o:
+	$(MAKE) -C ztcodec_dte KFLAGS="$(KFLAGS) -I.." CFLAGS="$(CFLAGS) -I.."
 
 devel: tor2ee 
 
@@ -426,9 +433,11 @@
 ifeq ($(HOTPLUG_FIRMWARE),yes)
 	if [ -d $(INSTALL_PREFIX)/usr/lib/hotplug/firmware ]; then \
 		$(INSTALL) -m 644 wct4xxp/*.ima $(INSTALL_PREFIX)/usr/lib/hotplug/firmware; \
+		$(INSTALL) -m 644 ztcodec_dte/*.bin $(INSTALL_PREFIX)/usr/lib/hotplug/firmware; \
 	fi
 	if [ -d $(INSTALL_PREFIX)/lib/firmware ]; then \
 		$(INSTALL) -m 644 wct4xxp/*.ima $(INSTALL_PREFIX)/lib/firmware; \
+		$(INSTALL) -m 644 ztcodec_dte/*.bin $(INSTALL_PREFIX)/lib/firmware; \
 	fi
 	@echo "Installed firmware"
 else
@@ -494,6 +503,7 @@
 	$(MAKE) -C $(KSRC) SUBDIRS=$(PWD) clean
 else
 	$(MAKE) -C wct4xxp clean
+	$(MAKE) -C ztcodec_dte clean
 	$(MAKE) -C datamods clean
 endif
 	rm -f xpp/*.ko xpp/*.mod.c xpp/.*o.cmd

Modified: trunk/zaptel.h
URL: http://svn.digium.com/view/zaptel/trunk/zaptel.h?view=diff&rev=1839&r1=1838&r2=1839
==============================================================================
--- trunk/zaptel.h (original)
+++ trunk/zaptel.h Wed Jan 17 15:42:45 2007
@@ -724,6 +724,7 @@
 #define ZT_TCOP_TRANSCODE	2			/* Begin transcoding a block */
 #define ZT_TCOP_GETINFO		3			/* Get information (use zt_transcode_info) */
 #define ZT_TCOP_RELEASE		4			/* Release DTE channel */
+#define ZT_TCOP_TEST		5			/* Test DTE card */
 
 typedef struct zt_transcode_info {
 	unsigned int op;

Added: trunk/ztcodec_dte/Kbuild
URL: http://svn.digium.com/view/zaptel/trunk/ztcodec_dte/Kbuild?view=auto&rev=1839
==============================================================================
--- trunk/ztcodec_dte/Kbuild (added)
+++ trunk/ztcodec_dte/Kbuild Wed Jan 17 15:42:45 2007
@@ -1,0 +1,15 @@
+obj-m += ztcodec_dte.o
+
+EXTRA_CFLAGS := -I$(src)/.. -Wno-undef
+
+ztcodec_dte-objs := base.o 
+
+ifneq ($(HOTPLUG_FIRMWARE),yes)
+ztcodec_dte-objs += firmware_dte.o
+endif
+
+$(obj)/base.o: $(src)/../zaptel.h
+
+$(obj)/firmware_dte.o: $(src)/dte_firm.bin $(obj)/base.o
+	@echo Making firmware object file for $(notdir $<)
+	@cd $(src) && ../build_tools/make_firmware_object $(notdir $<) $@ $(obj)/base.o

Propchange: trunk/ztcodec_dte/Kbuild
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/ztcodec_dte/Kbuild
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/ztcodec_dte/Kbuild
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: trunk/ztcodec_dte/Makefile
URL: http://svn.digium.com/view/zaptel/trunk/ztcodec_dte/Makefile?view=auto&rev=1839
==============================================================================
--- trunk/ztcodec_dte/Makefile (added)
+++ trunk/ztcodec_dte/Makefile Wed Jan 17 15:42:45 2007
@@ -1,0 +1,25 @@
+ifneq ($(KBUILD_EXTMOD),)
+
+include $(obj)/Kbuild
+
+else
+
+all: ztcodec_dte.o
+
+%.o: %.c
+	$(CC) $(KFLAGS) -o $@ -c $<
+
+base.o: ../zaptel.h 
+
+
+firmware_dte.o: dte_firm.bin base.o
+	@echo Making firmware object file for $<
+	../build_tools/make_firmware_object $< $@ base.o
+
+ztcodec_dte.o: base.o firmware_dte.o
+	$(LD) -r -o $@ $^
+
+clean:
+	rm -f *.o
+
+endif

Propchange: trunk/ztcodec_dte/Makefile
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/ztcodec_dte/Makefile
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/ztcodec_dte/Makefile
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: trunk/ztcodec_dte/base.c (from r1833, trunk/ztcodec_dte.c)
URL: http://svn.digium.com/view/zaptel/trunk/ztcodec_dte/base.c?view=diff&rev=1839&p1=trunk/ztcodec_dte.c&r1=1833&p2=trunk/ztcodec_dte/base.c&r2=1839
==============================================================================
--- trunk/ztcodec_dte.c (original)
+++ trunk/ztcodec_dte/base.c Wed Jan 17 15:42:45 2007
@@ -50,8 +50,14 @@
 #include <linux/zaptel.h>
 #endif
 #include <linux/moduleparam.h>
-
-#include "dte_firm.h"
+#ifdef HOTPLUG_FIRMWARE
+#include <linux/firmware.h>
+static const char *dte_firmware = "dte_firm.bin";
+#else
+extern const unsigned char _binary_dte_firm_bin_start[];
+extern const unsigned int _binary_dte_firm_bin_size;
+#endif
+
 
 /* #define USE_TEST_HW */
 #define USE_TDM_CONFIG
@@ -569,6 +575,78 @@
 	return val;
 }
 
+unsigned int test_seqno;
+unsigned int test_timestamp;
+unsigned int emc_errorcnt;
+unsigned int emc_rcvd;
+
+
+static int wcdte_send_test_packet(struct wcdte *wc)
+{
+	unsigned int inbytes = 0;
+	unsigned int timestamp_inc = 0;
+	int i = 0;
+	unsigned long flags;
+	unsigned int ipchksum;
+
+				
+	inbytes = 160; /* 80; */
+	timestamp_inc = 160; /* 80; */
+
+	{
+		unsigned char fifo[300] = CMD_MSG_IP_UDP_RTP(
+			 ((inbytes+40) >> 8)              & 0xFF,
+			  (inbytes+40)                    & 0xFF,
+			   test_seqno                      & 0xFF,
+			   0x00,
+			   0x00,
+			   0x50,
+			   0x01,
+			   0x50,
+			   0x00,
+			 ((inbytes+20) >> 8)              & 0xFF,
+			  (inbytes+20)                    & 0xFF,
+			   0x00,
+			   0x00,
+			   0x00,					 
+			 ((test_seqno) >> 8)              & 0xFF, // Sequence number
+			  (test_seqno)                    & 0xFF,
+			 ((test_timestamp) >> 24)         & 0xFF, // JRSTEST: This needs to be checked
+			 ((test_timestamp) >> 16)         & 0xFF, // JRSTEST: This needs to be checked
+			 ((test_timestamp) >> 8)          & 0xFF, // JRSTEST: This needs to be checked
+			  (test_timestamp)                & 0xFF); // JRSTEST: This needs to be checked
+
+		ipchksum = 0x9869 + (fifo[14+2*1] << 8) + fifo[15+2*1] + (fifo[14+2*2] << 8) + fifo[15+2*2];		// JRSETST: remove  add/mults
+		while (ipchksum >> 16)
+			ipchksum = (ipchksum & 0xFFFF) + (ipchksum >> 16);
+		ipchksum = (~ipchksum) & 0xFFFF;
+
+		fifo[24] = ipchksum >> 8;
+		fifo[25] = ipchksum & 0xFF;
+
+		test_seqno += 1;
+		test_timestamp += timestamp_inc;
+
+		for (i = 0; i < inbytes; i++)
+			fifo[i+CMD_MSG_IP_UDP_RTP_LEN]= 0xAA;
+
+		spin_lock_irqsave(&wc->reglock, flags);
+		if (((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx)
+			printk("ERROR: cmdq is full.  This is CRITICAL.\n");
+		else
+		{
+			wc->cmdq[wc->cmdq_wndx].cmdlen = CMD_MSG_IP_UDP_RTP_LEN+inbytes;
+			for (i = 0; i < CMD_MSG_IP_UDP_RTP_LEN+inbytes; i++)
+				wc->cmdq[wc->cmdq_wndx].cmd[i] = fifo[i];
+			wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS;
+		}
+		spin_unlock_irqrestore(&wc->reglock, flags);
+	}
+
+	transmit_demand(wc);
+
+	return 0;
+}
 
 static int dte_operation(struct zt_transcoder_channel *ztc, int op)
 {
@@ -579,10 +657,22 @@
 	unsigned char *chars;
 	unsigned int inbytes = 0;
 	unsigned int timestamp_inc = 0;
-	int i = 0;
+	int i = 0, j = 0, reg = 0;
 	int res = 0;
 	unsigned int ipchksum, ndx;
 	switch(op) {
+	case ZT_TCOP_TEST:
+		printk("Starting EMC Loop test\n");
+		do {
+			wcdte_send_test_packet(wc);
+			if (j%50 == 0) {
+				reg = wcdte_getctl(wc, 0x00fc);
+				printk(KERN_EMERG "sent = %d, received = %d, bad = %d, reg 0xFC = %X\n", j, emc_rcvd, emc_errorcnt, reg);
+			}
+			j++;
+			mdelay(20);
+		} while (j < 15000); /* Time for test */
+		break;
 	case ZT_TCOP_RESET:
 		down(&wc->chansem);
 		if (ztc->chan_built == 0)
@@ -1261,8 +1351,11 @@
 	return;
 }
 
-
-static int wcdte_boot_processor(struct wcdte *wc)	
+#ifdef HOTPLUG_FIRMWARE
+static int wcdte_boot_processor(struct wcdte *wc, const struct firmware *firmware)
+#else
+static int wcdte_boot_processor(struct wcdte *wc)
+#endif
 {
 	int i, j, byteloc, last_byteloc, length, delay_count;
 	unsigned int reg, ret;
@@ -1312,12 +1405,12 @@
 
 	byteloc = 17;
 	j = 0;
-
+#ifdef HOTPLUG_FIRMWARE
 	do
 	{
 		last_byteloc = byteloc;
 
-		length = (wcdte_firmware[byteloc] << 8) | wcdte_firmware[byteloc+1];
+		length = (firmware->data[byteloc] << 8) |firmware->data[byteloc+1];
 		byteloc += 2;
 		
 		down(&wc->cmdqsem);
@@ -1327,7 +1420,7 @@
 		{
 			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[wc->cmdq_wndx].cmd[i] = firmware->data[byteloc++];
 			wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS;
 		}
 	
@@ -1341,16 +1434,45 @@
 			byteloc = last_byteloc;
 		j++;
 
-	} while (byteloc < sizeof(wcdte_firmware)-20);
-
+	} while (byteloc < firmware->size-20);
+#else
+	do
+	{
+		last_byteloc = byteloc;
+
+		length = (_binary_dte_firm_bin_start[byteloc] << 8) | _binary_dte_firm_ima_start[byteloc+1];
+		byteloc += 2;
+		
+		down(&wc->cmdqsem);
+		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] = _binary_dte_firm_bin_start[byteloc++];
+			wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS;
+		}
+	
+		__transmit_demand(wc);
+  		up(&wc->cmdqsem);
+
+		ret = wcdte_waitfor_csmencaps(wc, RCV_CSMENCAPS_ACK, 1);
+		if (ret == 1)
+			return(1);
+		else if (ret == 2)		/* Retransmit if dte processor times out */
+			byteloc = last_byteloc;
+		j++;
+
+	} while (byteloc < _binary_dte_firm_bin_size-20);
+#endif
 	wc->timeout = 10 * HZ;
 	if (wcdte_waitfor_csmencaps(wc, RCV_CSMENCAPS, 1))
 		return(1);
 	
 	/* Turn on booted LED */
 	wcdte_setctl(wc, 0x00A0, 0x04080000);
-
-	if (debug)
+	if(debug)
 		printk("wcdte: Successfully booted DTE processor.\n");
 
 	return(0);
@@ -1460,7 +1582,9 @@
 	static int initd_ifaces=0;
 	unsigned char g729_numchannels, g723_numchannels, min_numchannels, dte_firmware_ver;
 	unsigned int complexfmts;
-	
+#ifdef HOTPLUG_FIRMWARE
+	const struct firmware *firmware;
+#endif
 	if(initd_ifaces){
 		memset((void *)ifaces,0,(sizeof(struct wcdte *))*WC_MAX_IFACES);
 		initd_ifaces=1;
@@ -1530,10 +1654,19 @@
 			/* Initialize the work queue */
 			wc->dte_wq = create_workqueue("tc400b");
 			INIT_WORK(&wc->dte_work, (void (*)(void *))dte_wque_run, wc);
-
-			g729_numchannels = wcdte_firmware[1];
-			g723_numchannels = wcdte_firmware[2];
-			dte_firmware_ver = wcdte_firmware[0];
+#ifdef HOTPLUG_FIRMWARE
+			if ((request_firmware(&firmware, dte_firmware, &wc->dev->dev) != 0) || !firmware) {
+				printk("TC400B: firmware %s not available from userspace\n", dte_firmware);
+				return -1;
+			}
+			dte_firmware_ver = firmware->data[0];
+			g729_numchannels = firmware->data[1];
+			g723_numchannels = firmware->data[2];
+#else
+			dte_firmware_ver = _binary_dte_firm_bin_start[0];
+			g729_numchannels = _binary_dte_firm_bin_start[1];
+			g723_numchannels = _binary_dte_firm_bin_start[2];
+#endif
 
 			if (g723_numchannels < g729_numchannels)
 				min_numchannels = g723_numchannels;
@@ -1542,7 +1675,7 @@
 
 			/* Setup Encoders nad Decoders */
 
-			if (!mode)
+			if (!mode || strlen(mode) < 4)
 			{
 				sprintf(wc->complexname, "g.729a / g.723.1 5.3kbps");
  				complexfmts = ZT_FORMAT_G729A | ZT_FORMAT_G723_1;
@@ -1646,9 +1779,15 @@
 
 			/* Start DMA */
 			wcdte_start_dma(wc);
-
-			if (wcdte_boot_processor(wc))
+#ifdef HOTPLUG_FIRMWARE
+			if (wcdte_boot_processor(wc,firmware))
 			{
+				release_firmware(firmware);
+
+#else
+			if (wcdte_boot_processor(wc)) 
+			{
+#endif
 				/* Set Reset Low */
 				wcdte_stop_dma(wc);
 				/* Free Resources */

Added: trunk/ztcodec_dte/codec_test.c
URL: http://svn.digium.com/view/zaptel/trunk/ztcodec_dte/codec_test.c?view=auto&rev=1839
==============================================================================
--- trunk/ztcodec_dte/codec_test.c (added)
+++ trunk/ztcodec_dte/codec_test.c Wed Jan 17 15:42:45 2007
@@ -1,0 +1,71 @@
+/*
+ * Wilcard TC400B Digium Transcoder Engine Interface Driver for Zapata Telephony interface test tool.
+ *
+ * Written by Matt O'Gorman <mogormandigium.com>
+ *
+ * Copyright (C) 2006, Digium, Inc.
+ *
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
+ *
+ */
+
+
+
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <zaptel/zaptel.h>
+
+struct format_map {
+        unsigned int map[32][32];
+};
+
+static int find_transcoders(void)
+{
+	struct zt_transcode_info info = { 0, };
+	struct format_map map = { { { 0 } } };
+	int fd, res;
+	unsigned int x, y;
+	
+	info.op = ZT_TCOP_GETINFO;
+	if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0) {
+	        printf("Warning: No Zaptel transcoder support!\n");
+	        return 0;
+	}
+	for (info.tcnum = 0; !(res = ioctl(fd, ZT_TRANSCODE_OP, &info)); info.tcnum++) {
+		printf("Found transcoder %d, '%s'.\n",info.tcnum, info.name);
+		x = ZT_TCOP_TEST;
+		ioctl(fd, ZT_TRANSCODE_OP, &x);
+	}
+	close(fd);
+	if (!info.tcnum)
+		printf("No hardware transcoders found.\n");
+	return 0;
+}
+
+int main() 
+{
+	printf("this is a test\n");
+	find_transcoders();
+	return 0;
+}

Propchange: trunk/ztcodec_dte/codec_test.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/ztcodec_dte/codec_test.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/ztcodec_dte/codec_test.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: trunk/ztcodec_dte/dte_firm.bin
URL: http://svn.digium.com/view/zaptel/trunk/ztcodec_dte/dte_firm.bin?view=auto&rev=1839
==============================================================================
Binary file - no diff available.

Propchange: trunk/ztcodec_dte/dte_firm.bin
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: trunk/zttranscode.c
URL: http://svn.digium.com/view/zaptel/trunk/zttranscode.c?view=diff&rev=1839&r1=1838&r2=1839
==============================================================================
--- trunk/zttranscode.c (original)
+++ trunk/zttranscode.c Wed Jan 17 15:42:45 2007
@@ -347,6 +347,9 @@
 	case ZT_TCOP_RELEASE:
 		ret = ztc->parent->operation(ztc, ZT_TCOP_RELEASE);
 		break;
+	case ZT_TCOP_TEST:
+		ret = ztc->parent->operation(ztc, ZT_TCOP_TEST);
+		break;
 	case ZT_TCOP_TRANSCODE:
 		if (!ztc->parent->operation)
 			return -EINVAL;



More information about the zaptel-commits mailing list