Embedded Systems Firmware Demystified

In the preceding chapter, I built a clean system reset for MicroMonitor with warmstart, exception handlers, and serial interface functions. In this chapter, I will implement a user interface through the console port. Over the last few years, I ve probably rewritten this command line interface (CLI) half of a dozen times. I haven t had any need to change it for quite some time now, so maybe this version is a keeper.
The design goal of this CLI is to provide a good amount of flexibility without excess complexity. This CLI provides shell variables and symbols, command line editing and history, command output redirection, user levels, and password protection. If you don t want all of these features, most of this functionality can be optionally removed from the code at build time by setting a few macros in the main MicroMonitor configuration file. To support this configurability without being forced to scatter #ifdefs throughout the code, I have modularized the functionality and accepted a few limitations. The end result is a fairly robust but not very complex CLI handler.
The CLI I develop in this chapter provides MicroMonitor with the following features:
Functional Command Execution All of the command line processing, except for history and editing, is provided by a single function: docommand(). The docommand() is passed a string from the command line and a verbosity level. Other modules in MicroMonitor (not just the console connection) can also use docommand() to invoke commands from within...