Automatic PRB allocation using bitmap in Downlink [Issue-ID: ODUHIGH-380] 25/6825/8
authorlal.harshita <Harshita.Lal@radisys.com>
Wed, 6 Oct 2021 23:38:20 +0000 (05:08 +0530)
committerlal.harshita <Harshita.Lal@radisys.com>
Wed, 13 Oct 2021 07:34:24 +0000 (13:04 +0530)
Change-Id: I5f2888c53cf7e48f8d50727ac4adfb4cb5fa4a36
Signed-off-by: lal.harshita <Harshita.Lal@radisys.com>
src/5gnrmac/mac_ue_mgr.c
src/5gnrsch/sch.c
src/5gnrsch/sch.h
src/5gnrsch/sch_common.c
src/5gnrsch/sch_rach.c
src/5gnrsch/sch_slot_ind.c
src/5gnrsch/sch_ue_mgr.c
src/5gnrsch/sch_utils.c
src/5gnrsch/sch_utils.h
src/du_app/du_mgr_main.c

index a3c2a70..77fc0f9 100644 (file)
@@ -2697,7 +2697,7 @@ void deletePucchResourcesCfg(PucchResrcCfg *resrcCfg)
 
 uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
 {
-   uint8_t ueIdx =0, lcIdx = 0, isCrntiValid = 0;
+   uint8_t ueIdx =0, isCrntiValid = 0;
    uint16_t cellIdx=0;
    uint8_t ret = RFAILED;
    UeDeleteStatus result;
index 8476c1d..5fd4bed 100644 (file)
@@ -703,7 +703,6 @@ void fillSchSib1Cfg(uint8_t mu, uint8_t bandwidth, uint8_t numSlots, SchSib1Cfg
    /* TODO : This should be filled through freqDomRscAllocType0() */
    uint8_t FreqDomainResource[6] = {15, 0, 0, 0, 0, 0};
    uint16_t tbSize = 0;
-   uint8_t numPdschSymbols = 11; /* considering pdsch region from symbols 3 to 13 */
    uint8_t ssbIdx = 0;
 
    PdcchCfg *pdcch = &(sib1SchCfg->sib1PdcchCfg);
@@ -816,14 +815,14 @@ void fillSchSib1Cfg(uint8_t mu, uint8_t bandwidth, uint8_t numSlots, SchSib1Cfg
    pdsch->dmrs.dmrsAddPos                    = DMRS_ADDITIONAL_POS;
 
    pdsch->pdschFreqAlloc.resourceAllocType   = 1; /* RAT type-1 RIV format */
-   pdsch->pdschFreqAlloc.freqAlloc.startPrb  = offsetPointA + SCH_SSB_NUM_PRB + 1; /* the RB numbering starts from coreset0,
-                                                                           and PDSCH is always above SSB */
-   pdsch->pdschFreqAlloc.freqAlloc.numPrb    = schCalcNumPrb(tbSize,sib1SchCfg->sib1Mcs,numPdschSymbols);
+   /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
+   pdsch->pdschFreqAlloc.freqAlloc.startPrb  = offsetPointA + SCH_SSB_NUM_PRB;
+   pdsch->pdschFreqAlloc.freqAlloc.numPrb    = schCalcNumPrb(tbSize,sib1SchCfg->sib1Mcs, NUM_PDSCH_SYMBOL);
    pdsch->pdschFreqAlloc.vrbPrbMapping       = 0; /* non-interleaved */
    pdsch->pdschTimeAlloc.rowIndex            = 1;
    /* This is Intel's requirement. PDSCH should start after PDSCH DRMS symbol */
    pdsch->pdschTimeAlloc.timeAlloc.startSymb = 3; /* spec-38.214, Table 5.1.2.1-1 */
-   pdsch->pdschTimeAlloc.timeAlloc.numSymb   = numPdschSymbols;
+   pdsch->pdschTimeAlloc.timeAlloc.numSymb   = NUM_PDSCH_SYMBOL;
    pdsch->beamPdschInfo.numPrgs              = 1;
    pdsch->beamPdschInfo.prgSize              = 1;
    pdsch->beamPdschInfo.digBfInterfaces      = 0;
@@ -1078,6 +1077,146 @@ uint8_t MacSchSrUciInd(Pst *pst, SrUciIndInfo *uciInd)
    }
    return ROK;
 }
+
+/*******************************************************************
+ *
+ * @brief Allocates requested PRBs for DL
+ *
+ * @details
+ *
+ *    Function : allocatePrbDl
+ *
+ *    Functionality:
+ *      Allocates requested PRBs in DL
+ *      Keeps track of allocated PRB (using bitmap) and remaining PRBs
+ *
+ * @params[in] prbAlloc table
+ *             Start symbol
+ *             Number of symbols
+ *             Start PRB
+ *             Number of PRBs
+ *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, \
+   uint8_t startSymbol, uint8_t symbolLength, uint16_t *startPrb, uint16_t numPrb)
+{
+   uint8_t        symbol = 0;
+   uint16_t       broadcastPrbStart=0, broadcastPrbEnd=0;
+   FreePrbBlock   *freePrbBlock = NULLP;
+   CmLList        *freePrbNode = NULLP;
+   PduTxOccsaion  ssbOccasion=0, sib1Occasion=0;
+   SchDlSlotInfo  *schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
+   SchPrbAlloc    *prbAlloc = &schDlSlotInfo->prbAlloc;
+
+   /* If startPrb is set to MAX_NUM_RB, it means startPrb is not known currently.
+    * Search for an appropriate location in PRB grid and allocate requested resources */
+   if(*startPrb == MAX_NUM_RB)
+   {
+      /* Check if SSB/SIB1 is also scheduled in this slot  */
+      ssbOccasion = schCheckSsbOcc(cell, slotTime);
+      sib1Occasion = schCheckSib1Occ(cell, slotTime);
+
+      if(ssbOccasion && sib1Occasion)
+      {
+         broadcastPrbStart = cell->cellCfg.ssbSchCfg.ssbOffsetPointA; 
+         broadcastPrbEnd = broadcastPrbStart + SCH_SSB_NUM_PRB + cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc.numPrb -1;
+      }
+      else if(ssbOccasion)
+      {
+         broadcastPrbStart = cell->cellCfg.ssbSchCfg.ssbOffsetPointA;
+         broadcastPrbEnd = broadcastPrbStart + SCH_SSB_NUM_PRB -1;
+      }
+      else if(sib1Occasion)
+      {
+         broadcastPrbStart = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc.startPrb;
+         broadcastPrbEnd = broadcastPrbStart + cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc.numPrb -1;
+      }
+
+      /* Iterate through all free PRB blocks */
+      freePrbNode = prbAlloc->freePrbBlockList.first; 
+      while(freePrbNode)
+      {
+         freePrbBlock = (FreePrbBlock *)freePrbNode->node; 
+
+         /* If broadcast message is scheduled in this slot, then check if its PRBs belong to the current free block.
+          * Since SSB/SIB1 PRB location is fixed, these PRBs cannot be allocated to other message in same slot */
+         if((ssbOccasion || sib1Occasion) && 
+            ((broadcastPrbStart >= freePrbBlock->startPrb) && (broadcastPrbStart <= freePrbBlock->endPrb)) && \
+            ((broadcastPrbEnd >= freePrbBlock->startPrb) && (broadcastPrbEnd <= freePrbBlock->endPrb)))
+         {
+            /* Implmentation is done such that highest-numbered free-RB is allocated first */ 
+            if((freePrbBlock->endPrb > broadcastPrbEnd) && ((freePrbBlock->endPrb - broadcastPrbEnd) >= numPrb))
+            {
+               /* If sufficient free PRBs are available above bradcast message then,
+                * endPrb = freePrbBlock->endPrb
+                * startPrb = endPrb - numPrb +1;
+                */
+               *startPrb = freePrbBlock->endPrb - numPrb +1;
+               break;
+            }
+            else if((broadcastPrbStart > freePrbBlock->startPrb) && ((broadcastPrbStart - freePrbBlock->startPrb) >= numPrb))
+            {
+               /* If free PRBs are available below broadcast message then,
+                * endPrb = broadcastPrbStart - 1
+                * startPrb = endPrb - numPrb +1
+                */
+               *startPrb = broadcastPrbStart - numPrb; 
+               break;
+            }
+            else
+            {
+               freePrbNode = freePrbNode->next;
+               continue;
+            }
+         }
+         else
+         {
+            /* Check if requested number of blocks can be allocated from the current block */ 
+            if (freePrbBlock->numFreePrb < numPrb)
+            {
+               freePrbNode = freePrbNode->next;
+               continue;
+            }
+            *startPrb = freePrbBlock->endPrb - numPrb +1;
+            break;  
+         }
+      }
+
+      /* If no free block can be used to allocated request number of RBs */
+      if(*startPrb == MAX_NUM_RB)
+         return RFAILED;
+   }
+
+   /* If startPrb is known already, check if requested PRBs are available for allocation */
+   else
+   {
+      freePrbNode = isPrbAvailable(&prbAlloc->freePrbBlockList, *startPrb, numPrb);
+      if(!freePrbNode)
+      {
+         DU_LOG("\nERROR  -->  SCH: Requested PRB unavailable");
+         return RFAILED;
+      }
+   }
+
+   /* Update bitmap to allocate PRBs */
+   for(symbol=startSymbol; symbol < (startSymbol+symbolLength); symbol++)
+   {
+      if(fillPrbBitmap(prbAlloc->prbBitMap[symbol], *startPrb, numPrb) != ROK)
+      {
+         DU_LOG("\nERROR  -->  SCH: fillPrbBitmap() failed for symbol [%d] ", symbol);
+         return RFAILED;
+      }
+   }
+
+   /* Update the remaining number for free PRBs */
+   removeAllocatedPrbFromFreePrbList(&prbAlloc->freePrbBlockList, freePrbNode, *startPrb, numPrb);
+
+   return ROK;
+}
+
 /**********************************************************************
   End of file
  **********************************************************************/
index cbf18e7..bacee40 100644 (file)
 #define SCH_MAX_SSB_BEAM 8 /* since we are supporting only SCS=15KHz and 30KHz */
 #define SCH_SYMBOL_PER_SLOT 14
 #define SCH_SSB_NUM_SYMB 4
-#define SCH_SSB_NUM_PRB 20
+#define SCH_SSB_NUM_PRB 21 /* One extra PRB as buffer */
 #define SCHED_DELTA 1
 #define BO_DELTA 1
 #define RAR_DELAY   2
 #define MSG4_DELAY  1
 #define PDSCH_START_RB 10
+/* Considering pdsch region from 3 to 13, DMRS exclued.
+ * Overlapping of PDSCH DRMS and PDSCH not supported by Intel L1 */
+#define NUM_PDSCH_SYMBOL 11
 #define PUSCH_START_RB 15
 #define PUCCH_NUM_PRB_FORMAT_0_1_4 1  /* number of PRBs in freq domain, spec 38.213 - 9.2.1 */
 #define SI_RNTI 0xFFFF
@@ -59,6 +62,9 @@
 #define MAC_HDR_SIZE  3   /* 3 bytes of MAC Header */
 #define UL_GRANT_SIZE 224
 
+#define PRB_BITMAP_IDX_LEN 64
+#define PRB_BITMAP_MAX_IDX ((MAX_NUM_RB + PRB_BITMAP_IDX_LEN-1) / PRB_BITMAP_IDX_LEN)
+
 typedef struct schCellCb SchCellCb;
 typedef struct schUeCb SchUeCb;
 
@@ -106,21 +112,36 @@ typedef struct schGenCb
 #endif
 }SchGenCb;
 
+typedef struct freePrbBlock
+{
+   uint16_t numFreePrb;
+   uint16_t startPrb;
+   uint16_t endPrb;
+}FreePrbBlock;
+
+/**
+ * @brief
+ * PRB allocations for a symbol within a slot
+ */
+typedef struct schPrbAlloc
+{
+   CmLListCp freePrbBlockList;           /*!< List of continuous blocks for available PRB */
+   uint64_t  prbBitMap[SCH_SYMBOL_PER_SLOT][PRB_BITMAP_MAX_IDX];  /*!< BitMap to store the allocated PRBs */
+}SchPrbAlloc;
+
 /**
  * @brief
  * scheduler allocationsfor DL per cell.
  */
 typedef struct schDlSlotInfo
 {
-   uint16_t  totalPrb;                          /*!< Number of RBs in the cell */
-   uint16_t  assignedPrb[SCH_SYMBOL_PER_SLOT];  /*!< Num RBs and corresponding symbols allocated */
-   uint16_t  resAllocBitMap;                    /*!< Resource allocation bitmap */
-   bool      ssbPres;                           /*!< Flag to determine if SSB is present in this slot */
-   uint8_t   ssbIdxSupported;                   /*!< Max SSB index */
-   SsbInfo   ssbInfo[MAX_SSB_IDX];              /*!< SSB info */
-   bool      sib1Pres;                          /*!< Flag to determine if SIB1 is present in this slot */
-   RarAlloc  *rarAlloc;                         /*!< RAR allocation */
-   DlMsgInfo *dlMsgInfo;                        /*!< DL dedicated Msg info */
+   SchPrbAlloc  prbAlloc;                 /*!< PRB allocated/available in this slot */
+   bool         ssbPres;                  /*!< Flag to determine if SSB is present in this slot */
+   uint8_t      ssbIdxSupported;          /*!< Max SSB index */
+   SsbInfo      ssbInfo[MAX_SSB_IDX];     /*!< SSB info */
+   bool         sib1Pres;                 /*!< Flag to determine if SIB1 is present in this slot */
+   RarAlloc     *rarAlloc;                /*!< RAR allocation */
+   DlMsgInfo    *dlMsgInfo;               /*!< DL dedicated Msg info */
 }SchDlSlotInfo;
 
 typedef struct schRaCb
@@ -134,14 +155,12 @@ typedef struct schRaCb
  */
 typedef struct schUlSlotInfo
 {
-   uint16_t     totalPrb;  /*!< Number of RBs in the cell */
-   uint16_t     assignedPrb[SCH_SYMBOL_PER_SLOT]; /*!< Num RBs and corresponding symbols allocated */
-   uint16_t     resAllocBitMap;                    /*!< Resource allocation bitmap */
-   uint8_t      puschCurrentPrb; /* Current PRB for PUSCH allocation */
-   bool         puschPres; /*!< PUSCH presence field */
-   SchPuschInfo *schPuschInfo; /*!< PUSCH info */
-   bool         pucchPres; /*!< PUCCH presence field */
-   SchPucchInfo schPucchInfo; /*!< PUCCH info */
+   SchPrbAlloc  prbAlloc; /*!< PRB allocated/available per symbol */
+   uint8_t      puschCurrentPrb;                /* Current PRB for PUSCH allocation */
+   bool         puschPres;                      /*!< PUSCH presence field */
+   SchPuschInfo *schPuschInfo;                  /*!< PUSCH info */
+   bool         pucchPres;                      /*!< PUCCH presence field */
+   SchPucchInfo schPucchInfo;                   /*!< PUCCH info */
 }SchUlSlotInfo;
 
 /**
@@ -280,35 +299,41 @@ typedef struct schCb
 SchCb schCb[SCH_MAX_INST];
 
 /* function declarations */
-SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti);
+short int schActvTmr(Ent ent,Inst inst);
+
+/* Configuration related function declarations */
 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo);
 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo);
+void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, \
+   SchPdschCfgCmn pdschCmnCfg,SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl);
+void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], \
+   uint16_t puschSymTblSize, SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl);
 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm);
-short int schActvTmr(Ent ent,Inst inst);
-uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,uint16_t slot);
+SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti);
+
+/* Incoming message handler function declarations */
 uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst inst);
+uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
+
+/* DL scheduling related function declarations */
+PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime);
+PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime);
+uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
+uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc);
+void schProcessRaReq(SlotTimingInfo currTime, SchCellCb *cellCb);
+uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueIdx, RarAlloc *rarAlloc, uint8_t k0Index);
+uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo slotTime, DlMsgAlloc *msg4Alloc);
+uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
+   uint32_t *accumalatedSize, DlMsgAlloc *dlMsgAlloc);
+uint16_t schAccumalateLcBoSize(SchCellCb *cell, uint16_t ueIdx);
+
+/* UL scheduling related function declarations */
 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst);
-uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot, bool ssbPresent, bool sib1Present);
-uint16_t schCalcTbSize(uint32_t payLoadSize);
-uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
 uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot);
-uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst);
 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo);
 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo);
-uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t crnti,
-   uint32_t *accumalatedSize, uint16_t slot);
-uint16_t schAccumalateLcBoSize(SchCellCb *cell, uint16_t ueIdx);
-uint8_t schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t offsetPointA, \
-    uint8_t k0Index, bool ssbPresent, bool sib1Present);
-void schProcessRaReq(SlotTimingInfo currTime, SchCellCb *cellCb);
-
-void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, \
-SchPdschCfgCmn pdschCmnCfg,SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl);
-void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], \
-uint16_t puschSymTblSize, SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl);
-
-PduTxOccsaion schCheckSsbOcc(SlotTimingInfo slotTime, SchCellCb *cell);
-PduTxOccsaion schCheckSib1Occ(SlotTimingInfo slotTime, SchCellCb *cell);
+uint8_t allocatePrbDl(SchCellCb *cell, SlotTimingInfo slotTime, uint8_t startSymbol, uint8_t symbolLength, \
+   uint16_t *startPrb, uint16_t numPrb);
 
 /**********************************************************************
   End of file
index 89f1969..2db25f0 100644 (file)
@@ -61,70 +61,81 @@ SchMacUlSchInfoFunc schMacUlSchInfoOpts[] =
  *
  * @details
  *
- *     Function : schBroadcastAlloc
+ *     Function : schBroadcastSsbAlloc
  *     
- *     This function handles common scheduling for DL
+ *     This function handles common scheduling for SSB
  *     
  *  @param[in]  SchCellCb *cell, cell cb
  *  @param[in]  DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
  *  @return  void
  **/
-uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,
-      uint16_t slot)
+uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc)
 {
    /* schedule SSB */
-   uint8_t ssbStartPrb, ssbStartSymb, idx;
+   uint8_t ssbStartSymb, idx;
+   uint16_t ssbStartPrb;
    SchDlSlotInfo *schDlSlotInfo;
    SsbInfo ssbInfo;
 
-   schDlSlotInfo = cell->schDlSlotInfo[slot];
+   schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
+   ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA; //+Kssb
+   ssbStartSymb = cell->ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are
+                                                                             supporting only 1 ssb beam */
 
-   if(dlBrdcstAlloc->ssbTrans)
+   /* Assign interface structure */
+   for(idx=0; idx<dlBrdcstAlloc->ssbIdxSupported; idx++)
    {
-      ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA; //+Kssb
-      ssbStartSymb = cell->ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are
-                                                                                supporting only 1 ssb beam */
-
-      /* Assign interface structure */
-      for(idx=0; idx<dlBrdcstAlloc->ssbIdxSupported; idx++)
-      {
-         ssbInfo.ssbIdx              = idx;
-         ssbInfo.fdAlloc.startPrb    = ssbStartPrb;
-         ssbInfo.fdAlloc.numPrb      = SCH_SSB_NUM_PRB;
-         ssbInfo.tdAlloc.startSymb   = ssbStartSymb;
-         ssbInfo.tdAlloc.numSymb     = SCH_SSB_NUM_SYMB;
-         dlBrdcstAlloc->ssbInfo[idx] = ssbInfo;
-         schDlSlotInfo->ssbInfo[idx] = ssbInfo;
-      }
+      ssbInfo.ssbIdx              = idx;
+      ssbInfo.fdAlloc.startPrb    = ssbStartPrb;
+      ssbInfo.fdAlloc.numPrb      = SCH_SSB_NUM_PRB;
+      ssbInfo.tdAlloc.startSymb   = ssbStartSymb;
+      ssbInfo.tdAlloc.numSymb     = SCH_SSB_NUM_SYMB;
+      dlBrdcstAlloc->ssbInfo[idx] = ssbInfo;
+      schDlSlotInfo->ssbInfo[idx] = ssbInfo;
+   }
 
-      schDlSlotInfo->ssbPres = true;
-      schDlSlotInfo->ssbIdxSupported = dlBrdcstAlloc->ssbIdxSupported;
-      for(idx=ssbStartSymb; idx<ssbStartSymb+SCH_SSB_NUM_SYMB; idx++)
-      {
-         schDlSlotInfo->assignedPrb[idx] = ssbStartPrb + SCH_SSB_NUM_PRB + 1; /* +1 for kSsb */
-      }
+   if((allocatePrbDl(cell, slotTime, ssbStartSymb, SCH_SSB_NUM_SYMB, &ssbInfo.fdAlloc.startPrb, ssbInfo.fdAlloc.numPrb)) != ROK)
+   {
+       DU_LOG("\nERROR  -->  SCH: PRB allocation failed for SSB in SFN:SLOT [%d : %d]", slotTime.sfn, slotTime.slot);
+       return RFAILED;
    }
 
-   /* SIB1 allocation */
-   if(dlBrdcstAlloc->sib1Trans)
+
+   schDlSlotInfo->ssbPres = true;
+   schDlSlotInfo->ssbIdxSupported = dlBrdcstAlloc->ssbIdxSupported;
+   return ROK;
+}
+
+/**
+ * @brief common resource allocation for SIB1
+ *
+ * @details
+ *
+ *     Function : schBroadcastSib1Alloc
+ *     
+ *     This function handles common scheduling for SIB1
+ *     
+ *  @param[in]  SchCellCb *cell, cell cb
+ *  @param[in]  DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
+ *  @return  void
+ **/
+uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc)
+{
+   FreqDomainAlloc freqAlloc = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc;
+   TimeDomainAlloc timeAlloc = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschTimeAlloc.timeAlloc;
+   SchDlSlotInfo *schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
+
+   if((allocatePrbDl(cell, slotTime, timeAlloc.startSymb, timeAlloc.numSymb, &freqAlloc.startPrb, freqAlloc.numPrb)) != ROK)
    {
-      uint16_t tbSize         = 0;
-      uint8_t numPdschSymbols = 12; /* considering pdsch region from 2 to 13 */
-      uint8_t mcs             = 4;  /* MCS fixed to 4 */
-      uint8_t numSib1Prb      = 0;
-      schDlSlotInfo->sib1Pres = true;
-
-      tbSize = schCalcTbSize(cell->cellCfg.sib1SchCfg.sib1PduLen); /* send this value to the func in bytes when considering sib1 size */
-      numSib1Prb = schCalcNumPrb(tbSize,mcs,numPdschSymbols);
-      for(idx=0; idx<SCH_SYMBOL_PER_SLOT; idx++)
-      {
-         schDlSlotInfo->assignedPrb[idx] = ssbStartPrb + SCH_SSB_NUM_PRB + 1 + numSib1Prb; /* 10 PRBs for sib1 */
-      }
-      memcpy(&dlBrdcstAlloc->sib1Alloc.bwp, &cell->cellCfg.sib1SchCfg.bwp, sizeof(BwpCfg)); 
-      memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg, &cell->cellCfg.sib1SchCfg.sib1PdcchCfg, sizeof(PdcchCfg)); 
-      memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdschCfg, &cell->cellCfg.sib1SchCfg.sib1PdschCfg, sizeof(PdschCfg)); 
-      dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg.dci.pdschCfg = &dlBrdcstAlloc->sib1Alloc.sib1PdschCfg;
+       DU_LOG("\nERROR  -->  SCH: PRB allocation failed for SIB1 in SFN:Slot [%d : %d]", slotTime.sfn, slotTime.slot);
+       return RFAILED;
    }
+
+   memcpy(&dlBrdcstAlloc->sib1Alloc.bwp, &cell->cellCfg.sib1SchCfg.bwp, sizeof(BwpCfg)); 
+   memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg, &cell->cellCfg.sib1SchCfg.sib1PdcchCfg, sizeof(PdcchCfg)); 
+   memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdschCfg, &cell->cellCfg.sib1SchCfg.sib1PdschCfg, sizeof(PdschCfg)); 
+   dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg.dci.pdschCfg = &dlBrdcstAlloc->sib1Alloc.sib1PdschCfg;
+   schDlSlotInfo->sib1Pres = true;
    return ROK;
 }
 
@@ -240,7 +251,7 @@ void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo
             dataType |= SCH_DATATYPE_PRACH;
             /* Considering first slot in the frame for PRACH */
             idx = 0;
-            schUlSlotInfo->assignedPrb[idx] = freqStart+numPrachRb;
+            //schUlSlotInfo->assignedPrb[idx] = freqStart+numPrachRb;
          }
          ulSchedInfo->dataType = dataType;
          /* prach info */
@@ -558,7 +569,7 @@ uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot, bool ssbPresent, bool sib1Present)
+uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo slotTime, DlMsgAlloc *msg4Alloc)
 {
    uint8_t coreset0Idx = 0;
    uint8_t numRbs = 0;
@@ -568,10 +579,8 @@ uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot
    uint8_t offsetPointA;
    uint8_t FreqDomainResource[6] = {0};
    uint16_t tbSize = 0;
-   uint8_t numPdschSymbols = 11;            /* considering pdsch region from 3 to 13 */
    uint8_t mcs = 4;                         /* MCS fixed to 4 */
    SchBwpDlCfg *initialBwp;
-   FreqDomainAlloc *sib1PdschFreqAlloc = NULL;
 
    PdcchCfg *pdcch = &msg4Alloc->dlMsgPdcchCfg;
    PdschCfg *pdsch = &msg4Alloc->dlMsgPdschCfg;
@@ -617,7 +626,7 @@ uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot
    pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
    pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
    pdcch->numDlDci = 1;
-   pdcch->dci.rnti = cell->schDlSlotInfo[slot]->dlMsgInfo->crnti;
+   pdcch->dci.rnti = cell->schDlSlotInfo[slotTime.slot]->dlMsgInfo->crnti;
    pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
    pdcch->dci.scramblingRnti = 0;
    pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
@@ -633,7 +642,7 @@ uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot
    /* fill the PDSCH PDU */
    uint8_t cwCount = 0;
    pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
-   pdsch->rnti = cell->schDlSlotInfo[slot]->dlMsgInfo->crnti;
+   pdsch->rnti = cell->schDlSlotInfo[slotTime.slot]->dlMsgInfo->crnti;
    pdsch->pduIndex = 0;
    pdsch->numCodewords = 1;
    for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
@@ -659,24 +668,23 @@ uint8_t schDlRsrcAllocMsg4(DlMsgAlloc *msg4Alloc, SchCellCb *cell, uint16_t slot
    pdsch->dmrs.mappingType      = DMRS_MAP_TYPE_A; /* Setting to Type-A */
    pdsch->dmrs.nrOfDmrsSymbols  = NUM_DMRS_SYMBOLS;
    pdsch->dmrs.dmrsAddPos       = DMRS_ADDITIONAL_POS;
+
+   pdsch->pdschTimeAlloc.timeAlloc.startSymb = 3; /* spec-38.214, Table 5.1.2.1-1 */
+   pdsch->pdschTimeAlloc.timeAlloc.numSymb = NUM_PDSCH_SYMBOL;
+
    pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
-   /* The RB numbering starts from coreset0 */ 
-   pdsch->pdschFreqAlloc.freqAlloc.startPrb = PDSCH_START_RB;
-   if(ssbPresent)
-   {
-      /* PDSCH is always above SSB */
-      pdsch->pdschFreqAlloc.freqAlloc.startPrb = offsetPointA + SCH_SSB_NUM_PRB + 1;
-   }
-   if(sib1Present)
+   pdsch->pdschFreqAlloc.freqAlloc.startPrb = MAX_NUM_RB;
+   pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, mcs, NUM_PDSCH_SYMBOL);
+   pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
+
+   /* Allocate the number of PRBs required for RAR PDSCH */
+   if((allocatePrbDl(cell, slotTime, pdsch->pdschTimeAlloc.timeAlloc.startSymb, pdsch->pdschTimeAlloc.timeAlloc.numSymb,\
+      &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
    {
-      /* Must not overlap with SIB1 */
-      sib1PdschFreqAlloc = &cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc;
-      pdsch->pdschFreqAlloc.freqAlloc.startPrb = sib1PdschFreqAlloc->startPrb + sib1PdschFreqAlloc->numPrb + 1; 
+      DU_LOG("\nERROR  --> SCH : Resource allocation failed for MSG4");
+      return RFAILED;
    }
-   pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, mcs, numPdschSymbols);
-   pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
-   pdsch->pdschTimeAlloc.timeAlloc.startSymb = 3; /* spec-38.214, Table 5.1.2.1-1 */
-   pdsch->pdschTimeAlloc.timeAlloc.numSymb = numPdschSymbols;
+
    pdsch->beamPdschInfo.numPrgs = 1;
    pdsch->beamPdschInfo.prgSize = 1;
    pdsch->beamPdschInfo.digBfInterfaces = 0;
@@ -738,8 +746,8 @@ uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot)
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t crnti,
-      uint32_t *accumalatedSize, uint16_t slot)
+uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
+      uint32_t *accumalatedSize, DlMsgAlloc *dlMsgAlloc)
 {
    uint8_t ueIdx;
    uint16_t tbSize = 0;
@@ -823,13 +831,24 @@ uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t cr
    pdsch->dmrs.mappingType      = DMRS_MAP_TYPE_A; /* Setting to Type-A */
    pdsch->dmrs.nrOfDmrsSymbols  = NUM_DMRS_SYMBOLS;
    pdsch->dmrs.dmrsAddPos       = pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos;
+
+   pdsch->pdschTimeAlloc.timeAlloc.startSymb = pdschCfg.timeDomRsrcAllociList[0].startSymbol;
+   pdsch->pdschTimeAlloc.timeAlloc.numSymb = pdschCfg.timeDomRsrcAllociList[0].symbolLength;
+
+   pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
    pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
-   pdsch->pdschFreqAlloc.freqAlloc.startPrb = PDSCH_START_RB;
+   pdsch->pdschFreqAlloc.freqAlloc.startPrb = MAX_NUM_RB;
    pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, ueCb.ueCfg.dlModInfo.mcsIndex, \
                   pdschCfg.timeDomRsrcAllociList[0].symbolLength);
-   pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
-   pdsch->pdschTimeAlloc.timeAlloc.startSymb = pdschCfg.timeDomRsrcAllociList[0].startSymbol;
-   pdsch->pdschTimeAlloc.timeAlloc.numSymb = pdschCfg.timeDomRsrcAllociList[0].symbolLength;
+
+   /* Allocate the number of PRBs required for DL PDSCH */
+   if((allocatePrbDl(cell, slotTime, pdsch->pdschTimeAlloc.timeAlloc.startSymb, pdsch->pdschTimeAlloc.timeAlloc.numSymb,\
+      &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
+   {
+      DU_LOG("\nERROR  --> SCH : allocatePrbDl() failed for DL MSG");
+      return RFAILED;
+   }
+
    pdsch->beamPdschInfo.numPrgs = 1;
    pdsch->beamPdschInfo.prgSize = 1;
    pdsch->beamPdschInfo.digBfInterfaces = 0;
index 9f37d1c..54d27ba 100644 (file)
@@ -115,14 +115,13 @@ SchPuschInfo* schAllocMsg3Pusch(Inst schInst, uint16_t crnti, uint8_t k2Index, u
    uint8_t    numRb         = 0;
    uint8_t    idx           = 0;
    uint8_t    mcs            = 4;
-   uint8_t    numPdschSymbols= 11;
    uint16_t   tbSize         = 0;
 
    cell = schCb[schInst].cells[schInst];
    if(cell == NULL)
    {
       DU_LOG("\n\nERROR  -->  SCH :  Failed to find cell in schAllocMsg3Pusch");
-      return RFAILED;
+      return NULLP;
    }
 
    startSymb = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].startSymbol;
@@ -130,7 +129,7 @@ SchPuschInfo* schAllocMsg3Pusch(Inst schInst, uint16_t crnti, uint8_t k2Index, u
 
    startRb = cell->schUlSlotInfo[msg3Slot]->puschCurrentPrb;
    tbSize = schCalcTbSize(8); /* 6 bytes msg3  and 2 bytes header */
-   numRb = schCalcNumPrb(tbSize, mcs, numPdschSymbols);
+   numRb = schCalcNumPrb(tbSize, mcs, NUM_PDSCH_SYMBOL);
 
    /* allocating 1 extra RB for now */
    numRb++;
@@ -139,7 +138,7 @@ SchPuschInfo* schAllocMsg3Pusch(Inst schInst, uint16_t crnti, uint8_t k2Index, u
 
    for(idx=startSymb; idx<symbLen; idx++)
    {
-      cell->schUlSlotInfo[msg3Slot]->assignedPrb[idx] = startRb + numRb;
+      //cell->schUlSlotInfo[msg3Slot]->assignedPrb[idx] = startRb + numRb;
    }
    schUlSlotInfo = cell->schUlSlotInfo[msg3Slot];
 
@@ -150,7 +149,7 @@ SchPuschInfo* schAllocMsg3Pusch(Inst schInst, uint16_t crnti, uint8_t k2Index, u
       return NULLP;
    }
    tbSize = 0;  /* since nPrb has been incremented, recalculating tbSize */
-   tbSize = schCalcTbSizeFromNPrb(numRb, mcs, numPdschSymbols);
+   tbSize = schCalcTbSizeFromNPrb(numRb, mcs, NUM_PDSCH_SYMBOL);
    tbSize = tbSize / 8 ; /*bits to byte conversion*/
    schUlSlotInfo->schPuschInfo->crnti             = crnti;
    schUlSlotInfo->schPuschInfo->harqProcId        = SCH_HARQ_PROC_ID;
@@ -227,15 +226,14 @@ void schProcessRaReq(SlotTimingInfo currTime, SchCellCb *cell)
 #ifdef NR_TDD
    uint8_t   totalCfgSlot = 0;
 #endif
-   uint16_t  dciSlot = 0, rarSlot = 0, msg3Slot = 0;
-   SlotTimingInfo dciTime, rarTime;
-   RarAlloc *dciSlotAlloc = NULLP;  /* Stores info for transmission of PDCCH for RAR */
-   RarAlloc *rarSlotAlloc = NULLP;  /* Stores info for transmission of RAR PDSCH */
-   SchPuschInfo *msg3PuschInfo = NULLP;          /* Stores MSG3 PUSCH scheduling information */
-   PduTxOccsaion  ssbOccasion=0, sib1Occasion=0;
+   uint16_t             dciSlot = 0, rarSlot = 0, msg3Slot = 0;
+   SlotTimingInfo       dciTime, rarTime;
+   RarAlloc             *dciSlotAlloc = NULLP;    /* Stores info for transmission of PDCCH for RAR */
+   RarAlloc             *rarSlotAlloc = NULLP;    /* Stores info for transmission of RAR PDSCH */
+   SchPuschInfo         *msg3PuschInfo = NULLP;   /* Stores MSG3 PUSCH scheduling information */
    SchK0K1TimingInfoTbl *k0K1InfoTbl=NULLP;    
-   SchK2TimingInfoTbl *msg3K2InfoTbl=NULLP;
-   RaRspWindowStatus windowStatus=0;
+   SchK2TimingInfoTbl   *msg3K2InfoTbl=NULLP;
+   RaRspWindowStatus    windowStatus=0;
 
    while(ueIdx < MAX_NUM_UE)
    {
@@ -326,14 +324,14 @@ void schProcessRaReq(SlotTimingInfo currTime, SchCellCb *cell)
          }
          cell->schDlSlotInfo[dciSlot]->rarAlloc = dciSlotAlloc;
 
-         /* Check if RAR PDSCH occasion same as SSB and SIB1 occasion */
-         ssbOccasion = schCheckSsbOcc(rarTime, cell);
-         sib1Occasion = schCheckSib1Occ(rarTime, cell);
-
          /* Fill PDCCH and PDSCH scheduling information for RAR */
-         schFillRar(dciSlotAlloc, cell->raReq[ueIdx]->raRnti,
-            cell->cellCfg.phyCellId, cell->cellCfg.ssbSchCfg.ssbOffsetPointA, k0Index,
-            ssbOccasion, sib1Occasion);
+         if((schFillRar(cell, rarTime, ueIdx, dciSlotAlloc, k0Index)) != ROK)
+         {
+            DU_LOG("\nERROR  -->  SCH: Scheduling of RAR failed in slot [%d]", rarSlot);
+            SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
+            cell->schDlSlotInfo[dciSlot]->rarAlloc = NULLP;
+            return;
+         }
 
          /* Allocate resources for msg3 */
          msg3PuschInfo = schAllocMsg3Pusch(cell->instIdx, cell->raReq[ueIdx]->rachInd->crnti, k2Index, msg3Slot);
@@ -370,6 +368,7 @@ void schProcessRaReq(SlotTimingInfo currTime, SchCellCb *cell)
             {
                DU_LOG("\nERROR  -->  SCH : Memory Allocation failed for rarSlotAlloc");
                SCH_FREE(dciSlotAlloc, sizeof(RarAlloc));
+               cell->schDlSlotInfo[dciSlot]->rarAlloc = NULLP;
                return;
             }
             cell->schDlSlotInfo[rarSlot]->rarAlloc = rarSlotAlloc;
@@ -470,10 +469,8 @@ uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst)
  *  @param[in]  offset to pointA to determine freq alloc
  *  @return  ROK
  **/
-uint8_t schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t offsetPointA, \
-uint8_t k0Index, bool ssbPresent, bool sib1Present)
+uint8_t schFillRar(SchCellCb *cell, SlotTimingInfo rarTime, uint16_t ueIdx, RarAlloc *rarAlloc, uint8_t k0Index)
 {
-   Inst inst = 0;
    uint8_t coreset0Idx = 0;
    uint8_t numRbs = 0;
    uint8_t firstSymbol = 0;
@@ -483,17 +480,10 @@ uint8_t k0Index, bool ssbPresent, bool sib1Present)
    uint16_t tbSize = 0;
    uint8_t mcs = 4;  /* MCS fixed to 4 */
 
-   if(schCb[inst].cells[inst] == NULL)
-   {
-      DU_LOG("\nERROR  -->  SCH: Cell not found");
-      return RFAILED;
-   }
-
-   SchBwpDlCfg *initialBwp = &schCb[inst].cells[inst]->cellCfg.schInitialDlBwp;
+   SchBwpDlCfg *initialBwp = &cell->cellCfg.schInitialDlBwp;
    PdcchCfg *pdcch = &rarAlloc->rarPdcchCfg;
    PdschCfg *pdsch = &rarAlloc->rarPdschCfg;
    BwpCfg *bwp = &rarAlloc->bwp;
-   FreqDomainAlloc *sib1PdschFreqAlloc = NULL;
 
    coreset0Idx     = initialBwp->pdcchCommon.commonSearchSpace.coresetId;
 
@@ -514,7 +504,7 @@ uint8_t k0Index, bool ssbPresent, bool sib1Present)
    }
 
    /* calculate the PRBs */
-   freqDomRscAllocType0(((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
+   freqDomRscAllocType0(((cell->cellCfg.ssbSchCfg.ssbOffsetPointA - offset)/6), (numRbs/6), FreqDomainResource);
 
    /* fill BWP */
    bwp->freqAlloc.numPrb   = initialBwp->bwp.freqAlloc.numPrb;
@@ -530,11 +520,11 @@ uint8_t k0Index, bool ssbPresent, bool sib1Present)
    pdcch->coresetCfg.regBundleSize = 6;    /* spec-38.211 sec 7.3.2.2 */
    pdcch->coresetCfg.interleaverSize = 2;  /* spec-38.211 sec 7.3.2.2 */
    pdcch->coresetCfg.coreSetType = 0;
-   pdcch->coresetCfg.shiftIndex = pci;
+   pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
    pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
    pdcch->numDlDci = 1;
-   pdcch->dci.rnti = raRnti; /* RA-RNTI */
-   pdcch->dci.scramblingId = pci;
+   pdcch->dci.rnti = cell->raReq[ueIdx]->raRnti; /* RA-RNTI */
+   pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
    pdcch->dci.scramblingRnti = 0;
    pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
    pdcch->dci.aggregLevel = 4;
@@ -550,7 +540,7 @@ uint8_t k0Index, bool ssbPresent, bool sib1Present)
    /* fill the PDSCH PDU */
    uint8_t cwCount = 0;
    pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
-   pdsch->rnti = raRnti; /* RA-RNTI */
+   pdsch->rnti = cell->raReq[ueIdx]->raRnti; /* RA-RNTI */
    pdsch->pduIndex = 0;
    pdsch->numCodewords = 1;
    for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
@@ -564,38 +554,37 @@ uint8_t k0Index, bool ssbPresent, bool sib1Present)
       tbSize = schCalcTbSize(RAR_PAYLOAD_SIZE + TX_PAYLOAD_HDR_LEN);
       pdsch->codeword[cwCount].tbSize = tbSize;
    }
-   pdsch->dataScramblingId = pci;
+   pdsch->dataScramblingId = cell->cellCfg.phyCellId;
    pdsch->numLayers = 1;
    pdsch->transmissionScheme = 0;
    pdsch->refPoint = 0;
    pdsch->dmrs.dlDmrsSymbPos = 4;  /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
    pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
-   pdsch->dmrs.dlDmrsScramblingId = pci;
+   pdsch->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
    pdsch->dmrs.scid = 0;
    pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
    pdsch->dmrs.dmrsPorts = 0;
    pdsch->dmrs.mappingType      = DMRS_MAP_TYPE_A;  /* Type-A */
    pdsch->dmrs.nrOfDmrsSymbols  = NUM_DMRS_SYMBOLS;
    pdsch->dmrs.dmrsAddPos       = DMRS_ADDITIONAL_POS;
+
+   pdsch->pdschTimeAlloc.timeAlloc.startSymb = initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].startSymbol;
+   pdsch->pdschTimeAlloc.timeAlloc.numSymb = initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].lengthSymbol;
+
+   pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
    pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
-   /* The RB numbering starts from coreset0 */ 
-   pdsch->pdschFreqAlloc.freqAlloc.startPrb = PDSCH_START_RB;
-   if(ssbPresent)
-   {
-      /* PDSCH is always above SSB */
-      pdsch->pdschFreqAlloc.freqAlloc.startPrb = offsetPointA + SCH_SSB_NUM_PRB + 1;
-   }
-   if(sib1Present)
+   pdsch->pdschFreqAlloc.freqAlloc.startPrb = MAX_NUM_RB;
+   pdsch->pdschFreqAlloc.freqAlloc.numPrb = \
+      schCalcNumPrb(tbSize, mcs, initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].lengthSymbol);
+
+   /* Allocate the number of PRBs required for RAR PDSCH */
+   if((allocatePrbDl(cell, rarTime, pdsch->pdschTimeAlloc.timeAlloc.startSymb, pdsch->pdschTimeAlloc.timeAlloc.numSymb,\
+      &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
    {
-      /* Must not overlap with SIB1 */
-      sib1PdschFreqAlloc = &schCb[inst].cells[inst]->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc;
-      pdsch->pdschFreqAlloc.freqAlloc.startPrb = sib1PdschFreqAlloc->startPrb + sib1PdschFreqAlloc->numPrb + 1; 
+      DU_LOG("\nERROR  --> SCH : allocatePrbDl() failed for RAR");
+      return RFAILED;
    }
-   pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, mcs, \
-      initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].lengthSymbol);
-   pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
-   pdsch->pdschTimeAlloc.timeAlloc.startSymb = initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].startSymbol;
-   pdsch->pdschTimeAlloc.timeAlloc.numSymb = initialBwp->pdschCommon.timeDomRsrcAllocList[k0Index].lengthSymbol;
+
    pdsch->beamPdschInfo.numPrgs = 1;
    pdsch->beamPdschInfo.prgSize = 1;
    pdsch->beamPdschInfo.digBfInterfaces = 0;
index 7b7a1f7..97ea00a 100644 (file)
@@ -132,7 +132,7 @@ void schCalcSlotValues(SlotTimingInfo slotInd, SchSlotValue *schSlotValue)
  * @return  Pdu transmission 
  *
  * ****************************************************************/
-PduTxOccsaion schCheckSsbOcc(SlotTimingInfo slotTime, SchCellCb *cell)
+PduTxOccsaion schCheckSsbOcc(SchCellCb *cell, SlotTimingInfo slotTime)
 {
    uint8_t  ssb_rep;
 
@@ -170,7 +170,7 @@ PduTxOccsaion schCheckSsbOcc(SlotTimingInfo slotTime, SchCellCb *cell)
  * @return  Pdu transmission
  *
  * ****************************************************************/
-PduTxOccsaion schCheckSib1Occ(SlotTimingInfo slotTime, SchCellCb *cell)
+PduTxOccsaion schCheckSib1Occ(SchCellCb *cell, SlotTimingInfo slotTime)
 {
    /* Identify SIB1 occasions */
    if((slotTime.sfn % SCH_SIB1_TRANS == 0) && (slotTime.slot ==0))
@@ -257,13 +257,21 @@ uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlM
       {
          DU_LOG("\nDEBUG  -->  SCH : No pending BO for any LC id\n");
          /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
-         SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
-               sizeof(DlMsgInfo));
+         SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
+         dlSchedInfo->dlMsgAlloc = NULLP;
          return ROK;
       }
 
       /* pdcch and pdsch data is filled */
-      schDlRsrcAllocDlMsg(dlMsgAlloc, cell, crnti, &accumalatedSize, slot);
+      if((schDlRsrcAllocDlMsg(cell, dlSchedInfo->schSlotValue.dlMsgTime, crnti, &accumalatedSize, dlMsgAlloc)) != ROK)
+      {
+         DU_LOG("\nERROR  --> SCH : Scheduling of DL dedicated message failed");
+         /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
+         SCH_FREE(dlMsgAlloc, sizeof(DlMsgAlloc));
+         dlSchedInfo->dlMsgAlloc = NULLP;
+         return RFAILED;
+
+      }
 
       /* TODO : Update the scheduling byte report for multiple LC based on QCI
        * and Priority */
@@ -278,11 +286,6 @@ uint8_t schFillBoGrantDlSchedInfo(SchCellCb *cell, DlSchedInfo *dlSchedInfo, DlM
       /* PUCCH resource */
       schAllocPucchResource(cell, dlMsgAlloc->crnti, slot);
 
-      /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
-      SCH_FREE(cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo, \
-           sizeof(DlMsgInfo));
-      cell->schDlSlotInfo[dlSchedInfo->schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
-
       /* after allocation is done, unset the bo bit for that ue */
       UNSET_ONE_BIT(ueIdx, cell->boIndBitMap);
    }
@@ -332,36 +335,48 @@ uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
    memcpy(&cell->slotInfo, slotInd, sizeof(SlotTimingInfo));
    dlBrdcstAlloc->ssbIdxSupported = SSB_IDX_SUPPORTED;
 
-   slot = dlSchedInfo.schSlotValue.currentTime.slot;
-
    dlSchedInfo.cellId = cell->cellId;
 
-   /* Check if this slot is SSB occassion */
-   dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(dlSchedInfo.schSlotValue.broadcastTime, cell); 
-   if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
-      cell->firstSsbTransmitted = true;
+   slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
 
-   /* Check if this slot is SIB1 occassion */
-   dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(dlSchedInfo.schSlotValue.broadcastTime, cell);
-   if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
-      cell->firstSib1Transmitted = true;
+   /* Check for SSB occassion */
+   dlBrdcstAlloc->ssbTrans = schCheckSsbOcc(cell, dlSchedInfo.schSlotValue.broadcastTime); 
+   if(dlBrdcstAlloc->ssbTrans)
+   {
+      if(schBroadcastSsbAlloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
+      {
+         DU_LOG("\nERROR  -->  SCH : schBroadcastSsbAlloc failed");
+         dlBrdcstAlloc->ssbTrans = NO_TRANSMISSION;
+      }
+      else 
+      {
+         dlSchedInfo.isBroadcastPres = true;
+         if((dlBrdcstAlloc->ssbTrans == NEW_TRANSMISSION) && (!cell->firstSsbTransmitted))
+            cell->firstSsbTransmitted = true;
+      }
+   }
 
-   if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
+   /* Check for SIB1 occassion */
+   dlBrdcstAlloc->sib1Trans = schCheckSib1Occ(cell, dlSchedInfo.schSlotValue.broadcastTime);
+   if(dlBrdcstAlloc->sib1Trans)
    {
-      dlSchedInfo.isBroadcastPres = true;
-      slot = dlSchedInfo.schSlotValue.broadcastTime.slot;
-      ret = schBroadcastAlloc(cell,dlBrdcstAlloc,slot);
-      if(ret != ROK)
+      if(schBroadcastSib1Alloc(cell, dlSchedInfo.schSlotValue.broadcastTime, dlBrdcstAlloc) != ROK)
+      {
+         DU_LOG("\nERROR  -->  SCH : schBroadcastSib1Alloc failed");
+         dlBrdcstAlloc->sib1Trans = NO_TRANSMISSION;
+      }
+      else 
       {
-         DU_LOG("\nERROR  -->  SCH : schBroadcastAlloc failed");
-         return ret;
+         dlSchedInfo.isBroadcastPres = true;
+         if((dlBrdcstAlloc->sib1Trans == NEW_TRANSMISSION) && (!cell->firstSib1Transmitted))
+            cell->firstSib1Transmitted = true;
       }
    }
 
    /* Check for Pending RA Requests */
    schProcessRaReq(*slotInd, cell);
 
-   /* check for RAR */
+   /* Check for RAR */
    if(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.rarTime.slot]->rarAlloc != NULLP)
    {
       slot = dlSchedInfo.schSlotValue.rarTime.slot;
@@ -369,7 +384,7 @@ uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
       cell->schDlSlotInfo[slot]->rarAlloc = NULLP;
    }
 
-   /* check for MSG4 */
+   /* Check for MSG4 */
    if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
       (cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
    {
@@ -389,16 +404,22 @@ uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
            sizeof(DlMsgInfo));
 
       /* pdcch and pdsch data is filled */
-      schDlRsrcAllocMsg4(msg4Alloc, cell, dlSchedInfo.schSlotValue.dlMsgTime.slot, dlBrdcstAlloc->ssbTrans, dlBrdcstAlloc->sib1Trans); 
+      if((schDlRsrcAllocMsg4(cell, dlSchedInfo.schSlotValue.dlMsgTime, msg4Alloc)) != ROK)
+      {
+         DU_LOG("\nERROR  -->  SCH : MSG4 scheduling failed");
+         SCH_FREE(msg4Alloc, sizeof(DlMsgAlloc));
+         dlSchedInfo.dlMsgAlloc = NULLP;
+         SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
+         return RFAILED;
+      }
 
       /* PUCCH resource */
       schAllocPucchResource(cell, msg4Alloc->dlMsgInfo.crnti, dlSchedInfo.schSlotValue.dlMsgTime.slot);
 
       SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
-      cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo = NULL;
    }
 
-   /* check if UL grant must be sent in this slot for a SR/BSR that had been received */
+   /* Check if UL grant must be sent in this slot for a SR/BSR that had been received */
    for(ueIdx=0; ueIdx<cell->numActvUe; ueIdx++)
    {
       uint32_t totDataReq = 0; /* in bytes */
@@ -446,10 +467,18 @@ uint8_t schProcessSlotInd(SlotTimingInfo *slotInd, Inst schInst)
    if((cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo != NULLP) &&
       (!cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo->isMsg4Pdu))
    {
-      schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc);
+      if((schFillBoGrantDlSchedInfo(cell, &dlSchedInfo, dlMsgAlloc)) != ROK)
+      {
+         DU_LOG("\nERROR  -->  SCH : DL MSG scheduling failed");
+         SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
+         return RFAILED;
+      }
+
+      /* Free the dl ded msg info allocated in macSchDlRlcBoInfo */
+      SCH_FREE(cell->schDlSlotInfo[dlSchedInfo.schSlotValue.dlMsgTime.slot]->dlMsgInfo, sizeof(DlMsgInfo));
    }
 
-   /* send msg to MAC */
+   /* Send msg to MAC */
    ret = sendDlAllocToMac(&dlSchedInfo, schInst);
    if(ret != ROK)
    {
index 4b56ce4..f1de4f4 100644 (file)
@@ -557,7 +557,7 @@ uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, S
   /* Update pusch in cell */
   for(idx=startSymb; idx<symbLen; idx++)
   {
-     cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
+     //cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
   }
 
   schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
index 3331915..b01ca05 100644 (file)
@@ -772,6 +772,184 @@ uint8_t pucchResourceSet[MAX_PUCCH_RES_SET_IDX][4] = {
 uint8_t minMsg3SchTime[MAX_NUM_MU] = {6, 6, 6, 6};
 
 uint8_t defaultUlAckTbl[DEFAULT_UL_ACK_LIST_COUNT]= {1, 2, 3 , 4, 5, 6, 7, 8};
+
+
+/**
+ * @brief Function to add a node to a linked list
+ *
+ * @details
+ *
+ *     Function: addNodeToLList
+ *
+ *     This function adds a new node to the linked list
+ *
+ *  @param[in]  Pointer to the list
+ *              Pointer to node to be added
+ *              Pointer to current node
+ *  @return     ROK
+ *              RFAILED
+ **/
+uint8_t addNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode)
+{
+   CmLList  *newNode;
+
+   SCH_ALLOC(newNode, sizeof(CmLList));
+   if(newNode)
+   {
+      newNode->node = (PTR)blockToAdd;
+      
+      if(currNode == NULLP)
+         cmLListAdd2Tail(llist, newNode);
+      else
+      {
+         llist->crnt = currNode;
+         cmLListInsAfterCrnt(llist, newNode);
+      }
+      return ROK;
+   } 
+   return RFAILED;
+}
+
+/**
+ * @brief Function to delete a node from linked list
+ *
+ * @details
+ *
+ *     Function: deleteNodeFromLList
+ *
+ *     This function deletes a node from the linked list
+ *
+ *  @param[in]  Pointer to the list
+ *              Pointer to node to be deleted
+ *  @return     Pointer to the deleted node
+ **/
+uint8_t deleteNodeFromLList(CmLListCp *llist, CmLList *node)
+{
+   node = cmLListDelFrm(llist, node);
+   SCH_FREE(node, sizeof(CmLList));
+
+   return ROK;
+}
+
+/**
+ * @brief Checks if requested PRBs are free
+ *
+ * @details
+ *
+ *     Function: isPrbAvailable
+ *
+ *     This functions loops through all free PRB blocks and 
+ *     checks if request PRB block is available for allocation
+ *
+ *  @param[in]  List of free PRB blocks
+ *              First PRB requested
+ *              Total number of PRB requested
+ *
+ *  @return     Returns Pointer to free block
+ *              NULL
+ **/
+CmLList* isPrbAvailable(CmLListCp *freePrbBlockList, uint16_t startPrb, uint16_t numPrb)
+{
+   uint16_t      endPrb = 0;
+   CmLList       *node = NULLP;
+   FreePrbBlock  *freeBlock = NULLP;
+
+   endPrb = startPrb + numPrb - 1; 
+
+   /* Iterate through all blocks of free PRB to check if requested PRBs can be assigned */
+   node = freePrbBlockList->first;
+   while(node)
+   {
+      freeBlock = (FreePrbBlock *)node->node;
+
+      /* Check if requested number of blocks can be allocated from the current block */
+      if(freeBlock->numFreePrb < numPrb)
+         continue;
+
+      /* Check if requested PRBs belong within the range of current free block */
+      if(((startPrb >= freeBlock->startPrb) && (startPrb <= freeBlock->endPrb)) && \
+         ((endPrb >= freeBlock->startPrb) && (endPrb <= freeBlock->endPrb)))
+      {
+         return node;
+      }
+
+      /* If current block is unable to provide resources, check the next block */
+      node = node->next;
+   }
+   return NULLP;
+}
+
+/**
+ * @brief Function to update free PRB list
+ *
+ * @details
+ *
+ *     Function: removeAllocatedPrbFromFreePrbList
+ *
+ *     This function removes the allocated PRBs from the
+ *     list of free PRBs
+ *
+ *  @param[in]  Pointer to the list
+ *              Pointer to node from which PRB was allocated
+ *              Start PRB allocated
+ *              Number of PRBs allocated
+ *  @return     void
+ **/
+void removeAllocatedPrbFromFreePrbList(CmLListCp *freePrbBlockList, CmLList *node, uint16_t startPrb, uint16_t numPrb)
+{
+   uint8_t       endPrb;
+   FreePrbBlock  *newBlock = NULLP;
+   FreePrbBlock  *freeBlock = (FreePrbBlock *)node->node;
+
+   if(!node) 
+      return;
+   
+   endPrb = startPrb + numPrb -1;
+
+   /* If the whole block is allocated, remove it from linked list */
+   if(freeBlock->numFreePrb == numPrb)
+   {
+      if(deleteNodeFromLList(freePrbBlockList, node) == ROK)
+         SCH_FREE(freeBlock, sizeof(FreePrbBlock));
+   }
+
+   /* If PRB is allocated from start of free block, move the start of free block
+    * after last alloctaed PRB */
+   else if(freeBlock->startPrb == startPrb)
+   {
+      freeBlock->startPrb = endPrb+1;
+      freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
+   }
+
+   /* If PRB is allocated from end of free block, move the end of free block
+    * before the first allocated PRB */
+   else if(freeBlock->endPrb == endPrb)
+   {
+      freeBlock->endPrb = startPrb-1;
+      freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
+   }
+
+   /* If PRBs are allocated somewhere in between the free block, split it into 2
+    * nodes. Fist node contains free PRBs after the allocated PRBs. Second node
+    * contains free PRBs present before the allocated PRBs */
+   else
+   {
+      /* Block 2 */
+      SCH_ALLOC(newBlock, sizeof(FreePrbBlock));
+      if(newBlock)
+      {
+         newBlock->startPrb = freeBlock->startPrb;
+         newBlock->endPrb = startPrb-1;
+         newBlock->numFreePrb = newBlock->endPrb - newBlock->startPrb +1;
+         addNodeToLList(freePrbBlockList, newBlock, node);
+      }
+
+      /* Block 1 */
+      freeBlock->startPrb = endPrb+1;
+      freeBlock->numFreePrb = freeBlock->endPrb - freeBlock->startPrb +1;
+   }
+}
+
 /**
  * @brief frequency domain allocation function. 
  *
@@ -839,7 +1017,7 @@ uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols)
    nreDash = ceil( (12 * numSymbols) - numDmrsRePerPrb - 0);
 
    if (nreDash > 156)
-      nre = 156;
+      nreDash = 156;
 
    numPrb = ceil((float)nre / nreDash);   
    return numPrb;
@@ -921,6 +1099,7 @@ uint16_t schCalcTbSizeFromNPrb(uint16_t numPrb, uint16_t mcs, uint8_t numSymbols
    }
    return tbSize;
 }
+
 /**
  * @brief fetching ueCb from cellCb
  *
@@ -955,16 +1134,37 @@ SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti)
  **/
 void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo)
 {
+   CmLList *node = NULLP, *next = NULLP;
+   FreePrbBlock *freeBlock;
+
+   /* Delete the old blocks */
+   if(schUlSlotInfo->prbAlloc.freePrbBlockList.count)
+   {
+      node = schUlSlotInfo->prbAlloc.freePrbBlockList.first;
+   }
+   while(node)
+   {
+      next = node->next;
+      freeBlock = (FreePrbBlock *)node->node;
+      if(deleteNodeFromLList(&schUlSlotInfo->prbAlloc.freePrbBlockList, node) == ROK)
+         SCH_FREE(freeBlock, sizeof(FreePrbBlock));
+      node = next;
+   }
+
+   /* Initilize UL Slot info and mark all PRBs as free */
    memset(schUlSlotInfo, 0, sizeof(SchUlSlotInfo));
-   schUlSlotInfo->totalPrb = MAX_NUM_RB;
-   for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
+   cmLListInit(&schUlSlotInfo->prbAlloc.freePrbBlockList);
+   SCH_ALLOC(freeBlock, sizeof(FreePrbBlock));
+   if(freeBlock)
    {
-      schUlSlotInfo->assignedPrb[itr] = 0;
+      freeBlock->numFreePrb = MAX_NUM_RB;
+      freeBlock->startPrb = 0;
+      freeBlock->endPrb = MAX_NUM_RB-1;
+      addNodeToLList(&schUlSlotInfo->prbAlloc.freePrbBlockList, freeBlock, NULL);
    }
-   schUlSlotInfo->resAllocBitMap = 0;
+
    schUlSlotInfo->puschCurrentPrb = PUSCH_START_RB;
    schUlSlotInfo->schPuschInfo = NULLP;
-
 }
 
 /**
@@ -981,25 +1181,114 @@ void schInitUlSlot(SchUlSlotInfo *schUlSlotInfo)
  **/
 void schInitDlSlot(SchDlSlotInfo *schDlSlotInfo)
 {
-   memset(schDlSlotInfo, 0, sizeof(SchDlSlotInfo));
-   schDlSlotInfo->totalPrb = MAX_NUM_RB;
-   for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
+   CmLList *node = NULLP, *next = NULLP;
+   FreePrbBlock *freeBlock;
+
+   /* Delete the old blocks */
+   if(schDlSlotInfo->prbAlloc.freePrbBlockList.count)
+      node = schDlSlotInfo->prbAlloc.freePrbBlockList.first;
+   while(node)
    {
-      schDlSlotInfo->assignedPrb[itr] = 0;
+      next = node->next;
+      freeBlock = (FreePrbBlock *)node->node;
+      if(deleteNodeFromLList(&schDlSlotInfo->prbAlloc.freePrbBlockList, node) == ROK)
+         SCH_FREE(freeBlock, sizeof(FreePrbBlock));
+      node = next;
    }
-   schDlSlotInfo->resAllocBitMap = 0; 
-   for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
+
+   /* Initilize DL Slot info and mark all PRBs as free */
+   memset(schDlSlotInfo, 0, sizeof(SchDlSlotInfo));
+   cmLListInit(&schDlSlotInfo->prbAlloc.freePrbBlockList);
+   SCH_ALLOC(freeBlock, sizeof(FreePrbBlock));
+   if(freeBlock)
    {
-      memset(&schDlSlotInfo->ssbInfo[itr], 0, sizeof(SsbInfo));
+      freeBlock->numFreePrb = MAX_NUM_RB;
+      freeBlock->startPrb = 0;
+      freeBlock->endPrb = MAX_NUM_RB-1;
+      addNodeToLList(&schDlSlotInfo->prbAlloc.freePrbBlockList, freeBlock, NULL);
    }
-#if 0
-   //make allocation for SSB
-   if(cell->firstSsbTransmitted)
+}
+
+/**
+ * @brief Fill resource bit map
+ *
+ * @details
+ *
+ *     Function: fillPrbBitmap
+ *
+ *     This function updates bitMap to mark the allocated PRBs
+ *
+ *  @param[in]  schDlSlotInfo
+ *  @return     void
+ **/
+bool fillPrbBitmap(uint64_t *prbBitMap, uint16_t startPrb, uint16_t numPrb)
+{
+   uint16_t bitMapIdx = 0;
+   uint16_t offsetInFirstIdx = 0;
+   uint32_t numBitsToSetInFirstIdx = 0;
+   uint64_t mask = MASK_BIT64_ON;
+   uint64_t bitmapBackup[PRB_BITMAP_MAX_IDX];
+
+   /* Store backup of the bitmap in order to roll back if PRB allocation fails */
+   memcpy(bitmapBackup, prbBitMap, sizeof(bitmapBackup));
+
+   /* Calculate the bitmap idx and offset of bit in that idx, to start
+    * allocating PRBs from */
+   bitMapIdx = startPrb / PRB_BITMAP_IDX_LEN;
+   offsetInFirstIdx = startPrb % PRB_BITMAP_IDX_LEN;
+
+   /* If number of PRBs allocated >= number of unset bits in first idx starting from offset bit
+    * then set all bits in first idx starting from offset bit
+    * else set bits equal to number of PRBs allocated
+    */
+   numBitsToSetInFirstIdx = \
+      (numPrb >= (PRB_BITMAP_IDX_LEN-offsetInFirstIdx)) ? (PRB_BITMAP_IDX_LEN-offsetInFirstIdx) : numPrb;
+
+   mask = mask >> (PRB_BITMAP_IDX_LEN-numBitsToSetInFirstIdx);
+   mask = mask<<offsetInFirstIdx;
+
+   /* If PRBs to be allocated are not already in use, mark these PRBs as allocated */
+   if(!(prbBitMap[bitMapIdx] & mask))
    {
-      //TODO check if this slot and sfn are for ssb
+      prbBitMap[bitMapIdx] = prbBitMap[bitMapIdx] | mask;
 
+      bitMapIdx++;
+      numPrb = numPrb - numBitsToSetInFirstIdx;
+      /* Set all bits in a bitMapIdx until remaining numPrb is less than PRB_BITMAP_IDX_LEN */
+      while(numPrb > PRB_BITMAP_IDX_LEN)
+      {
+         if(prbBitMap[bitMapIdx])
+         {
+            memcpy(prbBitMap, bitmapBackup, sizeof(bitmapBackup));
+            return RFAILED;
+         }
+         prbBitMap[bitMapIdx] = MASK_BIT64_ON;
+         bitMapIdx++;
+         numPrb = numPrb - PRB_BITMAP_IDX_LEN;
+      }
+
+      /* Set bits for the remaining PRBs */
+      if(numPrb)
+      {
+         mask = MASK_BIT64_ON;
+         mask = mask >> (PRB_BITMAP_IDX_LEN-numPrb);
+         if(!(prbBitMap[bitMapIdx] & mask))
+         {
+            prbBitMap[bitMapIdx] = prbBitMap[bitMapIdx] | mask;
+         }
+         else
+         {
+            memcpy(prbBitMap, bitmapBackup, sizeof(bitmapBackup));
+            return RFAILED;
+         }
+      }
    }
-#endif
+   else
+   {
+      return RFAILED;
+   }
+   
+   return ROK;
 }
 
 #ifdef NR_TDD
index bc88c62..9081fd7 100644 (file)
@@ -32,6 +32,7 @@
 #define MAX_MU_PUSCH           4
 #define TOTAL_TBSIZE_VALUES    93
 #define DEFAULT_UL_ACK_LIST_COUNT 8 /* Max number of pusch time domain uplink allocation */
+#define MASK_BIT64_ON 0xFFFFFFFFFFFFFFFF
 
 #define SET_BITS_MSB(_startBit, _numBits, _byte) \
 {                                                \
@@ -101,16 +102,26 @@ int8_t searchSpaceIdxTable[MAX_SEARCH_SPACE_INDEX][4];
 uint8_t defaultUlAckTbl[DEFAULT_UL_ACK_LIST_COUNT];
 uint8_t minMsg3SchTime[MAX_NUM_MU];
 
-/* functions declarations */
-void freqDomRscAllocType0(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain);
-uint16_t schCalcTbSize(uint32_t payLoadSize);
-uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
-uint16_t schCalcTbSizeFromNPrb(uint16_t numPrb, uint16_t mcs, uint8_t numSymbols);
+/* Functions declarations : Linked list handler */
+uint8_t addNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode);
+uint8_t deleteNodeFromLList(CmLListCp *llist, CmLList *node);
+
+/* Functions declarations : Slot format handler */
 #ifdef NR_TDD
 SlotConfig schGetSlotSymbFrmt(uint16_t slot, uint32_t bitMap);
 uint8_t calculateSlotPatternLength(uint8_t scs, uint8_t periodicity);
 #endif
 
+/* Functions declarations : Resource allocation handler */
+void freqDomRscAllocType0(uint16_t startPrb, uint16_t prbSize, uint8_t *freqDomain);
+uint16_t schCalcTbSize(uint32_t payLoadSize);
+uint16_t schCalcNumPrb(uint16_t tbSize, uint16_t mcs, uint8_t numSymbols);
+uint16_t schCalcTbSizeFromNPrb(uint16_t numPrb, uint16_t mcs, uint8_t numSymbols);
+bool fillPrbBitmap(uint64_t *prbBitmap, uint16_t startPrb, uint16_t numPrb);
+CmLList* isPrbAvailable(CmLListCp *freePrbBlockList, uint16_t startPrb, uint16_t numPrb);
+void removeAllocatedPrbFromFreePrbList(CmLListCp *freePrbBlockList, CmLList *node, \
+   uint16_t startPrb, uint16_t numPrb);
+
 /**********************************************************************
   End of file
  **********************************************************************/
index 14c810f..bd31af4 100644 (file)
@@ -395,7 +395,7 @@ uint8_t commonInit()
       DU_LOG("\nERROR  -->  DU_APP : System Task creation for DU APP failed");
       return RFAILED;
    }
-   ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
+   //ODU_SET_THREAD_AFFINITY(&du_app_stsk, SS_AFFINITY_MODE_EXCL, 16, 0);
 
    /* system task for EGTP */
    if(ODU_CREATE_TASK(PRIOR0, &egtp_stsk) != ROK)
@@ -403,7 +403,7 @@ uint8_t commonInit()
       DU_LOG("\nERROR  -->  DU_APP : System Task creation for EGTP failed");
       return RFAILED;
    }
-   ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
+   //ODU_SET_THREAD_AFFINITY(&egtp_stsk, SS_AFFINITY_MODE_EXCL, 17, 0);
 
    /* system task for RLC_DL and MAC */
    if(ODU_CREATE_TASK(PRIOR0, &rlc_mac_cl_stsk) != ROK)
@@ -413,7 +413,7 @@ uint8_t commonInit()
    }
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-   ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
+   //ODU_SET_THREAD_AFFINITY(&rlc_mac_cl_stsk, SS_AFFINITY_MODE_EXCL, 18, 0);
 
    /* system task for RLC UL */
    if(ODU_CREATE_TASK(PRIOR1, &rlc_ul_stsk) != ROK)
@@ -421,7 +421,7 @@ uint8_t commonInit()
       DU_LOG("\nERROR  -->  DU_APP : System Task creation for RLC UL failed");
       return RFAILED;
    }
-   ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
+   //ODU_SET_THREAD_AFFINITY(&rlc_ul_stsk, SS_AFFINITY_MODE_EXCL, 19, 0);
 
    /* system task for SCTP receiver thread */
    if(ODU_CREATE_TASK(PRIOR0, &sctp_stsk) != ROK)
@@ -429,7 +429,7 @@ uint8_t commonInit()
       DU_LOG("\nERROR  -->  DU_APP : System Task creation for SCTP failed");
       return RFAILED;
    }
-   ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
+   //ODU_SET_THREAD_AFFINITY(&sctp_stsk, SS_AFFINITY_MODE_EXCL, 20, 0);
 
    /* system task for lower-mac receiver thread */
    if(ODU_CREATE_TASK(PRIOR0, &lwr_mac_stsk) != ROK)
@@ -437,7 +437,7 @@ uint8_t commonInit()
       DU_LOG("\nERROR  -->  DU_APP : System Task creation for Lower MAC failed");
       return RFAILED;
    }
-   ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 21, 0);
+   //ODU_SET_THREAD_AFFINITY(&lwr_mac_stsk, SS_AFFINITY_MODE_EXCL, 21, 0);
 
 #ifndef INTEL_WLS_MEM
    /* system task for phy stub's slot indication generator thread */