📄 ixethaal5app.c
字号:
}IX_STATUS ixEthInit(BOOL speed, BOOL duplex, BOOL autoneg){ BOOL getLink, getSpeed, getDuplex, getAutoneg; BOOL phyPresent[IX_EAA_NUM_ETH_PORTS]; UINT32 i; UINT32 j; IxOsalThreadAttr threadAttr; ixOsalMemSet(phyPresent, 0, sizeof(phyPresent)); if( ixEAAEthNpeInit() ) return IX_FAIL; /*Initialize Ethernet Access component*/ if(ixEthAccInit()!=IX_ETH_ACC_SUCCESS) { printf("ixEthAccInit failed\n"); return IX_FAIL; } /* Initialize both ports */ printf("Initializing port 1..."); if(ixEthAccPortInit(IX_ETH_PORT_1)!=IX_ETH_ACC_SUCCESS) { printf("ixEthAccPortInit failed for port 1\n"); return IX_FAIL; } printf("Succeeded\n"); printf("Initializing port 2..."); if(ixEthAccPortInit(IX_ETH_PORT_2)!=IX_ETH_ACC_SUCCESS) { printf("ixEthAccPortInit failed for port 2\n"); return IX_FAIL; } printf("Succeeded\n"); printf("Scanning for Ethernet PHYs..."); if(ixEthAccMiiPhyScan(phyPresent) == IX_FAIL) { printf("ixEthAccMiiPhyScan Failed\n"); return IX_FAIL; } else { printf("Phy init Succeeded\n"); printf("PHYs discovered at addresses: "); j=0; for(i=0;i<IX_EAA_NUM_ETH_PORTS;i++) { if(phyPresent[i] == TRUE) { printf("%d ",i); phyAddresses[j]=i; ++j; } } printf("\n"); } for(i=0;i<IX_EAA_NUM_ETH_PORTS; i++) { /* Reset each phy */#ifdef IXEAA_DEBUG printf("Resetting PHY %d address %d\n", i, phyAddresses[i]);#endif ixEthAccMiiPhyReset(phyAddresses[i]); /* Set each phy's config - speed, duplex, autonegotiation mode */#ifdef IXEAA_DEBUG printf("Configuring PHY %d address:%d\n", i,phyAddresses[i]);#endif ixEthAccMiiPhyConfig(phyAddresses[i], speed, duplex, autoneg); } for(i=0;i<IX_EAA_NUM_ETH_PORTS; i++) { unsigned int retry = 20; if (IX_EAA_INVALID_PHY_ADDR == phyAddresses[i]) continue; printf("Get link Status PHY %d address:%d\n", i,phyAddresses[i]); do { ixOsalSleep(100); ixEthAccMiiLinkStatus(phyAddresses[i], &getLink, &getDuplex, &getSpeed, &getAutoneg); } while (retry-- > 0 && getLink == FALSE); ixEthAccMiiShow(phyAddresses[i]); } /* obtain current link status for each phy - in case autonegotiation was used set the proper duplex mode */ for(i=IX_ETH_PORT_1;i<=IX_ETH_PORT_2;i++) {#ifdef IXEAA_DEBUG printf("Set port %d mode\n", i);#endif ixEthAccMiiLinkStatus(phyAddresses[i], &getLink, &getDuplex, &getSpeed, &getAutoneg); if (getLink != TRUE) { /* ensure the default duplex mode is as required */ getDuplex = duplex; } if(getDuplex) { ixEthAccPortDuplexModeSet (i, IX_ETH_ACC_FULL_DUPLEX); } else { ixEthAccPortDuplexModeSet (i, IX_ETH_ACC_HALF_DUPLEX); } /* additional small delay between the MAC settings */ ixOsalSleep(100); }#ifdef IXEAA_DEBUG printf("MII PHY configuration complete\n");#endif /* Enable generation of FCS on both ports */ if(ixEthAccPortTxFrameAppendFCSEnable (IX_ETH_PORT_1)!=IX_ETH_ACC_SUCCESS) { printf("Error enabling FCS on port 1\n"); return IX_FAIL; } if(ixEthAccPortTxFrameAppendFCSEnable (IX_ETH_PORT_2)!=IX_ETH_ACC_SUCCESS) { printf("Error enabling FCS on port 2\n"); return IX_FAIL; }#ifdef IXEAA_DEBUG printf("MAC setup\n");#endif /* Set default MAC addresses to both ports. They are defined at the top of this file. */ if(ixEthAccPortUnicastMacAddressSet (IX_ETH_PORT_1, &macAddr1) !=IX_ETH_ACC_SUCCESS) { printf("Error setting mac on port 1\n"); return IX_FAIL; } printf("PHY 0 MAC address is:\t"); ixEthAccPortUnicastAddressShow(IX_ETH_PORT_1); if(ixEthAccPortUnicastMacAddressSet (IX_ETH_PORT_2, &macAddr2) !=IX_ETH_ACC_SUCCESS) { printf("Error setting mac on port 2\n"); return IX_FAIL; } printf("PHY 1 MAC address is:\t"); ixEthAccPortUnicastAddressShow(IX_ETH_PORT_2); /* Start a Ethernet Link Monitor task to keep Phy and MAC in sychronization */ threadAttr.name = "LinkStateMonitor"; threadAttr.stackSize = IX_ETHAAL5APP_THREAD_STACK_SIZE; threadAttr.priority = IX_EAA_LINE_MONITOR_PRI; /* Create thread for LinkStateMonitorLoop */ if (IX_SUCCESS != ixOsalThreadCreate( &lineMonitorTask, &threadAttr, (IxOsalVoidFnVoidPtr)ixEAAEthLinkStateMonitorLoop, NULL)) { printf ("Error spawning ixEAAEthLinkStateMonitorLoop task\n"); return IX_FAIL; } /* Starting thread for LinkStateMonitorLoop */ if (ixOsalThreadStart(&lineMonitorTask) != IX_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDERR, "Error starting thread ixEAAEthLinkStateMonitorLoop task\n", 0, 0, 0, 0, 0, 0); return IX_FAIL; } return IX_SUCCESS;}IX_STATUS ixEAAEthChannelInit( void ){ int bufCnt; int bufSize; int cnt; /* Register Callbacks in ixEthAcc for obtaining 'Tx done' buffers */ if( ixEthAccPortTxDoneCallbackRegister(IX_ETH_PORT_1, ixEAAEthTxDoneCallback, 0) != IX_ETH_ACC_SUCCESS) { printf("Failed to register Tx done callback for port 1\n"); return IX_FAIL; } if( ixEthAccPortTxDoneCallbackRegister(IX_ETH_PORT_2, ixEAAEthTxDoneCallback, 1) != IX_ETH_ACC_SUCCESS) { printf("Failed to register Tx done callback for port 2\n"); return IX_FAIL; } /* We doesn't have any scheduling constraints... */ ixEthAccTxSchedulingDisciplineSet( IX_ETH_PORT_1,FIFO_NO_PRIORITY ); ixEthAccTxSchedulingDisciplineSet( IX_ETH_PORT_2,FIFO_NO_PRIORITY ); /* Register Callbacks in ixEthAcc for receiving Rx buffers */ if( ixEthAccPortRxCallbackRegister(IX_ETH_PORT_1, (IxEthAccPortRxCallback)ixEAAEthRxCallback, 0) != IX_ETH_ACC_SUCCESS) { printf("Failed to register Rx callback for port 1\n"); return IX_FAIL; } if( ixEthAccPortRxCallbackRegister(IX_ETH_PORT_2, (IxEthAccPortRxCallback)ixEAAEthRxCallback, 1) != IX_ETH_ACC_SUCCESS) { printf("Failed to register Rx callback for port 2\n"); return IX_FAIL; } /* Enable both ports */ printf("Enabling port 1\n"); if(ixEthAccPortEnable(IX_ETH_PORT_1) != IX_ETH_ACC_SUCCESS) { printf("ixEthAccPortEnable failed for port 1\n"); return IX_FAIL; } printf("Enabling port 2\n"); if(ixEthAccPortEnable(IX_ETH_PORT_2) != IX_ETH_ACC_SUCCESS) { printf("ixEthAccPortEnable failed for port 2\n"); return IX_FAIL; } /* Replenish free buffers to both ports */ for (cnt = IX_ETH_PORT_1; cnt <= IX_ETH_PORT_2; cnt++) { /* nbuf pool initialisation */ bufSize = IX_EAA_DEFAULT_MBUF_DATA_SIZE+IX_EAA_MBUF_USER_SPACE; mBufEthPool[cnt] = IX_OSAL_MBUF_POOL_INIT(IX_EAA_NUM_BUFFERS_PER_ETH, bufSize, "Eth Aal5 Codelet Pool for Eth"); for( bufCnt = 0; bufCnt < IX_EAA_NUM_BUFFERS_PER_ETH; bufCnt++ ) { /* get a mbuf from the pool */ IX_OSAL_MBUF *mbufPtr; mbufPtr = IX_OSAL_MBUF_POOL_GET(mBufEthPool[cnt]); /* initialise the user space part of the mbuf */ ixEAABufferInit(mbufPtr, IX_EAA_ETH_MARK | cnt); /* recycle the mbuf */ ixEAAEthBufferRecycle( cnt, mbufPtr);#ifdef IXEAA_DEBUG printf("Eth %d. Buf:%p->%p\n", cnt+1, mbufPtr, IX_OSAL_MBUF_MDATA(mbufPtr));#endif } } return IX_SUCCESS;}#ifndef __linux /* i.e. VxWorks* & WinCE *//* Below we have continuous dispatching loop. Only tasks with higher priority can preempt that loop. Dispatching loop guarantees faster buffer processing than dispatching through interrupts, however Tasks with lower priority will be blocked until the loop works. For that reason current thread is assigned relatively low priority (lower than all vxWorks threads) to avoid blocking them. */static IX_STATUS ixEAAPollTask(void *arg, void **ptrRetObj){ while(1) { /* We need to dispatch only queues from lower group: serving 'Rx' and 'TxDone' for ixEthAcc and AtmdAcc. Queue manager consist of upper and lower group, containing each 32 queues. */ (*dispatcherFunc) (IX_QMGR_QUELOW_GROUP); ixOsalSleep(dispatcherSleepDuration); } *ptrRetObj = NULL; return IX_SUCCESS;}#ifdef __vxworksvoid ixEAAQDispatcherSleepDurationSet(UINT32 timeInMS){ UINT32 sysClkRate; /* Get number of ticks per second*/ sysClkRate = sysClkRateGet(); /* * Make sure resolution of OS system clock * can support minimum sleep time duration. * * See explanation below: * * Resolution of OS system clock, R = sysClkRateGet() (ticks per second) * So 1/R = timing interval of OS System Clock * Sleep time duration, T = timeInMS (millisecond) * * Minimum of T = timing interval of OS System Clock * Minimum of T = 1/R * 1000 (millisecond) * T >= 1000/R * R * T >= 1000 * */ /* If resolution is not sufficient for 1ms interval, * i.e. R*T < 1000 */ if( sysClkRate * timeInMS < 1000 ) { /* Set to highest resolution in system clock */ sysClkRateSet(1000); } dispatcherSleepDuration = timeInMS;}#endif /* #ifdef __vxworks */#endif /* #ifndef __linux *//* display the current counters */int ixEAAShow(void){ IX_ETHAAL5APP_CODELET_DEBUG_DO( printf("ixEAANumAtmRxDropBuffers .......... : %10u (should be 0)\n", ixEAANumAtmRxDropBuffers); printf("ixEAANumAtmRxChainedBuffers ....... : %10u (should be 0)\n", ixEAANumAtmRxChainedBuffers); printf("ixEAANumAtmRxMACDroppedBuffers .... : %10u (should be 0)\n", ixEAANumAtmRxMACDroppedBuffers); ); printf("ixEAANumAtmRxEthFramesForwarded ... : %10u\n", ixEAANumAtmRxEthFramesForwarded); printf("ixEAANumAtmRxPackets .............. : %10u\n", ixEAANumAtmRxPackets); IX_ETHAAL5APP_CODELET_DEBUG_DO( printf("ixEAANumEthRxDropBuffers .......... : %10u (should be 0)\n", ixEAANumEthRxDropBuffers); printf("ixEAANumEthRxChainedBuffers ....... : %10u (should be 0)\n", ixEAANumEthRxChainedBuffers); printf("ixEAANumEthRxMACDroppedBuffers .... : %10u (should be 0)\n", ixEAANumEthRxMACDroppedBuffers); ); printf("ixEAANumEthRxEthFramesForwarded ... : %10u\n", ixEAANumEthRxEthFramesForwarded); printf("ixEAANumEthRxFrames ............... : %10u\n", ixEAANumEthRxFrames); printf("\n"); return IX_SUCCESS;}void ixEAAEthDBRecordsShow(void){ printf ("\nEthernet Database Show Records\n"); if (IX_ETH_DB_SUCCESS != ixEthDBFilteringDatabaseShowRecords(IX_ETH_DB_ALL_PORTS,IX_ETH_DB_ALL_RECORD_TYPES)) { printf ("\nUnable to show
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -