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

📄 cli.c

📁 Switch,Ic,driver,英飛凌6996m驅動程式,包括bandwidth-control以及basic-control功能
💻 C
📖 第 1 页 / 共 5 页
字号:
		    return;
        }
    }

	printf("=== Port[%d] == RxPkt == RxByte == TxPkt == TxByte == Collision == Error\n",port_no);

	for (i = 0; i < 6; i++) {
	    printf("  %08ld", SWPortCounter(port_no, i));
    }	 
    printf("\n");   
}


#ifdef  EEPROM

/************************************************************************************/
/* CmdEEPROMRead:                                                                   */
/************************************************************************************/
void CmdEEPROMRead(int argc, char **argv)
{
    word offset, value;

    // option description:
    // offset: the EEPROM address (0..0x9c)

	// Get the EEPROM address to read from.
    sscanf(argv[1], "0x%x", &offset);

	if (offset < 0 || offset > 0x9c) {
		printf("ArgErr: the EEPROM address must be in the range [0..0x9c]!\n");
		return;
	}

    value = ReadEEPROM(offset);
	
	printf("Read EEPROM[%#x]=%#x\n", offset, value);    
}


/************************************************************************************/
/* CmdEEPROMWrite:                                                                  */
/************************************************************************************/    
void CmdEEPROMWrite(int argc, char **argv)
{
    word offset, value;

    // option description:
    // offset: the EEPROM address (0..0x9c)
    // value:  the data written in EEPROM

	// Get the EEPROM address to read from.
    sscanf(argv[1], "0x%x", &offset);

	if (offset < 0 || offset > 0x9c) {
		printf("ArgErr: the EEPROM address must be in the range [0..0x9c]!\n");
		return;
	}

    // Get the setting value 
    sscanf(argv[2], "0x%x", &value);

	WriteEEPROM(offset, value);
    delay(EEPROM_ACCESS_DELAY);
    value = ReadEEPROM(offset);
	
	printf("Write EEPROM[%#x]=%#x\n", offset, value);    
}

#endif // EEPROM


/************************************************************************************/
/* CmdSWIRegRead:                                                                   */
/************************************************************************************/
void CmdSWIRegRead(int argc, char **argv)
{
    word offset, value;

    // option description:
    // offset: the SMI register address (0..0x288)

	// Get the SMI register address to read from.
    sscanf(argv[1], "0x%x", &offset);

	if (offset < 0 || offset > 0x288) {
		printf("ArgErr: the SMI register address must be in the range [0..0x288]!\n");
		return;
	}

    value = (word)ReadSMI(offset);
	
	printf("Read SMIReg[%#x]=%#x\n", offset, value);    
}


/************************************************************************************/
/* CmdSWIRegWrite:                                                                  */
/************************************************************************************/
void CmdSWIRegWrite(int argc, char **argv)
{
    word offset, value;

    // option description:
    // offset: the SMI register address (0..0x288)
    // value:  the data written in SMI registers

	// Get the SMI register address to read from.
    sscanf(argv[1], "0x%x", &offset);

	if (offset < 0 || offset > 0x288) {
		printf("ArgErr: the SMI register address must be in the range [0..0x288]!\n");
		return;
	}

    sscanf(argv[2], "0x%x", &value);

	WriteSMI(offset, (dword)value);
    value = (word)ReadSMI(offset);
	
	printf("Write SMIReg[%#x]=%#x\n", offset, value);
}


/************************************************************************************/
/* CmdReadPhy:                                                                      */
/************************************************************************************/
void CmdReadPhy(int argc, char **argv)
{
    int  port_no, regAddr;    
    word regValue;

    // option description:
    // port_no: the port numer (0..4)
    // regAddr:  the phy register number (0..5)

	// Get the port_no.
    sscanf(argv[1], "%d", &port_no);

	if ((port_no < 0) || (port_no > 4)) {
		printf("ArgErr: the port_no must be in 0..4 !\n");
		return;
	}

	// Get the phy register number.
    sscanf(argv[2], "%d", &regAddr);

	if (regAddr < 0 || regAddr > 5) {
		printf("ArgErr: the PHY regsiter address must be in the range [0..5]!\n");
		return;
	}

	regValue = ReadPhyReg(port_no, regAddr);
	
	printf("Read PHY Port[%d].Reg[%d]=%#x\n", port_no, regAddr, regValue);
}


/************************************************************************************/
/* CmdWritePhy:                                                                     */
/************************************************************************************/
void CmdWritePhy(int argc, char **argv)
{
    int  port_no, regAddr;    
    word regValue;

    // option description:
    // port_no: the port numer (0..4)
    // regAddr:  the phy register number (0..5)
    // regValue: the setting value for the phy register

	// Get the port_no.
    sscanf(argv[1], "%d", &port_no);

	if ((port_no < 0) || (port_no > 4)) {
		printf("ArgErr: the port_no must be in 0..4 !\n");
		return;
	}

	// Get the phy register number.
    sscanf(argv[2], "%d", &regAddr);

	if (regAddr < 0 || regAddr > 5) {
		printf("ArgErr: the PHY regsiter address must be in the range [0..5]!\n");
		return;
	}	

	// Get the setting value.
    sscanf(argv[3], "0x%x", &regValue);

	WritePhyReg(port_no, regAddr, regValue);
	
	printf("Write PHY Port[%d].Reg[%d]=%#x\n", port_no, regAddr, ReadPhyReg(port_no, regAddr));
}


/************************************************************************************/
/* CmdResetSwitch:                                                                  */
/************************************************************************************/
void CmdResetSwitch(int argc, char **argv)
{
	printf("ADM6996X will be restarted !\n");
    SWI_Reset();
}


/************************************************************************************/
/* CmdExit:                                                                         */
/************************************************************************************/	
void CmdExit(int argc, char **argv) // add - 06/28/09,bolo
{
    printf("%s%s", CLEAR_SCREEN, NORMAL_DISPLAY); // Clear screen
    exit(0);
}


/************************************************************************************/
/* CmdHelp:                                                                         */
/************************************************************************************/	
#define PAGE_LINE_NUM	9 // mod - 06/29/05,bolo; org: 10

void CmdHelp(int argc, char **argv)
{
	int i, j, cmdcnt=0, len =0;
	int ch;
	char *leadingStr = NULL;

	printf("\n           Samurai Command Line Interface. v%s",version); // mod - 09/12/05,bolo
	printf("\n======================================================\n");

	if (argc > 1) {
	    len = strlen(argv[1]);
	    leadingStr = argv[1]; 
	}
		    
    for (i=0, j=0; i< NumCmd; i++) {

        if (len) {
		    if(strncmp(cli_tab[i].cmdname, leadingStr, len) == 0)
		    {
                printf("%-10s: %s.\n", cli_tab[i].cmdname, cli_tab[i].cmddesc); // mod - 06/29/05,bolo
                printf("            Usage : %s %s\n", cli_tab[i].cmdname, cli_tab[i].cmdusage);
			    cmdcnt ++;
			    break;
            }
        } else {

            printf("%-10s: %s.\n", cli_tab[i].cmdname, cli_tab[i].cmddesc); // mod - 06/29/05,bolo
            printf("            Usage : %s %s\n", cli_tab[i].cmdname, cli_tab[i].cmdusage);
            cmdcnt ++;
            j++;
        }

		if ((j >= PAGE_LINE_NUM) && (i < NumCmd-1)) {   
		    
			j = 0;
			printf("\n\n Press [q] to quit, [enter] key to continue..");
			ch = getchar(); // mod - 06/27/05,bolo
			if ((char) ch == 'q')  break;
			printf("\n\n");
		}
	}

	if (argc > 1) {
	    
		if (cmdcnt)		
			printf("\n\nThere are %d command found\n", cmdcnt);    
		else
			printf("\n\nThere is no command starting with \"%s\"!!\n", argv[1]);
	}
	else
		printf("\n\n");
	
}


/************************************************************************************/
/* CliShowPrompt:                                                                   */
/************************************************************************************/
void CliShowPrompt(void)
{
    int  i;
    char cli_prompt[] = "$>";

    for (i = 0; i < MAX_CMD_LEN; i++)
        clibuf[i] = 0;

    printf("\n%s ", cli_prompt);
}


/************************************************************************************/
/* CliProcess:                                                                      */
/************************************************************************************/
void CliProcess(void)
{ 
	int i, esc_cnt, key;
	char *token, ch;

	printf("\n==========================================================================");
	printf("\n                  Samurai Command Line Interface. v%s ", version);
	printf("\n==========================================================================\n");	
	
    esc_cnt = 0;
	NumCmd = sizeof(cli_tab) / sizeof(CLI_ENTRY);
	CliShowPrompt();

	while (1)
	{
        key = getchar(); // mod - 06/27/05,bolo; org: _getkey()
		
        if(key == EOF)
        {
            /* Clear the EOF flag */
            clearerr(stdin);
            continue;
        }

		if (esc_cnt)
		{
			esc_cnt--;
			continue;
		}

		// Put the character into the command line buffer
		ch = clibuf[bufidx++] = (char) key;

		switch(ch)
		{
			case 0xa:           // New line for Linux - 06/28/05,bolo; org: '\r' Carrage return
				printf("\n");

				// Terminate the command line with NULL character (0x00)
				clibuf[bufidx] = 0;

				// Break the input line into arguments
				argcnt = 0;
				token = (char *) strtok(clibuf, " \t\n\r");

				while(token != NULL)
				{
					argarray[argcnt++] = token;

					if (argcnt >= MAX_ARG_NUM) break;
					else
                        token = (char *) strtok(NULL, " \t\n\r");
				}

				if(argcnt > 0)
				{
					// Dispatch the command
					for(i=0; i< NumCmd; i++)
					{
						if(strcmp(argarray[0], cli_tab[i].cmdname)==0)
						{
							// The command has been found.
							
							// Check the argument count
							if(argcnt < cli_tab[i].minargc)
							{
								printf("Err: Too few arguments\n");
							}
							else if(argcnt > cli_tab[i].maxargc)
							{
								printf("Err: Too many arguments\n");
							}
							else
							{
								// Execute the command
								(*cli_tab[i].cmd)(argcnt, argarray);
							}
							break;
						}
					}
					if(i == NumCmd)
					{
						// Unknown Command
						printf("Err: Unknown command!!\n");
					}
				}
				// Empty the command buffer
				

⌨️ 快捷键说明

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