Netcruzer Webserver Project  V1.02
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Debugging

Debugging can be performed:

Debug Terminal

The Debug Terminal is very efficient and easy to use. Just plug your board into a USB port of your PC, and debug messages will be received on the Netcruzer USB Terminal.

The "debug.c" file contains code that implements a Debug Terminal. It's main function is to send and receive debug messages to and from a configurable port. By default it is configured to use the USB HID port of the board, and the Netcruzer USB Terminal (Application running on PC, and connected to board via USB port). This configuration allows the Netcruzer USB Terminal to:

All *.c files that want to send debug messages should have the following defined at the top of the file (where XXX is the filename):

//Add debugging to this file. The DEBUG_CONF_XXX macro sets debugging to desired level, and is configured in "Debug Configuration" section of projdefs.h file
#define MY_DEBUG_LEVEL DEBUG_CONF_XXX
#define DEBUG_PUT_STR(lvl, str) {if (MY_DEBUG_LEVEL >= lvl) {debugPutString(str);}}
#define DEBUG_PUT_WORD(lvl, w) {if (MY_DEBUG_LEVEL >= lvl) {debugPutWord(w);}}

The DEBUG_PUT_STR and DEBUG_PUT_WORD macros can then be used to send debug information.

The "Debug Configuration" section in the Hardware Profile file (located in Configs folder, HWP_SBC66EC-R2.h for example) is used to set the debug level of each file. For example, for the main.c file, the following define will result in only macros with a Debug Level equal to, or higher than, "Warning" to be executed.

#define DEBUG_CONF_MAIN DEBUG_LEVEL_WARNING

For this example, the following code will result in a debug message being sent to the debug port.

DEBUG_PUT_STR(DEBUG_LEVEL_WARNING, "\nSomething seems wrong in main.c!");

This is the case because we set the Debug Level of DEBUG_CONF_MAIN to warning, meaning all debug messages with Critical, Error or Warning level will be sent. The following message will however not be sent:

DEBUG_PUT_STR(DEBUG_LEVEL_INFO, "\nSomething interesting happened in main.c!");

Additionally the following line in the Hardware Prifile file will disable all debug messages. It is commented by default. For production code, it is a good idea uncommenting this line. This will make the code smaller and faster (no debug messages are sent.

#define DEBUG_LEVEL_ALLOFF

Details

Debugging is implemented in the debug.c file. It provides a simple way for the application to send and receive text based debug messages. The debugPutString() and debugPutWord() functions can be used to write text based debug information to the debug port. The debugGetString() function is used to get the last received debug message.

By default debugging is configured to use the USB HID port, and the Netcruzer USB Terminal. This can be changed if debugging should use some other port, like a Serial Port, UDP or something else.

Using the Netcruzer USB Terminal for debugging is very efficient and easy. The debugService() function in "debug.c" parses strings received from the Netcruzer USB Terminal (entered in the "Send Debug Text" box), and sends a reply debug message. This reply message is displayed in the "Received From Device" message box. To try it, connect the USB port of the board, start the Netcruzer USB Terminal, and enter "ip" in the "Send Debug Text" box. The current IP address should be received from the board, and displayed in the "Received From Device" message box. See example debugService() function in ex_debugService.c example file. It shows how to implement two debug commands.