📄 nchal.c
字号:
/******************************************************************************
Copyright (C) 2003, 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.
NCHAL.C
NetChip Hardware Abstraction Layer (HAL) for NET2272 access.
The upper edge of NcHal exposes a small set of macros to access the
NET2272. The lower edge does the actual chip accesses, and is very hardware
specific. You are invited to change the lower edge as required for your
hardware platform. Preserving the upper edge eases portability.
NcHal includes debug and high performance "direct access" versions. During
initial development NetChip recommends using the debug version. The high
performance version is well-optimized, but may require further optimizations
for specific 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 <NcCommon.h> // Collection of common NetChip header files
#include <NET2272.h>
#include <NcHal.h>
///////////////////////////////////////////////////////////////////////////////
extern PNETCHIP_DATA_TYPE NetchipBaseAddress;
///////////////////////////////////////////////////////////////////////////////
// When using direct chip access, the rest of this NcHal file does not need
// to be compiled. Performance-optimized, direct-access macros are used instead
#if !NET2272_DIRECT_ACCESS
///////////////////////////////////////////////////////////////////////////////
// Show chip access info (show register name, register value, read or write)
// - Useful during early debug
// - When emailing support@netchip.com, including these listings can help us help you!
#define SHOW_CHIP_ACCESS TRUE // TRUE: Print chip access info
#if _NCDEBUG
///////////////////////////////////////////////////////////////////////////////
// NET2272 register names (ASCII text)
// - Often useful during early development and debug
// - For convenience, these register names map directly to NET2272 addresss
char *Net2272_RegisterNames[] =
{ // Directly addressable registers (if all five NET2272 address bits used):
"REGADDRPTR", "REGDATA", "IRQSTAT0", "IRQSTAT1",
"PAGESEL", "EP_DATA", "EP_STAT0", "EP_STAT1",
"EP_TRANSFER0", "EP_TRANSFER1", "EP_TRANSFER2", "EP_IRQENB",
"EP_AVAIL0", "EP_AVAIL1", "EP_RSPCLR", "EP_RSPSET",
"0x10", "0x11", "0x12", "0x13", // Reserved
"0x14", "0x15", "0x16", "0x17", // Reserved
"USBCTL0", "USBCTL1", "FRAME0", "FRAME1",
"DMAREQ", "SCRATCH", "0x1E", "0x1F",
// Indirect only:
// - These registers can only be accessed using REGADDRPTR/REGDATA registers
"IRQENB0", "IRQENB1", "LOCCTL", "CHIPREV",
"0x24", "0x25", "0x26", "0x27", // Reserved
"EP_MAXPKT0", "EP_MAXPKT1", "EP_CFG", "0x2B",
"0x2C", "0x2D", "0x2E", "0x2F", // Reserved
"OURADDR", "USBDIAG", "USBTEST", "XCVRDIAG",
"0x34", "0x35", "0x36", "0x37", // Reserved
"0x38", "0x39", "0x3A", "0x3B", // Reserved
"0x3C", "0x3D", "0x3E", "0x3F", // Reserved
"SETUP0", "SETUP1", "SETUP2", "SETUP3",
"SETUP4", "SETUP5", "SETUP6", "SETUP7"
};
#endif // _NCDEBUG
///////////////////////////////////////////////////////////////////////////////
#if _NCHISTO
char *Net2272_BriefRegisterNames[] =
{ // Short (four chars max) NET2272 Register names
// - Short names fit into History buffer entries
"RADD", "RDAT", "IST0", "IST1",
"PAGE", "EDAT", "EST0", "EST1",
"ETX0", "ETX1", "ETX2", "EIRQ",
"EAV0", "EAV1", "ERSC", "ERST",
"0x10", "0x11", "0x12", "0x13", // Reserved
"0x14", "0x15", "0x16", "0x17", // Reserved
"USB0", "USB1", "FRM0", "FRM1",
"DMAR", "SCRA", "0x1E", "0x1F",
"IEN0", "IEN1", "LCTL", "CHRV",
"0x24", "0x25", "0x26", "0x27", // Reserved
"EMX0", "EMX1", "ECFG", "0x2B",
"0x2C", "0x2D", "0x2E", "0x2F", // Reserved
"OURA", "USBD", "USBT", "XCVR",
"0x34", "0x35", "0x36", "0x37", // Reserved
"0x38", "0x39", "0x3A", "0x3B", // Reserved
"0x3C", "0x3D", "0x3E", "0x3F", // Reserved
"SET0", "SET1", "SET2", "SET3",
"SET4", "SET5", "SET6", "SET7"
};
#endif // _HISTO
///////////////////////////////////////////////////////////////////////////////
// Lowest level chip access primitives:
// - These are the lowest level abstraction layers for chip register access
// - We apply them as functions to aid during early development and debug.
// - Replace or rewrite these function as appropriate for your design and development requirements
///////////////////////////////////////////////////////////////////////////////
void
NcWrite8(
UINT Reg,
BYTE Val
)
{ // Write value to 8 bit NetChip register
// - Performance tip: after debug, replace with in-line function
BYTE Tmp;
if (Reg >= NET2272_INDIRECT_THRESHOLD)
{ // Indirect access to register (via REGADDRPTR/REGDATA)
// - Save and restore REGADDRPTR. This prevents REGADDRPTR from
// changes between other code sections, but it is time consuming.
// - Performance tips: either do not save and restore REGADDRPTR (if it
// is safe) or do save/restore operations only in critical sections.
Tmp = ((BYTE)NETCHIP_BASEADDRESS[REGADDRPTR].NcReg);
(NETCHIP_BASEADDRESS[REGADDRPTR].NcReg) = (BYTE)Reg;
(NETCHIP_BASEADDRESS[REGDATA].NcReg) = Val;
(NETCHIP_BASEADDRESS[REGADDRPTR].NcReg) = Tmp;
}
else
{ // Direct access to register
(NETCHIP_BASEADDRESS[Reg].NcReg) = (BYTE)Val;
}
#if SHOW_CHIP_ACCESS && _NCDEBUG
NCPRINTF(VOLUME_MAXIMUM, (" Write %2.2x %-12.12s %2.2x %s\n",
Reg,
Net2272_RegisterNames[Reg],
Val,
(Reg >= NET2272_INDIRECT_THRESHOLD)? "via REGADDRPTR/REGDATA": ""
));
#elif _HISTO
HISTO(VOLUME_MAXIMUM, Net2272_BriefRegisterNames[Reg], Reg, Val, 0x00000000);
#endif
}
///////////////////////////////////////////////////////////////////////////////
volatile BYTE
NcRead8(
UINT Reg
)
{ // Read 8 bit value from NET2272 register
// - Performance tip: after debug, replace with in-line function
BYTE Val, Tmp;
if (Reg >= NET2272_INDIRECT_THRESHOLD)
{ // Indirect access to register (via REGADDRPTR/REGDATA)
// - Save and restore REGADDRPTR. This prevents REGADDRPTR from
// changes between other code sections, but it is time consuming.
// - Performance tips: either do not save and restore REGADDRPTR (if it
// is safe) or do save/restore operations only in critical sections.
Tmp = ((BYTE)NETCHIP_BASEADDRESS[REGADDRPTR].NcReg);
(NETCHIP_BASEADDRESS[REGADDRPTR].NcReg) = (BYTE)Reg;
Val = ((BYTE)NETCHIP_BASEADDRESS[REGDATA].NcReg);
(NETCHIP_BASEADDRESS[REGADDRPTR].NcReg) = Tmp;
}
else
{ // Direct access to register
Val = ((BYTE)NETCHIP_BASEADDRESS[Reg].NcReg);
}
#if SHOW_CHIP_ACCESS && _NCDEBUG
NCPRINTF(VOLUME_MAXIMUM, (" Read %2.2x %-12.12s %2.2x %s\n",
Reg,
Net2272_RegisterNames[Reg],
Val,
(Reg >= NET2272_INDIRECT_THRESHOLD)? "via REGADDRPTR/REGDATA": ""
));
#elif _HISTO
HISTO(VOLUME_MAXIMUM, Net2272_BriefRegisterNames[Reg], Reg, (UINT)Val, 0xffffffff);
#endif
return Val;
}
///////////////////////////////////////////////////////////////////////////////
#endif // !NET2272_DIRECT_ACCESS
///////////////////////////////////////////////////////////////////////////////
// End of file
///////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -