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

📄 ixethacccodeletmain.c

📁 intel IXP400系列cpu(2.3版)的库文件
💻 C
📖 第 1 页 / 共 4 页
字号:
 */void ixEthAccCodeletShow(void){    static IxEthEthObjStats *portStats = NULL;    UINT32 portNo;    if (!ixEthAccCodeletInitialised)    {	printf("CodeletMain: Codelet is not initialized!\n");	return;    }    if(portStats == NULL)    {	/*	 * The statistics are gathered by the NPE therefore we use DMA_MALLOC	 * to make it cache safe for us to read.	 */	if((portStats = IX_OSAL_CACHE_DMA_MALLOC(sizeof(IxEthEthObjStats))) == NULL)	{	    printf("CodeletMain: Unable to create port stats!\n");	    return;	}    }    for(portNo=0; portNo<IX_ETHACC_CODELET_MAX_PORT; portNo++)    {	if (ixEthAccCodeletHardwareExists[portNo])	{	    memset(portStats, 0, sizeof(IxEthEthObjStats));	    	    printf("\nStatistics for port %d:\n", portNo);	    if(ixEthAccMibIIStatsGetClear(portNo, portStats) != IX_ETH_ACC_SUCCESS)	    {		printf("Unable to retrieve statistics for port %d!\n", portNo);	    }	    else	    {                printf (" dot3portStatsAlignmentErrors:           %u\n",                    (unsigned) portStats->dot3StatsAlignmentErrors);                printf (" dot3portStatsFCSErrors:                 %u\n",                    (unsigned) portStats->dot3StatsFCSErrors);                printf (" dot3portStatsInternalMacReceiveErrors:  %u\n",                    (unsigned) portStats->dot3StatsInternalMacReceiveErrors);                        printf (" RxOverrunDiscards:                      %u\n",                    (unsigned) portStats->RxOverrunDiscards);                printf (" RxLearnedEntryDiscards:                 %u\n",                    (unsigned) portStats->RxLearnedEntryDiscards);                printf (" RxLargeFramesDiscards:                  %u\n",                    (unsigned) portStats->RxLargeFramesDiscards);                printf (" RxSTPBlockedDiscards:                   %u\n",                    (unsigned) portStats->RxSTPBlockedDiscards);                    printf (" RxVLANTypeFilterDiscards:               %u\n",                    (unsigned) portStats->RxVLANTypeFilterDiscards);                printf (" RxVLANIdFilterDiscards:                 %u\n",                    (unsigned) portStats->RxVLANIdFilterDiscards);                printf (" RxInvalidSourceDiscards:                %u\n",                    (unsigned) portStats->RxInvalidSourceDiscards);                printf (" RxWhiteListDiscards:                    %u\n",                    (unsigned) portStats->RxWhiteListDiscards);                printf (" RxBlackListDiscards:                    %u\n",                    (unsigned) portStats->RxBlackListDiscards);                printf (" RxUnderflowEntryDiscards:               %u\n",                    (unsigned) portStats->RxUnderflowEntryDiscards);                printf (" dot3portStatsSingleCollisionFrames:     %u\n",                    (unsigned) portStats->dot3StatsSingleCollisionFrames);                printf (" dot3portStatsMultipleCollisionFrames:   %u\n",                    (unsigned) portStats->dot3StatsMultipleCollisionFrames);                printf (" dot3portStatsDeferredTransmissions:     %u\n",                    (unsigned) portStats->dot3StatsDeferredTransmissions);                printf (" dot3portStatsLateCollisions:            %u\n",                    (unsigned) portStats->dot3StatsLateCollisions);                printf (" dot3portStatsExcessiveCollsions:        %u\n",                    (unsigned) portStats->dot3StatsExcessiveCollsions);                printf (" dot3portStatsInternalMacTransmitErrors: %u\n",                    (unsigned) portStats->dot3StatsInternalMacTransmitErrors);                printf (" dot3portStatsCarrierSenseErrors:        %u\n",                    (unsigned) portStats->dot3StatsCarrierSenseErrors);                printf (" TxLargeFrameDiscards:                   %u\n",                    (unsigned) portStats->TxLargeFrameDiscards);                printf (" TxVLANIdFilterDiscards:                 %u\n",                    (unsigned) portStats->TxVLANIdFilterDiscards);                printf (" RxValidFramesTotalOctets:               %u\n",                    (unsigned) portStats->RxValidFramesTotalOctets);                printf (" RxUcastPkts:                            %u\n",                    (unsigned) portStats->RxUcastPkts);                printf (" RxBcastPkts:                            %u\n",                    (unsigned) portStats->RxBcastPkts);                printf (" RxMcastPkts:                            %u\n",                    (unsigned) portStats->RxMcastPkts);                printf (" RxPkts64Octets:                         %u\n",                    (unsigned) portStats->RxPkts64Octets);                printf (" RxPkts65to127Octets:                    %u\n",                    (unsigned) portStats->RxPkts65to127Octets);                printf (" RxPkts128to255Octets:                   %u\n",                    (unsigned) portStats->RxPkts128to255Octets);                printf (" RxPkts256to511Octets:                   %u\n",                    (unsigned) portStats->RxPkts256to511Octets);                printf (" RxPkts512to1023Octets:                  %u\n",                    (unsigned) portStats->RxPkts512to1023Octets);                printf (" RxPkts1024to1518Octets:                 %u\n",                    (unsigned) portStats->RxPkts1024to1518Octets);                printf (" RxInternalNPEReceiveErrors:             %u\n",                    (unsigned) portStats->RxInternalNPEReceiveErrors);                printf (" TxInternalNPETransmitErrors:            %u\n",                    (unsigned) portStats->TxInternalNPETransmitErrors);		printf("\n");	    }	}    }}/** * @fn void ixEthAccCodeletStatsPollTask * * This task polls the Codelet Stats and displays the rate of Rx and  * Tx packets per second. *  */PRIVATE void ixEthAccCodeletStatsPollTask(void* arg, void** ptrRetObj){    int portNo = 0;    static char stillRunning[] = "|/-\\";    static int  stillRunningIndex = 0;    static char displayString[20 + (21 * IX_ETHACC_CODELET_MAX_PORT)];    static char *stringPtr;    static UINT32 busTimestampEnd = 0;    static UINT32 busTimestampStart = 0;    static UINT32 pTimeCycles = 0;    static UINT64 rxCount = 0;    static UINT64 txCount = 0;    static UINT64 pTimeUsecs = 0;    ixEthAccCodeletStatsPollTaskStop = FALSE;    if (ixOsalMutexLock (&ixEthAccCodeletStatsPollTaskRunning,			 IX_OSAL_WAIT_FOREVER) != IX_SUCCESS)    {        printf("CodeletMain: Error starting Stats thread! Failed to lock mutex.\n");        return;    }    while (1)    {	while (ixEthAccCodeletTrafficPollEnabled == FALSE)	{	    /* Sleep 1 sec */	    ixOsalSleep(1000);	    if (ixEthAccCodeletStatsPollTaskStop)	    {		break;  /* Exit the thread */	    }	}	if (ixEthAccCodeletStatsPollTaskStop)	{	    break;  /* Exit the thread */	}	printf("\n");#ifdef __wince	printf("\r");#endif	for(portNo=0; portNo<IX_ETHACC_CODELET_MAX_PORT; portNo++)	{	    printf("Port%d Rates:        |",portNo);	}	printf("\n");#ifdef __wince	printf("\r");#endif	for(portNo=0; portNo<IX_ETHACC_CODELET_MAX_PORT; portNo++)	{	    printf("=====================");	}	printf("=\n");#ifdef __wince	printf("\r");#endif	/* reset the stats */	for(portNo=0; portNo<IX_ETHACC_CODELET_MAX_PORT; portNo++)	{	    ixEthAccCodeletStats[portNo].rxCount=0;	    ixEthAccCodeletStats[portNo].txCount=0;	}	while (ixEthAccCodeletTrafficPollEnabled)	{	    busTimestampStart = ixOsalTimestampGet();	    /* Sleep approximatively 1 sec */	    ixOsalSleep(1000);       	    /* check if the task should stop */ 	    if (ixEthAccCodeletStatsPollTaskStop)	    {	        break;  /* Exit the thread */	    }	    if  (ixEthAccCodeletTrafficPollEnabled)	    {		/* \r : reset print curser to beginning of line */		stringPtr = displayString;		*stringPtr++ = '\r';		for(portNo=0; portNo<IX_ETHACC_CODELET_MAX_PORT; portNo++)		{		    /* get a snapshot */		    busTimestampEnd = ixOsalTimestampGet();		    rxCount = ixEthAccCodeletStats[portNo].rxCount;		    txCount = ixEthAccCodeletStats[portNo].txCount;		    /* Got stats, now clear counters */		    ixEthAccCodeletStats[portNo].rxCount=0;		    ixEthAccCodeletStats[portNo].txCount=0;		    /* get the measurement interval using a unsigned		     * subtraction in order to handle wrap-around. The time unit 		     * is in APB bus cycles.		     */		    pTimeCycles = busTimestampEnd - busTimestampStart;		    /* convert the time in APB bus cycles to microseconds		     *		     * multiplications are done before divisions and		     * will not overflow the UINT64.		     */		    pTimeUsecs = (UINT64)pTimeCycles;				    pTimeUsecs = IX_ETHACC_CODELET_MULDIV(pTimeUsecs,			     IX_ETHACC_CODELET_PCLOCK_DIVIDER, 			     IX_ETHACC_CODELET_XCLOCK_FREQ);		    if (!pTimeUsecs) 		    {			/* time may be 0 as the result of the previous operation			 * In this case (very unlikely to occur), 			 * just skip the remaining of this loop.			 * The display will not be updated before the next			 * loop.			 */			continue;		    }		    /* convert from the packet count to a rate in pkts per second 		     *		     * rate = pkts * usecsPerSec / timeUsec		     *		     * multiplications are done before divisions and		     * will not overflow the UINT64.		     */		    rxCount = IX_ETHACC_CODELET_MULDIV(rxCount, 			        IX_ETHACC_CODELET_USEC_PER_SEC, pTimeUsecs);		    txCount = IX_ETHACC_CODELET_MULDIV(txCount, 			        IX_ETHACC_CODELET_USEC_PER_SEC, pTimeUsecs);		    /* print stats */		    stringPtr += sprintf(stringPtr, "Rx:%6u Tx:%6u |", 					 (unsigned)rxCount, 					 (unsigned)txCount);		}		*stringPtr++ = stillRunning[stillRunningIndex++ & 3];		*stringPtr = 0;		printf("%s", displayString);	    }	}	printf("\n");#ifdef __wince	printf("\r");#endif    }    ixOsalMutexUnlock (&ixEthAccCodeletStatsPollTaskRunning);}/** * @fn void ixEthAccCodeletLoop() * * This function is called once a operation has started. It spawns the * stats poll task and waits for use interrupt to end the codelet. *  * @return IX_SUCCESS - operation successfully run * @return IX_FAIl - error spawning stats poll task */PRIVATE IX_STATUS ixEthAccCodeletLoop(void){#ifdef __wince    char str[16];#elif defined (__vxworks)    int ch = 0;#elif defined (__linux)#endif    printf(IX_ETHACC_CODELET_USER_INSTRUCTION);    ixEthAccCodeletTrafficPollEnabled = TRUE;#ifdef __wince    /* wait for the user to enter the sequence q<CR> */    do    {        gets(str);    }    while(str[0] != 'q');#elif defined (__linux)    /* wait for the user to stop the codelet */    ixEthAccCodelet_wait();#elif defined (__vxworks)    /* wait for the user to enter the sequence <ESC><CR> */    do    {	ch = getchar();    }    while(ch != 27);#else#error "Unsupported platform"#endif        ixEthAccCodeletTrafficPollEnabled = FALSE;    return (IX_SUCCESS);}#ifdef __wince/** * @fn int wmain(int argc, WCHAR **argv) * * This function is the entryPoint for winCE menu *  * @return 0 (always) */int wmain(int argc, WCHAR **argv){    int ethAccCodeletTestNr;    BOOL ethAccCodeletRun = TRUE;    char line[256];    IxEthAccPortId inPort;    IxEthAccPortId outPort;    while (ethAccCodeletRun)    {        printf("\n");        printf("************* ethAcc Codelet *********************************\n");        printf("  %d. RxOnly: All frames received (from external device)\n",	       IX_ETHACC_CODELET_RX_SINK);        printf("     will be sinked, for all available ports.\n");        printf("  %d. Loopback: All frames received are software loopbacked\n",	       IX_ETHACC_CODELET_SW_LOOPBACK);        printf("     to the same port, for all available ports.\n");        printf("  %d. TxGenRxSink: Frames generated and transmitted from outPort,\n",	        IX_ETHACC_CODELET_TXGEN_RXSINK);        printf("     and received on inPort.\n");        printf("  %d. PhyLoopback: Frames generated and PHY loopbacked on the\n",	       IX_ETHACC_CODELET_PHY_LOOPBACK);        printf("     same port, for all available ports.\n");        printf("  %d. Bridge: Frames received on one port will be transmitted\n",	       IX_ETHACC_CODELET_BRIDGE);        printf("  %d. QoS Bridge: VLAN-tagged Frames received on inPort will be\n",	       IX_ETHACC_CODELET_BRIDGE_QOS);        printf("     prioritized and untagged before being transmitted through\n");	printf("     the outPort and vice-versa.\n");        printf("  %d. Firewall bridge: Only the frames with one of the\n",	       IX_ETHACC_CODELET_BRIDGE_FIREWALL );        printf("     authorized source MAC address will be transmitted\n");	printf("     through the other port.\n");        printf("  %d. EthDB: Ethernet Learning Facility where it adds some static\n",	       IX_ETHACC_CODELET_ETH_LEARNING);        printf("     and dynamic entries. Dynamic entries are then aged and\n");        printf("     verified that they no longer appear in the database.\n");        printf("  %d. WiFi bridge: Frames received on one port get their WIFI\n",	       IX_ETHACC_CODELET_BRIDGE_WIFI );        printf("     header stripped. Trafic is forwarded to the other port.\n");        printf("100. Exit ethAcc Codelet\n");        printf("\n");        printf("Enter test number: ");	/* read the menu option */	gets(line);        ethAccCodeletTestNr = atoi(line);	/* read the port numbers */        printf("\n");        printf("Enter inPort number: ");	gets(line);        inPort = atoi(line);        printf("\n");        printf("Enter outPort number: ");	gets(line);        outPort = atoi(line);        if (ethAccCodeletTestNr == 100)	{	    /* exit the codelet */	    ethAccCodeletRun = FALSE;	}	else if ((ethAccCodeletTestNr >= IX_ETHACC_CODELET_RX_SINK) 		 && (ethAccCodeletTestNr <= IX_ETHACC_CODELET_BRIDGE_WIFI))	{	    /* run the codelet's option */	    ixEthAccCodeletMain(ethAccCodeletTestNr,inPort,outPort);	}    }    return 0;}#endif

⌨️ 快捷键说明

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