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

📄 cf_ifc.h

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 H
📖 第 1 页 / 共 4 页
字号:
//* Function: 		cf_IsTxDownloadReady
//*	Description:	Polls device to see if TxDnLdRdy is set.
//* Returns			IX_STATUS_SUCCESS if device is ready for transmit download. 
//*						IX_STATUS_DEVICE_BUSY if not.
//* Date:			04/02/2003
//*************************************************************************
__inline IX_STATUS cf_IsTxDownloadReady(PCF_OBJECT pCf )
{
    USHORT usval;
	ASSERT( pCf != NULL );

    //      Set command length
    NdisRawReadPortUshort( pCf -> ulMrvDrvVirtualIoBase + CFMACREG_CCR_CARD_STATUS,
    						&usval);
#if DBG
    if ( !(usval & CFMACREG_CCR_CS_TxDnLdRdy) )
        DBGPRINT(DBG_HWIF,("Download not ready %x\n",usval));
#endif // end of DBG>0        
    return (usval & CFMACREG_CCR_CS_TxDnLdRdy) ? IX_STATUS_SUCCESS : IX_STATUS_DEVICE_BUSY;
}


//*************************************************************************
//* Function: 		cf_IsRxUploadReady
//*	Description:	Polls device to see if RxUpLdRdy bit is set.
//* Returns			IX_STATUS_SUCCESS if device is ready for a receive data transfer. 
//*						IX_STATUS_DEVICE_BUSY if not.
//* Date:			04/02/2003
//*************************************************************************
__inline IX_STATUS cf_IsRxUploadReady(PCF_OBJECT pCf )
{
    //      Set command length
    USHORT usval;
	ASSERT( pCf != NULL );
    NdisRawReadPortUshort( pCf -> ulMrvDrvVirtualIoBase + CFMACREG_CCR_CARD_STATUS,
    						&usval);
    return usval & CFMACREG_HCR_HIM_RxUpLdRdy ? IX_STATUS_SUCCESS : IX_STATUS_NO_DATA;
}


//*************************************************************************
//* Function: 		cf_TxStartPacket
//*	Description:	Sets transmit packet write length.
//*					 packet is transmitted by first setting the packet length
//*						in the device, then downloading all the data, then
//*						setting the txDnLdOvr bit.
//*					Starting a packet is just a matter of programming the total 
//*						length of the packet.
//* Returns			IX_STATUS_DEVICE_BUSY if device busy, IX_STATUS_SUCCESS otherwise
//* Date:			04/08/2003
//*************************************************************************
__inline IX_STATUS cf_TxStartPacket(PCF_OBJECT pCf, USHORT totalPacketLengthInBytes )
{
	//-------------------------------------------------------------------------------
	// Debug assertions from specifciation.
	//-------------------------------------------------------------------------------
	ASSERT( pCf != NULL );
//	ASSERT(!pCf -> bTxPacketOpen );
	ASSERT( pCf -> ulSignatureTop == CF_Signature );
	ASSERT( pCf -> ulSignatureBottom == CF_Signature );
	ASSERT( pCf -> ulMrvDrvVirtualIoBase != 0 );
	ASSERT( totalPacketLengthInBytes != 0 );
	ASSERT( totalPacketLengthInBytes <= MRVDRV_ETH_TX_PACKET_BUFFER_SIZE ); 
#if DBG
    if ( totalPacketLengthInBytes > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE )
    {
        DBGPRINT(DBG_ERROR,("ERORR: max packet exceeded: max %d, packet size %d",MRVDRV_ETH_TX_PACKET_BUFFER_SIZE,totalPacketLengthInBytes));
    }
#endif    
	
	//-------------------------------------------------------------------------------
	// First check if device is ready. If not then wait return BUSY status.
	//		upper layer must block on and wait or reschedule for device on Device Busy status.
	// PDM: Also check for a packet in progress and return same if so.
	//-------------------------------------------------------------------------------
	if ( !IX_SUCCESS(cf_IsTxDownloadReady(pCf))  || pCf->bTxPacketOpen )
	{
		DBGPRINT(DBG_WARNING,("cf_TxStartPacket: Device is not ready for data\n"));
		return IX_STATUS_DEVICE_BUSY;
	}

    DBGPRINT(DBG_HWIF | DBG_TXDATA,("Starting TX packet, size %d\n",
                                        totalPacketLengthInBytes));
	pCf -> ulTxPacketSize = totalPacketLengthInBytes;		// remember our packet size.
	pCf -> bTxPacketOpen = TRUE;							// set that we have packet open.
	pCf -> ulTxPacketByteCount = 0;							// initialize our byte accumulator.
	
	//-------------------------------------------------------------------------------
	// Write out the packet length to the device.
	//-------------------------------------------------------------------------------
    NdisRawWritePortUshort(
  		 pCf -> ulMrvDrvVirtualIoBase + CFMACREG_HCR_IO_WRITE_LEN,
	         totalPacketLengthInBytes );
	return IX_STATUS_SUCCESS;
}	         

//************************************************************************************
//* Function: 		cf_TxBlock
//*	Description:	Transmits a block of data to the device.
//* Returns			void
//* Date:			04/08/2003
//************************************************************************************
__inline void cf_TxBlock
( 
	PCF_OBJECT pCf, 					// Pointer to our interface object.
	UCHAR *packetBuf, 					// Pointer to packet to transmit.
	USHORT packetSizeBytes 				// size in bytes of current packet.
)		
{
	USHORT leftOverByte = packetSizeBytes % sizeof(USHORT);		// see if we divide evenly.
	USHORT cmdSizeWords = packetSizeBytes/sizeof(USHORT);		//  get the whole number of words.
	int ii;

	DBGPRINT(DBG_HWIF,("Sending packet size %d from %x\n",packetSizeBytes,packetBuf));
	//-------------------------------------------------------------------------------
	// Debug assertions from specifciation.
	//-------------------------------------------------------------------------------
	ASSERT( pCf != NULL );
	ASSERT( pCf -> ulSignatureTop == CF_Signature );
	ASSERT( pCf -> ulSignatureBottom == CF_Signature );
	ASSERT( pCf -> bTxPacketOpen);
	ASSERT( pCf -> ulMrvDrvVirtualIoBase != 0);
	ASSERT( packetSizeBytes != 0 );
	ASSERT( pCf -> ulTxPacketByteCount + packetSizeBytes <= MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
	
	//-------------------------------------------------------------------------------
    //      Download command words.
	//-------------------------------------------------------------------------------

    for( ii = 0; ii < (int)cmdSizeWords; ii++ )
    {
        NdisRawWritePortUshort(
  		    pCf -> ulMrvDrvVirtualIoBase + CFMACREG_HCR_IO_WRITE_PORT,
            *((PUSHORT)packetBuf));
        packetBuf+=2;
    }

	//-------------------------------------------------------------------------------
    //      If cmd was not even number of bytes write the leftover byte to the device.
    //-------------------------------------------------------------------------------
    if ( leftOverByte )
    {
    	NdisRawWritePortUchar(
    	pCf -> ulMrvDrvVirtualIoBase + CFMACREG_HCR_IO_WRITE_PORT,
        (UCHAR)*((UCHAR *)packetBuf));
    }
    // PDM: first flush the fifo to make sure all data is transfered to 
    // device memory.
    // don't do it here!  wait till packet is complete
//	cf_UshortRegSetBits(pCf, CFMACREG_HCR_HOST_STATUS,    CFMACREG_HCR_HS_FlushDataFifo );
    
    pCf -> ulTxPacketByteCount += packetSizeBytes;	// keep running total.
    DBGPRINT(DBG_HWIF,("Sent size %d from 0x%x, total %d bytes\n",
                        packetSizeBytes,packetBuf, pCf -> ulTxPacketByteCount));
}

//************************************************************************************
//* Function: 		cf_TxEndPacket
//*	Description:	Ends transmit of current packet to the device.
//*						Block is ended by setting the download complete bit in the
//*						host status register and by signaling a download complete
//*						interrupt cause to the device in the card interrupt cause
//*						register.
//* Returns			void
//* Date:			04/08/2003
//************************************************************************************
__inline void cf_TxEndPacket
( 
	PCF_OBJECT pCf 					// Pointer to our interface object.
)
{
	//USHORT usRegVal;
	
	//-------------------------------------------------------------------------------
	// Debug assertions from specifciation.
	//-------------------------------------------------------------------------------
	ASSERT( pCf != NULL );
	ASSERT( pCf -> ulSignatureTop == CF_Signature );
	ASSERT( pCf -> ulSignatureBottom == CF_Signature );
	ASSERT( pCf -> bTxPacketOpen );
	ASSERT( pCf -> ulMrvDrvVirtualIoBase != 0 );
	ASSERT( pCf -> ulTxPacketByteCount == pCf -> ulTxPacketSize );
	
#if DBG    
    if ( pCf -> ulTxPacketByteCount != pCf -> ulTxPacketSize )
    {
        DBGPRINT(DBG_ERROR,("TxPacket ENDS with wrong size: tx count %d, open size %d\n",pCf -> ulTxPacketByteCount,pCf -> ulTxPacketSize));        
    }
#endif    

    // PDM: first flush the fifo to make sure all data is transfered to 
    // device memory.
	//cf_UshortRegSetBits(pCf, CFMACREG_HCR_HOST_STATUS, CFMACREG_HCR_HS_FlushDataFifo );

	//-------------------------------------------------------------------------------
	// Set the CFMACREG_HCR_HS_TxDnLdOvr bit in the host status register.
	//-------------------------------------------------------------------------------
	cf_UshortRegSetBits(pCf, CFMACREG_HCR_HOST_STATUS, CFMACREG_HCR_HS_TxDnLdOvr );

	//-------------------------------------------------------------------------------
	// Set the CFMACREG_HCR_CIC_TxDnLdOvr bit in the interrupt cause register.
	//		This triggers an interrupt in the card FW.
	//-------------------------------------------------------------------------------
	cf_UshortRegSetBits(pCf, CFMACREG_HCR_CARD_INT_CAUSE, CFMACREG_HCR_CIC_TxDnLdOvr );

	pCf -> ulTxPacketSize = 0;						// reset transmit packet size.
	pCf -> ulTxPacketByteCount = 0;					// reset the byte accumulator.
	pCf -> bTxPacketOpen = FALSE;					// close out the packet.

    // clean mask bit to allow FW to interrupt us when its done
//    cf_UshortRegClearBits(pCf, CFMACREG_HCR_HOST_INT_MASK,CFMACREG_HCR_HIM_TxDnLdRdy);
    
	DBGPRINT(DBG_HWIF,("Finalizing TX packet\n"));
}

//************************************************************************************
//* Function: 		cf_TxPacket
//*	Description:	Transmits a packet to the device.
//* Returns			IX_STATUS_SUCCESS if packet transmit ok, IX_STATUS_DEVICE_BUSY
//*						if device is busy.
//* Date:			04/02/2003
//************************************************************************************
__inline IX_STATUS cf_TxPacket 
	( 
		PVOID iface, 						// Pointer to our interface object.
		UCHAR *packet, 						// Pointer to packet to transmit.
		USHORT packetSizeBytes 				// size in bytes of current packet.
	)
{
	PCF_OBJECT pCf = (PCF_OBJECT)iface;
	IX_STATUS ixStatus = IX_STATUS_SUCCESS;	// return code status.
	
	//-------------------------------------------------------------------------------
	// Debug assertions from specifciation.
	//-------------------------------------------------------------------------------
	ASSERT( pCf != NULL );
	ASSERT(!pCf -> bTxPacketOpen ); // This fails if start packet hasn't been called
	ASSERT( pCf -> ulSignatureTop == CF_Signature );
	ASSERT( pCf -> ulSignatureBottom == CF_Signature );
	ASSERT( pCf -> ulMrvDrvVirtualIoBase != 0 );
	ASSERT( packetSizeBytes != 0 );
	ASSERT( packet != NULL );
	ASSERT( packetSizeBytes <= MRVDRV_ETH_TX_PACKET_BUFFER_SIZE ); 
	
	//-------------------------------------------------------------------------------
    //      Set transmit packet length to start tx packet.
	//-------------------------------------------------------------------------------
	if ( !IX_SUCCESS( ixStatus = cf_TxStartPacket( pCf, packetSizeBytes)))	
	{
		DBGPRINT(DBG_WARNING,("cf_TxStartPacket: Device is not ready for data"));
		return ixStatus;
	}
	
	//-------------------------------------------------------------------------------
    //    	Transmit block of data that makes up this packet to the device.
	//-------------------------------------------------------------------------------
	cf_TxBlock ( pCf, packet, packetSizeBytes);
	

⌨️ 快捷键说明

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