SMSC LAN1198 Manual De Usuario

Descargar
Página de 45
LAN9118 Family Programmer Reference Guide
SMSC AN 12.12
41
Revision 1.0 (12-14-09)
APPLICATION NOTE
 
Instrumentation and Debug
This chapter is based upon the experience gained from the development of the simple Linux Driver for
the LAN9118 family.  It assumes that the driver will have a rich feature set in its run-time environment
to draw upon for debugging.  While not every operating system offers the functionality of a Linux, the
concepts remain useful and are offered to the driver developer as tips.
When something goes wrong in the driver, it is very helpful to have facilities for observing its internal
workings. This chapter will describe the various methods available to the driver writer.
8.1   Debug Prints
One of the simplest methods of debugging is Debug Prints. These are similar to printf() statements
that might be used by any software. They can be used to reveal the contents of a variable or a register
at some special location during code execution. They are useful when the driver is behaving
unexpectedly. Debug prints should not be left in performance-sensitive paths of the driver, because
debug prints are down execution tremendously.  Debug prints can cause “Heisenberg-bugs”, since their
very presence alters timing. They may mask or even induce problems. 
The simple driver uses the following macros for debug prints. See simp911x.c for details.
8.1.1   SMSC_TRACE(message, parameters)
SMSC_TRACE points work just like a printf() statement, in fact they call the Linux kernel routine
printk(). For debugging, SMSC_TRACE points can temporarily be added anywhere they are needed.
SMSC_TRACE points are enabled when USE_TRACE is defined during compile time and
((debug_mode&0x01UL) == 0x01UL ) during run time. It is used to indicate general information such
as driver parameters used at load time.
For example:
int globalDriverParameter=0;
void DriverInitializationEntryPoint()
{
SMSC_TRACE(“globalDriverParameter = %d”,globalDriverParameter);
Do other initialization;
}
//When loading a driver in Linux
//  globalDriverParameter could be modified before
//  DriverInitializationEntryPoint is called. Therefore 
//  it is useful to display what ever setting has been applied to 
//  globalDriverParameter.
8.1.2   SMSC_WARNING(message, parameters)
SMSC_WARNING points work just like SMSC_TRACE points, with the exception that they are enabled
when USE_WARNING is define during compile time and ((debug_mode&0x02UL)==0x02UL) during
run time. The slight difference in enabling allows SMSC_WARNING points to be enabled while
SMSC_TRACE points are disabled. SMSC_WARNING points are not intended to indicate general
information. They are intended for the purpose of exposing unexpected situations, but only those
situations that can be handled without crashing the driver. 
For example:
void SomeDriverEntryPoint(int parameter) 
{
if (parameter==invalid) {
SMSC_WARNING(“Invalid Parameter = %d”,parameter);
return;
}
do work;
//if Linux calls an entry point of the driver with 
// invalid parameters, issue a warning and 
// just return with out any further problems.