source: rtems-schedsim/schedsim/shell/shared/main_semcreate.c @ abb18dc

base initial
Last change on this file since abb18dc was abb18dc, checked in by Joel Sherrill <joel.sherrill@…>, on 04/25/11 at 15:53:10

Initial import.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  Task Create Shell Command Implmentation
3 *
4 *  COPYRIGHT (c) 1989-2010.
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#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#define __need_getopt_newlib
19#include <newlib/getopt.h>
20
21#include <stdio.h>
22
23#include <rtems.h>
24#include "shell.h"
25#include <rtems/stringto.h>
26#include <schedsim_shell.h>
27#include <rtems/error.h>
28
29int rtems_shell_main_semaphore_create(
30  int   argc,
31  char *argv[]
32)
33{
34  char                 name[5];
35  rtems_id             id;
36  rtems_status_code    status;
37  long                 tmp;
38  rtems_task_priority  ceiling;
39  rtems_attribute      attr;
40  struct getopt_data   getopt_reent;
41  char                 option;
42  int                  value;
43
44  CHECK_RTEMS_IS_UP();
45
46  ceiling = 0;
47  attr    = RTEMS_DEFAULT_ATTRIBUTES;
48  value   = 0;
49
50  memset(&getopt_reent, 0, sizeof(getopt_data));
51  while ( (option = getopt_r( argc, argv, "bcsfpiC:V:", &getopt_reent)) != -1 ) {
52    switch (option) {
53       case 'b': attr |= RTEMS_BINARY_SEMAPHORE;   break;
54       case 'c': attr |= RTEMS_COUNTING_SEMAPHORE; break;
55       case 's': attr |= RTEMS_SIMPLE_BINARY_SEMAPHORE; break;
56
57       case 'f': attr |= RTEMS_FIFO; break;
58       case 'p': attr |= RTEMS_PRIORITY; break;
59
60       case 'i': attr |= RTEMS_INHERIT_PRIORITY; break;
61       case 'C':
62         attr |= RTEMS_PRIORITY_CEILING;
63         if ( rtems_string_to_long(getopt_reent.optarg, &tmp, NULL, 0) ) {
64           printf( "Ceiling argument (%s) is not a number\n", argv[1] );
65           return -1;
66         }
67         ceiling = tmp;
68         break;
69
70       case 'V':
71         if ( rtems_string_to_long(getopt_reent.optarg, &tmp, NULL, 0) ) {
72           printf( "Ceiling argument (%s) is not a number\n", argv[1] );
73           return -1;
74         }
75         value = tmp;
76         break;
77
78       default:
79         fprintf( stderr, "%s: Usage [-bcsfpiC:V:] name\n", argv[0] );
80         return -1;
81     }
82  }
83
84  if ( getopt_reent.optind >= argc ) {
85    fprintf( stderr, "No name specified\n" );
86    return -1;
87  }
88
89  /*
90   *  Now create the semaphore
91   */
92  memset( name, '\0', sizeof(name) );
93  strncpy( name, argv[getopt_reent.optind], 4 );
94
95  status = rtems_semaphore_create(
96    rtems_build_name( name[0], name[1], name[2], name[3] ),
97    value,
98    attr,
99    ceiling,
100    &id
101  );
102  if ( status ) {
103    fprintf(
104      stderr,
105      "Semaphore create(%s) returned %s\n",
106      argv[1],
107      rtems_status_text( status )
108    );
109    return -1;
110  }
111
112  printf( "Semaphore (%s) created: id=0x%08x\n", argv[1], id );
113 
114  return 0;
115}
116
117rtems_shell_cmd_t rtems_shell_SEMAPHORE_CREATE_Command = {
118  "semaphore_create",                 /* name */
119  "semaphore_create name priority",   /* usage */
120  "rtems",                            /* topic */
121  rtems_shell_main_semaphore_create,  /* command */
122  NULL,                               /* alias */
123  NULL                                /* next */
124};
Note: See TracBrowser for help on using the repository browser.