source: rtems-schedsim/schedsim/shell/shared/main_taskcreate.c @ 40cadee

Last change on this file since 40cadee was ac6e5c7, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/11 at 19:31:16

2011-05-17 Joel Sherrill <joel.sherrill@…>

  • Makefile.am: Merge and update code. Simulators for Deterministic Priority and SMP Simple Schedulers now work.
  • run_scenarios: New file.
  • Property mode set to 100644
File size: 3.5 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#include <stdio.h>
19
20#define __need_getopt_newlib
21#include <newlib/getopt.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
29static void print_mode(
30  const char *prefix,
31  rtems_mode  mode
32)
33{
34  printf(
35    "%sPreemption: %s Timeslicing: %s\n",
36    prefix,
37    ((mode & RTEMS_NO_PREEMPT) ? "no" : "yes"),
38    ((mode & RTEMS_TIMESLICE) ? "yes" : "no")
39  );
40}
41
42rtems_task dummy_task(
43  rtems_task_argument arg
44)
45{
46}
47
48int rtems_shell_main_task_create(
49  int   argc,
50  char *argv[]
51)
52{
53  char               name[5];
54  rtems_id           id;
55  rtems_status_code  status;
56  long               priority;
57  rtems_mode         mode;
58  rtems_mode         mask;
59  struct getopt_data getopt_reent;
60  char               option;
61  int                arg;
62 
63  CHECK_RTEMS_IS_UP();
64
65  mode = 0;
66  mask = 0;
67  memset(&getopt_reent, 0, sizeof(getopt_data));
68  while ( (option = getopt_r( argc, argv, "tTpP", &getopt_reent)) != -1 ) {
69    switch (option) {
70      case 't':
71        mask |= RTEMS_TIMESLICE_MASK;
72        mode  = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_NO_TIMESLICE;
73        break;
74      case 'T':
75        mask |= RTEMS_TIMESLICE_MASK;
76        mode  = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE;
77        break;
78      case 'p':
79        mask |= RTEMS_PREEMPT_MASK;
80        mode  = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_NO_PREEMPT;
81        break;
82      case 'P':
83        mask |= RTEMS_PREEMPT_MASK;
84        mode  = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_PREEMPT;
85        break;
86      default:
87        fprintf( stderr, "%s: Usage [-tTpP]\n", argv[0] );
88        return -1;
89    }
90  }
91
92  print_mode( "Creating task with:  ", mode );
93
94  /*
95   *  Rest of arguments
96   */
97  arg = getopt_reent.optind;
98  if ((argc - arg) != 2) {
99    fprintf( stderr, "%s: Usage [args] name priority\n", argv[0] );
100    return -1;
101  }
102
103  if ( rtems_string_to_long(argv[arg+1], &priority, NULL, 0) ) {
104    printf( "Seconds argument (%s) is not a number\n", argv[1] );
105    return -1;
106  }
107
108  /*
109   *  Now create the task
110   */
111  memset( name, '\0', sizeof(name) );
112  strncpy( name, argv[arg], 4 );
113
114  status = rtems_task_create(
115    rtems_build_name( name[0], name[1], name[2], name[3] ),
116    (rtems_task_priority) priority,
117    RTEMS_MINIMUM_STACK_SIZE,
118    mode,
119    RTEMS_DEFAULT_ATTRIBUTES,
120    &id
121  );
122  if ( status ) {
123    fprintf(
124      stderr,
125      "Task Create(%s) returned %s\n",
126      name,
127      rtems_status_text( status )
128    );
129    return -1;
130  }
131
132  printf(
133    "Task (%s) created: id=0x%08x, priority=%ld\n",
134    name,
135    id,
136    priority
137  );
138 
139  printf(
140    "Task (%s) starting: id=0x%08x, priority=%ld\n",
141    name,
142    id,
143    priority
144  );
145
146  status = rtems_task_start( id, dummy_task, 1 );
147  if ( status ) {
148    fprintf(
149      stderr,
150      "Task Start(%s) returned %s\n",
151      name,
152      rtems_status_text( status )
153    );
154    return -1;
155  }
156
157  return 0;
158}
159
160rtems_shell_cmd_t rtems_shell_TASK_CREATE_Command = {
161  "task_create",                 /* name */
162  "task_create name priority",   /* usage */
163  "rtems",                       /* topic */
164  rtems_shell_main_task_create,  /* command */
165  NULL,                          /* alias */
166  NULL                           /* next */
167};
Note: See TracBrowser for help on using the repository browser.