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

📄 aal2txcp.c

📁 摩托罗拉Motolola公司网络处理器C3的示范代码.实现了ATM的AAL2层交换功能.想了解网络处理器的可以
💻 C
📖 第 1 页 / 共 3 页
字号:
	int16u TempCount = 0;		int32u *pDataOut = NULL;#endif	TimeoutDescriptor = qsMessageGetData (&(pAal2TxContext->TimeoutDescriptorMsg));	memset(TimeoutDescriptor, 0, sizeof(TimeoutDesc));	cellDescPtr = qsMessageGetData (&cellDescMsg);	memset(cellDescPtr, 0, sizeof(CellDescriptor));	XpQueueDesc = qsMessageGetData (&(pAal2TxContext->XpInQueueDescMsg));	memset(XpQueueDesc, 0, sizeof(XpInQueueDesc));	/* Initialize the CU_Timer start command and cp id in XP queue message */	XpQueueDesc->command = TIMER_START_COMMAND;	XpQueueDesc->data.timerStartCommand.cpId = gAal2TxCpId;	while (TRUE)	{                MSG_EVENT("CPRC AAL2TX FWDR : PROCESSING START");		/*Aal2TxDebugValPrint ("AAL2TxFwdr: Fwdr For CpId = ", gAal2TxCpId);*/		/* Switch the context till next CPS control block is ready to be read or CU_Timer 		 * expiry event has arrived.		 */		/* Get the location of the Fwdr processind done flag in the context for this block id */		pFwdrProcDoneFlag = &(pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].FwderProcDone);		do		{			FwdrEventAbsent = FALSE;			/* Check if CPS control block is available to read */			if (*pFwdrProcDoneFlag EQ FALSE)			{				FwdrCpsEvent = TRUE;			}			/* Check if CU_Timer expiry event has come */			if (qsQueueGetLength (pAal2TxContext->Aal2TxCuTimerEventQ))			{				FwdrCuTimerEvent = TRUE;			}			/* No event is true, switch the context, give Hdlr a chance to execute */			else if (FwdrCpsEvent EQ FALSE)			{				FwdrEventAbsent = TRUE;				ksContextSwitch(aal2HdlrContext);			}		} while (FwdrEventAbsent EQ TRUE);		/* CPS control block is ready to be read */		if (FwdrCpsEvent)		{					/* Make flag FALSE for the next iteration */			FwdrCpsEvent = FALSE;						/* Read the VC index from the CPS control Block */			VcIndex = pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].VcIndex;						/* Use lower 9 bits of VC Index to index in to the DMEM table. */			Aal2TxDmemTableIndex = VcIndex & DMEM_TABLE_INDEX_MASK;					/* Get the count of bytes packed in this ATM SDU */			AtmSduBytesCount = pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBytesCount; 			/* Get the buffer handle used for ATM SDU storage */			AtmSduBufHandle = pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBufHandle;						/* Get the number of ATM SDUs (partial or complete), prepared by the CPS packet */			CountAtmSdu = pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].CountAtmSdu;						Aal2TxDebugValPrint ("AAL2TxFwdr: VcIndex = ", VcIndex);			Aal2TxDebugValPrint ("AAL2TxFwdr: AtmSduBytesCount = ", AtmSduBytesCount);			Aal2TxDebugValPrint ("AAL2TxFwdr: AtmSduBufHandle = ", AtmSduBufHandle);			Aal2TxDebugValPrint ("AAL2TxFwdr: CountAtmSdu = ", CountAtmSdu);						/* Process all of these SDUs */			do			{				/* If buffer handle is NOT_ALLOCATED, allocate memory to it */				if (AtmSduBufHandle EQ NOT_ALLOCATED)				{					while(bsError(AtmSduBufHandle = bsBufferAllocate (poolId)));					Aal2TxDebugValPrint ("AAL2TxFwdr: New Allocated AtmSduBufHandle = ", AtmSduBufHandle);				}								/* Get a PDU handle for Fwdr scope number */				pduHandle = pduHandleForScopeNumber(FwdrScopeNumber);				/* Wait till extract space is not available */				while (IS_EXTRACT_SPACE_BUSY())				{					ksContextSwitch(aal2HdlrContext);				}				/* Now read the extract space for number of bytes transmitted */				Aal2TxExtSpc = (Aal2TxExtractSpace *)pduRxHeaderGet (pduHandle);				/* Wait till extract space reading is available */				while(Aal2TxExtSpc->AtmSduBytesCount EQ 0)				{					ksContextSwitch(aal2HdlrContext);				}								/* Read the extract space value */				ExtSpaceVal = Aal2TxExtSpc->AtmSduBytesCount;				/* Set the DMEM location for this RxByte scope again, as it gets incremented 				 * after DMA.				 */				pDmemLocation = rxTempPdu[FwdrScopeNumber];				pduRxToDmem (pduHandle, (int32u*) pDmemLocation);								/* Handover the scope to RxByte */				pduRxFree(pduHandle);				/* Write 0 in the next to last byte, so that it does not require to pad in 				 * case Cu_Timer expires.				 */				pDmemLocation[ExtSpaceVal] = 0;				Aal2TxDebugValPrint ("AAL2TxFwdr: RxByte Wrote in Ext Space = ", ExtSpaceVal);#ifdef AAL2_TX_DEBUG 		pDataOut = (int32u *) &pDmemLocation[0];		for (TempCount = 0; TempCount < 5; TempCount++)		{		    ksPrintf("AAL2 Tx Out: 0x%x, 0x%x, 0x%x", 				    *pDataOut++, *pDataOut++, *pDataOut++);		}		ksPrintf("AAL2 Tx Out: 0x%x -----------", *pDataOut);#endif								/* Copy these bytes to SDRAM */				bsBufferWrite (pDmemLocation, (64 - AtmSduBytesCount), AtmSduBufHandle, 					           AtmSduBytesCount);						   				/* Update bytes count */				AtmSduBytesCount += ExtSpaceVal;				Aal2TxDebugValPrint ("AAL2TxFwdr: Bytes Packed in SDRAM = ", AtmSduBytesCount);								/* Check if buffer write is complete, otherwie switch the scope */				while (bsBufferWriteComplete () EQ FALSE)				{					ksContextSwitch(aal2HdlrContext);				}				/* If SDU is completely filled by this CPS packet, or CU_Timer was expired 				 * for this SDU, en-queue the cell descriptor. Otherwise start the CU_Timer.				 */				if ((AtmSduBytesCount EQ ATM_SDU_SIZE) OR 					(pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerExpired))				{					Aal2TxDebugStrPrint ("AAL2TxFwdr: En-queuing Cell Descriptor.");					EnqueueCellDescriptor (AtmSduBufHandle, AtmSduBytesCount, VcIndex);					AtmSduBytesCount = 0;					AtmSduBufHandle = NOT_ALLOCATED;										/* Make CU_Timer flags in DMEM table to FALSE */					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerStarted = FALSE;					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerExpired = FALSE;				}				/* Start the CU_Timer, if it is not started already */				else				{					payloadEnqueue = FALSE;					/* Check if CU_Timer was not started already */					if (pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerStarted EQ FALSE)					{						Aal2TxDebugStrPrint ("AAL2TxFwdr: Starting CU_timer");						/* Start the CU_Timer */						XpQueueDesc->data.timerStartCommand.seqNo = 							 pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerSeqNum;						XpQueueDesc->data.timerStartCommand.vcIndex = VcIndex;						/* En-queueu the timer start descriptor to XP queue */						qsMessageSend(gXpBaseQId, &(pAal2TxContext->XpInQueueDescMsg));												/* Make CU_Timer started flag in DMEM table to TRUE */						pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerStarted = TRUE;					}					/* Otherwise, CU_Timer was already started during an earlier CPS packet 					 * processing. Nothing to do now.					 */				}				/* Update other DMEM table entries */				pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBytesCount = AtmSduBytesCount;				pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBufHandle = AtmSduBufHandle;				/* Change the Fwdr scope number */				FwdrScopeNumber ^= 0x01;							} while (--CountAtmSdu);			/* Get ready to process the next CPS control block, reset the values  */			pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].VcIndex = INVALID_VC_ID;			pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].CountAtmSdu = 0;			pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].FwderProcDone = TRUE;			NextCpcCtrlBlkId ^= 0x01;		}				/* CU_Timer expiry event has come, en-queue the cell descriptor after checking 		 * the validity.		 */		if (FwdrCuTimerEvent)		{					/* Make flag FALSE for the next iteration */			FwdrCuTimerEvent = FALSE;						/* Cu_Timer expiry event is not to be ignored */			CuTimerExpiryEventIgnore = FALSE;			/* Start receiving the CU_Timer expiry message */			qsMessageReceiveStart (pAal2TxContext->Aal2TxCuTimerEventQ, 				                &(pAal2TxContext->TimeoutDescriptorMsg)) ;			/* Till message receive completes, switch the context */			while (qsMessageReceiveComplete (pAal2TxContext->Aal2TxCuTimerEventQ, 				                             &(pAal2TxContext->TimeoutDescriptorMsg)) EQ FALSE)			{				/* Do not switch scope here, as Handler might change the DMEM table entry.*/				/* ksContextSwitch(aal2HdlrContext); */			}			/* Read the DMEM tabel index and CU_Timer seq num from the CU_Timer 			 * expiry message. 			 */			VcIndex = TimeoutDescriptor->vcIndex;			Aal2TxDmemTableIndex = VcIndex & DMEM_TABLE_INDEX_MASK;			/* Check if CU_Timer seq num value is same as in expiry message 			 * and in DMEM table for the given VC Index. If not, just ignore 			 * the expiry message. Expiry message is coming after en-queuing 			 * the cell descriptor, it has to be ignored.			 */			if (pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerSeqNum				NE TimeoutDescriptor->seqNo)			{				/* CU_Timer expiry event has to be ignored */				CuTimerExpiryEventIgnore = TRUE;			}			/* The CU_Timer was running for the given VC Index, seq num is correct */			else			{				/* Check if CPS packet for this VC Index is being processed by 				 * either Hdlr or Fwdr at this moment. If yes, can not en-queue the 				 * cell descriptor, discard the expiry message.				 */				if ( (pAal2TxContext->CpsControlBlocks[0].VcIndex EQ VcIndex) ||					 (pAal2TxContext->CpsControlBlocks[1].VcIndex EQ VcIndex) )				{					/* CU_Timer expiry event has to be ignored */					CuTimerExpiryEventIgnore = TRUE;					/* Make CU_Timer expired flag in DMEM table to TRUE, so that cell descriptor can 					 * be en-queued at the next earliest opportunity.					 */					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerExpired = TRUE;				}				/* CU_Timer expiry event can not be ignored at all, en-queuing of the cell descriptor 				 * has to be performed now. 				 */				if (CuTimerExpiryEventIgnore EQ FALSE)				{					/* Enqueue the cell descriptor, no need to pad the payload, already 0 is 					 * written in the last byte.					 */					EnqueueCellDescriptor 						(pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBufHandle, 						 pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBytesCount, 						 VcIndex);					/* Make timer flags in DMEM table to FALSE */					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerStarted = FALSE;					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].CuTimerExpired = FALSE;					/* Reset the ATM SDU variables in the DMEM table */					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBytesCount = 0;					pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBufHandle = NOT_ALLOCATED;				}			}		}                MSG_EVENT("CPRC AAL2TX FWDR : PROCESSING END");	} /* while (TRUE) */}	/*****************************************************************************/

⌨️ 快捷键说明

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