Index: pcmmio/original/ChangeLog
===================================================================
--- pcmmio/original/ChangeLog	(revision 541e6d8c312e2f6777f59690b7d727363cefbac8)
+++ pcmmio/original/ChangeLog	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -1,2 +1,9 @@
+2011-02-17	Joel Sherrill <joel.sherrill@oarcorp.com>
+
+	* Makefile, main_pcmmio_adc.c, pcmmio_commands.h, pcmmio_shell.c: Add
+	set mode command. Add capability to read a single ADC. Updates from
+	Ada version.
+	* rootfs/set_adc_modes, rootfs/test_adc: New files.
+
 2011-02-17	Joel Sherrill <joel.sherrill@oarcorp.com>
 
Index: pcmmio/original/Makefile
===================================================================
--- pcmmio/original/Makefile	(revision 541e6d8c312e2f6777f59690b7d727363cefbac8)
+++ pcmmio/original/Makefile	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -8,6 +8,8 @@
 #
 
-MAINS= buffered.c dacbuff.c dacout.c flash.c getall.c getvolt.c \
-  poll.c repeat.c simple_rtems.c pcmmio_shell.c
+#MAINS= buffered.c dacbuff.c dacout.c flash.c getall.c getvolt.c \
+#  poll.c repeat.c simple_rtems.c pcmmio_shell.c
+
+MAINS= pcmmio_shell.c
 
 PGMS=$(MAINS:%.c=${ARCH}/%.exe)
@@ -20,4 +22,5 @@
 #SHARED_CSRCS += mio_io_linux.c
 SHARED_CSRCS = mio_io.c kbhit.c 
+SHARED_CSRCS += main_pcmmio_adc_mode.c
 SHARED_CSRCS += main_pcmmio_din.c main_pcmmio_dout.c
 SHARED_CSRCS += main_pcmmio_adc.c main_pcmmio_dac.c
@@ -25,7 +28,10 @@
 SHARED_CSRCS += main_pcmmio_benchmark.c
 SHARED_CSRCS += mio_io_rtems.c
+SHARED_CSRCS += FilesystemImage.c
 
 SHARED_COBJS = $(SHARED_CSRCS:%.c=${ARCH}/%.o)
 SHARED_CONFIG = ${ARCH}/rtems_config.o
+
+CLEAN_ADDITIONS += FilesystemImage FilesystemImage.c FilesystemImage.h
 
 include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
@@ -33,7 +39,8 @@
 include $(PROJECT_ROOT)/make/leaf.cfg
 
+LDFLAGS += -g
 OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) $(SHARED_COBJS) $(SHARED_CONFIG)
 
-all:    ${ARCH} $(OBJS) $(PGMS)
+all:    ${ARCH} FilesystemImage.c FilesystemImage.h $(OBJS) $(PGMS)
 
 ${ARCH}/pcmmio_shell.exe: pcmmio_shell.c $(OBJS)
@@ -42,2 +49,13 @@
 ${ARCH}/%.exe: %.c $(OBJS)
 	$(CC) $(LDFLAGS) -o $@ $< $(SHARED_COBJS) $(SHARED_CONFIG)
+
+FilesystemImage: rootfs/test_adc rootfs/set_adc_modes
+	(cd rootfs ; tar cf - --exclude=.svn \
+	  --exclude=CVS --exclude=.cvsignore .) >$(@)
+
+FilesystemImage.c FilesystemImage.h: FilesystemImage
+	$(PROJECT_ROOT)/bin/rtems-bin2c FilesystemImage FilesystemImage
+
+FilesystemImage.o: FilesystemImage.c
+	$(CC) $(CFLAGS) $(CPU_CFLAGS) -c $<
+
Index: pcmmio/original/main_pcmmio_adc.c
===================================================================
--- pcmmio/original/main_pcmmio_adc.c	(revision 541e6d8c312e2f6777f59690b7d727363cefbac8)
+++ pcmmio/original/main_pcmmio_adc.c	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -35,5 +35,6 @@
 
 void pcmmio_adc_printf(
-  float *adc
+  float *adc,
+  int    channel
 )
 {
@@ -41,15 +42,20 @@
 
   (void) rtems_clock_get_uptime( &ts );
-  printf(
-    "%03ld:%06ld %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n" 
-    "%11s%7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n",
-    ts.tv_sec, ts.tv_nsec/1000,
-    adc[0], adc[1], adc[2], adc[3], adc[4], adc[5], adc[6], adc[7],
-    "", adc[8], adc[9], adc[10], adc[11], adc[12], adc[13], adc[14], adc[15]
-  );
+  printf( "%03ld:%06ld ", ts.tv_sec, ts.tv_nsec/1000 );
+
+  if ( channel == -1 ) {
+    printf(
+      "%7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n" 
+      "%11s%7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n",
+      adc[0], adc[1], adc[2], adc[3], adc[4], adc[5], adc[6], adc[7],
+      "", adc[8], adc[9], adc[10], adc[11], adc[12], adc[13], adc[14], adc[15]
+    );
+  } else {
+    printf( "%7.4f\n", adc[channel] );
+  }
 }
 
 char pcmmio_adc_usage[] =
-  "Usage: %s [-i iterations] [-p period] [-v]\n"
+  "Usage: %s [-i iterations] [-p period] [-v] [channel]\n"
   "Where: maximum iterations defaults to 1\n"
   "       the period is in milliseconds and defaults to 1000\n";
@@ -63,4 +69,6 @@
   int                 maximum;
   int                 iterations;
+  int                 channel;
+  int                 i;
   char                ch;
   bool                changed;
@@ -75,6 +83,7 @@
    */
   milliseconds = 1000;
-  maximum = 1;
-  verbose = false;
+  maximum      = 1;
+  channel      = -1;
+  verbose      = false;
 
   memset(&getopt_reent, 0, sizeof(getopt_data));
@@ -113,5 +122,5 @@
   }
 
-  if ( maximum != 1 )
+  if ( maximum != 1 ) {
     printf(
       "Polling analog inputs for %d iterations with %d msec period\n",
@@ -119,4 +128,20 @@
       milliseconds
     );
+  }
+
+  /*
+   *  Is there a specific ADC we are interested in?
+   */
+  i = getopt_reent.optind;
+  if ( i < argc ) {
+    if ( rtems_string_to_int( argv[i], &channel, NULL, 0 ) ) {
+      printf( "ADC (%s) is not a number\n", argv[i] );
+      return -1;
+    }
+    if ( channel < 0 || channel > 15 ) {
+      puts( "ADC number must be 0-15" );
+      return -1;
+    }
+  }
 
   /*
@@ -129,11 +154,15 @@
     pcmmio_adc_read(adc_current);
    
-    if ( iterations == 1 )
+    if ( iterations == 1 ) {
       changed = true;
-    else if ( memcmp( adc_last, adc_current, sizeof(adc_current) ) )
-      changed = true;
-    
+    } else if ( channel == -1 ) {
+      if ( memcmp( adc_last, adc_current, sizeof(adc_current) ) )
+	changed = true;
+    } else if ( adc_last[channel] != adc_current[channel] ) {
+       changed = true;
+    } 
+
     if ( verbose || changed ) {
-      pcmmio_adc_printf(adc_current);
+      pcmmio_adc_printf(adc_current, channel);
       memcpy( adc_last, adc_current, sizeof(adc_current) );
       changed = false;
Index: pcmmio/original/pcmmio_commands.h
===================================================================
--- pcmmio/original/pcmmio_commands.h	(revision 541e6d8c312e2f6777f59690b7d727363cefbac8)
+++ pcmmio/original/pcmmio_commands.h	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -20,4 +20,5 @@
 extern rtems_shell_cmd_t Shell_PCMMIO_DIN_Command;
 extern rtems_shell_cmd_t Shell_PCMMIO_DOUT_Command;
+extern rtems_shell_cmd_t Shell_PCMMIO_ADC_Mode_Command;
 extern rtems_shell_cmd_t Shell_PCMMIO_ADC_Command;
 extern rtems_shell_cmd_t Shell_PCMMIO_DAC_Command;
@@ -29,4 +30,5 @@
   &Shell_PCMMIO_DOUT_Command, \
   &Shell_PCMMIO_ADC_Command, \
+  &Shell_PCMMIO_ADC_Mode_Command, \
   &Shell_PCMMIO_DAC_Command, \
   &Shell_PCMMIO_IRQ_Command, \
@@ -36,4 +38,5 @@
 extern rtems_shell_alias_t Shell_PCMMIO_DOUT_Alias;
 extern rtems_shell_alias_t Shell_PCMMIO_ADC_Alias;
+extern rtems_shell_alias_t Shell_PCMMIO_ADC_Mode_Alias;
 extern rtems_shell_alias_t Shell_PCMMIO_DAC_Alias;
 
@@ -42,4 +45,5 @@
   &Shell_PCMMIO_DOUT_Alias, \
   &Shell_PCMMIO_ADC_Alias, \
+  &Shell_PCMMIO_ADC_Mode_Alias, \
   &Shell_PCMMIO_DAC_Alias
   
Index: pcmmio/original/pcmmio_shell.c
===================================================================
--- pcmmio/original/pcmmio_shell.c	(revision 541e6d8c312e2f6777f59690b7d727363cefbac8)
+++ pcmmio/original/pcmmio_shell.c	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -12,8 +12,18 @@
 #include "pcmmio_commands.h"
 
+#include <stdlib.h>
+
+#include <rtems/untar.h>
+/*
+ *  The tarfile image is built automatically externally.
+ */
+#include "FilesystemImage.h"
+
 rtems_task Init(
   rtems_task_argument ignored
 )
 {
+  int status;
+
   /*
    *  Initialize the PCMMIO module to use IRQ6.  Ours is jumpered for 0x300
@@ -26,4 +36,14 @@
     for (i=1 ; i<=48 ; i++ )
       dio_enab_bit_int(i, 1);
+  }
+
+  /*
+   * Untar initial filesystem contents from program image
+   */
+  printk("Loading filesystem image\n");
+  status = Untar_FromMemory( (char *)FilesystemImage, FilesystemImage_size );
+  if ( status ) {
+    printf("Unable to untar initial filesystem contents\n");
+    exit(0);    
   }
 
@@ -77,4 +97,7 @@
 #define CONFIGURE_INIT_TASK_ATTRIBUTES      RTEMS_FLOATING_POINT
 
+/* We need the full IMFS to create initial files */
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
 #define CONFIGURE_STACK_CHECKER_ENABLED
 #define CONFIGURE_MALLOC_STATISTICS
Index: pcmmio/original/rootfs/set_adc_modes
===================================================================
--- pcmmio/original/rootfs/set_adc_modes	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
+++ pcmmio/original/rootfs/set_adc_modes	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -0,0 +1,3 @@
+#! joel
+echo "Setting all ADCs to +/-10V (bipolar) and single ended"
+pcmmio_adc_mode 0 15
Index: pcmmio/original/rootfs/test_adc
===================================================================
--- pcmmio/original/rootfs/test_adc	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
+++ pcmmio/original/rootfs/test_adc	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -0,0 +1,54 @@
+#! joel
+
+echo "*** assume dac 4 is connected to ADC 0 ***"
+echo "Cycle from -5v to +5v with one second between on dac 4"
+
+pcmmio_dac 4 -5.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -4.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -3.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -2.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -1.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 0.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 1.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 2.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 3.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 4.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 5.0
+sleep 1
+pcmmio_adc 0
+
+echo "Write 0.0v to dac 4"
+pcmmio_dac 4 0.0
+sleep 1
+pcmmio_adc 0
+
Index: pcmmio/rootfs/set_adc_modes
===================================================================
--- pcmmio/rootfs/set_adc_modes	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
+++ pcmmio/rootfs/set_adc_modes	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -0,0 +1,3 @@
+#! joel
+echo "Setting all ADCs to +/-10V (bipolar) and single ended"
+pcmmio_adc_mode 0 15
Index: pcmmio/rootfs/test_adc
===================================================================
--- pcmmio/rootfs/test_adc	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
+++ pcmmio/rootfs/test_adc	(revision 6957d53593f9ce6edd85cca4934549ab6ac76cdc)
@@ -0,0 +1,54 @@
+#! joel
+
+echo "*** assume dac 4 is connected to ADC 0 ***"
+echo "Cycle from -5v to +5v with one second between on dac 4"
+
+pcmmio_dac 4 -5.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -4.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -3.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -2.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 -1.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 0.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 1.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 2.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 3.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 4.0
+sleep 1
+pcmmio_adc 0
+
+pcmmio_dac 4 5.0
+sleep 1
+pcmmio_adc 0
+
+echo "Write 0.0v to dac 4"
+pcmmio_dac 4 0.0
+sleep 1
+pcmmio_adc 0
+
