source: multiio/pcmmio/original/main_pcmmio_irq.c @ 45abed9

Last change on this file since 45abed9 was 45abed9, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/09 at 20:58:43

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

  • Makefile, README, main_pcmmio_dac.c, mio_io.h, mio_io_rtems.c, pcmmio_commands.h, pcmmio_shell.c, rtems_config.c: Add pcmmio_irq command and do some cleanup as noticed on other files.
  • main_pcmmio_irq.c: New file.
  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 *  pcmmio_irq 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#define __need_getopt_newlib
19#include <getopt.h>
20
21char pcmmio_irq_usage[] =
22  "Usage: %s [-i iterations] [-p period] [-v] [-d|-D DAC|-a ADC]\n"
23  "Where: maximum iterations defaults to 1\n"
24  "       the period is in milliseconds and defaults to 1000\n";
25
26#define PRINT_USAGE() \
27   printf( pcmmio_irq_usage, argv[0] )
28
29int main_pcmmio_irq(int argc, char **argv)
30{
31  int                 milliseconds;
32  int                 maximum;
33  int                 iterations;
34  int                 sc;
35  char                ch;
36  bool                changed;
37  bool                verbose;
38  struct getopt_data  getopt_reent;
39  const  char        *s;
40  bool                do_dac = false;
41  bool                do_adc = false;
42  bool                do_din = false;
43  int                 dac = -1;
44  int                 adc = -1;
45  int                 selected;
46  const char         *irq = "";
47
48  /*
49   * Parse arguments here
50   */
51  milliseconds = 1000;
52  maximum = 1;
53  verbose = false;
54
55  memset(&getopt_reent, 0, sizeof(getopt_data));
56  while ((ch = getopt_r(argc, argv, "i:p:vdD:a:", &getopt_reent)) != -1) {
57    switch (ch) {
58      case 'i': /* maximum iterations */
59        s = getopt_reent.optarg;
60        if ( !rtems_string_to_int( s, &maximum, NULL, 0 ) ) {
61          printf( "Maximum iterations (%s) is not a number\n", s );
62          PRINT_USAGE();
63          return -1;
64        }
65
66        break;
67      case 'p': /* sampling period */
68        s = getopt_reent.optarg;
69        if ( !rtems_string_to_int( s, &milliseconds, NULL, 0 ) ) {
70          printf( "Sampling period (%s) is not a number\n", s );
71          PRINT_USAGE();
72          return -1;
73        }
74        if ( milliseconds == 0 ) {
75          printf( "Sampling period (%d) is 0\n", milliseconds );
76          PRINT_USAGE();
77          return -1;
78        }
79        break;
80      case 'd': /* DIN enable */
81        do_din = true;
82        break;
83      case 'D': /* DAC enable */
84        s = getopt_reent.optarg;
85        if ( !rtems_string_to_int( s, &dac, NULL, 0 ) ) {
86          printf( "DAC (%s) is not a number\n", s );
87          PRINT_USAGE();
88          return -1;
89        }
90
91        if ( dac < 0 || dac > 7 ) {
92          puts( "DAC number must be 0-7" );
93          PRINT_USAGE();
94          return -1;
95        }
96
97        do_dac = true;
98        break;
99      case 'a': /* ADC enable */
100        s = getopt_reent.optarg;
101        if ( !rtems_string_to_int( s, &adc, NULL, 0 ) ) {
102          printf( "ADC (%s) is not a number\n", s );
103          PRINT_USAGE();
104          return -1;
105        }
106
107        if ( adc < 0 || adc > 7 ) {
108          puts( "ADC number must be 0-7" );
109          PRINT_USAGE();
110          return -1;
111        }
112        do_adc = true;
113        break;
114      case 'v': /* verbose */
115        verbose = true;
116        break;
117      default:
118        printf( pcmmio_irq_usage, argv[0] );
119        return -1;
120    }
121  }
122
123  /*
124   *  Did they select one item and ONLY one item?
125   */
126  selected = 0;
127  if ( do_din == true ) selected++;
128  if ( do_dac == true ) selected++;
129  if ( do_adc == true ) selected++;
130
131  if ( selected == 0 ) {
132    puts( "No IRQ Sources selected" );
133    return -1;
134  }
135
136  if ( selected > 1 ) {
137    puts( "More than 1 IRQ Sources selected" );
138    return -1;
139  }
140
141  if ( do_din == true ) {
142    irq = "DIN";
143  } else if ( do_dac == true ) {
144    irq = "DAC";
145  } else if ( do_adc == true ) {
146    irq = "ADC";
147  }
148  if ( maximum != 1 )
149    printf(
150      "Polling for %s IRQ for %d iterations with %d msec period\n",
151      irq,
152      maximum,
153      milliseconds
154    );
155
156  /*
157   *  Now sample in the loop
158   */
159  changed = false;
160
161  iterations = 1;
162  while (1) {
163   
164    if ( do_din == true ) {
165      sc = wait_dio_int_with_timeout(milliseconds);
166    } else if ( do_dac == true ) {
167      sc = wait_dac_int_with_timeout(dac, milliseconds);
168    } else if ( do_adc == true ) {
169      sc = wait_dac_int_with_timeout(adc, milliseconds);
170    }
171
172    #ifdef TESTING
173      fprintf( stderr, "%d ", sc );
174    #endif
175    if (iterations++ >= maximum )
176      break;
177
178  }
179  fprintf( stderr, "\n" );
180  return 0;
181}
182
183rtems_shell_cmd_t Shell_PCMMIO_IRQ_Command = {
184  "pcmmio_irq",                                    /* name */
185  "Wait for PCMMIO Interrupts",                    /* usage */
186  "pcmmio",                                        /* topic */
187  main_pcmmio_irq,                                 /* command */
188  NULL,                                            /* alias */
189  NULL                                             /* next */
190};
Note: See TracBrowser for help on using the repository browser.