ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

USING A BOOT MONITOR IN EMBEDDED SYSTEMS


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

USING A BOOT MONITOR IN EMBEDDED SYSTEMS

Lessons from the Trenches Part 2ýBuilding on the Basics
by Ed Sutter

Start ý The Ethernet Interface ý The Command Line Interface ý "Get Your Tokens Here" ý One Last Topic About CLI ý Executable Scripts ý Application-to-Monitor Hook-Up ý The Moncom() Function ý The Monconnect() Function ý Letýs Regroup ý Xmodem and Tftp ý OK, Iým Done! ý Sources and PDF

EXECUTABLE SCRIPTS

Iýve talked about a fairly useful CLI processor, but if all you can do is execute one command at a time by typing the command in manually, you still donýt have anything really special. Iýve hinted at this already and shown an example (the monrc file), so letýs combine the capabilities of the CLI with the underlying flash file system (TFS) and provide some scripting capabilities. For the sake of this article, scripting is simply the ability to create a file of commands, one per line, and execute that file as if it was a command. This capability, coordinated with a handful of commands that provide some conditional branching and looping, provides you with a small programming environment right in the monitor.

First, take a step back and consider the command set in the monitor. The core set of monitor capabilities will include commands that twiddle with memory and I/O a bit, some interface commands for Ethernet and RS-232, a CLI interface into the flash file system, and a handful of commands that are dedicated to providing some simple programming capabilities like conditional branching and subroutines (see Table 2).

Command

Description

dm

Display memory

pm

Patch memory

tfs

Interface to tiny file system

pio

Read/write parallel I/O of CPU

tftp

tftp client

read

Interact with (wait for input from) the console

if

Conditional test with branch

goto

Jump to tag

gosu

Call subroutine

sleep

Delay for some interval

let

Expression evaluator

Table 2ýHere is a list of commands with a brief description of each.

Based on my earlier CLI discussion, if this was your command set, then each of the entries in the left column would be the name of the function, and the text in the right column would be the first line of the helptext[] string array for that command.

Because scripting fundamentally requires a file system (because the script itself is a file of commands), the scripting capability comes with TFS and is actually quite simple. In the simplest case, all youýll need to do is retrieve one line of the file at a time and pass that line to the docommand() function discussed earlier. When you reach the end of the file, youýre done. The script runner in Listing 7 does just that, plus just a little more for handling tags and subroutines. Note, however, that there are some limitations.

The script runner in Listing 7 uses the TFS API to interface with the script file. Some of the variables are manipulated by the goto, gosub, and return commands with their code shown in Listing 8 Note that this code would be executed during the execution of the script and would alter the state of the script runner slightly.

And finally, Listing 9 is the code associated with the exit command. Notice how the goto, gosub, and return command have a similar look.

char *ExitHelp[] = {
"Exit a script",
"-[r]",
"Options:",
" -r remove script after exit",
0,
};
int
Exit(int argc, char *argv[])
{
ScriptExitFlag = EXIT_SCRIPT;
if ((argc == 2) && (!strcmp(argv[1],"-r")))
ScriptExitFlag |= REMOVE_SCRIPT;
return(0);
}

Listing 9ýHere you can see the code connected with the exit command.

With this fundamental set of functions plus the use of shell variables, additional capabilities can be added easily. For example, a powerful if command is available to do conditional testing and branching. Without going into the detail of the code behind if, just think about it. The CLI syntax is if {item1} {test} {item2} {action}, where item1 and item2 would be the variables being tested, test would be one of some set of strings that represent greater than, less than, and so forth, and action could be exit, return, gosub tag, or goto tag. To keep things simple, this script runner does make the assumption that there is one complete command per line, so there is no interactive mode.

To finish up without getting into a lot of detail about each of the commands, you can build a script. You can blink a memory-mapped I/O pin that has an LED on it until a location in memory is nonzero (see Listing 10).

PREVIOUSNEXT


Circuit Cellar provides up-to-date information for engineers. Visit www.circuitcellar.com for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com or subscribe online. ýCircuit Cellar, the Magazine for Computer Applications. Posted with permission.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ