📄 ncdebug.c
字号:
/******************************************************************************
Copyright (C) 2004, NetChip Technology, Inc. (http://www.netchip.com)
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
NCDEBUG.C
NetChip device firmware debugging support:
'Debug' is a collection of firmware debugging aids. These functions can be
invaluable for debugging your USB device. As provided, they work on
the NetChip PCI-RDK. Some changes may required for them to operate
correctly on different platforms.
NetChip support: If you have technical problems, comments or feedback about this product,
please contact us: support@netchip.com. Please write "Firmware API" in the subject.
In the body, please provide the software release code (e.g. RE010203), the application
filename, the NetChip chip you are using, plus any helpful details.
******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stddef.h>
#include <string.h>
///////////////////////////////////////////////////////////////////////////////
#include <NcCommon.h> // Collection of common NetChip header files
#include <NcDevice.h> // Useful NET2272 functions, types and macros (for USB transfers, etc.)
///////////////////////////////////////////////////////////////////////////////
extern PNC_DEVICE_OBJECT PrivDeviceObject;
///////////////////////////////////////////////////////////////////////////////
extern NC_ENDPOINT_OBJECT LogicalEndpoints[NCAPI_MAX_ENDPOINT_COUNT];
#if _NCDEBUG || _NCHISTO
///////////////////////////////////////////////////////////////////////////////
// Print volume control
// - A message is printed if the volume parameter to NetChip's print function is
// this level or lower:
UINT gPrintVolume = DEFAULT_PRINT;
#endif
///////////////////////////////////////////////////////////////////////////////
#if _NCDEBUG || _NCHISTO
///////////////////////////////////////////////////////////////////////////////
// History or print volume
PCHAR VolumeMsg[] =
{
"Off", // VOLUME_NONE
"Minimum", // VOLUME_MINIMUM
"Low", // VOLUME_LOW
"Medium", // VOLUME_MEDIUM
"High", // VOLUME_HIGH
"Maximum", // VOLUME_MAXIMUM
};
#endif
///////////////////////////////////////////////////////////////////////////////
#if _NCDEBUG || _NCSTATISTICS
///////////////////////////////////////////////////////////////////////////////
PCHAR EpTypeString[] =
{
"CTRL",
"ISOC",
"BULK",
"INTR"
};
///////////////////////////////////////////////////////////////////////////////
PCHAR EpDirString[] =
{
"OUT",
"IN "
};
#endif
#if _NCHISTO
///////////////////////////////////////////////////////////////////////////////
// History
// - Record critical firmware events into a history trace log (in RAM)
// - Useful for nitty-gritty real-time debug.
///////////////////////////////////////////////////////////////////////////////
#pragma message(_NC_MESSAGE"Compiled with trace logging (History) enabled (_NCHISTO)")
// Trace logging is an invaluable tool when bringing up and debugging any firmware.
// Scattered throughout NetChip firmware are HISTO() calls. These calls log critical
// code events and parameters into a large ring buffer. When an unexpected event
// occurs, the trace log usually shows enough detail to determine the cause of the
// problematic event.
// - RDK customers can email trace logs to NetChip for expert evaluation.
// - HISTO is a macro, so as development nears completion it can be redefined to "do
// nothing", so it won't consume code space or execution time.
// - Recommendation: *Never* remove the HISTO() lines from the sources (even when
// development is complete)!
// - Feel free to apply HISTO any place in your code
///////////////////////////////////////////////////////////////////////////////
// History volume control
// - A history entry is added to the history log if the volume parameter
// to NetChip's History function is this level or lower:
UINT gHistoryVolume = DEFAULT_HISTORY;
HISTORY_ENTRY HistoBuf[HISTORY_ENTRIES];
ULONG HistoryCount = 0;
///////////////////////////////////////////////////////////////////////////////
void
History(
UINT Volume,
char * Text,
ULONG Arg1,
ULONG Arg2,
ULONG Arg3
)
{ // Quickly log an event:
// - Called by any function to add one line to the historical trace log
// - Use your debugger to examine the history buffer
// - The text parameter should be a helpful string like "TxEv" for Transmit Event
// - The remaining arguments can anything you want
// This implementation has been 'tuned' to be human-readable using the MSVC
// debugger. Feel free to re-tune as appropriate for your debugger
// Print history in real-time (if volume is set high enough)
// - During early debug, printing each History call can be useful, however
// it significantly slows overall performance. Once the system is proving
// to be reliable and stable, specify a high volume. Events will still be
// logged for analysis, but without much less performance impact
CHAR WideString[10];
if (Volume <= gPrintVolume)
{
wsprintf((LPWSTR)WideString, TEXT("%S"), Text);
RETAILMSG(TRUE, (TEXT(HistoPrintFormat),
WideString,
Arg1,
Arg2,
Arg3
));
}
if (Volume > gHistoryVolume)
{ // Ignore this historical event
return;
}
memcpy(&HistoBuf[HistoryCount].Text, Text, sizeof(HistoBuf[HistoryCount].Text));
HistoBuf[HistoryCount].Arg1 = Arg1;
HistoBuf[HistoryCount].Arg2 = Arg2;
HistoBuf[HistoryCount].Arg3 = Arg3;
HistoryCount++;
if (HistoryCount >= HISTORY_ENTRIES)
{ // History will now re-write itself
HistoryCount = 0;
}
// Add an easy-to-spot terminator in history
memset(&HistoBuf[HistoryCount], 0xff, sizeof(HISTORY_ENTRY));
}
///////////////////////////////////////////////////////////////////////////////
void
ShowHistory(
void
)
{
INT LineCount;
//printf(" History:\n");
// Assert: Statistics may get skewed if interrupts occur while printing!
ASSERT(System_InterruptController(NCSYS_INTERRUPT_STATUS) == NCSYS_INTERRUPT_DISABLE);
for (LineCount = HISTORY_ENTRIES; LineCount; LineCount--)
{
// Get an index into history buffer (adjusted for wraparound)
// - We want to show the oldest history entries first so the
// last lines printed are the most recent history entries. That
// means the second portion of the history buffer (above the
// current History Count) will be shown first:
CHAR WideString[10];
UINT ii = (((INT)HistoryCount - LineCount) >= 0)?
HistoryCount - LineCount: // First portion of buffer
HistoryCount + (HISTORY_ENTRIES - LineCount); // Second portion of buffer
wsprintf((LPWSTR)WideString, TEXT("%S"), &HistoBuf[ii].Text);
RETAILMSG(TRUE, (
TEXT(" -%3u: ")
TEXT(HistoPrintFormat)
TEXT("\n"),
LineCount - 1,
WideString,
HistoBuf[ii].Arg1,
HistoBuf[ii].Arg2,
HistoBuf[ii].Arg3
));
}
}
///////////////////////////////////////////////////////////////////////////////
void
HistoryFlush(
void
)
{ // Pre-fill history buffer
UINT ii;
memset(&HistoBuf[0], 0x00, sizeof(HistoBuf));
for (ii = 0; ii < HISTORY_ENTRIES; ii++)
memset(&HistoBuf[ii].Text, '-', sizeof(HistoBuf[ii].Text));
}
#endif // _NCHISTO
#if _NCDEBUG && _NC_RDK_AND_WINDOWS
///////////////////////////////////////////////////////////////////////////////
// Display memory
///////////////////////////////////////////////////////////////////////////////
#define NCDEBUG_BYTES_PER_LINE 16
///////////////////////////////////////////////////////////////////////////////
STATIC void
GetWord(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -