source: multiio/commands/main_multiio_dout.c @ 0ecf946

Last change on this file since 0ecf946 was e38d987, checked in by Joel Sherrill <joel.sherrill@…>, on 03/18/11 at 13:19:33

2011-03-18 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, Makefile, commands/Makefile, commands/main_multiio_adc.c, commands/main_multiio_benchmark.c, commands/main_multiio_dac.c, commands/main_multiio_din.c, commands/main_multiio_dout.c, commands/main_multiio_irq.c, commands/multiio_commands.h, include/multiio.h, stub/multio_stub.c: New files.
  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[e38d987]1/*
2 *  dout 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 <stdio.h>
15#include <stdlib.h>
16#include <rtems.h>
17#include <rtems/shell.h>
18#include <rtems/stringto.h>
19#include "multiio.h"
20
21static char dout_usage[] =
22  "Usage: %s bit value\n"
23  "Where: bit must be 0-%d\n"
24  "       value must be 0 or 1\n";
25
26#define PRINT_USAGE() \
27   printf( dout_usage, argv[0], maximum )
28
29int main_multiio_dout(int argc, char **argv)
30{
31  int    bit;
32  int    value;
33  bool   fail = false;
34  int    maximum = rtems_dout_get_maximum();
35
36  /*
37   *  Verify that we have the right number of arguments.
38   */
39  if ( argc != 3 ) {
40    printf( "Incorrect number of arguments\n" );
41    PRINT_USAGE();
42    return -1;
43  }
44
45  /*
46   *  Convert the string arguments into number values
47   */
48  if ( rtems_string_to_int( argv[1], &bit, NULL, 0 ) ) {
49    printf( "Bit (%s) is not a number\n", argv[1] );
50    fail = true;
51  }
52
53  if ( rtems_string_to_int(argv[2], &value, NULL, 0) ) {
54    printf( "Value (%s) is not a number\n", argv[2] );
55    fail = true;
56  }
57
58  /*
59   *  Validate the output bit and value.
60   */
61  if ( bit < 0 || bit > maximum ) {
62    printf( "Bit number must be 0-maximum\n" );
63    fail = true;
64  }
65
66  if ( value != 0 && value != 1 ) {
67    printf( "Value must be 0 or 1\n" );
68    fail = true;
69  }
70
71  if ( fail ) {
72    PRINT_USAGE();
73    return -1;
74  }
75
76  /*
77   *  Now write the value
78   */
79  printf( "Write %d to to bit %d\n", value, bit );
80  rtems_set_dout(bit, value);
81
82  return 0;
83}
84
85rtems_shell_cmd_t Shell_MULTIIO_DOUT_Command = {
86  "multiio_dout",                           /* name */
87  "Write Discrete Outputs",                 /* usage */
88  "multiio",                                /* topic */
89  main_multiio_dout,                        /* command */
90  NULL,                                     /* alias */
91  NULL                                      /* next */
92};
93
94rtems_shell_alias_t Shell_MULTIIO_DOUT_Alias = {
95  "multiio_dout",         /* command */
96  "dout"                  /* alias */
97};
Note: See TracBrowser for help on using the repository browser.