The Application main() Functionmain() Function

The Application main() Function

The main() function of the application (see Listing 11.6) is called from start() . The start() function established the connection with the monitor through the monConnect() call and immediately executed the mon_getargv() API function to retrieve an argument list from the monitors space. This argument list can be built by the monitors argv command, or it is automatically loaded when a TFS-based executable is called from the monitor command line. Thus a main() function in an application running on the monitor basically looks like any other main() function.

Listing 11.6: main() .
image from book
  #include "monlib.h"   main(int argc,char *argv[])   {   int     i;   char    *env;   for(i=0;i<argc;i++) {   mon_printf("argv[%d] = %s\n",i,argv[i]);   }   mon_printf("Hello embedded world!\n");   env = mon_getenv("ENV");   if (env) {   mon_printf(" The ENV variable is : %s\n",env);   }   mon_appexit(0);   }  
image from book
 

The three different mon_xxx calls in the example of Listing 11.6 demonstrate additional API functions available to the application when the monitor is present. Some key features are:

  • applications that are loaded from TFS can be passed different argument lists to invoke different actions depending on the need;

  • the application immediately has access to the monitors console interface through mon_printf();

  • shell variables created in monitor space are accessible by the application through the mon_getenv() API call;

  • the application can return control to the monitor by either returning to the caller of start() or by issuing the mon_appexit() API call.



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