1 | /* |
---|
2 | * Task Delete 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 | #define __need_getopt_newlib |
---|
17 | #include <newlib/getopt.h> |
---|
18 | |
---|
19 | #include <stdio.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 | |
---|
27 | static 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 | |
---|
40 | int rtems_shell_main_task_mode( |
---|
41 | int argc, |
---|
42 | char *argv[] |
---|
43 | ) |
---|
44 | { |
---|
45 | rtems_status_code status; |
---|
46 | rtems_mode mode; |
---|
47 | rtems_mode mask; |
---|
48 | rtems_mode old; |
---|
49 | struct getopt_data getopt_reent; |
---|
50 | char option; |
---|
51 | |
---|
52 | CHECK_RTEMS_IS_UP(); |
---|
53 | |
---|
54 | mode = 0; |
---|
55 | mask = 0; |
---|
56 | memset(&getopt_reent, 0, sizeof(getopt_data)); |
---|
57 | while ( (option = getopt_r( argc, argv, "tTpP", &getopt_reent)) != -1 ) { |
---|
58 | switch (option) { |
---|
59 | case 't': |
---|
60 | mask |= RTEMS_TIMESLICE_MASK; |
---|
61 | mode = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_NO_TIMESLICE; |
---|
62 | break; |
---|
63 | case 'T': |
---|
64 | mask |= RTEMS_TIMESLICE_MASK; |
---|
65 | mode = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE; |
---|
66 | break; |
---|
67 | case 'p': |
---|
68 | mask |= RTEMS_PREEMPT_MASK; |
---|
69 | mode = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_NO_PREEMPT; |
---|
70 | break; |
---|
71 | case 'P': |
---|
72 | mask |= RTEMS_PREEMPT_MASK; |
---|
73 | mode = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_PREEMPT; |
---|
74 | break; |
---|
75 | default: |
---|
76 | fprintf( stderr, "%s: Usage [-tTpP]\n", argv[0] ); |
---|
77 | return -1; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | /* |
---|
82 | * Now change the task mode |
---|
83 | */ |
---|
84 | status = rtems_task_mode( mode, mask, &old ); |
---|
85 | if ( status != RTEMS_SUCCESSFUL ) { |
---|
86 | fprintf( |
---|
87 | stderr, |
---|
88 | "Task Mode returned %s\n", |
---|
89 | rtems_status_text( status ) |
---|
90 | ); |
---|
91 | return -1; |
---|
92 | } |
---|
93 | |
---|
94 | print_mode( "Previous Mode: ", old ); |
---|
95 | if ( mask ) { |
---|
96 | (void) rtems_task_mode( RTEMS_CURRENT_MODE , RTEMS_CURRENT_MODE, &old ); |
---|
97 | print_mode( "Current Mode: ", mode ); |
---|
98 | } |
---|
99 | |
---|
100 | return 0; |
---|
101 | } |
---|
102 | |
---|
103 | rtems_shell_cmd_t rtems_shell_TASK_MODE_Command = { |
---|
104 | "task_mode", /* name */ |
---|
105 | "task_mode [-tTpP]", /* usage */ |
---|
106 | "rtems", /* topic */ |
---|
107 | rtems_shell_main_task_mode, /* command */ |
---|
108 | NULL, /* alias */ |
---|
109 | NULL /* next */ |
---|
110 | }; |
---|