Tuesday, August 18, 2015

aMon - Another small system monitor.

I recently wrote a small command line program for minimal resource single board computers. It is intended to aid experimentation and testing of boards based of processors like Atmel's AVRs and ST's STM32s. It features limited line editing (backspace), command history, registers, argument parsing and number formatting.

Long ago monitors were common and often provided by the microprocessor manufacturers. When I had the urge to use one I looked around on the internet and found nothing smaller than uboot.

I found some code on the Fundamental Code website at http://fundamental-code.com/interp/ that had similar properties but a different focus. In the end I kept the register concept and wrote the rest from scratch.

Instead of using 'strtok' to pick apart the command line I tried 're2c'. It does a good job and adds flexibility without bloat. Unfortunately the documentation is very thin for what appears to be a powerful tool.

There is a lot of documentation built into the code. Check the Doxygen output for details on how it works and how to modify it.

Line Editing

Entering character a long a command perfectly is a pain. aMon buffers it's input and allows backspacing and re-typing over errors.

Command History

Working with a command line frequently requires entering the same thing over and over. aMon saves the last three commands and allows using the up and down keys (or ctrl-u and ctrl-d) to recall those commands.

Registers

There are currently eight registers named 'a' to 'h' that are available to store numbers and strings. Once registers were available I started looking for better ways to use them. The first idea was to use them to store frequently used constants like memory addresses, to support this I added the $ operator that inserts the value of a register in a command. The next idea was to use registers to store entire commands as strings. For this I added the ! operator that executes a string as a command and inserts the result in a command.

Building the Program

The source is available on GitHub at https://github.com/alan-backlund/aMon/tree/master.

Building the code requires: 

  • re2c - "A tool for writing very fast and very flexible scanners." is available at 'http://re2c.org/'. 
  • unifdef - "A utility selectively processes conditional C preprocessor #if and #ifdef directives." is available at 'http://dotat.at/prog/unifdef/'.
Once the preceding tools are installed just run make.

Building the Documentation

Doxygen must be installed, it's available at 'http://www.stack.nl/~dimitri/doxygen/'. Run 'make doc' to generate html documentation in 'doc/html/index.html'.

Running the Built in Tests

Three basic test files are included. 'make test' runs aMon with each of the test files: test1, test2 and test3 as input and compares the outputs with the files: expect1, expect2 and expect3.


No comments: