CLI Data Structure and the Command Table

Each general-purpose command in MicroMonitor has the data structure shown in Listing 5.1. The command data structures are stored in the command table.

Listing 5.1: CLI Data Structure.
image from book
 struct  monCommand {     char    *name;      /* Name of command seen by user. */     int     (*func)();  /* Function called when command is invoked. */     char    **helptxt;  /* Help text. */ }; 
image from book
 

The first member, name , points to the string that must match the first token typed on the command line. The function pointer, func , points to the code that is to be called as a result of the token match, and the helptxt pointer shows the location of the help text for the specific command.

At the base of the command table is a preprocessor #include directive that allows you to add additional, target-specific commands that are independent of the core generic commands. [1] The CLI handler scans a table of these structures looking for a match between the first token on the command line and the name member. Listing 5.2 is a small example of the command table.

Listing 5.2: A Section of the Command Table.
image from book
 extern  int     Add(), Echo(), Help(), Version(); extern  char    *AddHelp[], *EchoHelp[], *HelpHelp[]; extern  char    *VersionHelp[]; struct monCommand cmdlist[] = {     { "add",        Add,        AddHelp, },     { "echo",       Echo,       EchoHelp, },     { "help",       Help,       HelpHelp, },     { "?",          Help,       HelpHelp, },     { "version",    Version,    VersionHelp, }, #include "xcmdtbl.h"     { 0,0,0, }, }; 
image from book
 

[1] Remember that we are discussing a boot monitor that supports extensions for various target specific needs. This #include allows the extensions to be added without actually touching the monitors generic command table.



Embedded Systems Firmware Demystified
Embedded Systems Firmware Demystified (With CD-ROM)
ISBN: 1578200997
EAN: 2147483647
Year: 2002
Pages: 118
Authors: Ed Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net