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

📄 chip.c

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 C
📖 第 1 页 / 共 3 页
字号:
void FECParseMIIAnar(
	IN UINT RegVal,
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	UINT Status;
	volatile UINT *s;
	
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECParseMIIAnar\r\n")));
	
	s = &(pFEC->MIIPhyStatus);
	
	Status = *s & ~(PHY_CONF_SPMASK);
	
	if(RegVal & 0x0020)
		Status |= PHY_CONF_10HDX;
	if(RegVal & 0x0040)
		Status |= PHY_CONF_10FDX;
	if(RegVal & 0x0080)
		Status |= PHY_CONF_100HDX;
	if(RegVal & 0x0100)
		Status |= PHY_CONF_100FDX;
		
	*s = Status;
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECParseMIIAnar\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECParseAm79c874Dr
//
// This function parses the diagnostic register data of the external Am79c874
// PHY.
//
// Parameters:
//		RegVal
//			[in] the Adiagnostic Register value get from external Am79c874 PHY
//
//		MiniportAdapterHandle
//			[in] Specifies the handle to the driver allocated context area in
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize
//
// Return Value:
//		None
//
//------------------------------------------------------------------------------
void FECParseAm79c874Dr(
	IN UINT RegVal,
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	UINT Status;
	volatile UINT *s;
	
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECParseAm79c874Dr\r\n")));
	
	s = &(pFEC->MIIPhyStatus);
	
	Status = *s & ~(PHY_STAT_SPMASK | PHY_STAT_ANC);
	
	if(RegVal & 0x0080)
		Status |= PHY_STAT_ANC;
	if(RegVal & 0x0400)
	{
		Status |= ((RegVal & 0x0800) ? PHY_STAT_100FDX : PHY_STAT_100HDX);
		pEthernet->SpeedMode = TRUE;
	}
	else
	{
		Status |= ((RegVal & 0x0800) ? PHY_STAT_10FDX : PHY_STAT_10HDX);
		pEthernet->SpeedMode = FALSE;
	}	
	*s = Status;
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECParseAm79c874Dr\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECParsePHYLink
//
// This function will update the link status according to the Status register
// of the external PHY.
// 
// Parameters:
//		RegVal
//			[in] the MII frame value which is read from external PHY registers
//
//		MiniportAdapterHandle
//			[in] Specifies the handle to the driver allocated context area in
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None.
//
//------------------------------------------------------------------------------
void FECParsePHYLink(
	IN UINT RegVal,
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	NDIS_MEDIA_STATE oldState;
	PNDIS_PACKET pNdisPacket;
	NDIS_STATUS Status;
	
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECParsePHYLink\r\n")));
	
	oldState = pEthernet->MediaState;
	
	pFEC->LinkStatus = (pFEC->MIIPhyStatus & PHY_STAT_LINK)? TRUE : FALSE;
	
	if(pFEC->LinkStatus)
	{
		pEthernet->MediaState = NdisMediaStateConnected;
		Status = NDIS_STATUS_MEDIA_CONNECT;
	}
	else
	{
		pEthernet->MediaState = NdisMediaStateDisconnected;
		Status = NDIS_STATUS_MEDIA_DISCONNECT;
	}
		
	if(oldState != pEthernet->MediaState)
	{
		if(oldState	== NdisMediaStateConnected && pEthernet->MediaState == NdisMediaStateDisconnected)
		{
			// Remove the packet from the queue
			EnterCriticalSection (&gFECBufCs);
			pNdisPacket = pEthernet->HeadPacket;
			
			while(pNdisPacket != NULL)
            {
                pEthernet->HeadPacket = RESERVED(pNdisPacket)->Next;
                if (pNdisPacket == pEthernet->TailPacket) 
                {
                    pEthernet->TailPacket = NULL;
                }

                NdisMSendComplete(pEthernet->ndisAdapterHandle, pNdisPacket, NDIS_STATUS_SUCCESS);
                pNdisPacket = pEthernet->HeadPacket;    
            }
            LeaveCriticalSection (&gFECBufCs);

		}
		
		if ( pEthernet->CurrentState != NdisHardwareStatusInitializing )
        {
            NdisMIndicateStatus( pEthernet->ndisAdapterHandle, Status, NULL, 0 );
            NdisMIndicateStatusComplete( pEthernet->ndisAdapterHandle );
        }	
	}
	
		
	// Finished the link status checking process
	pEthernet->MediaStateChecking = FALSE;
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECParsePHYLink\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECGetPHYId
// 
// Scan all of the MII PHY addresses looking for someone to respond with a valid
// ID. This usually happens quickly.
//
// Parameters:
//		MIIReg
//			[in] the MII frame value which is read from external PHY registers
//
//      MiniportAdapterHandle
//			[in] Specifies the handle to the driver allocated context area in
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None
//
//------------------------------------------------------------------------------
void FECGetPHYId(
	IN UINT MIIReg,
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	UINT PhyType;
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECGetPHYId\r\n")));
	
	if(pFEC->MIIPhyAddr < PHY_MAX_COUNT)
	{
		if((PhyType = (MIIReg & 0xffff)) != 0xffff && PhyType != 0)
		{
			// The first part of the ID have been got, then get the 
			// the remainder
			pFEC->MIIPhyId = PhyType << 16;
			FECQueueMII(pFEC, MII_READ_COMMAND(MII_REG_PHYIR2), FECGetPHYId2);
		}
		else
		{
			// Try the next PHY address
			pFEC->MIIPhyAddr++;
			FECQueueMII(pFEC, MII_READ_COMMAND(MII_REG_PHYIR1), FECGetPHYId);
		}
	}
	else
	{
		// Close the clock for MII
		pFEC->MIIPhySpeed = 0;
		INSREG32BF( &gpFECReg->MSCR, FEC_MSCR_MIISPEED, pFEC->MIIPhySpeed );
		
		
		DEBUGMSG(ZONE_INFO,
			(TEXT("%s: No external PHY found\r\n"), __WFUNCTION__));
	}
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECGetPHYId\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECGetPHYId2
//
// Read the second part of the external PHY id.
//
// Parameters:
//		MIIReg
//			[in] the MII frame value which is read from external PHY registers
//
//		MiniportAdapterHandle
//			[in] Specifies the handle to the driver allocated context area in 
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None
//
//------------------------------------------------------------------------------
void FECGetPHYId2(
	IN UINT MIIReg,
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	UINT i;
	
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECGetPHYId2\r\n")));
	
	pFEC->MIIPhyId |= (MIIReg & 0xffff);
	
	for(i = 0; PhyInfo[i] != NULL; i++)
	{
		if(PhyInfo[i]->PhyId == pFEC->MIIPhyId)
			break;
	}
	
	if(PhyInfo[i])
		DEBUGMSG(ZONE_INFO,
			(TEXT("%s: The name for the external PHY is %s\r\n"), __WFUNCTION__, PhyInfo[i]->PhyName));
	else
		DEBUGMSG(ZONE_INFO,
			(TEXT("%s: No supported PHY found\r\n"), __WFUNCTION__));
			
	pFEC->MIIPhy = PhyInfo[i];
	pFEC->MIIPhyIdDone = TRUE;

#if 0
	if(pFEC->MIIPhy) {
		// Set to auto-negotiation mode and restart the
		// auto-negotiation process
		FECDoMIICmd(pFEC, pFEC->MIIPhy->PhyStartup);
		FECDoMIICmd(pFEC, pFEC->MIIPhy->PhyActint);
		FECDoMIICmd(pFEC, pFEC->MIIPhy->PhyConfig);
		// FECDoMIICmd(pFEC, pFEC->MIIPhy->PhyStartup);
		FECDoMIICmd(pFEC, PHYCmdCfg);		
	}
#endif
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECGetPHYId2\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECGetLinkStatus
//
// This function will send the command to the external PHY to get the link 
// status of the cable. The updated link status is stored in the context
// area designated by the parameter MiniportAdapterContext.
//
// Parameters:
//		MiniportAdapterHandle
//			[in] Specifies the handle to a FEC driver allocated context area
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None
//
//------------------------------------------------------------------------------
void FECGetLinkStatus(
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECGetLinkStatus\r\n")));
	
	FECDoMIICmd(pFEC, pFEC->MIIPhy->PhyActint);
	FECDoMIICmd(pFEC, PHYCmdLink);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECGetLinkStatus\r\n")));
}

//------------------------------------------------------------------------------
//
// Function: FECDispPHYCfg
//
// This function displays the current status of the external PHY
//
// Parameters:
//		MIIReg
//			[in] the MII frame value which is read from external PHY registers
//
//		MiniportAdapterHandle
//			[in] Specifies the handle to the driver allocated context area in
//				 which the driver maintains FEC adapter state, set up by
//				 FECInitialize.
//
// Return Value:
//		None
//
//------------------------------------------------------------------------------
void FECDispPHYCfg(
	IN UINT MIIReg,
	IN NDIS_HANDLE MiniportAdapterHandle
	)
{
	UINT Status;
	
	pFEC_t pEthernet = ((pFEC_t)(MiniportAdapterHandle));
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECDispPHYCfg\r\n")));
	
	Status = pFEC->MIIPhyStatus;
	
	if(Status & PHY_CONF_ANE)
		DEBUGMSG(ZONE_INFO, (TEXT("%s: Auto-negotiation is on\r\n"), __WFUNCTION__));
	else
		DEBUGMSG(ZONE_INFO, (TEXT("%s: Auto-negotiation is off\r\n"), __WFUNCTION__));
		
	if(Status & PHY_CONF_100FDX)
		DEBUGMSG(ZONE_INFO, (TEXT("%s: 100M Full Duplex Mode\r\n"), __WFUNCTION__));
	if(Status & PHY_CONF_100HDX)
		DEBUGMSG(ZONE_INFO, (TEXT("%s: 100M Half Duplex Mode\r\n"), __WFUNCTION__));
	if(Status & PHY_CONF_10FDX)
		DEBUGMSG(ZONE_INFO, (TEXT("%s: 10M Full Duplex Mode\r\n"), __WFUNCTION__));
	if(Status & PHY_CONF_10HDX)
		DEBUGMSG(ZONE_INFO, (TEXT("%s: 10M Half Duplex Mode\r\n"), __WFUNCTION__));
		
	if(!(Status & PHY_CONF_SPMASK))
		DEBUGMSG(ZONE_INFO, (TEXT("%s: No speed/duplex selected\r\n"), __WFUNCTION__));
		
	if(Status & PHY_CONF_LOOP)
		DEBUGMSG(ZONE_INFO, (TEXT("%s: Loop back mode is enabled\r\n"), __WFUNCTION__));
		
	pFEC->MIISeqDone =  TRUE;
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: -FECDispPHYCfg\r\n")));
	
	return;
}

//------------------------------------------------------------------------------
//
// Function: FECEnetInit
//
// This function initializes the FEC hardware and the external PHY(s). The FEC
// hardware initialization process includes:
// 		1. allocate DMA memory for buffer descriptors(BDs)
//		2. allocate DMA memory for receiving buffers
//		3. allocate DMA memory for transmitting buffers
//		4. set the FEC hardware registers so that the FEC hardware is ready for
//		   receiving and transmitting frames, and responsing to interrupts
//		5. to detect and initialize the external PHY(s)
//
// Parameters:
//		pEthernet
//			[in] the FEC driver context area allocated in function FECInitialize
//
// Return Value:
//		returns TRUE if the initialization process is successful, otherwise 
//		returns FALSE.
//
//------------------------------------------------------------------------------
BOOL FECEnetInit(pFEC_t pEthernet)
{
	PUCHAR MemAddr;
	PHYSICAL_ADDRESS	MemPhysicalBase;
	
	volatile PBUFFER_DESC BufferDescPointer;
	PBUFFER_DESC DescriptorBase;
	DMA_ADAPTER_OBJECT Adapter;
	
	UINT i;
	PFEC_ENET_PRIVATE pFEC = &(pEthernet->FECPrivateInfo);
	
	DEBUGMSG(ZONE_FUNCTION, (TEXT("FEC: +FECEnetInit\r\n")));
	
	// enable gpio and clock for FEC hardware
	BSPFECIomuxConfig( TRUE );
	BSPFECClockConfig( TRUE );
	
	
	memset(&Adapter, 0, sizeof(DMA_ADAPTER_OBJECT));
	Adapter.InterfaceType = Internal;
	Adapter.ObjectSize = sizeof(DMA_ADAPTER_OBJECT);

	// allocate DMA compatible memory for both receiving and transmitting
	// buffer descriptors(BDs)
	
	pFEC->RingBase = HalAllocateCommonBuffer(
							&Adapter,
							(FEC_RX_RING_SIZE + FEC_TX_RING_SIZE) * sizeof(BUFFER_DESC),
							&(pFEC->RingPhysicalBase),
							FALSE);
							
	if(pFEC->RingBase == NULL)
	{
		DEBUGMSG(ZONE_ERROR, (TEXT("FECEnetInit: Allocate DMA memory for BDs failed\r\n")));
		return FALSE;
	}
							
	DescriptorBase = (PBUFFER_DESC)pFEC->RingBase;
	
	// Set receive and transmit descriptor base
	pFEC->RxBufferDescBase = DescriptorBase;
	pFEC->TxBufferDescBase = DescriptorBase + FEC_RX_RING_SIZE;

⌨️ 快捷键说明

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