Mux Code Changes
[o-du/l2.git] / src / 5gnrmac / lwr_mac_fsm.c
index 56224e1..be8a4b1 100644 (file)
  ################################################################################
  *******************************************************************************/
 
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
 
 /* header include files -- defines (.h) */
-#include "envopt.h"        /* environment options */
-#include "envdep.h"        /* environment dependent */
-#include "envind.h"        /* environment independent */
-#include "gen.h"           /* general layer */
-#include "ssi.h"           /* system service interface */
-#include "cm_hash.h"       /* common hash list */
-#include "cm_mblk.h"       /* common memory link list library */
-#include "cm_llist.h"      /* common linked list library */
-#include "cm_err.h"        /* common error */
-#include "cm_lte.h"        /* common LTE */
+#include "common_def.h"
 #include "lrg.h"           /* Layer manager interface includes*/
 #include "crg.h"           /* CRG interface includes*/
 #include "rgu.h"           /* RGU interface includes*/
 #include "lwr_mac_fsm.h"
 
 /* header/extern include files (.x) */
-#include "gen.x"           /* general layer typedefs */
-#include "ssi.x"           /* system services typedefs */
-#include "cm5.x"           /* common timers */
-#include "cm_hash.x"       /* common hash list */
-#include "cm_lib.x"        /* common library */
-#include "cm_llist.x"      /* common linked list */
-#include "cm_mblk.x"       /* memory management */
-#include "cm_tkns.x"       /* common tokens */
-#include "cm_lte.x"       /* common tokens */
 #include "rgu.x"           /* RGU types */
 #include "tfu.x"           /* RGU types */
 #include "lrg.x"           /* layer management typedefs for MAC */
@@ -63,8 +42,6 @@
 #include "mac.h"
 #include "rg.x"            /* typedefs for MAC */
 #include "lwr_mac_phy.h"
-#include "common_def.h"
-#include "math.h"
 
 #define MIB_SFN_BITMASK 0xFC
 #define PDCCH_PDU_TYPE 0
@@ -72,6 +49,7 @@
 #define SSB_PDU_TYPE 3
 #define PRACH_PDU_TYPE 0
 #define PUSCH_PDU_TYPE 1
+#define PUCCH_PDU_TYPE 2
 #define PDU_PRESENT 1
 #define SET_MSG_LEN(x, size) x += size
 
@@ -118,7 +96,7 @@ S16 lwr_mac_handleInvalidEvt(void *msg)
    RETVALUE(ROK);
 }
 
-#ifdef FAPI
+#ifdef INTEL_FAPI
 /*******************************************************************
   *
   * @brief Fills FAPI message header
@@ -1320,7 +1298,7 @@ uint32_t getParamValue(fapi_uint16_tlv_t *tlv, uint16_t type)
 
 S16 lwr_mac_handleParamReqEvt(void *msg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    /* startGuardTimer(); */
    uint32_t msgLen = 0;             //Length of message Body
    fapi_param_req_t *paramReq = NULL;
@@ -1362,7 +1340,7 @@ S16 lwr_mac_handleParamReqEvt(void *msg)
 
 S16 lwr_mac_handleParamRspEvt(void *msg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
   /* stopGuardTimer(); */
    uint8_t index;
    uint32_t encodedVal;
@@ -1899,7 +1877,7 @@ S16 lwr_mac_handleParamRspEvt(void *msg)
 
 S16 lwr_mac_handleConfigReqEvt(void *msg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    Inst inst = 0;
    uint8_t idx = 0;
    uint8_t index = 0;
@@ -2069,7 +2047,7 @@ S16 lwr_mac_handleConfigReqEvt(void *msg)
 
 S16 lwr_mac_handleConfigRspEvt(void *msg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    fapi_config_resp_t *configRsp;
    configRsp = (fapi_config_resp_t *)msg;
 
@@ -2122,7 +2100,7 @@ S16 lwr_mac_handleConfigRspEvt(void *msg)
  * ****************************************************************/
 S16 lwr_mac_handleStartReqEvt(void *msg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    uint32_t msgLen = 0;
    fapi_start_req_t *startReq;
 
@@ -2163,7 +2141,7 @@ S16 lwr_mac_handleStartReqEvt(void *msg)
 
 S16 lwr_mac_handleStopReqEvt(void *msg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    uint32_t msgLen = 0;
    fapi_stop_req_t *stopReq = NULLP;
    LWR_MAC_ALLOC(stopReq, sizeof(fapi_stop_req_t));
@@ -2205,7 +2183,7 @@ PUBLIC void setMibPdu(uint8_t *mibPdu, uint32_t *val, uint16_t sfn)
     DU_LOG("\nLWR_MAC: MIB PDU %x", *val);
 }
 
-#ifdef FAPI
+#ifdef INTEL_FAPI
 /*******************************************************************
  *
  * @brief fills SSB PDU required for DL TTI info in MAC
@@ -3073,6 +3051,7 @@ uint8_t fillRarTxDataReq(fapi_tx_pdu_desc_t *pduDesc, RarInfo *rarInfo,
 uint8_t fillMsg4TxDataReq(fapi_tx_pdu_desc_t *pduDesc, Msg4Info *msg4Info,
    uint32_t *msgLen, uint16_t pduIndex)
 {
+   uint16_t idx = 0;
    uint32_t pduLen = 0;
    uint32_t *msg4TxDataValue = NULLP;
 
@@ -3088,7 +3067,10 @@ uint8_t fillMsg4TxDataReq(fapi_tx_pdu_desc_t *pduDesc, Msg4Info *msg4Info,
    {
       return RFAILED;
    }
-   memcpy(msg4TxDataValue, msg4Info->msg4Pdu, msg4Info->msg4PduLen);
+       for(idx = 0; idx < msg4Info->msg4PduLen; idx++)
+       {
+         msg4TxDataValue[idx] = msg4Info->msg4Pdu[idx]; 
+       }
    pduDesc[pduIndex].tlvs[0].value = (uint32_t)msg4TxDataValue;
 
    /* The total length of the PDU description and PDU data */
@@ -3126,7 +3108,7 @@ uint8_t fillMsg4TxDataReq(fapi_tx_pdu_desc_t *pduDesc, Msg4Info *msg4Info,
  * ****************************************************************/
 uint16_t handleDlTtiReq(SlotIndInfo currTimingInfo)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    uint8_t idx;
    uint8_t nPdu = 0;
    uint8_t numPduEncoded = 0;
@@ -3282,11 +3264,13 @@ uint16_t handleDlTtiReq(SlotIndInfo currTimingInfo)
                                fillMsgHeader(&dlTtiReq->header, FAPI_DL_TTI_REQUEST, msgLen);
                                LwrMacSendToPhy(dlTtiReq->header.message_type_id, dlTtiReqMsgSize, (void *)dlTtiReq);
                        }
+                       memset(currDlSlot, 0, sizeof(MacDlSlot));
                        return ROK;
                }
                else
                {
                        DU_LOG("\nLWR_MAC: Failed to allocate memory for DL TTI Request");
+                       memset(currDlSlot, 0, sizeof(MacDlSlot));
                        return RFAILED;
                }
        }
@@ -3317,7 +3301,7 @@ uint16_t handleDlTtiReq(SlotIndInfo currTimingInfo)
  * ****************************************************************/
 uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    uint8_t nPdu = 0;
    uint32_t msgLen = 0;
    uint16_t pduIndex = 0;
@@ -3373,13 +3357,16 @@ uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo)
          MAC_FREE(dlInfo->rarAlloc,sizeof(RarAlloc));
          dlInfo->rarAlloc = NULLP;
       }
-      if(dlInfo->msg4Alloc != NULLP)
+      if(dlInfo->msg4Alloc != NULLP && dlInfo->msg4Alloc->msg4Info.msg4Pdu != NULLP)
       {
          fillMsg4TxDataReq(txDataReq->pduDesc, &dlInfo->msg4Alloc->\
              msg4Info, &msgLen, pduIndex);
          pduIndex++;
          txDataReq->numPdus++;
-
+    
+         MAC_FREE(dlInfo->msg4Alloc->msg4Info.msg4Pdu,\
+             dlInfo->msg4Alloc->msg4Info.msg4PduLen);
+         dlInfo->msg4Alloc->msg4Info.msg4Pdu = NULLP;
          MAC_FREE(dlInfo->msg4Alloc,sizeof(Msg4Alloc));
          dlInfo->msg4Alloc = NULLP;
       }
@@ -3407,7 +3394,7 @@ uint16_t sendTxDataReq(SlotIndInfo currTimingInfo, DlSchedInfo *dlInfo)
  *             Pointer to CurrUlSlot
  * @return count
  * ********************************************************************/
-#ifdef FAPI
+#ifdef INTEL_FAPI
 uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
 {
    uint8_t pduCount = 0;
@@ -3426,20 +3413,19 @@ uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
                }
                if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH_UCI)
                {
-                       pduCount++;
-                       ulTtiReq->nUlsch++;
-                       ulTtiReq->nUlsch = PDU_PRESENT;
-               }
-               if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
-               {
-                       pduCount++;
-                       ulTtiReq->nUlcch = PDU_PRESENT;
-               }
-               if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_SRS)
-               {
-                       pduCount++;
-               }
-       }
+                  pduCount++;
+         ulTtiReq->nUlsch = PDU_PRESENT;
+      }
+      if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
+      {
+         pduCount++;
+         ulTtiReq->nUlcch = PDU_PRESENT;
+      }
+      if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_SRS)
+      {
+         pduCount++;
+      }
+   }
    return pduCount;
 }
 #endif
@@ -3461,7 +3447,7 @@ uint8_t getnPdus(fapi_ul_tti_req_t *ulTtiReq, MacUlSlot *currUlSlot)
 
 void setNumCs(uint8_t *numCs, MacCellCfg *macCellCfg)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    uint8_t idx;
    if(macCellCfg != NULLP)
    {
@@ -3488,7 +3474,7 @@ void setNumCs(uint8_t *numCs, MacCellCfg *macCellCfg)
  *             Pointer to msgLen
  * ********************************************************************/
 
-#ifdef FAPI
+#ifdef INTEL_FAPI
 void fillPrachPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, MacUlSlot *currUlSlot, uint32_t *msgLen)
 {
    if(ulTtiReqPdu != NULLP)
@@ -3574,6 +3560,56 @@ void fillPuschPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, Ma
          sizeof(ulTtiReqPdu->pduSize) + sizeof(fapi_ul_pusch_pdu_t)));
    }
 }
+
+void fillPucchPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg,\
+  MacUlSlot *currUlSlot, uint32_t *msgLen)
+{
+   if(ulTtiReqPdu != NULLP)
+   {
+          ulTtiReqPdu->pduType                  = PUCCH_PDU_TYPE;
+          ulTtiReqPdu->u.pucch_pdu.rnti         = currUlSlot->ulInfo.schPucchInfo.rnti;
+               /* TODO : Fill handle in raCb when scheduling pucch and access here */
+          ulTtiReqPdu->u.pucch_pdu.handle       = 100;
+          ulTtiReqPdu->u.pucch_pdu.bwpSize      = macCellCfg->initialUlBwp.bwp.numPrb;
+          ulTtiReqPdu->u.pucch_pdu.bwpStart     = macCellCfg->initialUlBwp.bwp.firstPrb;
+          ulTtiReqPdu->u.pucch_pdu.subCarrierSpacing = macCellCfg->initialUlBwp.bwp.scs;
+          ulTtiReqPdu->u.pucch_pdu.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
+          ulTtiReqPdu->u.pucch_pdu.formatType   = currUlSlot->ulInfo.schPucchInfo.pucchFormat; /* Supporting PUCCH Format 0 */
+          ulTtiReqPdu->u.pucch_pdu.multiSlotTxIndicator = 0; /* No Multi Slot transmission */
+          ulTtiReqPdu->u.pucch_pdu.pi2Bpsk              = 0; /* Disabled */
+          ulTtiReqPdu->u.pucch_pdu.prbStart     = currUlSlot->ulInfo.schPucchInfo.fdAlloc.startPrb;
+          ulTtiReqPdu->u.pucch_pdu.prbSize      = currUlSlot->ulInfo.schPucchInfo.fdAlloc.numPrb;
+          ulTtiReqPdu->u.pucch_pdu.startSymbolIndex = currUlSlot->ulInfo.schPucchInfo.tdAlloc.startSymb;
+          ulTtiReqPdu->u.pucch_pdu.nrOfSymbols  = currUlSlot->ulInfo.schPucchInfo.tdAlloc.numSymb;
+          ulTtiReqPdu->u.pucch_pdu.freqHopFlag  = 0; /* Disabled */
+          ulTtiReqPdu->u.pucch_pdu.secondHopPrb = 0;
+          ulTtiReqPdu->u.pucch_pdu.groupHopFlag = 0;     
+          ulTtiReqPdu->u.pucch_pdu.sequenceHopFlag = 0;
+          ulTtiReqPdu->u.pucch_pdu.hoppingId    = 0;
+          ulTtiReqPdu->u.pucch_pdu.initialCyclicShift = 0;
+          ulTtiReqPdu->u.pucch_pdu.dataScramblingId = 0; /* Valid for Format 2, 3, 4 */
+          ulTtiReqPdu->u.pucch_pdu.timeDomainOccIdx = 0; /* Valid for Format 1 */
+          ulTtiReqPdu->u.pucch_pdu.preDftOccIdx     = 0; /* Valid for Format 4 */
+          ulTtiReqPdu->u.pucch_pdu.preDftOccLen     = 0; /* Valid for Format 4 */
+          ulTtiReqPdu->u.pucch_pdu.addDmrsFlag      = 0; /* Valid for Format 3, 4 */
+          ulTtiReqPdu->u.pucch_pdu.dmrsScramblingId = 0; /* Valid for Format 2 */
+          ulTtiReqPdu->u.pucch_pdu.dmrsCyclicShift  = 0; /* Valid for Format 4 */
+          ulTtiReqPdu->u.pucch_pdu.srFlag           = currUlSlot->ulInfo.schPucchInfo.srFlag;
+          ulTtiReqPdu->u.pucch_pdu.bitLenHarq       = currUlSlot->ulInfo.schPucchInfo.numHarqBits;
+          ulTtiReqPdu->u.pucch_pdu.bitLenCsiPart1   = 0; /* Valid for Format 2, 3, 4 */
+          ulTtiReqPdu->u.pucch_pdu.bitLenCsiPart2   = 0; /* Valid for Format 2, 3, 4 */
+      ulTtiReqPdu->u.pucch_pdu.beamforming.numPrgs = 0; /* Not Supported */
+      ulTtiReqPdu->u.pucch_pdu.beamforming.prgSize = 0;
+      ulTtiReqPdu->u.pucch_pdu.beamforming.digBfInterfaces = 0;
+      ulTtiReqPdu->u.pucch_pdu.beamforming.pmi_bfi[0].pmIdx = 0;
+      ulTtiReqPdu->u.pucch_pdu.beamforming.pmi_bfi[0].beamIdx[0].beamidx = 0;
+
+      ulTtiReqPdu->pduSize = sizeof(fapi_ul_pucch_pdu_t);
+      SET_MSG_LEN(*msgLen, (sizeof(ulTtiReqPdu->pduType) + \
+         sizeof(ulTtiReqPdu->pduSize) + sizeof(fapi_ul_pucch_pdu_t)));
+       }
+}
+
 #endif
 
 /*******************************************************************
@@ -3594,7 +3630,7 @@ void fillPuschPdu(fapi_ul_tti_req_pdu_t *ulTtiReqPdu, MacCellCfg *macCellCfg, Ma
  ******************************************************************/
 uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo)
 {
-#ifdef FAPI
+#ifdef INTEL_FAPI
    uint8_t    pduIdx = -1;
    uint8_t    numPdu = 0;
    uint32_t   msgLen = 0;
@@ -3624,8 +3660,8 @@ uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo)
                if(ulTtiReq != NULLP)
                {
                        memset(ulTtiReq, 0, msgSize);
-                       ulTtiReq->sfn  = currTimingInfo.sfn;
-                       ulTtiReq->slot = currTimingInfo.slot;
+                       ulTtiReq->sfn  = ulTtiReqTimingInfo.sfn;
+                       ulTtiReq->slot = ulTtiReqTimingInfo.slot;
                        ulTtiReq->nPdus = getnPdus(ulTtiReq, currUlSlot);
                        ulTtiReq->nGroup = 0;
                        if(ulTtiReq->nPdus > 0)
@@ -3645,9 +3681,15 @@ uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo)
                                        pduIdx++;
                                        fillPuschPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot, &msgLen);
                                }
-
+                               /* Fill PUCCH PDU */
+            if(currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI)
+                               {
+                                       pduIdx++;
+                                       fillPucchPdu(&ulTtiReq->pdus[pduIdx], &macCellCfg, currUlSlot, &msgLen);
+                               }
                                if((currUlSlot->ulInfo.dataType & SCH_DATATYPE_PRACH) || \
-                                               (currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH))
+                                               (currUlSlot->ulInfo.dataType & SCH_DATATYPE_PUSCH)|| \
+                                               (currUlSlot->ulInfo.dataType & SCH_DATATYPE_UCI))
                                {
                                        msgLen += (sizeof(fapi_ul_tti_req_t) - sizeof(fapi_msg_t));
                                        fillMsgHeader(&ulTtiReq->header, FAPI_UL_TTI_REQUEST, msgLen);
@@ -3664,13 +3706,13 @@ uint16_t handleUlTtiReq(SlotIndInfo currTimingInfo)
                                DU_LOG("\nLWR_MAC: Sending UL TTI Request");
                                LwrMacSendToPhy(ulTtiReq->header.message_type_id, msgSize, (void *)ulTtiReq);
                        }
-                       memset(&currUlSlot, 0, sizeof(MacUlSlot));
+                       memset(currUlSlot, 0, sizeof(MacUlSlot));
                        return ROK;
                }
                else
                {
                        DU_LOG("\nLWR_MAC: Failed to allocate memory for UL TTI Request");
-                       memset(&currUlSlot, 0, sizeof(MacUlSlot));
+                       memset(currUlSlot, 0, sizeof(MacUlSlot));
                        return RFAILED;
                }
        }