EE445M RTOS
Taken at the University of Texas Spring 2015
System-interaction calls

Invoke system calls. More...

Data Structures

struct  system_command
 

Macros

#define SYSTEM_MAX_COMMAND_NAME_LENGTH   16
 
#define SYSTEM_MAX_COMMANDS   16
 

Typedefs

typedef uint8_t system_iterator
 
typedef uint8_t exit_status_t
 
typedef struct system_command system_command
 

Functions

void system_init ()
 
bool system_register_command (const char *, int(*)())
 
bool system_deregister_command (const char *)
 
exit_status_t system_exec (const char *, const char **)
 
system_command_system_command_from_name (const char *command_name)
 

Detailed Description

Invoke system calls.

Every language offers a 'system' call – pass it a string and the system interprets it. This is that library for this RTOS.

Author
Eric Crosson
Version
0.1
Date
2014
Precondition
None

Macro Definition Documentation

#define SYSTEM_MAX_COMMAND_NAME_LENGTH   16

Maximum length of a callable command.

Definition at line 14 of file system.h.

#define SYSTEM_MAX_COMMANDS   16

Maximum number of commands supported by the system.

Definition at line 17 of file system.h.

Referenced by _system_command_from_name(), system_init(), and system_register_command().

Typedef Documentation

typedef uint8_t exit_status_t

Type definition of an exit code.

Definition at line 24 of file system.h.

typedef uint8_t system_iterator

Iterator optimized for size that is guaranteed to be able to iterate over .

Definition at line 21 of file system.h.

Function Documentation

system_command* _system_command_from_name ( const char *  command_name)

For internal use only. This function returns a pointer to the registered to the command name .

Definition at line 58 of file system.c.

References strcmp(), and SYSTEM_MAX_COMMANDS.

Referenced by system_deregister_command(), and system_exec().

58  {
59 
60  system_iterator i=0;
61  while(i<SYSTEM_MAX_COMMANDS &&
62  0 != strcmp(SYSTEM_COMMANDS[i].name, command_name)) {
63  ++i;
64  }
65  return &SYSTEM_COMMANDS[i];
66 }
#define SYSTEM_MAX_COMMANDS
Definition: system.h:17
int strcmp(const char *s1, const char *s2)
Definition: nexus.c:35
uint8_t system_iterator
Definition: system.h:21
static system_command SYSTEM_COMMANDS[16]
Definition: system.c:11

Here is the call graph for this function:

Here is the caller graph for this function:

bool system_deregister_command ( const char *  )

Remove a command from the index of executable system commands.

Returns
True if command was successfully deregistered.

Definition at line 45 of file system.c.

References _system_command_from_name(), CDL_DELETE, CDL_PREPEND, and system_command::valid.

45  {
46 
47  /* Grab the structure of the command to deregister and invaldiate
48  * the metadata. Move it from the registered to the unregistered
49  * pile. */
50  system_command* command = _system_command_from_name(command_name);
51  command->valid = false;
54  return true;
55 }
system_command * _system_command_from_name(const char *command_name)
Definition: system.c:58
#define CDL_DELETE(head, del)
Definition: utlist.h:705
bool valid
Definition: system.h:31
system_command * unregistered_commands
Definition: system.c:17
system_command * registered_commands
Definition: system.c:14
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

exit_status_t system_exec ( const char *  ,
const char **   
)

Execute a system command.

Returns
The exit code of the executed command.
Bug:
Currently argument passing is not supported.

Definition at line 69 of file system.c.

References _system_command_from_name(), system_command::command, postpone_death, and system_command::valid.

Referenced by shell_execute_command().

69  {
70 
71  system_command* sys_command = _system_command_from_name(command);
72  if (sys_command->valid) {
73  return sys_command->command(/*arguments*/);
74  } else {
75  /* TODO: determine what to do here */
76  postpone_death(); /* plan a */
77  return EXIT_FAILURE; /* plan b */
78  }
79 }
system_command * _system_command_from_name(const char *command_name)
Definition: system.c:58
#define postpone_death()
Definition: nexus.h:40
int(* command)()
Definition: system.h:33
bool valid
Definition: system.h:31

Here is the call graph for this function:

Here is the caller graph for this function:

void system_init ( )

Initialize internal data structures.

Note
Ensure this method is called before any commands are registered.

Definition at line 19 of file system.c.

References CDL_PREPEND, and SYSTEM_MAX_COMMANDS.

Referenced by main().

19  {
20 
22  /* All commands begin in the unregistered state */
23  for(i=0; i<SYSTEM_MAX_COMMANDS; ++i) {
25  }
26 }
#define SYSTEM_MAX_COMMANDS
Definition: system.h:17
uint8_t system_iterator
Definition: system.h:21
system_command * unregistered_commands
Definition: system.c:17
static system_command SYSTEM_COMMANDS[16]
Definition: system.c:11
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the caller graph for this function:

bool system_register_command ( const char *  ,
int(*)()   
)

Register a command for later execution.

Returns
True if command was successfully registered.

Definition at line 29 of file system.c.

References CDL_DELETE, CDL_PREPEND, system_command::command, memset(), system_command::name, SYSTEM_MAX_COMMANDS, unregistered_commands, ustrcpy(), and system_command::valid.

Referenced by main().

29  {
30 
31  /* Grab the first free command, move it from the unregisted to the
32  * registered pile, and populate it with this function's
33  * arguments */
35  CDL_DELETE(unregistered_commands, sys_command);
36  CDL_PREPEND(registered_commands, sys_command);
37 
38  sys_command->valid = true;
39  memset(sys_command->name, 0, SYSTEM_MAX_COMMANDS);
40  ustrcpy(sys_command->name, command_name);
41  sys_command->command = command;
42  return true;
43 }
char name[16]
Definition: system.h:32
void ustrcpy(char *dest, const char *source)
Definition: nexus.c:69
#define SYSTEM_MAX_COMMANDS
Definition: system.h:17
#define CDL_DELETE(head, del)
Definition: utlist.h:705
int(* command)()
Definition: system.h:33
bool valid
Definition: system.h:31
void * memset(void *b, int c, int len)
Definition: nexus.c:4
system_command * unregistered_commands
Definition: system.c:17
system_command * registered_commands
Definition: system.c:14
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

Here is the caller graph for this function: