[svn-commits] tzafrir: tools/trunk r6987 - /tools/trunk/xpp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Aug 13 10:15:53 CDT 2009


Author: tzafrir
Date: Thu Aug 13 10:15:49 2009
New Revision: 6987

URL: http://svn.asterisk.org/svn-view/dahdi?view=rev&rev=6987
Log:
xpp: Add astribank_is_starting:

astribank_is_running is used to tell when we may have an Astribank that
is initializing (and may be re-enumerating and thus not listed as a
device).

It uses a semaphore as we can always write to one and we can't always
write to a file.

Added:
    tools/trunk/xpp/astribank_is_starting.c   (with props)
Modified:
    tools/trunk/xpp/Makefile
    tools/trunk/xpp/waitfor_xpds
    tools/trunk/xpp/xpp_fxloader

Modified: tools/trunk/xpp/Makefile
URL: http://svn.asterisk.org/svn-view/dahdi/tools/trunk/xpp/Makefile?view=diff&rev=6987&r1=6986&r2=6987
==============================================================================
--- tools/trunk/xpp/Makefile (original)
+++ tools/trunk/xpp/Makefile Thu Aug 13 10:15:49 2009
@@ -65,8 +65,9 @@
 	   astribank_tool	\
 	   astribank_hexload	\
 	   astribank_allow	\
+	   astribank_is_starting	\
 	   test_parse
-PROG_INSTALL	+= fpga_load astribank_tool astribank_hexload astribank_allow
+PROG_INSTALL	+= fpga_load astribank_tool astribank_hexload astribank_allow astribank_is_starting
 endif
 ifneq	(,$(PERLLIBDIR))
 PROG_INSTALL	+= $(PERL_SCRIPTS)
@@ -113,6 +114,9 @@
 astribank_allow: $(ABALLOW_OBJS)
 	$(CC) -L. -o $@ $(ABALLOW_OBJS) $(EXTRA_LIBS) $(USB_LIB)
 
+astribank_is_starting: astribank_is_starting.o
+	$(CC) -L. -o $@ $^ $(EXTRA_LIBS)
+
 fpga_load.o: CFLAGS+=-D_GNU_SOURCE	# We use memrchr()
 
 test_parse: test_parse.o hexfile.o

Added: tools/trunk/xpp/astribank_is_starting.c
URL: http://svn.asterisk.org/svn-view/dahdi/tools/trunk/xpp/astribank_is_starting.c?view=auto&rev=6987
==============================================================================
--- tools/trunk/xpp/astribank_is_starting.c (added)
+++ tools/trunk/xpp/astribank_is_starting.c Thu Aug 13 10:15:49 2009
@@ -1,0 +1,120 @@
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+#include <errno.h>
+#include <getopt.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static char		*progname;
+static const key_t	key_astribanks = 0xAB11A0;
+static int		debug;
+
+static void usage(void)
+{
+	fprintf(stderr, "Usage: %s [-d] [-a] [-r]\n", progname);
+	exit(1);
+}
+
+static int absem_get(int createit)
+{
+	int	flags = (createit) ? IPC_CREAT | 0644 : 0;
+	int	absem;
+
+	if((absem = semget(key_astribanks, 1, flags)) < 0)
+		absem = -errno;
+	return absem;
+}
+
+static int absem_touch(void)
+{
+	int		absem;
+
+	if((absem = absem_get(1)) < 0) {
+		perror(__FUNCTION__);
+		return absem;
+	}
+	if(semctl(absem, 0, SETVAL, 0) < 0) {
+		perror("SETVAL");
+		return -errno;
+	}
+	if(debug)
+		fprintf(stderr, "%s: touched absem\n", progname);
+	return 0;
+}
+
+static int absem_remove(void)
+{
+	int	absem;
+
+	if((absem = absem_get(0)) < 0) {
+		if(absem == -ENOENT) {
+			if(debug)
+				fprintf(stderr, "%s: absem already removed\n", progname);
+			return 0;
+		}
+		perror(__FUNCTION__);
+		return absem;
+	}
+	if(semctl(absem, 0, IPC_RMID, 0) < 0) {
+		perror("RMID");
+		return -errno;
+	}
+	if(debug)
+		fprintf(stderr, "%s: removed absem\n", progname);
+	return 0;
+}
+
+static int absem_detected(void)
+{
+	int	absem;
+
+	if((absem = absem_get(0)) < 0) {
+		if(debug)
+			fprintf(stderr, "%s: absem does not exist\n", progname);
+		return absem;
+	}
+	if(debug)
+		fprintf(stderr, "%s: absem exists\n", progname);
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	const char	options[] = "darh";
+	int		val;
+
+	progname = argv[0];
+	while (1) {
+		int	c;
+
+		c = getopt (argc, argv, options);
+		if (c == -1)
+			break;
+
+		switch (c) {
+			case 'd':
+				debug++;
+				break;
+			case 'a':
+				if((val = absem_touch()) < 0) {
+					fprintf(stderr, "%s: Add failed: %d\n", progname, val);
+					return 1;
+				}
+				return 0;
+			case 'r':
+				if((val = absem_remove()) < 0) {
+					fprintf(stderr, "%s: Remove failed: %d\n", progname, val);
+					return 1;
+				}
+				return 0;
+			case 'h':
+			default:
+				fprintf(stderr, "Unknown option '%c'\n", c);
+				usage();
+		}
+	}
+	val = absem_detected();
+	return (val == 0) ? 0 : 1;
+}

Propchange: tools/trunk/xpp/astribank_is_starting.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tools/trunk/xpp/astribank_is_starting.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: tools/trunk/xpp/astribank_is_starting.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: tools/trunk/xpp/waitfor_xpds
URL: http://svn.asterisk.org/svn-view/dahdi/tools/trunk/xpp/waitfor_xpds?view=diff&rev=6987&r1=6986&r2=6987
==============================================================================
--- tools/trunk/xpp/waitfor_xpds (original)
+++ tools/trunk/xpp/waitfor_xpds Thu Aug 13 10:15:49 2009
@@ -40,7 +40,14 @@
 	echo >&2 "$0: Missing dahdi_hardware"
 	exit 0
 fi
-if [ "`$dahdi_hardware | grep xpp_usb`" = "" ]; then
+if ! astribank_is_starting="`which astribank_is_starting 2>/dev/null`"; then
+	echo >&2 "$0: Missing astribank_is_starting"
+	exit 0
+fi
+if [ "`$dahdi_hardware | grep xpp_usb`" != "" ]; then
+	astribank_is_starting -a
+fi
+if ! astribank_is_starting; then
 	exit 0
 fi
 
@@ -70,3 +77,6 @@
 	oldab="$ab"
 	cat $ab
 done
+
+# Handled astribanks
+astribank_is_starting -r

Modified: tools/trunk/xpp/xpp_fxloader
URL: http://svn.asterisk.org/svn-view/dahdi/tools/trunk/xpp/xpp_fxloader?view=diff&rev=6987&r1=6986&r2=6987
==============================================================================
--- tools/trunk/xpp/xpp_fxloader (original)
+++ tools/trunk/xpp/xpp_fxloader Thu Aug 13 10:15:49 2009
@@ -256,6 +256,9 @@
 	echo "$0 usb   : manual firmware loading: USB firmware only."
 	echo "$0 help  : this text."
 }
+
+# We have a potential astribank
+astribank_is_starting -a
 
 #########################
 ##




More information about the svn-commits mailing list