+uint16_t handleDlTtiReq(CmLteTimingInfo *currTimingInfo)
+{
+#ifdef FAPI
+ uint8_t idx;
+ uint8_t nPdu = 0;
+ uint8_t numPduEncoded = 0;
+ uint16_t pduIndex = 0;
+ uint32_t msgLen = 0;
+ uint32_t dlTtiReqMsgSize = 0;
+ fapi_dl_tti_req_t *dlTtiReq = NULLP;
+ RgCellCb *cellCbParams = NULLP;
+ MacDlSlot *currDlSlot = NULLP;
+ MacCellCfg macCellCfg;
+ memset(&macCellCfg, 0, sizeof(MacCellCfg));
+ Inst inst = 0;
+
+ if(clGlobalCp.phyState == PHY_STATE_RUNNING)
+ {
+ cellCbParams = rgCb[inst].cell;
+ macCellCfg = cellCbParams->macCellCfg;
+
+ if(currTimingInfo != NULLP)
+ {
+ currDlSlot = &macCb.macCell->dlSlot[currTimingInfo->slot % MAX_SLOT_SUPPORTED];
+ nPdu = calcDlTtiReqPduCount(&currDlSlot->dlInfo);
+ dlTtiReqMsgSize = sizeof(fapi_dl_tti_req_t) + (nPdu * \
+ sizeof(fapi_dl_tti_req_pdu_t));
+ if(nPdu > 0)
+ {
+ if(currDlSlot->dlInfo.isBroadcastPres)
+ {
+ if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
+ {
+ dlTtiReqMsgSize += sizeof(fapi_dl_dci_t);
+ }
+
+ }
+ if(currDlSlot->dlInfo.isRarPres)
+ {
+ dlTtiReqMsgSize += sizeof(fapi_dl_dci_t);
+ }
+ }
+ LWR_MAC_ALLOC(dlTtiReq, dlTtiReqMsgSize);
+
+ if(dlTtiReq != NULLP)
+ {
+ memset(dlTtiReq, 0, dlTtiReqMsgSize);
+
+ dlTtiReq->sfn = currTimingInfo->sfn;
+ dlTtiReq->slot = currTimingInfo->slot;
+ dlTtiReq->nPdus = calcDlTtiReqPduCount(&currDlSlot->dlInfo); /* get total Pdus */
+ nPdu = dlTtiReq->nPdus;
+ dlTtiReq->nGroup = 0;
+ if(dlTtiReq->nPdus > 0)
+ {
+ dlTtiReq->pdus = (fapi_dl_tti_req_pdu_t*)(dlTtiReq + \
+ (sizeof(fapi_dl_tti_req_t) - sizeof(fapi_dl_tti_req_pdu_t*)));
+ if(!dlTtiReq->pdus)
+ {
+ DU_LOG("\nLWR_MAC: Memory allocation failed");
+ return RFAILED;
+ }
+
+ if(currDlSlot->dlInfo.isBroadcastPres)
+ {
+ if(currDlSlot->dlInfo.brdcstAlloc.ssbTrans)
+ {
+ if(dlTtiReq->pdus != NULLP)
+ {
+ for(idx = 0; idx < currDlSlot->dlInfo.brdcstAlloc.ssbIdxSupported; idx++)
+ {
+ fillSsbPdu(&dlTtiReq->pdus[numPduEncoded], &macCellCfg, currDlSlot, &msgLen, idx);
+ numPduEncoded++;
+ }
+ }
+ printf("\033[1;31m");
+ DU_LOG("\nLWR_MAC: MIB sent..");
+ printf("\033[0m");
+ }
+ if(currDlSlot->dlInfo.brdcstAlloc.sib1Trans)
+ {
+ /* Filling SIB1 param */
+ if(numPduEncoded != nPdu)
+ {
+ fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo.brdcstAlloc.\
+ sib1Alloc.sib1PdcchCfg, &msgLen);
+ numPduEncoded++;
+ fillPdschPdu(&dlTtiReq->pdus[numPduEncoded],&currDlSlot->dlInfo.brdcstAlloc.\
+ sib1Alloc.sib1PdschCfg, &msgLen, pduIndex);
+ pduIndex++;
+ numPduEncoded++;
+ }
+ printf("\033[1;34m");
+ DU_LOG("\nLWR_MAC: SIB1 sent...");
+ printf("\033[0m");
+ }
+ }
+ if(currDlSlot->dlInfo.isRarPres)
+ {
+ /* Filling RAR param */
+ fillRarPdu(&currDlSlot->dlInfo.rarAlloc.rarInfo);
+ fillPdcchPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdcchCfg, &msgLen);
+ numPduEncoded++;
+ fillPdschPdu(&dlTtiReq->pdus[numPduEncoded], &currDlSlot->dlInfo.rarAlloc.rarPdschCfg,
+ &msgLen, pduIndex);
+ numPduEncoded++;
+ pduIndex++;
+
+ printf("\033[1;32m");
+ DU_LOG("\nLWR_MAC: RAR sent...");
+ printf("\033[0m");
+ }
+
+ msgLen += sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
+ fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
+ LwrMacSendToPhy(dlTtiReq->header.message_type_id, dlTtiReqMsgSize, \
+ (void *)dlTtiReq);
+
+ /* send Tx-DATA req message */
+ sendTxDataReq(currTimingInfo, &currDlSlot->dlInfo);
+ }
+ else
+ {
+ msgLen = sizeof(fapi_dl_tti_req_t) - sizeof(fapi_msg_t);
+ fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
+ LwrMacSendToPhy(dlTtiReq->header.message_type_id, dlTtiReqMsgSize, (void *)dlTtiReq);
+ }
+ return ROK;
+ }
+ else
+ {
+ DU_LOG("\nLWR_MAC: Failed to allocate memory for DL TTI Request");
+ return RFAILED;
+ }
+ }
+ else
+ {
+ DU_LOG("\nLWR_MAC: Current TTI Info is NULL");
+ return RFAILED;
+ }
+ }
+ else
+ {
+ lwr_mac_handleInvalidEvt(currTimingInfo);
+ return RFAILED;
+ }
+#endif
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Sends TX data Request to PHY
+ *
+ * @details
+ *
+ * Function : sendTxDataReq
+ *
+ * Functionality:
+ * -Sends FAPI TX data req to PHY
+ *
+ * @params[in] timing info
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint16_t sendTxDataReq(CmLteTimingInfo *currTimingInfo, DlAlloc *dlInfo)
+{
+#ifdef FAPI
+ uint8_t nPdu = 0;
+ uint32_t msgLen = 0;
+ uint16_t pduIndex = 0;
+ uint32_t txDataReqMsgSize = 0;
+ fapi_tx_data_req_t *txDataReq = NULLP;
+ Inst inst = 0;
+
+ /* send TX_Data request message */
+ nPdu = calcTxDataReqPduCount(dlInfo);
+ if(nPdu > 0)
+ {
+ txDataReqMsgSize = sizeof(fapi_tx_data_req_t) + \
+ (nPdu * sizeof(fapi_tx_pdu_desc_t));
+ if(dlInfo->brdcstAlloc.sib1Trans)
+ {
+ txDataReqMsgSize += rgCb[inst].cell->macCellCfg.sib1Cfg.sib1PduLen;
+ }
+ if(dlInfo->isRarPres)
+ {
+ txDataReqMsgSize += dlInfo->rarAlloc.rarInfo.rarPduLen;
+ }
+
+ LWR_MAC_ALLOC(txDataReq, txDataReqMsgSize);
+ if(txDataReq == NULLP)
+ {
+ DU_LOG("\nLWR_MAC: Failed to allocate memory for TX data Request");
+ return RFAILED;
+ }
+
+ memset(txDataReq, 0, txDataReqMsgSize);
+ txDataReq->sfn = currTimingInfo->sfn;
+ txDataReq->slot = currTimingInfo->slot;
+ txDataReq->pduDesc = (fapi_tx_pdu_desc_t *)(txDataReq + \
+ (sizeof(fapi_tx_data_req_t) - sizeof(fapi_tx_pdu_desc_t *)));
+
+ if(dlInfo->brdcstAlloc.sib1Trans)
+ {
+ fillSib1TxDataReq(txDataReq->pduDesc,
+ &rgCb[inst].cell->macCellCfg, &msgLen, pduIndex);
+ pduIndex++;
+ txDataReq->numPdus++;
+ }
+ if(dlInfo->isRarPres)
+ {
+ /* mux and form RAR pdu */
+ //fillRarPdu(&dlInfo->rarAlloc.rarInfo);
+ fillRarTxDataReq(txDataReq->pduDesc,
+ &dlInfo->rarAlloc.rarInfo, &msgLen, pduIndex);
+ pduIndex++;
+ txDataReq->numPdus++;
+ }
+
+ msgLen += sizeof(fapi_tx_data_req_t) - sizeof(fapi_msg_t);
+ fillMsgHeader(&txDataReq->header, FAPI_TX_DATA_REQUEST, msgLen);
+ LwrMacSendToPhy(txDataReq->header.message_type_id, txDataReqMsgSize, \
+ (void *)txDataReq);
+ }
+#endif
+ return ROK;
+}
+
+/***********************************************************************
+ *
+ * @brief calculates the total size to be allocated for UL TTI Req
+ *
+ * @details
+ *
+ * Function : getnPdus
+ *
+ * Functionality:
+ * -calculates the total pdu count to be allocated for UL TTI Req
+ *
+ * @params[in] Pointer to fapi Ul TTI Req
+ * Pointer to CurrUlSlot
+ * @return count
+ * ********************************************************************/
+#ifdef FAPI
+uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
+{
+ uint8_t pduCount = 0;
+
+ if(currUlSlot != NULLP)
+ {
+ if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_PRACH)
+ {
+ pduCount++;
+ if(ulTtiReq)
+ ulTtiReq->rachPresent = PDU_PRESENT;
+ }
+ if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
+ {
+ pduCount++;
+ if(ulTtiReq)
+ ulTtiReq->nUlsch = PDU_PRESENT;
+ }
+ if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_UCI)
+ {
+ pduCount++;
+ if(ulTtiReq)
+ ulTtiReq->nUlcch = PDU_PRESENT;
+ }
+ if(currUlSlot->ulCellInfo.dataType & SCH_DATATYPE_SRS)
+ {
+ pduCount++;
+ }
+ }
+ return pduCount;
+}
+#endif
+
+/***********************************************************************
+ *
+ * @brief Set the value of zero correlation config in PRACH PDU
+ *
+ * @details
+ *
+ * Function : setNumCs
+ *
+ * Functionality:
+ * -Set the value of zero correlation config in PRACH PDU
+ *
+ * @params[in] Pointer to zero correlation config
+ * Pointer to MacCellCfg
+ * ********************************************************************/
+
+void setNumCs(uint8_t *numCs, MacCellCfg *macCellCfg)