Changeset 6957d53 in multiio for pcmmio/original/main_pcmmio_adc.c


Ignore:
Timestamp:
Feb 17, 2011, 4:39:38 PM (8 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
master
Children:
c531584
Parents:
541e6d8
Message:

2011-02-17 Joel Sherrill <joel.sherrill@…>

  • 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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pcmmio/original/main_pcmmio_adc.c

    r541e6d8 r6957d53  
    3535
    3636void pcmmio_adc_printf(
    37   float *adc
     37  float *adc,
     38  int    channel
    3839)
    3940{
     
    4142
    4243  (void) rtems_clock_get_uptime( &ts );
    43   printf(
    44     "%03ld:%06ld %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n"
    45     "%11s%7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n",
    46     ts.tv_sec, ts.tv_nsec/1000,
    47     adc[0], adc[1], adc[2], adc[3], adc[4], adc[5], adc[6], adc[7],
    48     "", adc[8], adc[9], adc[10], adc[11], adc[12], adc[13], adc[14], adc[15]
    49   );
     44  printf( "%03ld:%06ld ", ts.tv_sec, ts.tv_nsec/1000 );
     45
     46  if ( channel == -1 ) {
     47    printf(
     48      "%7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n"
     49      "%11s%7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f %7.4f\n",
     50      adc[0], adc[1], adc[2], adc[3], adc[4], adc[5], adc[6], adc[7],
     51      "", adc[8], adc[9], adc[10], adc[11], adc[12], adc[13], adc[14], adc[15]
     52    );
     53  } else {
     54    printf( "%7.4f\n", adc[channel] );
     55  }
    5056}
    5157
    5258char pcmmio_adc_usage[] =
    53   "Usage: %s [-i iterations] [-p period] [-v]\n"
     59  "Usage: %s [-i iterations] [-p period] [-v] [channel]\n"
    5460  "Where: maximum iterations defaults to 1\n"
    5561  "       the period is in milliseconds and defaults to 1000\n";
     
    6369  int                 maximum;
    6470  int                 iterations;
     71  int                 channel;
     72  int                 i;
    6573  char                ch;
    6674  bool                changed;
     
    7583   */
    7684  milliseconds = 1000;
    77   maximum = 1;
    78   verbose = false;
     85  maximum      = 1;
     86  channel      = -1;
     87  verbose      = false;
    7988
    8089  memset(&getopt_reent, 0, sizeof(getopt_data));
     
    113122  }
    114123
    115   if ( maximum != 1 )
     124  if ( maximum != 1 ) {
    116125    printf(
    117126      "Polling analog inputs for %d iterations with %d msec period\n",
     
    119128      milliseconds
    120129    );
     130  }
     131
     132  /*
     133   *  Is there a specific ADC we are interested in?
     134   */
     135  i = getopt_reent.optind;
     136  if ( i < argc ) {
     137    if ( rtems_string_to_int( argv[i], &channel, NULL, 0 ) ) {
     138      printf( "ADC (%s) is not a number\n", argv[i] );
     139      return -1;
     140    }
     141    if ( channel < 0 || channel > 15 ) {
     142      puts( "ADC number must be 0-15" );
     143      return -1;
     144    }
     145  }
    121146
    122147  /*
     
    129154    pcmmio_adc_read(adc_current);
    130155   
    131     if ( iterations == 1 )
     156    if ( iterations == 1 ) {
    132157      changed = true;
    133     else if ( memcmp( adc_last, adc_current, sizeof(adc_current) ) )
    134       changed = true;
    135    
     158    } else if ( channel == -1 ) {
     159      if ( memcmp( adc_last, adc_current, sizeof(adc_current) ) )
     160        changed = true;
     161    } else if ( adc_last[channel] != adc_current[channel] ) {
     162       changed = true;
     163    }
     164
    136165    if ( verbose || changed ) {
    137       pcmmio_adc_printf(adc_current);
     166      pcmmio_adc_printf(adc_current, channel);
    138167      memcpy( adc_last, adc_current, sizeof(adc_current) );
    139168      changed = false;
Note: See TracChangeset for help on using the changeset viewer.