📄 aal2txcp.c
字号:
{ /*Aal2TxDebugStrPrint("AAL2TxHdlr: Prev CPS Proc, Switch Context.");*/ ksContextSwitch(aal2FwdrContext); } } /* Get the CPS packet payload length, LI is 1 less than the length */ CpsPaylodLength = (CpsDesc->li) + 1; /* Now CPS control block will be prepared. If control block is not ready * to be written, which is to be read by fwdr, switch the context to Fwdr. */ while (pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].FwderProcDone EQ FALSE) { ksContextSwitch(aal2FwdrContext); } /* Read sequence number for ATM SDU */ StfSequenceNumber = pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].StfSequenceNumber; /* Get the buffer handle for this VcIndex */ AtmSduBufHandle = pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBufHandle; /* Store the current ATM egress header in the DMEM table */ pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].atmEgressKey = CpsDesc->atmEgressKey; /* Now STF bytes and their location are to be calculated based on the * CPS packet attributes. Position of a STF means where STF byte has to be * inserted, measuring from CPS-PH. * * (i) If STF position is 0, it means, it has to be inserted in the begining, * before transmitting any CPS packet byte, and it is going to be a new ATM * SDU with that CPS packet. * * (ii) STF position > 0 & < 3, indicates that STF has to be inserted after * one or two bytes of CPS-PH. That means one or two bytes of CPS-PH are going * to fill previous ATM SDU, and remaining bytes of the CPS packet will be filled * in the next new ATM SDU after transmitting STF. * * (iii) STF position = 3, indicates that STF has to be inserted after transmitting * all CPS-PH bytes. It means all CPS-PH bytes will be filled in the previous SDU, * and CPS payload will be filled in the new SDU after STF. * * (iv) STF position > 3, indicates that STF will be inserted after all of the * CPS-PH bytes and few of the CPS payload bytes. */ FirstStfByte = 0; SecondStfByte = 0; Stf1Position = 0; /* Initialize CountSduFrags to 0 for this CPS packet */ CountSduFrags = 1; while (!bsBufferReadComplete()) ;#ifdef AAL2_TX_DEBUG pInData = (int32u *) &txTempPdu[1][0]; for (TempCount = 0; TempCount < 5; TempCount++) { ksPrintf("AAL2 Tx: 0x%x, 0x%x, 0x%x", *pInData++, *pInData++, *pInData++); } ksPrintf("AAL2 Tx: 0x%x -----------", *pInData);#endif if (AtmSduBufHandle EQ NOT_ALLOCATED) { /* If length of the CPS payload is > 44, two STF bytes will be required, * as this CPS packet will spread across two ATM cells. If payload is <= * 44, then only one STF byte would be needed. */ FirstStfByte = gAal2ParityTable[StfSequenceNumber]; if (CpsPaylodLength GT MAX_CPS_PL_IN_ATM_CELL) { /* Second STF Byte will have offset = LI+1-44 */ StfTableIndex = ((CpsPaylodLength - MAX_CPS_PL_IN_ATM_CELL) * 2) | (~StfSequenceNumber & 0x01); SecondStfByte = gAal2ParityTable[StfTableIndex]; /* CountSduFrags = 2 */ CountSduFrags++; } PrevAtmSduLength = 0; CountNonAlignBytes = 0; } /* If, buffer handle of ATM SDU in DMEM table is not NOT_ALLOCATED */ else { /* Get the count of the ATM SDU bytes, previously stored */ PrevAtmSduLength = pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBytesCount; /* If previously stored SDU is not 16 bytes aligned, recirculation of * this will be required. */ CountNonAlignBytes = PrevAtmSduLength % 16; /* If CPS payload + Prev ATM SDU Length <= 45, no new STF will * be required. This CPS packet fits in the previous ATM SDU. * But, if CPS payload + Prev ATM SDU Length > 45 and <= 92, one new * STF will be required for the next ATM SDU. * PrevAtmSduLength + 3(CPS-PH) + CpsPaylodLength = 48. * PrevAtmSduLength + 1(STF) + 3(CPS-PH) + CpsPaylodLength = 96. */ if ( ( (PrevAtmSduLength + CpsPaylodLength) GT (ATM_SDU_SIZE - CPS_PH_SIZE)) AND ((PrevAtmSduLength + CpsPaylodLength) LE ((2 * ATM_SDU_SIZE) - CPS_PH_SIZE - STF_SIZE))) { /* Offset in the new STF = (CPS_Payload + CPS-PH size) - (48 - Prev ATM SDU Length) */ StfTableIndex = (CpsPaylodLength + CPS_PH_SIZE - ATM_SDU_SIZE + PrevAtmSduLength); StfTableIndex = (StfTableIndex * 2) | (StfSequenceNumber & 0x01); FirstStfByte = gAal2ParityTable[StfTableIndex]; /* CountSduFrags = 2 */ CountSduFrags++; /* Set STF 1 position */ Stf1Position = ATM_SDU_SIZE - PrevAtmSduLength; } /* If CPS payload + Prev ATM SDU Length > 92, two new STF will * be required for the next two ATM SDUs. */ if ((PrevAtmSduLength + CpsPaylodLength) GT ((2 * ATM_SDU_SIZE) - CPS_PH_SIZE - STF_SIZE)) { /* Offset in the first STF = 47 */ StfTableIndex = ((ATM_SDU_SIZE - STF_SIZE) * 2) | (StfSequenceNumber & 0x01); FirstStfByte = gAal2ParityTable[StfTableIndex]; /* CountSduFrags = 2 */ CountSduFrags++; /* Set STF 1 position */ Stf1Position = ATM_SDU_SIZE - PrevAtmSduLength; /* Offset in the second STF = (CPS_Payload + CPS-PH size + STF Size) - (96 - Prev ATM SDU Length) */ StfTableIndex = (CpsPaylodLength + CPS_PH_SIZE + STF_SIZE - (2 * ATM_SDU_SIZE) + PrevAtmSduLength); StfTableIndex = (StfTableIndex * 2) | (~StfSequenceNumber & 0x01); SecondStfByte = gAal2ParityTable[StfTableIndex]; /* CountSduFrags = 3 */ CountSduFrags++; } } Aal2TxDebugValPrint ("AAL2TxHdlr: CPS Desc Arrived for VcIndex = ", VcIndex); Aal2TxDebugValPrint ("AAL2TxHdlr: Cid = ", CpsDesc->cid); Aal2TxDebugValPrint ("AAL2TxHdlr: Li = ", CpsDesc->li); Aal2TxDebugValPrint ("AAL2TxHdlr: Uui = ", CpsDesc->uui); Aal2TxDebugValPrint ("AAL2TxHdlr: Buffer Handle = ", AtmSduBufHandle); Aal2TxDebugValPrint ("AAL2TxHdlr: CPSPayloadLength = ", CpsPaylodLength); Aal2TxDebugValPrint ("AAL2TxHdlr: PrevAtmSduLength = ", PrevAtmSduLength); Aal2TxDebugValPrint ("AAL2TxHdlr: Stf-1 Byte = ", FirstStfByte); Aal2TxDebugValPrint ("AAL2TxHdlr: Stf-1 Pos = ", Stf1Position); Aal2TxDebugValPrint ("AAL2TxHdlr: Stf-2 Byte = ", SecondStfByte); Aal2TxDebugValPrint ("AAL2TxHdlr: Count of ATM SDUs prepared = ", CountSduFrags); Aal2TxDebugValPrint ("AAL2TxHdlr: Count Recirc Bytes = ", CountNonAlignBytes); /* Fill the CPS control block values */ pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].VcIndex = VcIndex; pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].CountAtmSdu = CountSduFrags; /* If a pdu handle is not available, switch the context */ while ((pduHandle = pduTxAllocate()) EQ NULL) { ksContextSwitch(aal2FwdrContext); } /* Get the merge space */ mergeSpc = (MergeSpc *) pduTxHeaderGet (pduHandle); /* If recirculation of the payload is required, copy those CPS payload bytes in * the merge space registers, for TxByte processor to read. */ if (CountNonAlignBytes) { /* Read the SDRAM to copy the non-aligned bytes in DMEM temporary location */ bsBufferRead (AtmSduBufHandle, (PrevAtmSduLength - CountNonAlignBytes), txTempPdu[0], 16); /* Write number of non-aligned recirculating bytes in merge space */ mergeSpc->Aal2TxMergeSpc.CountAtmBytesRecir = CountNonAlignBytes; /* Set STF entries in the merge space */ mergeSpc->Aal2TxMergeSpc.Stf1 = FirstStfByte; mergeSpc->Aal2TxMergeSpc.PositionStf1 = Stf1Position; mergeSpc->Aal2TxMergeSpc.Stf2 = SecondStfByte; /* Fill the CPS-PH values in merge space */ mergeSpc->Aal2TxMergeSpc.cid = CpsDesc->cid; mergeSpc->Aal2TxMergeSpc.li = CpsDesc->li; mergeSpc->Aal2TxMergeSpc.uui = CpsDesc->uui; /* Update number of bytes packed in DMEM table */ pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].AtmSduBytesCount -= CountNonAlignBytes; /* Wait till buffer read is complete */ while (bsBufferReadComplete () EQ FALSE) { ksContextSwitch(aal2FwdrContext); } /* Copy those non-aligned recirculating bytes in merge space. * To save cycles these bytes are copied after forming a int32u. * Caution: Beware of big\small endian problems for portability. */ pDest = (int32u *) (mergeSpc->Aal2TxMergeSpc.PrevAtmSduRecirBytes); pSource = (int32u *) (txTempPdu[0]); *pDest = *pSource; *(pDest+1) = *(pSource+1); *(pDest+2) = *(pSource+2); *(pDest+3) = *(pSource+3);#ifdef AAL2_TX_DEBUG for (TempCount = 0; TempCount < CountNonAlignBytes; TempCount ++) { Aal2TxDebugValPrint ("AAL2TxHdlr: Recirc Byte = ", mergeSpc->Aal2TxMergeSpc.PrevAtmSduRecirBytes[TempCount]); }#endif } else { /* There are no bytes that require re-circulation */ mergeSpc->Aal2TxMergeSpc.CountAtmBytesRecir = 0; /* Following merge space fields can be filled at a common place for * the above if-else clause, but written separately to maximize the * usage of buffer read completion wait. */ /* Set STF entries in the merge space */ mergeSpc->Aal2TxMergeSpc.Stf1 = FirstStfByte; mergeSpc->Aal2TxMergeSpc.PositionStf1 = Stf1Position; mergeSpc->Aal2TxMergeSpc.Stf2 = SecondStfByte; /* Fill the CPS-PH values in merge space */ mergeSpc->Aal2TxMergeSpc.cid = CpsDesc->cid; mergeSpc->Aal2TxMergeSpc.li = CpsDesc->li; mergeSpc->Aal2TxMergeSpc.uui = CpsDesc->uui; } /* Transmit payload to SDP Tx Byte processor */ // pduTxBufHandleSet (pduHandle, CpsDesc->cpsPckPayload); // ksPrintf (" Aal2 Tx : Length : %d ",CpsPaylodLength) ; // ksPrintf (" AAl2 Tx : Buf Handle : %x", CpsDesc->cpsPckPayload) ; // pduTxLengthSet (pduHandle, CpsPaylodLength, 0); pduTxFromDmem(pduHandle, (int32u*) &txTempPdu[1], CpsPaylodLength); /* Free the pdu handle, so the merge space will be owned by the TxByte processor */ pduTxFree (pduHandle); /* Free the CPS payload buffer handle */ bsBufferFree (CpsDesc->cpsPckPayload); /* Update the sequence number in DMEM table, for the next ATM SDU */ if ( (FirstStfByte) AND (SecondStfByte EQ 0) ) { pAal2TxContext->Aal2TxDmemTable[Aal2TxDmemTableIndex].StfSequenceNumber ^= 1; } /* Make Fwdr processing done flag to false, so that fwdr can process * this CPS packet. */ pAal2TxContext->CpsControlBlocks[NextCpcCtrlBlkId].FwderProcDone = FALSE; /* Increment the control block index and save the previous one */ PrevCpcCtrlBlkId = NextCpcCtrlBlkId; NextCpcCtrlBlkId ^= 0x01; MSG_EVENT ("CPRC AAL2TX HDLR : PROCESSING END"); } /* while (TRUE) */}/****************************************************************************** * Function : aal2TxFwdr * * Description : Forwarder thread for the AAL2Tx Module. * * Parameters : void* arg: Not used. * * Returns : None. * * Traceability : aal2_tx_design.doc. Section: 2.6. * ******************************************************************************/int32u aal2TxFwdr (void* arg){ BsBufHandle AtmSduBufHandle = NOT_ALLOCATED; int16u Aal2TxDmemTableIndex = 0; int16u VcIndex = 0; static int8u NextCpcCtrlBlkId = 0; static int8u FwdrScopeNumber = 0; int8u FwdrCpsEvent = FALSE; int8u FwdrCuTimerEvent = FALSE; int8u FwdrEventAbsent = FALSE; int8u CountAtmSdu = 0; int8u *pDmemLocation = NULL; Aal2TxExtractSpace *Aal2TxExtSpc = NULL; int8u AtmSduBytesCount = 0; int8u CuTimerExpiryEventIgnore = FALSE; PduHandle pduHandle = NULL; int8u ExtSpaceVal = 0; int8u *pFwdrProcDoneFlag = NULL;#ifdef AAL2_TX_DEBUG
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -