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

Jennifer Averett <jennifer.averett@oarcorp.com>

	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.
This commit is contained in:
Joel Sherrill
2010-12-17 14:49:40 +00:00
parent 9f8115f90a
commit abff6d226a
45 changed files with 3253 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@@ -0,0 +1,26 @@
2010-12-17 Joel Sherrill <joel.sherrill@oarcorp.com>
Jennifer Averett <jennifer.averett@oarcorp.com>
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.

View File

@@ -0,0 +1,12 @@
##
## $Id$
##
ACLOCAL_AMFLAGS = -I ../../aclocal
SUBDIRS = shared schedsim_priority
DIST_SUBDIRS = shared schedsim_priority
include $(top_srcdir)/../../automake/subdirs.am
include $(top_srcdir)/../../automake/host.am

View File

@@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@@ -0,0 +1,32 @@
##
## $Id$
##
bin_PROGRAMS = schedsim
schedsim_SOURCES = config.c \
schedsim.cc wrap_thread_dispatch.c printheir_executing.c
cpukitdir=$(srcdir)/../../../../cpukit
schedsim_CPPFLAGS = -I$(srcdir)/sched_cpu
schedsim_CPPFLAGS += -I$(srcdir)/../../rtems
schedsim_CPPFLAGS += -I$(cpukitdir)/include
schedsim_CPPFLAGS += -I$(cpukitdir)/score/include
schedsim_CPPFLAGS += -I$(cpukitdir)/score/inline
schedsim_CPPFLAGS += -I$(cpukitdir)/rtems/include
schedsim_CPPFLAGS += -I$(cpukitdir)/rtems/inline
schedsim_CPPFLAGS += -I$(cpukitdir)/sapi/include
schedsim_CPPFLAGS += -I$(cpukitdir)/sapi/inline
schedsim_CPPFLAGS += -I$(cpukitdir)/libcsupport/include
schedsim_CPPFLAGS += -I$(cpukitdir)/libmisc/stringto
schedsim_CPPFLAGS += -I$(srcdir)/../../rtems/sched_cpu
schedsim_CPPFLAGS += -I$(srcdir)/../shared/include
schedsim_CPPFLAGS += -I$(srcdir)/../shared
schedsim_LDFLAGS =-Wl,--wrap=_Thread_Dispatch
## schedsim_LDADD +=-Wl,--start-group
schedsim_LDADD = ../shared/libschedsim.a
schedsim_LDADD += ../../rtems/librtems.a
schedsim_LDADD += ../shared/libschedsim.a
## schedsim_LDADD +=-Wl,--end-group
include $(top_srcdir)/../../automake/host.am

View File

@@ -0,0 +1,7 @@
#include <rtems.h>
#define CONFIGURE_INIT
#define CONFIGURE_MAXIMUM_TASKS 1000
#define CONFIGURE_MAXIMUM_SEMAPHORES 1000
#include <confdefs.h>

View File

@@ -0,0 +1,31 @@
/*
* printheir_executing
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#include <stdio.h>
#include <rtems.h>
void PRINT_EXECUTING() {
printf(
" Thread Executing: 0x%08x priority=%ld\n",
_Thread_Executing->Object.id,
(long) _Thread_Executing->current_priority
);
}
void PRINT_HEIR() {
printf(
" Thread Heir: 0x%08x priority=%ld\n",
_Thread_Heir->Object.id,
(long) _Thread_Heir->current_priority
);
}

View File

@@ -0,0 +1,169 @@
/*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#include <newlib/getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "shell.h"
#include "rtems_sched.h"
/*
* Variables to control global behavior
*/
int verbose = 0;
const char *progname;
const char *scriptname;
FILE *Script;
int ScriptFileLine = 0;
/*
* Print program usage message
*/
void usage()
{
fprintf(
stderr,
"Usage: %s [-v] script\n"
"\n"
" -v - enable verbose output\n",
progname
);
exit( -1 );
}
#define RTEMS_SHELL_MAXIMUM_ARGUMENTS (128)
void ProcessScript(
FILE *script
)
{
char buffer[512];
char *cStatus;
char *c;
size_t length;
int argc;
char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS];
rtems_shell_cmd_t *shell_cmd;
while ( 1 ) {
cStatus = fgets( buffer, sizeof(buffer), script );
if ( cStatus == NULL )
break;
// If the last line does not have a CR, then we don't want to
// arbitrarily clobber an = instead of a \n.
length = strlen(buffer);
if ( buffer[ length - 1] == '\n' )
buffer[ length - 1] = '\0';
if ( verbose )
fprintf( stderr, "%d: %s\n", ++ScriptFileLine, buffer );
if ( buffer[0] == '#' )
continue;
for ( c = buffer ; *c ; c++ ) {
if (!isblank((int)*c))
break;
}
if (!strcmp(c,"bye") || !strcmp(c,"exit")) {
return;
}
if (rtems_shell_make_args(c, &argc, argv, RTEMS_SHELL_MAXIMUM_ARGUMENTS)) {
fprintf(stderr, "Error parsing arguments\n" );
continue;
}
shell_cmd = rtems_shell_lookup_cmd(argv[0]);
if ( !shell_cmd ) {
fprintf(stderr, "%s is unknown command\n", c );
continue;
}
shell_cmd->command(argc, argv);
}
}
int main(
int argc,
char **argv
)
{
int opt;
progname = argv[0];
while ((opt = getopt(argc, argv, "v")) != -1) {
switch (opt) {
case 'v': verbose = 1; break;
default: /* '?' */
usage();
}
}
if ( optind >= argc ) {
fprintf( stderr, "no script to process\n" );
usage();
}
scriptname = argv[ optind ];
if ( verbose ) {
fprintf(
stderr,
"Script File : %s\n"
"verbose : %d\n",
scriptname,
verbose
);
}
//
// Initialize the command interpreter
//
rtems_shell_initialize_command_set();
//
// Open the script file
//
Script = fopen( scriptname, "r" );
if ( !Script ) {
fprintf( stderr, "Unable to open script file (%s)\n", scriptname );
exit( -1 );
}
//
// Process the Script
//
ProcessScript( Script );
//
// Open the script file
//
(void) fclose( Script );
//
// Just in case something throws
//
try {
} catch (...) {
exit(-1);
}
return 0;
}

View File

@@ -0,0 +1,42 @@
/*
* Thread Dispatch Wrapper Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#include "shell.h"
#include <schedsim_shell.h>
#include <stdio.h>
#include <rtems.h>
Thread_Control *last_heir = NULL;
Thread_Control *last_executing = NULL;
extern void __real__Thread_Dispatch(void);
void check_heir_and_executing(void)
{
if ( last_heir != _Thread_Heir )
PRINT_HEIR();
if ( last_executing != _Thread_Executing )
PRINT_EXECUTING();
last_heir = _Thread_Heir;
last_executing = _Thread_Executing;
}
void __wrap__Thread_Dispatch(void)
{
check_heir_and_executing();
__real__Thread_Dispatch();
check_heir_and_executing();
}

View File

@@ -0,0 +1,11 @@
echo "*** TEST 01 ***"
rtems_init
echo "=== Create and delete 0x0a010001 ==="
task_create TA1 3
task_delete TA1
echo "=== Create and delete 0x0a010002 ==="
task_create TA1 3
task_delete 0x0a010002
echo "*** END OF TEST 01 ***"
exit
# We will not get here

View File

@@ -0,0 +1,9 @@
echo "*** TEST 02 ***"
rtems_init
echo "=== Create 0x0a010001 ==="
task_create TA1 1
task_wake_after 5
clock_tick 7
echo "*** END OF TEST 2 ***"
exit
# We will not get here

View File

@@ -0,0 +1,19 @@
echo "*** TEST 03 ***"
rtems_init
echo "=== Create 0x0a010001 ==="
task_create TA1 1
echo "** Mode - query"
task_mode
echo "** Mode - set no timeslicing"
task_mode -t
echo "** Mode - set timeslicing"
task_mode -T
echo "** Mode - set no timeslicing and no preempt"
task_mode -t -p
echo "** Mode - set timeslicing and preempt"
task_mode -T -P
echo "** Mode - query"
task_mode
echo "*** END OF TEST 03 ***"
exit
# We will not get here

View File

@@ -0,0 +1,10 @@
echo "*** TEST 04 ***"
rtems_init
echo Create 0x0a010001
task_create TA1 1
task_suspend TA1
task_create TA1 2
task_resume TA1
echo "*** END OF TEST 04 ***"
exit
# We will not get here

View File

@@ -0,0 +1,22 @@
echo "*** TEST 05 ***"
rtems_init
echo Create 0x0a010001
task_create TA1 1
task_create TA2 2
task_create TA3 3
semaphore_create SEM1
semaphore_obtain SEM1 0
semaphore_obtain SEM1 0
semaphore_obtain SEM1 0
semaphore_flush SEM1
echo "*** Now back to TA1 to do it differently"
semaphore_obtain SEM1 0
semaphore_obtain SEM1 0
semaphore_release SEM1
# as TA1
semaphore_obtain SEM1 0
semaphore_delete SEM1
# should preempt
echo "*** END OF TEST 05 ***"
exit
# We will not get here

View File

@@ -0,0 +1,14 @@
echo "*** TEST 06 ***"
rtems_init
echo Create 0x0a010001
task_create TA1 1
task_create TA2 2
task_create TA3 3
semaphore_create SEM1
semaphore_obtain SEM1 0
semaphore_obtain SEM1 0
semaphore_release SEM1
semaphore_delete SEM1
echo "*** END OF TEST 06 ***"
exit
# We will not get here

View File

@@ -0,0 +1,2 @@
Makefile
Makefile.in

View File

@@ -0,0 +1,61 @@
##
## $Id$
##
ACLOCAL_AMFLAGS = -I ../../../aclocal
lib_LIBRARIES = libschedsim.a
cpukitdir=$(srcdir)/../../../../cpukit
libschedsim_a_CPPFLAGS = -D__RTEMS_VIOLATE_KERNEL_VISIBILITY__
libschedsim_a_CPPFLAGS += -I$(srcdir)/sched_cpu
libschedsim_a_CPPFLAGS += -I$(srcdir)/../../rtems
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/include
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/score/include
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/score/inline
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/rtems/include
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/rtems/inline
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/sapi/include
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/sapi/inline
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/libcsupport/include
libschedsim_a_CPPFLAGS += -I$(cpukitdir)/libmisc/stringto
libschedsim_a_CPPFLAGS += -I$(srcdir)/../../rtems/sched_cpu
libschedsim_a_CPPFLAGS += -I$(srcdir)/include
libschedsim_a_SOURCES = \
commands.c \
getopt.c \
lookup_semaphore.c \
lookup_task.c \
main_echo.c \
main_executing.c \
main_heir.c \
main_help.c \
main_rtemsinit.c \
main_clocktick.c \
main_semcreate.c \
main_semdelete.c \
main_semflush.c \
main_semobtain.c \
main_semrelease.c \
main_taskcreate.c \
main_taskdelete.c \
main_taskmode.c \
main_taskpriority.c \
main_taskresume.c \
main_tasksuspend.c \
main_taskwakeafter.c \
shell_cmdset.c \
shell_makeargs.c
schedsim_shell_includedir = $(includedir)/schedsim
schedsim_newlib_includedir = $(includedir)/schedsim/newlib
schedsim_shell_include_HEADERS = include/shell.h schedsim_shell.h
schedsim_newlib_include_HEADERS = \
include/newlib/getopt.h \
include/newlib/_ansi.h
include $(top_srcdir)/../../automake/host.am

View File

@@ -0,0 +1,73 @@
/*
* BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#include "shell.h"
#include <stdio.h>
extern rtems_shell_cmd_t rtems_shell_ECHO_Command;
extern rtems_shell_cmd_t rtems_shell_HELP_Command;
extern rtems_shell_cmd_t rtems_shell_RTEMS_INIT_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_CREATE_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_DELETE_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_MODE_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_PRIORITY_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_SUSPEND_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_RESUME_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_WAKE_AFTER_Command;
extern rtems_shell_cmd_t rtems_shell_CLOCK_TICK_Command;
extern rtems_shell_cmd_t rtems_shell_SEMAPHORE_CREATE_Command;
extern rtems_shell_cmd_t rtems_shell_SEMAPHORE_DELETE_Command;
extern rtems_shell_cmd_t rtems_shell_SEMAPHORE_OBTAIN_Command;
extern rtems_shell_cmd_t rtems_shell_SEMAPHORE_RELEASE_Command;
extern rtems_shell_cmd_t rtems_shell_SEMAPHORE_FLUSH_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_EXECUTING_Command;
extern rtems_shell_cmd_t rtems_shell_TASK_HEIR_Command;
rtems_shell_cmd_t *rtems_shell_Initial_commands[] = {
/* Generic Commands */
&rtems_shell_ECHO_Command,
&rtems_shell_HELP_Command,
/* RTEMS Classic API Type Commands */
&rtems_shell_RTEMS_INIT_Command,
&rtems_shell_TASK_CREATE_Command,
&rtems_shell_TASK_DELETE_Command,
&rtems_shell_TASK_MODE_Command,
&rtems_shell_TASK_PRIORITY_Command,
&rtems_shell_TASK_SUSPEND_Command,
&rtems_shell_TASK_RESUME_Command,
&rtems_shell_TASK_WAKE_AFTER_Command,
&rtems_shell_CLOCK_TICK_Command,
&rtems_shell_SEMAPHORE_CREATE_Command,
&rtems_shell_SEMAPHORE_DELETE_Command,
&rtems_shell_SEMAPHORE_OBTAIN_Command,
&rtems_shell_SEMAPHORE_RELEASE_Command,
&rtems_shell_SEMAPHORE_FLUSH_Command,
/* RTEMS Helper Commands */
&rtems_shell_TASK_EXECUTING_Command,
&rtems_shell_TASK_HEIR_Command,
NULL
};
rtems_shell_alias_t *rtems_shell_Initial_aliases[] = {
NULL
};

View File

@@ -0,0 +1,477 @@
/****************************************************************************
getopt.c - Read command line options
AUTHOR: Gregory Pietsch
CREATED Fri Jan 10 21:13:05 1997
DESCRIPTION:
The getopt() function parses the command line arguments. Its arguments argc
and argv are the argument count and array as passed to the main() function
on program invocation. The argument optstring is a list of available option
characters. If such a character is followed by a colon (`:'), the option
takes an argument, which is placed in optarg. If such a character is
followed by two colons, the option takes an optional argument, which is
placed in optarg. If the option does not take an argument, optarg is NULL.
The external variable optind is the index of the next array element of argv
to be processed; it communicates from one call to the next which element to
process.
The getopt_long() function works like getopt() except that it also accepts
long options started by two dashes `--'. If these take values, it is either
in the form
--arg=value
or
--arg value
It takes the additional arguments longopts which is a pointer to the first
element of an array of type struct option. The last element of the array
has to be filled with NULL for the name field.
The longind pointer points to the index of the current long option relative
to longopts if it is non-NULL.
The getopt() function returns the option character if the option was found
successfully, `:' if there was a missing parameter for one of the options,
`?' for an unknown option character, and EOF for the end of the option list.
The getopt_long() function's return value is described in the header file.
The function getopt_long_only() is identical to getopt_long(), except that a
plus sign `+' can introduce long options as well as `--'.
The following describes how to deal with options that follow non-option
argv-elements.
If the caller did not specify anything, the default is REQUIRE_ORDER if the
environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options; stop option processing
when the first non-option is seen. This is what Unix does. This mode of
operation is selected by either setting the environment variable
POSIXLY_CORRECT, or using `+' as the first character of the optstring
parameter.
PERMUTE is the default. We permute the contents of ARGV as we scan, so that
eventually all the non-options are at the end. This allows options to be
given in any order, even with programs that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were written to
expect options and other argv-elements in any order and that care about the
ordering of the two. We describe each non-option argv-element as if it were
the argument of an option with character code 1. Using `-' as the first
character of the optstring parameter selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless of the
value of ordering. In the case of RETURN_IN_ORDER, only `--' can cause
getopt() and friends to return EOF with optind != argc.
COPYRIGHT NOTICE AND DISCLAIMER:
Copyright (C) 1997 Gregory Pietsch
This file and the accompanying getopt.h header file are hereby placed in the
public domain without restrictions. Just give the author credit, don't
claim you wrote it or prevent anyone else from using it.
Gregory Pietsch's current e-mail address:
gpietsch@comcast.net
****************************************************************************/
/* include files */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <newlib/getopt.h>
/* macros */
#define NO_ARG 0
#define REQUIRED_ARG 1
#define OPTIONAL_ARG 2
/* types */
typedef enum GETOPT_ORDERING_T
{
PERMUTE,
RETURN_IN_ORDER,
REQUIRE_ORDER
} GETOPT_ORDERING_T;
/* globally-defined variables */
char *optarg = 0;
int optind = 0;
int opterr = 1;
int optopt = '?';
/* static variables */
static int optwhere = 0;
/* functions */
/* reverse_argv_elements: reverses num elements starting at argv */
static void
reverse_argv_elements (char **argv, int num)
{
int i;
char *tmp;
for (i = 0; i < (num >> 1); i++)
{
tmp = argv[i];
argv[i] = argv[num - i - 1];
argv[num - i - 1] = tmp;
}
}
/* permute: swap two blocks of argv-elements given their lengths */
static void
permute (char *const argv[], int len1, int len2)
{
reverse_argv_elements ((char **) argv, len1);
reverse_argv_elements ((char **) argv, len1 + len2);
reverse_argv_elements ((char **) argv, len2);
}
/* is_option: is this argv-element an option or the end of the option list? */
static int
is_option (char *argv_element, int only)
{
return ((argv_element == 0)
|| (argv_element[0] == '-') || (only && argv_element[0] == '+'));
}
/* read_globals: read the values from the globals into a getopt_data
structure */
static void
read_globals (struct getopt_data *data)
{
data->optarg = optarg;
data->optind = optind;
data->opterr = opterr;
data->optopt = optopt;
data->optwhere = optwhere;
}
/* write_globals: write the values into the globals from a getopt_data
structure */
static void
write_globals (struct getopt_data *data)
{
optarg = data->optarg;
optind = data->optind;
opterr = data->opterr;
optopt = data->optopt;
optwhere = data->optwhere;
}
/* getopt_internal: the function that does all the dirty work */
static int
getopt_internal (int argc, char *const argv[], const char *shortopts,
const struct option *longopts, int *longind, int only,
struct getopt_data *data)
{
GETOPT_ORDERING_T ordering = PERMUTE;
size_t permute_from = 0;
int num_nonopts = 0;
int optindex = 0;
size_t match_chars = 0;
char *possible_arg = 0;
int longopt_match = -1;
int has_arg = -1;
char *cp = 0;
int arg_next = 0;
/* first, deal with silly parameters and easy stuff */
if (argc == 0 || argv == 0 || (shortopts == 0 && longopts == 0)
|| data->optind >= argc || argv[data->optind] == 0)
return EOF;
if (strcmp (argv[data->optind], "--") == 0)
{
data->optind++;
return EOF;
}
/* if this is our first time through */
if (data->optind == 0)
data->optind = data->optwhere = 1;
/* define ordering */
if (shortopts != 0 && (*shortopts == '-' || *shortopts == '+'))
{
ordering = (*shortopts == '-') ? RETURN_IN_ORDER : REQUIRE_ORDER;
shortopts++;
}
else
ordering = (getenv ("POSIXLY_CORRECT") != 0) ? REQUIRE_ORDER : PERMUTE;
/*
* based on ordering, find our next option, if we're at the beginning of
* one
*/
if (data->optwhere == 1)
{
switch (ordering)
{
default: /* shouldn't happen */
case PERMUTE:
permute_from = data->optind;
num_nonopts = 0;
while (!is_option (argv[data->optind], only))
{
data->optind++;
num_nonopts++;
}
if (argv[data->optind] == 0)
{
/* no more options */
data->optind = permute_from;
return EOF;
}
else if (strcmp (argv[data->optind], "--") == 0)
{
/* no more options, but have to get `--' out of the way */
permute (argv + permute_from, num_nonopts, 1);
data->optind = permute_from + 1;
return EOF;
}
break;
case RETURN_IN_ORDER:
if (!is_option (argv[data->optind], only))
{
data->optarg = argv[data->optind++];
return (data->optopt = 1);
}
break;
case REQUIRE_ORDER:
if (!is_option (argv[data->optind], only))
return EOF;
break;
}
}
/* we've got an option, so parse it */
/* first, is it a long option? */
if (longopts != 0
&& (memcmp (argv[data->optind], "--", 2) == 0
|| (only && argv[data->optind][0] == '+')) && data->optwhere == 1)
{
/* handle long options */
if (memcmp (argv[data->optind], "--", 2) == 0)
data->optwhere = 2;
longopt_match = -1;
possible_arg = strchr (argv[data->optind] + data->optwhere, '=');
if (possible_arg == 0)
{
/* no =, so next argv might be arg */
match_chars = strlen (argv[data->optind]);
possible_arg = argv[data->optind] + match_chars;
match_chars = match_chars - data->optwhere;
}
else
match_chars = (possible_arg - argv[data->optind]) - data->optwhere;
for (optindex = 0; longopts[optindex].name != 0; ++optindex)
{
if (memcmp
(argv[data->optind] + data->optwhere, longopts[optindex].name,
match_chars) == 0)
{
/* do we have an exact match? */
if (match_chars == (int) (strlen (longopts[optindex].name)))
{
longopt_match = optindex;
break;
}
/* do any characters match? */
else
{
if (longopt_match < 0)
longopt_match = optindex;
else
{
/* we have ambiguous options */
if (data->opterr)
fprintf (stderr, "%s: option `%s' is ambiguous "
"(could be `--%s' or `--%s')\n",
argv[0],
argv[data->optind],
longopts[longopt_match].name,
longopts[optindex].name);
return (data->optopt = '?');
}
}
}
}
if (longopt_match >= 0)
has_arg = longopts[longopt_match].has_arg;
}
/* if we didn't find a long option, is it a short option? */
if (longopt_match < 0 && shortopts != 0)
{
cp = strchr (shortopts, argv[data->optind][data->optwhere]);
if (cp == 0)
{
/* couldn't find option in shortopts */
if (data->opterr)
fprintf (stderr,
"%s: invalid option -- `-%c'\n",
argv[0], argv[data->optind][data->optwhere]);
data->optwhere++;
if (argv[data->optind][data->optwhere] == '\0')
{
data->optind++;
data->optwhere = 1;
}
return (data->optopt = '?');
}
has_arg = ((cp[1] == ':')
? ((cp[2] == ':') ? OPTIONAL_ARG : REQUIRED_ARG) : NO_ARG);
possible_arg = argv[data->optind] + data->optwhere + 1;
data->optopt = *cp;
}
/* get argument and reset data->optwhere */
arg_next = 0;
switch (has_arg)
{
case OPTIONAL_ARG:
if (*possible_arg == '=')
possible_arg++;
data->optarg = (*possible_arg != '\0') ? possible_arg : 0;
data->optwhere = 1;
break;
case REQUIRED_ARG:
if (*possible_arg == '=')
possible_arg++;
if (*possible_arg != '\0')
{
data->optarg = possible_arg;
data->optwhere = 1;
}
else if (data->optind + 1 >= argc)
{
if (data->opterr)
{
fprintf (stderr, "%s: argument required for option `", argv[0]);
if (longopt_match >= 0)
fprintf (stderr, "--%s'\n", longopts[longopt_match].name);
else
fprintf (stderr, "-%c'\n", *cp);
}
data->optind++;
return (data->optopt = ':');
}
else
{
data->optarg = argv[data->optind + 1];
arg_next = 1;
data->optwhere = 1;
}
break;
default: /* shouldn't happen */
case NO_ARG:
if (longopt_match < 0)
{
data->optwhere++;
if (argv[data->optind][data->optwhere] == '\0')
data->optwhere = 1;
}
else
data->optwhere = 1;
data->optarg = 0;
break;
}
/* do we have to permute or otherwise modify data->optind? */
if (ordering == PERMUTE && data->optwhere == 1 && num_nonopts != 0)
{
permute (argv + permute_from, num_nonopts, 1 + arg_next);
data->optind = permute_from + 1 + arg_next;
}
else if (data->optwhere == 1)
data->optind = data->optind + 1 + arg_next;
/* finally return */
if (longopt_match >= 0)
{
if (longind != 0)
*longind = longopt_match;
if (longopts[longopt_match].flag != 0)
{
*(longopts[longopt_match].flag) = longopts[longopt_match].val;
return 0;
}
else
return longopts[longopt_match].val;
}
else
return data->optopt;
}
int
getopt (int argc, char *const argv[], const char *optstring)
{
struct getopt_data data;
int r;
read_globals (&data);
r = getopt_internal (argc, argv, optstring, 0, 0, 0, &data);
write_globals (&data);
return r;
}
int
getopt_long (int argc, char *const argv[], const char *shortopts,
const struct option *longopts, int *longind)
{
struct getopt_data data;
int r;
read_globals (&data);
r = getopt_internal (argc, argv, shortopts, longopts, longind, 0, &data);
write_globals (&data);
return r;
}
int
getopt_long_only (int argc, char *const argv[], const char *shortopts,
const struct option *longopts, int *longind)
{
struct getopt_data data;
int r;
read_globals (&data);
r = getopt_internal (argc, argv, shortopts, longopts, longind, 1, &data);
write_globals (&data);
return r;
}
int
__getopt_r (int argc, char *const argv[], const char *optstring,
struct getopt_data *data)
{
return getopt_internal (argc, argv, optstring, 0, 0, 0, data);
}
int
__getopt_long_r (int argc, char *const argv[], const char *shortopts,
const struct option *longopts, int *longind,
struct getopt_data *data)
{
return getopt_internal (argc, argv, shortopts, longopts, longind, 0, data);
}
int
__getopt_long_only_r (int argc, char *const argv[], const char *shortopts,
const struct option *longopts, int *longind,
struct getopt_data *data)
{
return getopt_internal (argc, argv, shortopts, longopts, longind, 1, data);
}
/* end of file GETOPT.C */

View File

@@ -0,0 +1,99 @@
/* Provide support for both ANSI and non-ANSI environments. */
/* Some ANSI environments are "broken" in the sense that __STDC__ cannot be
relied upon to have it's intended meaning. Therefore we must use our own
concoction: _HAVE_STDC. Always use _HAVE_STDC instead of __STDC__ in newlib
sources!
To get a strict ANSI C environment, define macro __STRICT_ANSI__. This will
"comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
files aren't affected). */
#ifndef _ANSIDECL_H_
#define _ANSIDECL_H_
/* #include <newlib.h> */
/* #include <sys/config.h> */
/* First try to figure out whether we really are in an ANSI C environment. */
/* FIXME: This probably needs some work. Perhaps sys/config.h can be
prevailed upon to give us a clue. */
#ifdef __STDC__
#define _HAVE_STDC
#endif
#ifdef _HAVE_STDC
#define _PTR void *
#define _AND ,
#define _NOARGS void
#define _CONST const
#define _VOLATILE volatile
#define _SIGNED signed
#define _DOTS , ...
#define _VOID void
#ifdef __CYGWIN__
#define _EXFUN(name, proto) __cdecl name proto
#define _EXPARM(name, proto) (* __cdecl name) proto
#else
#define _EXFUN(name, proto) name proto
#define _EXPARM(name, proto) (* name) proto
#endif
#define _DEFUN(name, arglist, args) name(args)
#define _DEFUN_VOID(name) name(_NOARGS)
#define _CAST_VOID (void)
#ifndef _LONG_DOUBLE
#define _LONG_DOUBLE long double
#endif
#ifndef _LONG_LONG
#define _LONG_LONG long long
#endif
#ifndef _PARAMS
#define _PARAMS(paramlist) paramlist
#endif
#else
#define _PTR char *
#define _AND ;
#define _NOARGS
#define _CONST
#define _VOLATILE
#define _SIGNED
#define _DOTS
#define _VOID void
#define _EXFUN(name, proto) name()
#define _DEFUN(name, arglist, args) name arglist args;
#define _DEFUN_VOID(name) name()
#define _CAST_VOID
#define _LONG_DOUBLE double
#define _LONG_LONG long
#ifndef _PARAMS
#define _PARAMS(paramlist) ()
#endif
#endif
/* Support gcc's __attribute__ facility. */
#ifdef __GNUC__
#define _ATTRIBUTE(attrs) __attribute__ (attrs)
#else
#define _ATTRIBUTE(attrs)
#endif
/* ISO C++. */
#ifdef __cplusplus
#if !(defined(_BEGIN_STD_C) && defined(_END_STD_C))
#ifdef _HAVE_STD_CXX
#define _BEGIN_STD_C namespace std { extern "C" {
#define _END_STD_C } }
#else
#define _BEGIN_STD_C extern "C" {
#define _END_STD_C }
#endif
#endif
#else
#define _BEGIN_STD_C
#define _END_STD_C
#endif
#endif /* _ANSIDECL_H_ */

View File

@@ -0,0 +1,167 @@
/****************************************************************************
getopt.h - Read command line options
AUTHOR: Gregory Pietsch
CREATED Thu Jan 09 22:37:00 1997
DESCRIPTION:
The getopt() function parses the command line arguments. Its arguments argc
and argv are the argument count and array as passed to the main() function
on program invocation. The argument optstring is a list of available option
characters. If such a character is followed by a colon (`:'), the option
takes an argument, which is placed in optarg. If such a character is
followed by two colons, the option takes an optional argument, which is
placed in optarg. If the option does not take an argument, optarg is NULL.
The external variable optind is the index of the next array element of argv
to be processed; it communicates from one call to the next which element to
process.
The getopt_long() function works like getopt() except that it also accepts
long options started by two dashes `--'. If these take values, it is either
in the form
--arg=value
or
--arg value
It takes the additional arguments longopts which is a pointer to the first
element of an array of type GETOPT_LONG_OPTION_T, defined below. The last
element of the array has to be filled with NULL for the name field.
The longind pointer points to the index of the current long option relative
to longopts if it is non-NULL.
The getopt() function returns the option character if the option was found
successfully, `:' if there was a missing parameter for one of the options,
`?' for an unknown option character, and EOF for the end of the option list.
The getopt_long() function's return value is described below.
The function getopt_long_only() is identical to getopt_long(), except that a
plus sign `+' can introduce long options as well as `--'.
Describe how to deal with options that follow non-option ARGV-elements.
If the caller did not specify anything, the default is REQUIRE_ORDER if the
environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise.
REQUIRE_ORDER means don't recognize them as options; stop option processing
when the first non-option is seen. This is what Unix does. This mode of
operation is selected by either setting the environment variable
POSIXLY_CORRECT, or using `+' as the first character of the optstring
parameter.
PERMUTE is the default. We permute the contents of ARGV as we scan, so that
eventually all the non-options are at the end. This allows options to be
given in any order, even with programs that were not written to expect this.
RETURN_IN_ORDER is an option available to programs that were written to
expect options and other ARGV-elements in any order and that care about the
ordering of the two. We describe each non-option ARGV-element as if it were
the argument of an option with character code 1. Using `-' as the first
character of the optstring parameter selects this mode of operation.
The special argument `--' forces an end of option-scanning regardless of the
value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause
getopt() and friends to return EOF with optind != argc.
COPYRIGHT NOTICE AND DISCLAIMER:
Copyright (C) 1997 Gregory Pietsch
This file and the accompanying getopt.c implementation file are hereby
placed in the public domain without restrictions. Just give the author
credit, don't claim you wrote it or prevent anyone else from using it.
Gregory Pietsch's current e-mail address:
gpietsch@comcast.net
****************************************************************************/
/* use _GETOPT_H so we avoid dupe include of glibc getopt.h */
#ifndef _GETOPT_H
#define _GETOPT_H
#include <newlib/_ansi.h>
/* include files needed by this include file */
/* These #defines are to keep the namespace clear... */
#define getopt_r __getopt_r
#define getopt_long_r __getopt_long_r
#define getopt_long_only_r __getopt_long_only_r
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
/* types defined by this include file */
struct option
{
char *name; /* the name of the long option */
int has_arg; /* one of the above macros */
int *flag; /* determines if getopt_long() returns a
* value for a long option; if it is
* non-NULL, 0 is returned as a function
* value and the value of val is stored in
* the area pointed to by flag. Otherwise,
* val is returned. */
int val; /* determines the value to return if flag is
* NULL. */
};
/* The getopt_data structure is for reentrancy. Its members are similar to
the externally-defined variables. */
typedef struct getopt_data
{
char *optarg;
int optind, opterr, optopt, optwhere;
} getopt_data;
/* externally-defined variables */
extern char *optarg;
extern int optind;
extern int opterr;
extern int optopt;
/* function prototypes */
int _EXFUN (getopt,
(int __argc, char *const __argv[], const char *__optstring));
int _EXFUN (getopt_long,
(int __argc, char *const __argv[], const char *__shortopts,
const struct option * __longopts, int *__longind));
int _EXFUN (getopt_long_only,
(int __argc, char *const __argv[], const char *__shortopts,
const struct option * __longopts, int *__longind));
int _EXFUN (__getopt_r,
(int __argc, char *const __argv[], const char *__optstring,
struct getopt_data * __data));
int _EXFUN (__getopt_long_r,
(int __argc, char *const __argv[], const char *__shortopts,
const struct option * __longopts, int *__longind,
struct getopt_data * __data));
int _EXFUN (__getopt_long_only_r,
(int __argc, char *const __argv[], const char *__shortopts,
const struct option * __longopts, int *__longind,
struct getopt_data * __data));
#ifdef __cplusplus
};
#endif /* __cplusplus */
#endif /* GETOPT_H */
/* END OF FILE getopt.h */

View File

@@ -0,0 +1,61 @@
/*
* BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifndef __SHELL_h
#define __SHELL_h
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*rtems_shell_command_t)(int argc, char **argv);
struct rtems_shell_cmd_tt;
typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
struct rtems_shell_cmd_tt {
const char *name;
const char *usage;
const char *topic;
rtems_shell_command_t command;
rtems_shell_cmd_t *alias;
rtems_shell_cmd_t *next;
};
typedef struct {
const char *name;
const char *alias;
} rtems_shell_alias_t;
void rtems_shell_initialize_command_set(void);
rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
rtems_shell_cmd_t * rtems_shell_alias_cmd(
const char *cmd,
const char *alias
);
int rtems_shell_make_args(
char *commandLine,
int *argc_p,
char **argv_p,
int max_args
);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,15 @@
/*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#define METHOD_NAME lookup_semaphore
#define RTEMS_IDENT_NAME rtems_semaphore_ident
#include "lookup_task.c"

View File

@@ -0,0 +1,58 @@
/*
* Given Name or ID String, give Id
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include <rtems/stringto.h>
#ifndef METHOD_NAME
#define METHOD_NAME lookup_task
#endif
#ifndef RTEMS_IDENT_NAME
#define RTEMS_IDENT_NAME rtems_task_ident
#endif
int METHOD_NAME(
const char *string,
rtems_id *id
)
{
char name[5];
rtems_status_code status;
unsigned long tmp;
if ( string[0] != '0' ) {
memset( name, '\0', sizeof(name) );
strncpy( name, string, 4 );
status = RTEMS_IDENT_NAME(
rtems_build_name( name[0], name[1], name[2], name[3] ),
OBJECTS_SEARCH_ALL_NODES,
id
);
if ( status != RTEMS_SUCCESSFUL )
return 1;
} else {
if ( rtems_string_to_unsigned_long( string, &tmp, NULL, 0) ) {
fprintf( stderr, "Argument (%s) is not a number\n", string );
return 1;
}
*id = (rtems_id) tmp;
}
return 0;
}

View File

@@ -0,0 +1,75 @@
/*
* Task Priority Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_clock_tick(
int argc,
char *argv[]
)
{
rtems_status_code status;
rtems_interval ticks;
unsigned long tmp;
rtems_interval t;
if (argc != 2) {
fprintf( stderr, "%s: Usage ticks\n", argv[0] );
return -1;
}
if ( rtems_string_to_unsigned_long( argv[1], &tmp, NULL, 0) ) {
fprintf( stderr, "Argument (%s) is not a number\n", argv[2] );
return 1;
}
ticks = (rtems_interval) tmp;
/*
* Now delete the task
*/
for ( t=1 ; t<=ticks ; t++ ) {
fprintf( stderr, "ClockTick (%d) ...\n", t );
status = rtems_clock_tick();
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Clock Tick (%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
}
return 0;
}
rtems_shell_cmd_t rtems_shell_CLOCK_TICK_Command = {
"clock_tick", /* name */
"clock_tick ticks", /* usage */
"rtems", /* topic */
rtems_shell_main_clock_tick, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,140 @@
/* $NetBSD: echo.c,v 1.12 2005/02/06 04:43:43 perry Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)echo.c 8.1 (Berkeley) 5/31/93
*/
/*
* Echo command.
*
* echo is steeped in tradition - several of them!
* netbsd has supported 'echo [-n | -e] args' in spite of -e not being
* documented anywhere.
* Posix requires that -n be supported, output from strings containing
* \ is implementation defined
* The Single Unix Spec requires that \ escapes be treated as if -e
* were set, but that -n not be treated as an option.
* (ksh supports 'echo [-eEn] args', but not -- so that it is actually
* impossible to actually output '-n')
*
* It is suggested that 'printf "%b" "string"' be used to get \ sequences
* expanded. printf is now a builtin of netbsd's sh and csh.
*/
/*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "shell.h"
int rtems_shell_main_echo(
int argc,
char *argv[]
)
{
char **ap;
char *p;
char c;
int count;
int nflag = 0;
int eflag = 0;
ap = argv;
if (argc)
ap++;
if ((p = *ap) != NULL) {
if (!strcmp(p, "-n")) {
nflag = 1;
ap++;
} else if (!strcmp(p, "-e")) {
eflag = 1;
ap++;
}
}
while ((p = *ap++) != NULL) {
while ((c = *p++) != '\0') {
if (c == '\\' && eflag) {
switch (*p++) {
case 'a': c = '\a'; break; /* bell */
case 'b': c = '\b'; break;
case 'c': return 0; /* exit */
case 'e': c = 033; break; /* escape */
case 'f': c = '\f'; break;
case 'n': c = '\n'; break;
case 'r': c = '\r'; break;
case 't': c = '\t'; break;
case 'v': c = '\v'; break;
case '\\': break; /* c = '\\' */
case '0':
c = 0;
count = 3;
while (--count >= 0 && (unsigned)(*p - '0') < 8)
c = (c << 3) + (*p++ - '0');
break;
default:
/* Output the '/' and char following */
p--;
break;
}
}
putchar(c);
}
if (*ap)
putchar(' ');
}
if (! nflag)
putchar('\n');
return 0;
}
rtems_shell_cmd_t rtems_shell_ECHO_Command = {
"echo", /* name */
"echo [args]", /* usage */
"misc", /* topic */
rtems_shell_main_echo, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,42 @@
/*
* Thread Executing Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_executing(
int argc,
char *argv[]
)
{
PRINT_EXECUTING();
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_EXECUTING_Command = {
"executing", /* name */
"executing", /* usage */
"rtems", /* topic */
rtems_shell_main_executing, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,42 @@
/*
* Thread Heir Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_heir(
int argc,
char *argv[]
)
{
PRINT_HEIR();
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_HEIR_Command = {
"heir", /* name */
"heir", /* usage */
"rtems", /* topic */
rtems_shell_main_heir, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,150 @@
/*
* Shell Help Command
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "shell.h"
#include <schedsim_shell.h>
/*
* show the help for one command.
*/
int rtems_shell_help_cmd(
rtems_shell_cmd_t *shell_cmd
)
{
const char * pc;
int col,line;
printf("%-20.20s - ",shell_cmd->name);
col = 14;
line = 1;
if (shell_cmd->alias) {
printf("is an <alias> for command '%s'",shell_cmd->alias->name);
} else if (shell_cmd->usage) {
pc = shell_cmd->usage;
while (*pc) {
switch(*pc) {
case '\r':
break;
case '\n':
putchar('\n');
col = 0;
break;
default:
putchar(*pc);
col++;
break;
}
pc++;
if (col>78) { /* What daring... 78?*/
if (*pc) {
putchar('\n');
col = 0;
}
}
if (!col && *pc) {
printf(" ");
col = 12;line++;
}
}
}
puts("");
return line;
}
/*
* show the help. The first command implemented.
* Can you see the header of routine? Known?
* The same with all the commands....
*/
int rtems_shell_help(
int argc,
char * argv[]
)
{
int col,line,arg;
rtems_shell_topic_t *topic;
rtems_shell_cmd_t * shell_cmd = rtems_shell_first_cmd;
if (argc<2) {
printf("help: ('r' repeat last cmd - 'e' edit last cmd)\n"
" TOPIC? The topics are\n");
topic = rtems_shell_first_topic;
col = 0;
while (topic) {
if (!col){
col = printf(" %s",topic->topic);
} else {
if ((col+strlen(topic->topic)+2)>78){
printf("\n");
col = printf(" %s",topic->topic);
} else {
col+= printf(", %s",topic->topic);
}
}
topic = topic->next;
}
printf("\n");
return 1;
}
line = 0;
for (arg = 1;arg<argc;arg++) {
if (line>16) {
printf("Press any key to continue...");getchar();
printf("\n");
line = 0;
}
topic = rtems_shell_lookup_topic(argv[arg]);
if (!topic){
if ((shell_cmd = rtems_shell_lookup_cmd(argv[arg])) == NULL) {
printf("help: topic or cmd '%s' not found. Try <help> alone for a list\n",
argv[arg]);
line++;
} else {
line+= rtems_shell_help_cmd(shell_cmd);
}
continue;
}
printf("help: list for the topic '%s'\n",argv[arg]);
line++;
while (shell_cmd) {
if (!strcmp(topic->topic,shell_cmd->topic))
line+= rtems_shell_help_cmd(shell_cmd);
if (line>16) {
printf("Press any key to continue...");
getchar();
printf("\n");
line = 0;
}
shell_cmd = shell_cmd->next;
}
}
puts("");
return 0;
}
rtems_shell_cmd_t rtems_shell_HELP_Command = {
"help", /* name */
"help [topic] # list of usage of commands", /* usage */
"help", /* topic */
rtems_shell_help, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,43 @@
/*
* Initialize RTEMS Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <schedsim_shell.h>
int rtems_shell_main_rtems_init(
int argc,
char *argv[]
)
{
//
// Initialize RTEMS
//
rtems_initialize_data_structures();
return 0;
}
rtems_shell_cmd_t rtems_shell_RTEMS_INIT_Command = {
"rtems_init", /* name */
"rtems_init", /* usage */
"rtems", /* topic */
rtems_shell_main_rtems_init, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,122 @@
/*
* Task Create Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define __need_getopt_newlib
#include <newlib/getopt.h>
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_semaphore_create(
int argc,
char *argv[]
)
{
char name[5];
rtems_id id;
rtems_status_code status;
long tmp;
rtems_task_priority ceiling;
rtems_attribute attr;
struct getopt_data getopt_reent;
char option;
int value;
ceiling = 0;
attr = RTEMS_DEFAULT_ATTRIBUTES;
value = 0;
memset(&getopt_reent, 0, sizeof(getopt_data));
while ( (option = getopt_r( argc, argv, "bcsfpiC:V:", &getopt_reent)) != -1 ) {
switch (option) {
case 'b': attr |= RTEMS_BINARY_SEMAPHORE; break;
case 'c': attr |= RTEMS_COUNTING_SEMAPHORE; break;
case 's': attr |= RTEMS_SIMPLE_BINARY_SEMAPHORE; break;
case 'f': attr |= RTEMS_FIFO; break;
case 'p': attr |= RTEMS_PRIORITY; break;
case 'i': attr |= RTEMS_INHERIT_PRIORITY; break;
case 'C':
attr |= RTEMS_PRIORITY_CEILING;
if ( rtems_string_to_long(getopt_reent.optarg, &tmp, NULL, 0) ) {
printf( "Ceiling argument (%s) is not a number\n", argv[1] );
return -1;
}
ceiling = tmp;
break;
case 'V':
if ( rtems_string_to_long(getopt_reent.optarg, &tmp, NULL, 0) ) {
printf( "Ceiling argument (%s) is not a number\n", argv[1] );
return -1;
}
value = tmp;
break;
default:
fprintf( stderr, "%s: Usage [-bcsfpiC:V:] name\n", argv[0] );
return -1;
}
}
if ( getopt_reent.optind >= argc ) {
fprintf( stderr, "No name specified\n" );
return -1;
}
/*
* Now create the semaphore
*/
memset( name, '\0', sizeof(name) );
strncpy( name, argv[getopt_reent.optind], 4 );
status = rtems_semaphore_create(
rtems_build_name( name[0], name[1], name[2], name[3] ),
value,
attr,
ceiling,
&id
);
if ( status ) {
fprintf(
stderr,
"Semaphore create(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
printf( "Semaphore (%s) created: id=0x%08x\n", argv[1], id );
return 0;
}
rtems_shell_cmd_t rtems_shell_SEMAPHORE_CREATE_Command = {
"semaphore_create", /* name */
"semaphore_create name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_semaphore_create, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,68 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_semaphore_delete(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
if (argc != 2) {
fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
return -1;
}
if ( lookup_semaphore( argv[1], &id ) )
return -1;
/*
* Now delete the semaphore
*/
printf("Deleting semaphore (0x%08x)\n", id );
status = rtems_semaphore_delete( id );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Semaphore Delete(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_SEMAPHORE_DELETE_Command = {
"semaphore_delete", /* name */
"semaphore_delete name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_semaphore_delete, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,67 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_semaphore_flush(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
if (argc != 2) {
fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
return -1;
}
if ( lookup_semaphore( argv[1], &id ) )
return -1;
/*
* Now flush the semaphore
*/
printf("Flushing semaphore (0x%08x)\n", id );
status = rtems_semaphore_flush( id );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Semaphore flush(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_SEMAPHORE_FLUSH_Command = {
"semaphore_flush", /* name */
"semaphore_flush name", /* usage */
"rtems", /* topic */
rtems_shell_main_semaphore_flush, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,85 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_semaphore_obtain(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
long tmp;
rtems_interval ticks;
Thread_Control *caller;
/* XXX for now, do not support polling */
if (argc != 3) {
fprintf( stderr, "%s: Usage name|id timeout\n", argv[0] );
return -1;
}
if ( lookup_semaphore( argv[1], &id ) )
return -1;
if ( rtems_string_to_long(argv[2], &tmp, NULL, 0) ) {
printf( "Ceiling argument (%s) is not a number\n", argv[1] );
return -1;
}
ticks = tmp;
/*
* Now obtain the semaphore
*
* If the calling thread blocks, we will return as another thread
* but with a "unsatisfied" return code. So we check that we did
* a thread switch inside the semaphore obtain. If we did, then
* just return successfully.
*/
caller = _Thread_Executing;
printf("Obtain semaphore (0x%08x) with timeout %d\n", id, ticks );
status = rtems_semaphore_obtain( id, RTEMS_DEFAULT_OPTIONS, ticks );
if ( caller == _Thread_Executing ) {
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Semaphore obtain(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
}
return 0;
}
rtems_shell_cmd_t rtems_shell_SEMAPHORE_OBTAIN_Command = {
"semaphore_obtain", /* name */
"semaphore_obtain name ticks", /* usage */
"rtems", /* topic */
rtems_shell_main_semaphore_obtain, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,67 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_semaphore_release(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
if (argc != 2) {
fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
return -1;
}
if ( lookup_semaphore( argv[1], &id ) )
return -1;
/*
* Now release the semaphore
*/
printf("Releasing semaphore (0x%08x)\n", id );
status = rtems_semaphore_release( id );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Semaphore release(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_SEMAPHORE_RELEASE_Command = {
"semaphore_release", /* name */
"semaphore_release name", /* usage */
"rtems", /* topic */
rtems_shell_main_semaphore_release, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,111 @@
/*
* Task Create Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
rtems_task dummy_task(
rtems_task_argument arg
)
{
}
int rtems_shell_main_task_create(
int argc,
char *argv[]
)
{
char name[5];
rtems_id id;
rtems_status_code status;
long priority;
if (argc != 3) {
fprintf( stderr, "%s: Usage name priority\n", argv[0] );
return -1;
}
if ( rtems_string_to_long(argv[2], &priority, NULL, 0) ) {
printf( "Seconds argument (%s) is not a number\n", argv[1] );
return -1;
}
/*
* Now create the task
*/
memset( name, '\0', sizeof(name) );
strncpy( name, argv[1], 4 );
status = rtems_task_create(
rtems_build_name( name[0], name[1], name[2], name[3] ),
(rtems_task_priority) priority,
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES,
RTEMS_DEFAULT_ATTRIBUTES,
&id
);
if ( status ) {
fprintf(
stderr,
"Task Create(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
printf(
"Task (%s) created: id=0x%08x, priority=%ld\n",
argv[1],
id,
priority
);
printf(
"Task (%s) starting: id=0x%08x, priority=%ld\n",
argv[1],
id,
priority
);
status = rtems_task_start( id, dummy_task, 1 );
if ( status ) {
fprintf(
stderr,
"Task Start(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_CREATE_Command = {
"task_create", /* name */
"task_create name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_task_create, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,68 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_task_delete(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
if (argc != 2) {
fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
return -1;
}
if ( lookup_task( argv[1], &id ) )
return -1;
/*
* Now delete the task
*/
status = rtems_task_delete( id );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Task Delete(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
printf("Task (0x%08x) deleted\n", id );
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_DELETE_Command = {
"task_delete", /* name */
"task_delete name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_task_delete, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,111 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define __need_getopt_newlib
#include <newlib/getopt.h>
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
void print_mode(
const char *prefix,
rtems_mode mode
)
{
fprintf(
stderr,
"%sPreemption: %s Timeslicing: %s\n",
prefix,
((mode & RTEMS_NO_PREEMPT) ? "no" : "yes"),
((mode & RTEMS_TIMESLICE) ? "yes" : "no")
);
}
int rtems_shell_main_task_mode(
int argc,
char *argv[]
)
{
rtems_status_code status;
rtems_mode mode;
rtems_mode mask;
rtems_mode old;
struct getopt_data getopt_reent;
char option;
mode = 0;
mask = 0;
memset(&getopt_reent, 0, sizeof(getopt_data));
while ( (option = getopt_r( argc, argv, "tTpP", &getopt_reent)) != -1 ) {
switch (option) {
case 't':
mask |= RTEMS_TIMESLICE_MASK;
mode = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_NO_TIMESLICE;
break;
case 'T':
mask |= RTEMS_TIMESLICE_MASK;
mode = (mode & ~RTEMS_TIMESLICE_MASK) | RTEMS_TIMESLICE;
break;
case 'p':
mask |= RTEMS_PREEMPT_MASK;
mode = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_NO_PREEMPT;
break;
case 'P':
mask |= RTEMS_PREEMPT_MASK;
mode = (mode & ~RTEMS_PREEMPT_MASK) | RTEMS_PREEMPT;
break;
default:
fprintf( stderr, "%s: Usage [-tTpP]\n", argv[0] );
return -1;
}
}
/*
* Now change the task mode
*/
status = rtems_task_mode( mode, mask, &old );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Task Mode returned %s\n",
rtems_status_text( status )
);
return -1;
}
print_mode( "Previous Mode: ", old );
if ( mask ) {
(void) rtems_task_mode( RTEMS_CURRENT_MODE , RTEMS_CURRENT_MODE, &old );
print_mode( "Current Mode: ", mode );
}
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_MODE_Command = {
"task_mode", /* name */
"task_mode [-tTpP]", /* usage */
"rtems", /* topic */
rtems_shell_main_task_mode, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,78 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_task_priority(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
unsigned long tmp;
rtems_task_priority old;
rtems_task_priority new;
if (argc != 3) {
fprintf( stderr, "%s: Usage [name|id] priority\n", argv[0] );
return -1;
}
if ( lookup_task( argv[1], &id ) )
return -1;
if ( rtems_string_to_unsigned_long( argv[1], &tmp, NULL, 0) ) {
fprintf( stderr, "Argument (%s) is not a number\n", argv[2] );
return 1;
}
new = (rtems_task_priority) tmp;
/*
* Now priority the task
*/
status = rtems_task_set_priority( id, new, &old );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Task Set Priority(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
printf("Task (0x%08x) Chain Priority from %d to %d\n", id, old, new );
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_PRIORITY_Command = {
"task_priority", /* name */
"task_priority name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_task_priority, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,68 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_task_resume(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
if (argc != 2) {
fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
return -1;
}
if ( lookup_task( argv[1], &id ) )
return -1;
/*
* Now resume the task
*/
printf("Resuming task (0x%08x)\n", id );
status = rtems_task_resume( id );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Task resume(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_RESUME_Command = {
"task_resume", /* name */
"task_resume name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_task_resume, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,67 @@
/*
* Task Delete Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_task_suspend(
int argc,
char *argv[]
)
{
rtems_id id;
rtems_status_code status;
if (argc != 2) {
fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
return -1;
}
if ( lookup_task( argv[1], &id ) )
return -1;
/*
* Now suspend the task
*/
printf("Suspending task (0x%08x)\n", id );
status = rtems_task_suspend( id );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Task suspend(%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_SUSPEND_Command = {
"task_suspend", /* name */
"task_suspend name priority", /* usage */
"rtems", /* topic */
rtems_shell_main_task_suspend, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,75 @@
/*
* Task Priority Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <rtems.h>
#include "shell.h"
#include <rtems/stringto.h>
#include <schedsim_shell.h>
#include <rtems/error.h>
int rtems_shell_main_task_wake_after(
int argc,
char *argv[]
)
{
rtems_status_code status;
rtems_interval ticks;
unsigned long tmp;
rtems_id self;
if (argc != 2) {
fprintf( stderr, "%s: Usage ticks\n", argv[0] );
return -1;
}
if ( rtems_string_to_unsigned_long( argv[1], &tmp, NULL, 0) ) {
fprintf( stderr, "Argument (%s) is not a number\n", argv[2] );
return 1;
}
ticks = (rtems_interval) tmp;
self = _Thread_Executing->Object.id,
/*
* Now sleep
*/
printf( "Task (0x%08x) sleeping for %d ticks\n", self, ticks );
status = rtems_task_wake_after( ticks );
if ( status != RTEMS_SUCCESSFUL ) {
fprintf(
stderr,
"Task Wake After (%s) returned %s\n",
argv[1],
rtems_status_text( status )
);
return -1;
}
return 0;
}
rtems_shell_cmd_t rtems_shell_TASK_WAKE_AFTER_Command = {
"task_wake_after", /* name */
"task_wake_after ticks", /* usage */
"rtems", /* topic */
rtems_shell_main_task_wake_after, /* command */
NULL, /* alias */
NULL /* next */
};

View File

@@ -0,0 +1,56 @@
/*
* BASED UPON SOURCE IN RTEMS, MODIFIED FOR SIMULATOR
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifndef __SCHEDSIM_SHELL_h
#define __SCHEDSIM_SHELL_h
#include <rtems.h>
#ifdef __cplusplus
extern "C" {
#endif
void PRINT_EXECUTING(void);
void PRINT_HEIR(void);
struct rtems_shell_topic_tt;
typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
struct rtems_shell_topic_tt {
const char *topic;
rtems_shell_topic_t *next;
};
extern rtems_shell_cmd_t * rtems_shell_first_cmd;
extern rtems_shell_topic_t * rtems_shell_first_topic;
rtems_shell_topic_t * rtems_shell_lookup_topic(const char *topic);
extern rtems_shell_cmd_t *rtems_shell_Initial_commands[];
extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
int lookup_task(
const char *string,
rtems_id *id
);
int lookup_semaphore(
const char *string,
rtems_id *id
);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,229 @@
/*
* Shell Command Set Management
*
* Author:
* WORK: fernando.ruiz@ctv.es
* HOME: correo@fernando-ruiz.com
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <time.h>
#include <termios.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "shell.h"
#include <schedsim_shell.h>
/*
* Common linked list of shell commands.
*
* Because the help report is very long, there is a topic for each command.
*
* Help list the topics
* help [topic] list the commands for the topic
* help [command] help for the command
*
*/
rtems_shell_cmd_t * rtems_shell_first_cmd;
rtems_shell_topic_t * rtems_shell_first_topic;
/*
* Find the topic from the set of topics registered.
*/
rtems_shell_topic_t * rtems_shell_lookup_topic(const char * topic) {
rtems_shell_topic_t * shell_topic;
shell_topic=rtems_shell_first_topic;
while (shell_topic) {
if (!strcmp(shell_topic->topic,topic))
return shell_topic;
shell_topic=shell_topic->next;
}
return (rtems_shell_topic_t *) NULL;
}
/*
* Add a new topic to the list of topics
*/
rtems_shell_topic_t * rtems_shell_add_topic(const char * topic) {
rtems_shell_topic_t * current,*aux;
if (!rtems_shell_first_topic) {
aux = malloc(sizeof(rtems_shell_topic_t));
aux->topic = topic;
aux->next = (rtems_shell_topic_t*)NULL;
return rtems_shell_first_topic = aux;
}
current=rtems_shell_first_topic;
if (!strcmp(topic,current->topic))
return current;
while (current->next) {
if (!strcmp(topic,current->next->topic))
return current->next;
current=current->next;
}
aux = malloc(sizeof(rtems_shell_topic_t));
aux->topic = topic;
aux->next = (rtems_shell_topic_t*)NULL;
current->next = aux;
return aux;
}
/*
* Find the command in the set
*/
rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char * cmd) {
rtems_shell_cmd_t * shell_cmd;
shell_cmd=rtems_shell_first_cmd;
while (shell_cmd) {
if (!strcmp(shell_cmd->name,cmd)) return shell_cmd;
shell_cmd=shell_cmd->next;
};
return (rtems_shell_cmd_t *) NULL;
}
/*
* Add a command structure to the set of known commands
*/
rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
rtems_shell_cmd_t *shell_cmd
)
{
rtems_shell_cmd_t *shell_pvt;
shell_pvt = rtems_shell_first_cmd;
while (shell_pvt) {
if (strcmp(shell_pvt->name, shell_cmd->name) == 0)
return NULL;
shell_pvt = shell_pvt->next;
}
if ( !rtems_shell_first_cmd ) {
rtems_shell_first_cmd = shell_cmd;
} else {
shell_pvt = rtems_shell_first_cmd;
while (shell_pvt->next)
shell_pvt = shell_pvt->next;
shell_pvt->next = shell_cmd;
}
rtems_shell_add_topic( shell_cmd->topic );
return shell_cmd;
}
/*
* Add a command as a set of arguments to the set and
* allocate the command structure on the fly.
*/
rtems_shell_cmd_t * rtems_shell_add_cmd(
const char *name,
const char *topic,
const char *usage,
rtems_shell_command_t command
)
{
rtems_shell_cmd_t *shell_cmd = NULL;
char *my_name = NULL;
char *my_topic = NULL;
char *my_usage = NULL;
/* Reject empty commands */
if (name == NULL || command == NULL) {
return NULL;
}
/* Allocate command stucture */
shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
if (shell_cmd == NULL) {
return NULL;
}
/* Allocate strings */
my_name = strdup(name);
my_topic = strdup(topic);
my_usage = strdup(usage);
/* Assign values */
shell_cmd->name = my_name;
shell_cmd->topic = my_topic;
shell_cmd->usage = my_usage;
shell_cmd->command = command;
shell_cmd->alias = NULL;
shell_cmd->next = NULL;
if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
/* Something is wrong, free allocated resources */
free(my_usage);
free(my_topic);
free(my_name);
free(shell_cmd);
return NULL;
}
return shell_cmd;
}
void rtems_shell_initialize_command_set(void)
{
rtems_shell_cmd_t **c;
rtems_shell_alias_t **a;
for ( c = rtems_shell_Initial_commands ; *c ; c++ ) {
rtems_shell_add_cmd_struct( *c );
}
for ( a = rtems_shell_Initial_aliases ; *a ; a++ ) {
rtems_shell_alias_cmd( (*a)->name, (*a)->alias );
}
}
/* ----------------------------------------------- *
* you can make an alias for every command.
* ----------------------------------------------- */
rtems_shell_cmd_t *rtems_shell_alias_cmd(
const char *cmd,
const char *alias
)
{
rtems_shell_cmd_t *shell_cmd, *shell_aux;
shell_aux = (rtems_shell_cmd_t *) NULL;
if (alias) {
shell_aux = rtems_shell_lookup_cmd(alias);
if (shell_aux != NULL) {
return NULL;
}
shell_cmd = rtems_shell_lookup_cmd(cmd);
if (shell_cmd != NULL) {
shell_aux = rtems_shell_add_cmd(
alias,
shell_cmd->topic,
shell_cmd->usage,
shell_cmd->command
);
if (shell_aux)
shell_aux->alias = shell_cmd;
}
}
return shell_aux;
}

View File

@@ -0,0 +1,68 @@
/*
* Split string into argc/argv style argument list
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
* $Id$
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <ctype.h>
int rtems_shell_make_args(
char *commandLine,
int *argc_p,
char **argv_p,
int max_args
)
{
int argc;
char *ch;
int status = 0;
argc = 0;
ch = commandLine;
while ( *ch ) {
while ( isspace((unsigned char)*ch) ) ch++;
if ( *ch == '\0' )
break;
if ( *ch == '"' ) {
argv_p[ argc ] = ++ch;
while ( ( *ch != '\0' ) && ( *ch != '"' ) ) ch++;
} else {
argv_p[ argc ] = ch;
while ( ( *ch != '\0' ) && ( !isspace((unsigned char)*ch) ) ) ch++;
}
argc++;
if ( *ch == '\0' )
break;
*ch++ = '\0';
if ( argc == (max_args-1) ) {
status = -1;
break;
}
}
argv_p[ argc ] = NULL;
*argc_p = argc;
return status;
}