source: rtems/tools/schedsim/shell/shared/main_taskmode.c @ abff6d2

4.115
Last change on this file since abff6d2 was abff6d2, checked in by Joel Sherrill <joel.sherrill@…>, on 12/17/10 at 14:49:40

2010-12-17 Joel Sherrill <joel.sherrill@…>

Jennifer Averett <jennifer.averett@…>

Add RTEMS Scheduler Simulator. This is the shell scripting portion.

  • .cvsignore, ChangeLog?, Makefile.am, schedsim_priority/.cvsignore, schedsim_priority/Makefile.am, schedsim_priority/config.c, schedsim_priority/printheir_executing.c, schedsim_priority/schedsim.cc, schedsim_priority/wrap_thread_dispatch.c, scripts/script01, scripts/script02, scripts/script03, scripts/script04, scripts/script05, scripts/script06, shared/.cvsignore, shared/Makefile.am, shared/commands.c, shared/getopt.c, shared/lookup_semaphore.c, shared/lookup_task.c, shared/main_clocktick.c, shared/main_echo.c, shared/main_executing.c, shared/main_heir.c, shared/main_help.c, shared/main_rtemsinit.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, shared/shell_cmdset.c, shared/shell_makeargs.c, shared/include/shell.h, shared/include/newlib/_ansi.h, shared/include/newlib/getopt.h: New files.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  Task Delete 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
29void print_mode(
30  const char *prefix,
31  rtems_mode  mode
32)
33{
34  fprintf(
35    stderr,
36    "%sPreemption: %s Timeslicing: %s\n",
37    prefix,
38    ((mode & RTEMS_NO_PREEMPT) ? "no" : "yes"),
39    ((mode & RTEMS_TIMESLICE) ? "yes" : "no")
40  );
41}
42
43int rtems_shell_main_task_mode(
44  int   argc,
45  char *argv[]
46)
47{
48  rtems_status_code  status;
49  rtems_mode         mode;
50  rtems_mode         mask;
51  rtems_mode         old;
52  struct getopt_data getopt_reent;
53  char               option;
54
55  mode = 0;
56  mask = 0;
57  memset(&getopt_reent, 0, sizeof(getopt_data));
58  while ( (option = getopt_r( argc, argv, "tTpP", &getopt_reent)) != -1 ) {
59    switch (option) {
60      case 't':
61        mask |= RTEMS_TIMESLICE_MASK;
62        mode  = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_NO_TIMESLICE;
63        break;
64      case 'T':
65        mask |= RTEMS_TIMESLICE_MASK;
66        mode  = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE;
67        break;
68      case 'p':
69        mask |= RTEMS_PREEMPT_MASK;
70        mode  = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_NO_PREEMPT;
71        break;
72      case 'P':
73        mask |= RTEMS_PREEMPT_MASK;
74        mode  = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_PREEMPT;
75        break;
76      default:
77        fprintf( stderr, "%s: Usage [-tTpP]\n", argv[0] );
78        return -1;
79    }
80  }
81
82  /*
83   *  Now change the task mode
84   */
85  status = rtems_task_mode( mode, mask, &old );
86  if ( status != RTEMS_SUCCESSFUL ) {
87    fprintf(
88      stderr,
89      "Task Mode returned %s\n",
90      rtems_status_text( status )
91    );
92    return -1;
93  }
94
95  print_mode( "Previous Mode: ", old );
96  if ( mask ) {
97    (void) rtems_task_mode( RTEMS_CURRENT_MODE ,  RTEMS_CURRENT_MODE, &old );
98    print_mode( "Current Mode:  ", mode );
99  }
100 
101  return 0;
102}
103
104rtems_shell_cmd_t rtems_shell_TASK_MODE_Command = {
105  "task_mode",                     /* name */
106  "task_mode [-tTpP]",             /* usage */
107  "rtems",                         /* topic */
108  rtems_shell_main_task_mode,      /* command */
109  NULL,                            /* alias */
110  NULL                             /* next */
111};
Note: See TracBrowser for help on using the repository browser.