Adding SerialICE Monitor Commands

Adding commands to the SerialICE Monitor is very simple. You have two choices: Add the command to the SerialICE Monitor ROMs, or add the command to the SerialICE Driver. Adding the command to the SerialICE Driver avoids the need to rebuild the SerialICE Monitor ROM and is described below. To add the command to the SerialICE Monitor ROM follow the procedure for adding commands to PMON, except that you use the files in the imon directory instead of the pmon directory.

In this example, we wish to add a command called mycmd to the SerialICE Driver. This command simply identifies itself and prints out a list of its arguments. The function is placed in a file called mycmd.c in the bsps subdirectory. Notice that it is called with an argc/argv argument list in exactly the same way as a normal C program is called. As with UNIX, the name of the command is located in argv[0].

bsps/mycmd.c

	Optdesc mycmd_opts[] = {
		{"","My Command"},
		{0}};

	mycmd(argc,argv)
	int argc;
	char *argv[];
	{
	int i;

	printf("This is my command. Arguments were: ");
	for (i=1;i<argc;i++) printf("%s ",argv[i]);
	printf("\n");
	}
Note that you can also list any options that your new command accepts, to the mycmd_opts array. The first field can contain the list of options. Additional lines would explain those options. For example,

	Optdesc mycmd_opts[] = {
		{"[-fl]","My Command"},
		{"-f","Find bug"},
		{"-l","Lose bug"},
		{0}};
The name of this function must now be installed in the table of commands. The new command can be added to all drivers (iceif.c/icecmds), or just for a specific driver (eg. d4001.c/cmdlist).

The new command can be placed anywhere in the list. Its position determines where its name will appear in the list generated by the 'h' command.

bsps/d4001.c

	int mycmd();
	extern Optdesc mycmd_opts[];

	CmdRec cmdlist[] = {
		{"mycmd",mycmd_opts,mycmd},
Finally, the new module must be added to the list in the Makefile. For example,

bsps/Makefile
# a driver for a board that has a 4001
d4001 : $(DVROBJS) d4001.o 400x.o mycmd.o
	pmcc $(DVRFLAGS) -o $@ $(DVROBJS) d4001.o 400x.o mycmd.o
To support arguments that can be complex expressions, convert the argument from ascii to binary using the function get_rsa(). This function has the prototype:
	int get_rsa(unsigned long *value, char *source);
Where:

source is the input ascii string.
value is the place where the binary value is to be written.
The return value is 1 if the conversion was successful, otherwise it is zero. get_rsa() prints its own messages if the conversion was unsuccessful.

Example:

	if(!get_rsa(&adr,av[i])) return;
Once the files havebeen modified, you need to rebuild the driver and download it to the SerialICE Controller. Or if you chose to add the command to the ROM, you need to rebuild IMON and make new ROMs.


Navigation: Document Home | Document Contents | Document Index