source: rtems/tools/schedsim/shell/shared/main_taskcreate.c @ b467831a

4.115
Last change on this file since b467831a was b467831a, checked in by Joel Sherrill <joel.sherrill@…>, on 04/07/11 at 18:12:41

2011-04-07 Joel Sherrill <joel.sherrill@…>

  • shared/main_clocktick.c, shared/main_semcreate.c, shared/main_semdelete.c, shared/main_semflush.c, shared/main_semobtain.c, shared/main_semrelease.c, shared/main_taskcreate.c, shared/main_taskdelete.c, shared/main_taskmode.c, shared/main_taskpriority.c, shared/main_taskresume.c, shared/main_tasksuspend.c, shared/main_taskwakeafter.c, shared/schedsim_shell.h: Compiles now and do not core dump when RTEMS is not initialized.
  • Property mode set to 100644
File size: 2.2 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#include <rtems.h>
21#include "shell.h"
22#include <rtems/stringto.h>
23#include <schedsim_shell.h>
24#include <rtems/error.h>
25
26rtems_task dummy_task(
27  rtems_task_argument arg
28)
29{
30}
31
32int rtems_shell_main_task_create(
33  int   argc,
34  char *argv[]
35)
36{
37  char               name[5];
38  rtems_id           id;
39  rtems_status_code  status;
40  long               priority;
41 
42  CHECK_RTEMS_IS_UP();
43
44  if (argc != 3) {
45    fprintf( stderr, "%s: Usage name priority\n", argv[0] );
46    return -1;
47  }
48
49  if ( rtems_string_to_long(argv[2], &priority, NULL, 0) ) {
50    printf( "Seconds argument (%s) is not a number\n", argv[1] );
51    return -1;
52  }
53
54  /*
55   *  Now create the task
56   */
57  memset( name, '\0', sizeof(name) );
58  strncpy( name, argv[1], 4 );
59
60  status = rtems_task_create(
61    rtems_build_name( name[0], name[1], name[2], name[3] ),
62    (rtems_task_priority) priority,
63    RTEMS_MINIMUM_STACK_SIZE,
64    RTEMS_DEFAULT_MODES,
65    RTEMS_DEFAULT_ATTRIBUTES,
66    &id
67  );
68  if ( status ) {
69    fprintf(
70      stderr,
71      "Task Create(%s) returned %s\n",
72      argv[1],
73      rtems_status_text( status )
74    );
75    return -1;
76  }
77
78  printf(
79    "Task (%s) created: id=0x%08x, priority=%ld\n",
80    argv[1],
81    id,
82    priority
83  );
84 
85  printf(
86    "Task (%s) starting: id=0x%08x, priority=%ld\n",
87    argv[1],
88    id,
89    priority
90  );
91
92  status = rtems_task_start( id, dummy_task, 1 );
93  if ( status ) {
94    fprintf(
95      stderr,
96      "Task Start(%s) returned %s\n",
97      argv[1],
98      rtems_status_text( status )
99    );
100    return -1;
101  }
102
103  return 0;
104}
105
106rtems_shell_cmd_t rtems_shell_TASK_CREATE_Command = {
107  "task_create",                 /* name */
108  "task_create name priority",   /* usage */
109  "rtems",                       /* topic */
110  rtems_shell_main_task_create,  /* command */
111  NULL,                          /* alias */
112  NULL                           /* next */
113};
Note: See TracBrowser for help on using the repository browser.