Changeset f89686d in multiio for pcmmio/original/main_pcmmio_dac.c


Ignore:
Timestamp:
Jul 22, 2009, 6:24:22 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
master
Children:
d7d35da
Parents:
9175425
Message:

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • README, main_pcmmio_dac.c, rtems_config.c: Add mode to pcmmio_dac command where it can write a pattern.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pcmmio/original/main_pcmmio_dac.c

    r9175425 rf89686d  
    1919#if defined(TESTING)
    2020  #define set_dac_voltage(_dac, _voltage) \
    21     printf( "Testing: Write %6.4f to to dac %d\n", _voltage, _dac );
     21    /* printf( "Testing: Write %6.4f to to dac %d\n", _voltage, _dac ); */
    2222#endif
     23
     24#define VALIDATE_VOLTAGE(_v) \
     25  if ( (_v) < -10.0 || (_v) > 10.0 ) { \
     26    printf( "Voltage must be between -10.0V and +10.0V\n" ); \
     27    fail = true; \
     28  }
    2329
    2430char pcmmio_dac_usage[] =
    2531  "Usage: %s dac voltage\n"
     32  "       %s dac low high step time_per_step maximum_time\n"
     33  "\n"
    2634  "Where: dac must be 0-7\n"
    27   "       voltage must be -10V to +10V\n";
     35  "       voltages and step must be -10V to +10V\n"
     36  "       times are in milliseconds\n"
     37  "  First form is a single write.\n"
     38  "  Second form writes a pattern.\n";
    2839
    2940#define PRINT_USAGE() \
    30    printf( pcmmio_dac_usage, argv[0] );
     41   printf( pcmmio_dac_usage, argv[0], argv[0] );
    3142
    3243int main_pcmmio_dac(int argc, char **argv)
    3344{
    34   int    dac;
    35   float  voltage;
    36   bool   fail = false;
     45  int       dac;
     46  float     low_voltage;
     47  float     high_voltage;
     48  float     step_voltage;
     49  float     current_voltage;
     50  float     current_step;
     51  int       step_time;
     52  int       maximum_time;
     53  uint32_t  step_ticks;
     54  bool      fail = false;
     55  int       elapsed;
    3756
    3857  /*
    3958   *  Verify that we have the right number of arguments.
    4059   */
    41   if ( argc != 3 ) {
     60  if ( (argc != 3) && (argc != 7) ) {
    4261    printf( "Incorrect number of arguments\n" );
    4362    PRINT_USAGE();
     
    5372  }
    5473
    55   if ( !rtems_string_to_float( argv[2], &voltage, NULL ) ) {
     74  if ( !rtems_string_to_float( argv[2], &low_voltage, NULL ) ) {
    5675    printf( "Voltage (%s) is not a number\n", argv[2] );
    5776    fail = true;
     
    6685  }
    6786
    68   if ( voltage < -10.0 || voltage > 10.0 ) {
    69     printf( "Voltage must be between -10.0V and +10.0V\n" );
    70     fail = true;
    71   }
     87  VALIDATE_VOLTAGE( low_voltage );
     88
     89  /*
     90   *  Now do a single write to the DAC
     91   */
     92  if ( argc == 3 ) {
     93    if ( fail ) {
     94      PRINT_USAGE();
     95      return -1;
     96    }
     97    printf( "Write %6.4f to to dac %d\n", low_voltage, dac );
     98    set_dac_voltage(dac, low_voltage);
     99  }
     100
     101  /*
     102   *  Finish parsing the arguments to do a pattern
     103   */
     104  fail = false;
     105
     106  if ( !rtems_string_to_float( argv[3], &high_voltage, NULL ) ) {
     107    printf( "Voltage (%s) is not a number\n", argv[3] );
     108    fail = true;
     109  }
     110
     111  VALIDATE_VOLTAGE( high_voltage );
     112
     113  if ( !rtems_string_to_float( argv[4], &step_voltage, NULL ) ) {
     114    printf( "Step voltage (%s) is not a number\n", argv[4] );
     115    fail = true;
     116  }
     117
     118  VALIDATE_VOLTAGE( step_voltage );
     119
     120  if ( step_voltage < 0.0 ) {
     121    printf( "Step voltage must be greater than 0\n" );
     122    fail = true;
     123  }
     124
     125  if ( !rtems_string_to_int( argv[5], &step_time, NULL, 0 ) ) {
     126    printf( "Step time (%s) is not a number\n", argv[5] );
     127    fail = true;
     128  }
     129
     130  if ( !rtems_string_to_int( argv[6], &maximum_time, NULL, 0 ) ) {
     131    printf( "Maximum time (%s) is not a number\n", argv[6] );
     132    fail = true;
     133  }
     134
     135  if ( step_time >= maximum_time ) {
     136    printf(
     137      "Step time (%d) must be less than maximum time (%d)\n",
     138      step_time,
     139      maximum_time
     140    );
     141    fail = true;
     142  }
     143
     144  if ( step_time < 0 ) {
     145    printf( "Step time must be greater than 0\n" );
     146    fail = true;
     147  }
     148
     149  if ( maximum_time < 0 ) {
     150    printf( "Maximum time must be greater than 0\n" );
     151    fail = true;
     152  }
     153
     154  /*
     155   *  Now write the pattern to the DAC
     156   */
    72157
    73158  if ( fail ) {
     
    76161  }
    77162
    78   /*
    79    *  Now write the voltage
    80    */
    81   printf( "Write %6.4f to to dac %d\n", voltage, dac );
    82   set_dac_voltage(dac, voltage);
    83 
     163  printf(
     164    "Write %6.4f-%6.4f step=%6.4f stepTime=%d msecs dac=%d max=%d msecs\n",
     165    low_voltage,
     166    high_voltage,
     167    step_voltage,
     168    step_time,
     169    dac,
     170    maximum_time
     171  );
     172
     173  elapsed         = 0;
     174  step_ticks      = RTEMS_MILLISECONDS_TO_TICKS(step_time);
     175  current_voltage = low_voltage;
     176  current_step    = step_voltage;
     177
     178  if ( low_voltage > high_voltage )
     179    current_step    *= -1.0;
     180
     181  while (1) {
     182 
     183    #if defined(TESTING)
     184      printf( "%d: Write %6.4f to to dac %d\n", elapsed, current_voltage, dac );
     185    #endif
     186    set_dac_voltage(dac, current_voltage);
     187
     188    current_voltage += current_step;
     189    if ( current_voltage < low_voltage ) {
     190      current_step    = step_voltage;
     191      current_voltage = low_voltage;
     192    } else if ( current_voltage > high_voltage ) {
     193      current_step    = -1.0 * step_voltage;
     194      current_voltage = high_voltage;
     195    }
     196
     197    elapsed += step_time;
     198    if ( elapsed > maximum_time )
     199      break;
     200
     201    rtems_task_wake_after( step_ticks );
     202  }
     203   
    84204  return 0;
    85205}
Note: See TracChangeset for help on using the changeset viewer.