⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ks95mspi.h

📁 ks8995m5口交换机启动eeprom配置源码
💻 H
字号:
//--------------------------------------------------------------------------
//  
//  KS95MSPI.H  (c) Copyright 2002 Micrel-Kendin Operations
//  
//--------------------------------------------------------------------------


//#define LINUX
#define DOSBOX
//#define DEBUG

#ifdef LINUX

#include <termios.h>
#include <sys/times.h>

//
// Linux TIME structure
//

static struct termios orig, new;
static int peek = -1;

#endif

typedef unsigned char	BYTE;

//
//  Version number string
//
#define VERSIONNO   "V1.7"

//
//  Configuration file name
//
#define DELIMITER	'='

// Registers
#define KS8995M_CHIP_ID0	0
#define KS8995M_CHIP_ID1	1
#define GLOBALCTLBEGIN		2
#define GLOBALCTLEND		11
#define REGISTERTOTAL		128
#define INDIRECTCTL1		0x6E // 110	
#define INDIRECTCTL2		0x6f // 111
#define INDIRECTDATABASE	0x70 // 112
#define DTESTREGBEGIN		0x79 // 121
#define DTESTREGEND		    0x7C // 124
#define ATESTREGBEGIN		0x7D // 125
#define ATESTREGEND		    0x7F // 127


// Indirect commands
#define	INDIRECTREAD		0x10
#define INDIRECTWRITE		0x00
#define INDIRECTSMACTAB		0x00
#define INDIRECTVLANTAB		0x04
#define INDIRECTDMACTAB		0x08
#define INDIRECTMIBCNT		0x0C
#define INDIRECTDROPMIBCNT	0x01

// Bit masks
#define VALIDMACENTRY		0x10	
#define DMACTABREADY		0x80

// Port dropped packet MIB counters
#define DROPPEDMIBTOTAL		10		// Total number of dropped packet MIB counters

// MIB
#define MIBCOUNTEROFFSET	0x20	// Each port has these many MIB counters
#define MIBVALIDMASK		0x40000000
#define MIBOVERFLOWMASK		0x80000000

// VLAN
#define VLANENTRIES			16

// Static MAC table
#define SMACTABTOTAL	8	// Total 8 entries

// Constants
#define KS8995MID		0x95
#define MAXCMDLINELEN	256
#define BLANK			' '
#define MAXSUBCMDLEN	4
#define STATICMACTOTAL  8		// 8 static MAC address entries in total
#define VLANTABTOTAL	16		// 16 VLAN table entries in total
#define DMACTABTOTAL	1024	// 1024 dynamic MAC address entries in total
#define PORTTOTAL		5
#define MAXLINE        256

// ERROR CODE
#define FALSE			0
#define TRUE			1
#define FAIL			-1
#define NOPARAMETER		-1
#define SUCCESS			0
#define CMDERROR		1
#define SPIMINITERROR	2
#define PARMERROR		3


// SPI Commands
#define SPI_WRITE	2
#define SPI_READ	3


// SPIM Controls

// Data Rate
#define SPIMCONT_DIVIDE_BY_4		0
#define SPIMCONT_DIVIDE_BY_8		1
#define SPIMCONT_DIVIDE_BY_16		2
#define SPIMCONT_DIVIDE_BY_32		3
#define SPIMCONT_DIVIDE_BY_64		4
#define SPIMCONT_DIVIDE_BY_128		5
#define SPIMCONT_DIVIDE_BY_256		6
#define SPIMCONT_DIVIDE_BY_512		7

#define SPIMCONT_1_BIT				0
#define SPIMCONT_2_BIT				1
#define PIMCONT_3_BIT				2
#define SPIMCONT_4_BIT				3
#define SPIMCONT_5_BIT				4
#define SPIMCONT_6_BIT				5
#define SPIMCONT_7_BIT				6
#define SPIMCONT_8_BIT				7
#define SPIMCONT_9_BIT				8
#define SPIMCONT_10_BIT				9
#define SPIMCONT_11_BIT				10
#define SPIMCONT_12_BIT				11
#define SPIMCONT_13_BIT				12
#define SPIMCONT_14_BIT				13
#define SPIMCONT_15_BIT				14
#define SPIMCONT_16_BIT				15


#define VID				"vid="
#define FID				"fid="
#define MEMBERSHIP		"mbr="
#define VALID			"on="

#define VID1MASK		0xff
#define VID2MASK		0x0f
#define VTABFIDMASK		0xf0
#define MBRMASK			0x1f

#define VID1SHIFT		8
#define FIDSHIFT		4


#define UFID			"ufid="
#define OVERRIDE		"over="
#define FORWARDINGPORT	"port="
#define MAC				"mac="

#define FIDMASK			0x0f
#define UFIDMASK		0x80
#define OVERRIDEMASK	0x40
#define VALIDMASK		0x20
#define	FPORTSMASK		0x1f	

#define UFIDSHIFT		7
#define OVERRIDESHIFT	6
#define VALIDSHIFT		5



// Structures

typedef struct cmdtabletag
{
	char cmd[MAXSUBCMDLEN + 1];	// Sub command string
	int (* cmdfun ) ( int elem1, int elem2, int elem3 ); // Command functions
}cmdtable;

//
//	Advanced commands
//
typedef struct acmdtabletag
{
	char cmd[MAXSUBCMDLEN + 1];	// Sub command string
	int (* acmdfun ) ( char * sCmdBuf ); // Advanced command functions
}acmdtable;



// Function Prototypes
int GetChipID ();
int DumpAnalogTestReg( int elem1, int elem2, int elem3 );
int DumpDroppedPacketMIB( int elem1, int elem2, int elem3 );
int DumpDigitalTestReg( int elem1, int elem2, int elem3 );
int DumpDynaMACTable( int elem1, int elem2, int elem3 );
int DumpGlobalReg( int elem1, int elem2, int elem3 );
int DumpMAC( int elem1, int elem2, int elem3 );
int DumpMIBAll ( int elem1, int elem2, int elem3 );
int DumpMIB( int elem1, int elem2, int elem3 );
int DumpNext20Reg( int elem1, int elem2, int elem3 );
int DumpPortCtlReg( int elem1, int elem2, int elem3 );
int DumpReg( int elem1, int elem2, int elem3 );
int DumpStaticMACTable( int elem1, int elem2, int elem3 );
int DumpTOSReg( int elem1, int elem2, int elem3 );
int DumpVLANReg( int elem1, int elem2, int elem3 );
int ReadMIB( int elem1, int elem2, int elem3 );
int ReadNextReg( int elem1, int elem2, int elem3 );
int ReadReg( int elem1, int elem2, int elem3 );
int ReadCnt( int elem1, int elem2, int elem3 );
int WriteToNextReg( int elem1, int elem2, int elem3 );
int WriteToReg( int elem1, int elem2, int elem3 );
int WriteToStaticMACTable( int elem1, int elem2, int elem3 );
int WriteToVLANTable( int elem1, int elem2, int elem3 );
int UpdateVLANTab ( char *sCmdBuf );
int UpdateSMACTab ( char *sCmdBuf );
int ParseParameters( char * sBuf, char *sPrompt, unsigned int *uValue );
int ProcessSubCmds ( char *sCmdBuf, cmdtable *SubCMDTable );
int ParseMACAddress ( char *sBuf, char *sPrompt, unsigned long *uMACLow, unsigned long *MACHigh );
void Start95MSwitch ();
void WriteData ( BYTE cReg, BYTE cData );
void WriteDataBegin ( BYTE cReg, BYTE cData );
void WriteDataContinue ( BYTE cData );
void WriteDataEnd ( BYTE cData );
BYTE ReadData ( BYTE cReg );
BYTE ReadDataBegin ( BYTE cReg );
BYTE ReadDataContinue ();
BYTE ReadDataEnd ();
char *GetValue ( char *sBuf, int *iValue );
int  ElapseTime ( int iOn );
unsigned long GetMIBCounter ( BYTE bPort, BYTE bMIBNdx );
void DisplayMIBArray ();
void ConvertToBinaryDigits ( int iIn, char * sOut, int iDigits );
int ProcessConfig ();
int SPICmds ( char *sCmd );
void DisplayCmdList ();
int	GetHex ( char *sHexStr, unsigned int *uHex );
void ConvertToLowerRemoveExtraBlanks ( char *sCmd );

// Global Variables
extern int igRRegNdx;  // Point to current register. Next-20-register commands 
		        // start from igRRegNdx+1
extern int igWRegNdx;

extern int giMIBOverflow;

//
//	Every MIB reads will be accumulated into this table.
//
extern unsigned long ulMIB[PORTTOTAL][MIBCOUNTEROFFSET];

//
//  This array holds accumlated counter values
//
extern unsigned long ulMIBDroppedPacket[DROPPEDMIBTOTAL];

//
// This array holds the previous counter values. Compare
// the current counter readings again the previou values
// can determine whether overflow happened.
//
extern unsigned long ulMIBDroppedPacketPrev[DROPPEDMIBTOTAL];


//
// Command tabls
//
// Expand the table entry to add new commands. The first field is the command string, the second
// field is the function that process the command. The function takes three integers as parameters.
//      
//  
//

//
//  Dump commands
//
extern cmdtable DumpCmds [];
	

//
//  Read Commands
//
extern cmdtable ReadCmds [];


//
//  Write Commands
//
extern cmdtable WriteCmds [];


//
//  Update Commands
//
extern acmdtable UpdateCmds [];

//
//  MIB counter names
//
extern char *MIBNames[];


#ifdef DOSBOX

#define SPIDMASK    0x80
#define SPISMASK    0x01    // Bit 1 is inverted
#define SPIQMASK    0x40
#define SPICMASK    0x04

#define PTICKS      150     // Dealy after each parallel port access

extern unsigned int  uParallelBase;  // Default parallel port base    
extern unsigned short  uSPICPort; //= uParallelBase + 2;
extern unsigned short  uSPIDPort; //= uParallelBase;
extern unsigned short  uSPIQPort; //= uParallelBase + 1;
extern unsigned short  uSPISPort; //= uParallelBase + 2;

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -