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

Last change on this file since a2aad55 was a2aad55, checked in by Joel Sherrill <joel.sherrill@…>, on 05/01/13 at 00:41:56

Remove CVS $

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