source: multiio/pcmmio/original/main_pcmmio_dac.c @ 65bf116

Last change on this file since 65bf116 was 09da44f, checked in by Joel Sherrill <joel.sherrill@…>, on 10/13/09 at 17:54:39

2009-10-13 Joel Sherrill <joel.sherrill@…>

  • main_pcmmio_dac.c: Fix help message.
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 *  pcmmio_dac command
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include "pcmmio_commands.h"
15#include "mio_io.h"
16#include <rtems/stringto.h>
17
18#include <stdlib.h>
19
20#if defined(TESTING)
21  #define set_dac_voltage(_dac, _voltage) \
22    /* printf( "Testing: Write %6.4f to to dac %d\n", _voltage, _dac ); */
23#endif
24
25#define VALIDATE_VOLTAGE(_v) \
26  if ( (_v) < -10.0 || (_v) > 10.0 ) { \
27    printf( "Voltage must be between -10.0V and +10.0V\n" ); \
28    fail = true; \
29  }
30
31char pcmmio_dac_usage[] =
32  "Usage: %s dac voltage\n"
33  "       %s dac low high step time_per_step maximum_time\n"
34  "\n"
35  "Where: dac must be 0-7\n"
36  "       voltages and step must be -10V to +10V\n"
37  "       times are in milliseconds\n"
38  "  First form is a single write.\n"
39  "  Second form writes a pattern.\n";
40
41#define PRINT_USAGE() \
42   printf( pcmmio_dac_usage, argv[0], argv[0] );
43
44int main_pcmmio_dac(int argc, char **argv)
45{
46  int       dac;
47  float     low_voltage;
48  float     high_voltage;
49  float     step_voltage;
50  float     current_voltage;
51  float     current_step;
52  int       step_time;
53  int       maximum_time;
54  uint32_t  step_ticks;
55  bool      fail = false;
56  int       elapsed;
57
58  /*
59   *  Verify that we have the right number of arguments.
60   */
61  if ( (argc != 3) && (argc != 7) ) {
62    printf( "Incorrect number of arguments\n" );
63    PRINT_USAGE();
64    return -1;
65  }
66
67  /*
68   *  Convert the string arguments into number values
69   */
70  if ( rtems_string_to_int( argv[1], &dac, NULL, 0 ) ) {
71    printf( "DAC (%s) is not a number\n", argv[1] );
72    fail = true;
73  }
74
75  if ( rtems_string_to_float( argv[2], &low_voltage, NULL ) ) {
76    printf( "Voltage (%s) is not a number\n", argv[2] );
77    fail = true;
78  }
79
80  /*
81   *  Validate the output dac and voltage.
82   */
83  if ( dac < 0 || dac > 7 ) {
84    puts( "DAC number must be 0-7" );
85    fail = true;
86  }
87
88  VALIDATE_VOLTAGE( low_voltage );
89
90  /*
91   *  Now do a single write to the DAC
92   */
93  if ( argc == 3 ) {
94    if ( fail ) {
95      PRINT_USAGE();
96      return -1;
97    }
98    printf( "Write %6.4f to to dac %d\n", low_voltage, dac );
99    set_dac_voltage(dac, low_voltage);
100    return 0;
101  }
102
103  /*
104   *  Finish parsing the arguments to do a pattern
105   */
106  fail = false;
107
108  if ( rtems_string_to_float( argv[3], &high_voltage, NULL ) ) {
109    printf( "Voltage (%s) is not a number\n", argv[3] );
110    fail = true;
111  }
112
113  VALIDATE_VOLTAGE( high_voltage );
114
115  if ( rtems_string_to_float( argv[4], &step_voltage, NULL ) ) {
116    printf( "Step voltage (%s) is not a number\n", argv[4] );
117    fail = true;
118  }
119
120  VALIDATE_VOLTAGE( step_voltage );
121
122  if ( step_voltage < 0.0 ) {
123    printf( "Step voltage must be greater than 0\n" );
124    fail = true;
125  }
126
127  if ( rtems_string_to_int( argv[5], &step_time, NULL, 0 ) ) {
128    printf( "Step time (%s) is not a number\n", argv[5] );
129    fail = true;
130  }
131
132  if ( rtems_string_to_int( argv[6], &maximum_time, NULL, 0 ) ) {
133    printf( "Maximum time (%s) is not a number\n", argv[6] );
134    fail = true;
135  }
136
137  if ( step_time >= maximum_time ) {
138    printf(
139      "Step time (%d) must be less than maximum time (%d)\n",
140      step_time,
141      maximum_time
142    );
143    fail = true;
144  }
145
146  if ( step_time < 0 ) {
147    printf( "Step time must be greater than 0\n" );
148    fail = true;
149  }
150
151  if ( maximum_time < 0 ) {
152    printf( "Maximum time must be greater than 0\n" );
153    fail = true;
154  }
155
156  /*
157   *  Now write the pattern to the DAC
158   */
159
160  if ( fail ) {
161    PRINT_USAGE();
162    return -1;
163  }
164
165  printf(
166    "Write %6.4f-%6.4f step=%6.4f stepTime=%d msecs dac=%d max=%d msecs\n",
167    low_voltage,
168    high_voltage,
169    step_voltage,
170    step_time,
171    dac,
172    maximum_time
173  );
174
175  elapsed         = 0;
176  step_ticks      = RTEMS_MILLISECONDS_TO_TICKS(step_time);
177  current_voltage = low_voltage;
178  current_step    = step_voltage;
179
180  if ( low_voltage > high_voltage )
181    current_step    *= -1.0;
182
183  while (1) {
184 
185    #if defined(TESTING)
186      printf( "%d: Write %6.4f to to dac %d\n", elapsed, current_voltage, dac );
187    #endif
188    set_dac_voltage(dac, current_voltage);
189
190    current_voltage += current_step;
191    if ( current_voltage < low_voltage ) {
192      current_step    = step_voltage;
193      current_voltage = low_voltage;
194    } else if ( current_voltage > high_voltage ) {
195      current_step    = -1.0 * step_voltage;
196      current_voltage = high_voltage;
197    }
198
199    elapsed += step_time;
200    if ( elapsed > maximum_time )
201      break;
202
203    rtems_task_wake_after( step_ticks );
204  }
205   
206  return 0;
207}
208
209rtems_shell_cmd_t Shell_PCMMIO_DAC_Command = {
210  "pcmmio_dac",                                    /* name */
211  "Write PCMMIO Analog Outputs",                   /* usage */
212  "pcmmio",                                        /* topic */
213  main_pcmmio_dac,                                 /* command */
214  NULL,                                            /* alias */
215  NULL                                             /* next */
216};
217
218rtems_shell_alias_t Shell_PCMMIO_DAC_Alias = {
219  "pcmmio_dac",          /* command */
220  "dac"                  /* alias */
221};
222
Note: See TracBrowser for help on using the repository browser.