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 | |
---|
29 | void 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 | |
---|
43 | int 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 | CHECK_RTEMS_IS_UP(); |
---|
56 | |
---|
57 | mode = 0; |
---|
58 | mask = 0; |
---|
59 | memset(&getopt_reent, 0, sizeof(getopt_data)); |
---|
60 | while ( (option = getopt_r( argc, argv, "tTpP", &getopt_reent)) != -1 ) { |
---|
61 | switch (option) { |
---|
62 | case 't': |
---|
63 | mask |= RTEMS_TIMESLICE_MASK; |
---|
64 | mode = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_NO_TIMESLICE; |
---|
65 | break; |
---|
66 | case 'T': |
---|
67 | mask |= RTEMS_TIMESLICE_MASK; |
---|
68 | mode = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE; |
---|
69 | break; |
---|
70 | case 'p': |
---|
71 | mask |= RTEMS_PREEMPT_MASK; |
---|
72 | mode = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_NO_PREEMPT; |
---|
73 | break; |
---|
74 | case 'P': |
---|
75 | mask |= RTEMS_PREEMPT_MASK; |
---|
76 | mode = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_PREEMPT; |
---|
77 | break; |
---|
78 | default: |
---|
79 | fprintf( stderr, "%s: Usage [-tTpP]\n", argv[0] ); |
---|
80 | return -1; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | /* |
---|
85 | * Now change the task mode |
---|
86 | */ |
---|
87 | status = rtems_task_mode( mode, mask, &old ); |
---|
88 | if ( status != RTEMS_SUCCESSFUL ) { |
---|
89 | fprintf( |
---|
90 | stderr, |
---|
91 | "Task Mode returned %s\n", |
---|
92 | rtems_status_text( status ) |
---|
93 | ); |
---|
94 | return -1; |
---|
95 | } |
---|
96 | |
---|
97 | print_mode( "Previous Mode: ", old ); |
---|
98 | if ( mask ) { |
---|
99 | (void) rtems_task_mode( RTEMS_CURRENT_MODE , RTEMS_CURRENT_MODE, &old ); |
---|
100 | print_mode( "Current Mode: ", mode ); |
---|
101 | } |
---|
102 | |
---|
103 | return 0; |
---|
104 | } |
---|
105 | |
---|
106 | rtems_shell_cmd_t rtems_shell_TASK_MODE_Command = { |
---|
107 | "task_mode", /* name */ |
---|
108 | "task_mode [-tTpP]", /* usage */ |
---|
109 | "rtems", /* topic */ |
---|
110 | rtems_shell_main_task_mode, /* command */ |
---|
111 | NULL, /* alias */ |
---|
112 | NULL /* next */ |
---|
113 | }; |
---|