[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-415]: Paging Configuration
[o-du/l2.git] / src / 5gnrsch / sch_common.c
index 3cd0ff2..2d03702 100644 (file)
@@ -320,12 +320,14 @@ uint8_t fillUlSchedPucchFormat(uint8_t pucchFormat, SchPucchInfo *ulSchedPucch,\
  *  @return  void
  **/
 
-uint8_t fillUlSchedPucchDedicatedCfg(uint16_t numSlots, SchPucchCfg *pucchDedCfg,\
+uint8_t fillUlSchedPucchDedicatedCfg(SchCellCb *cell, SchPucchCfg *pucchDedCfg,\
    SlotTimingInfo *slotInfo, SchPucchInfo *ulSchedPucch)
 {
    uint8_t ret, resrcSetIdx, resrcIdx, schedReqIdx, srPeriodicity = 0;
    uint16_t srOffset = 0;
-
+   uint16_t numSlots = cell->numSlots;
+   bool isAllocated = false;
+   uint16_t pucchStartPrb;
    ret = ROK;
    if(pucchDedCfg->resrcSet && pucchDedCfg->resrc)
    {
@@ -335,20 +337,31 @@ uint8_t fillUlSchedPucchDedicatedCfg(uint16_t numSlots, SchPucchCfg *pucchDedCfg
          for(resrcIdx = 0; resrcIdx < pucchDedCfg->resrc->resrcToAddModListCount; resrcIdx++)
          {
             if(pucchDedCfg->resrcSet->resrcSetToAddModList[resrcSetIdx].resrcList[resrcSetIdx] ==\
-              pucchDedCfg->resrc->resrcToAddModList[resrcIdx].resrcId)
-           {
+                  pucchDedCfg->resrc->resrcToAddModList[resrcIdx].resrcId)
+            {
                ulSchedPucch->intraFreqHop = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].intraFreqHop;
                ulSchedPucch->secondPrbHop = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].secondPrbHop;
                ulSchedPucch->fdAlloc.startPrb = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].startPrb;
-              ulSchedPucch->pucchFormat = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].pucchFormat;
-              ret = fillUlSchedPucchFormat(ulSchedPucch->pucchFormat, ulSchedPucch,\
-                       &pucchDedCfg->resrc->resrcToAddModList[resrcIdx], NULLP);
-              if(ret == RFAILED)
-                 return ret;
-           }
+               ulSchedPucch->pucchFormat = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].pucchFormat;
+               ret = fillUlSchedPucchFormat(ulSchedPucch->pucchFormat, ulSchedPucch,\
+                     &pucchDedCfg->resrc->resrcToAddModList[resrcIdx], NULLP);
+               if(ret == RFAILED)
+                  return ret;
+
+               pucchStartPrb = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].startPrb;
+               ret = allocatePrbUl(cell, *slotInfo, ulSchedPucch->tdAlloc.startSymb, ulSchedPucch->tdAlloc.numSymb, &pucchStartPrb, PUCCH_NUM_PRB_FORMAT_0_1_4);
+               if(ret == ROK)
+               {
+                  isAllocated = true;
+                  break;
+               }
+            }
          }
+         if(isAllocated)
+         break;
       }
    }
+
    if(pucchDedCfg->format1)
    {
       memset(&ulSchedPucch->cmnFormatCfg, 0, sizeof(SchPucchFormatCfg));
@@ -356,7 +369,12 @@ uint8_t fillUlSchedPucchDedicatedCfg(uint16_t numSlots, SchPucchCfg *pucchDedCfg
       if(ret == RFAILED)
          return ret;
    }
-   
+
+   if(!isAllocated)
+   {
+      return RFAILED;
+   }
+
    /* setting SR and UCI flag */
    if(pucchDedCfg->schedReq)
    {
@@ -388,19 +406,21 @@ uint8_t fillUlSchedPucchDedicatedCfg(uint16_t numSlots, SchPucchCfg *pucchDedCfg
  *  @return  ROK/RFAILED
  **/
 
-uint16_t fillPucchResourceInfo(SchPucchInfo *schPucchInfo, Inst inst)
+uint16_t fillPucchResourceInfo(SchPucchInfo *schPucchInfo, Inst inst, SlotTimingInfo slotInfo)
 {
-   uint8_t ret = ROK, ueIdx = 0, pucchIdx = 0;
+   uint8_t ret = ROK, ueId = 0, ueIdx = 0, pucchIdx = 0;
    SchCellCb  *cell = schCb[inst].cells[inst];
    SchPucchCfgCmn *pucchCfg = NULLP;
    SchBwpParams *ulBwp = NULLP;
+   uint16_t startPrb;
 
-   GET_UE_IDX(schPucchInfo->rnti, ueIdx);
+   GET_UE_ID(schPucchInfo->rnti, ueId);
+   ueIdx = ueId -1;
    if(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres)
    {
       /* fill pucch dedicated cfg */
-      ret = fillUlSchedPucchDedicatedCfg(cell->numSlots,\
-       &cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg, &cell->slotInfo, schPucchInfo);
+      ret = fillUlSchedPucchDedicatedCfg(cell,\
+       &cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg, &slotInfo, schPucchInfo);
       if(ret == RFAILED)
       {
          memset(schPucchInfo, 0, sizeof(SchPucchInfo));
@@ -415,15 +435,21 @@ uint16_t fillPucchResourceInfo(SchPucchInfo *schPucchInfo, Inst inst)
       pucchCfg = &cell->cellCfg.schInitialUlBwp.pucchCommon;
       pucchIdx = pucchCfg->pucchResourceCommon;
       ulBwp = &cell->cellCfg.schInitialUlBwp.bwp;
-      schPucchInfo->fdAlloc.startPrb = ulBwp->freqAlloc.startPrb + pucchResourceSet[pucchIdx][3];
-      schPucchInfo->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
-      schPucchInfo->tdAlloc.startSymb = pucchResourceSet[pucchIdx][1];
-      schPucchInfo->tdAlloc.numSymb = pucchResourceSet[pucchIdx][2];
-      schPucchInfo->pucchFormat = pucchResourceSet[pucchIdx][0];
-
-      /* set SR and UCI flag to false */
-      schPucchInfo->srFlag  = true;
-      schPucchInfo->uciFlag = true;
+      startPrb = ulBwp->freqAlloc.startPrb + pucchResourceSet[pucchIdx][3];
+      ret = allocatePrbUl(cell, slotInfo, pucchResourceSet[pucchIdx][1], pucchResourceSet[pucchIdx][2],\
+            &startPrb, PUCCH_NUM_PRB_FORMAT_0_1_4);
+      if (ret == ROK)
+      {
+         schPucchInfo->fdAlloc.startPrb = ulBwp->freqAlloc.startPrb + pucchResourceSet[pucchIdx][3];
+         schPucchInfo->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
+         schPucchInfo->tdAlloc.startSymb = pucchResourceSet[pucchIdx][1];
+         schPucchInfo->tdAlloc.numSymb = pucchResourceSet[pucchIdx][2];
+         schPucchInfo->pucchFormat = pucchResourceSet[pucchIdx][0];
+
+         /* set SR and UCI flag to false */
+         schPucchInfo->srFlag  = true;
+         schPucchInfo->uciFlag = true;
+      }
    }
    /* set HARQ flag to true */
    schPucchInfo->harqFlag = true;
@@ -477,10 +503,13 @@ uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
 
    if(schUlSlotInfo->pucchPres)
    {
-      ulSchedInfo.dataType |= SCH_DATATYPE_UCI;
-      fillPucchResourceInfo(&schUlSlotInfo->schPucchInfo, schInst);
-      memcpy(&ulSchedInfo.schPucchInfo, &schUlSlotInfo->schPucchInfo,
-           sizeof(SchPucchInfo));
+      ret = fillPucchResourceInfo(&schUlSlotInfo->schPucchInfo, schInst, ulTimingInfo);
+      if (ret == ROK)
+      {
+         ulSchedInfo.dataType |= SCH_DATATYPE_UCI;
+         memcpy(&ulSchedInfo.schPucchInfo, &schUlSlotInfo->schPucchInfo,
+               sizeof(SchPucchInfo));
+      }
       memset(&schUlSlotInfo->schPucchInfo, 0, sizeof(SchPucchInfo));
    }
 
@@ -722,7 +751,7 @@ uint16_t schAllocPucchResource(SchCellCb *cell, SlotTimingInfo pucchTime, uint16
 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
                 uint32_t tbSize, DlMsgAlloc *dlMsgAlloc, uint16_t startPRB, uint8_t pdschStartSymbol, uint8_t pdschNumSymbols)
 {
-   uint8_t ueIdx;
+   uint8_t ueId=0;
    PdcchCfg *pdcch = NULLP;
    PdschCfg *pdsch = NULLP;
    BwpCfg *bwp = NULLP;
@@ -735,8 +764,8 @@ uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t c
    pdsch = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo].dlMsgPdschCfg;
    bwp = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo].bwp;
 
-   GET_UE_IDX(crnti, ueIdx);
-   ueCb  = cell->ueCb[ueIdx-1];
+   GET_UE_ID(crnti, ueId);
+   ueCb  = cell->ueCb[ueId-1];
    coreset1 = ueCb.ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
    pdschCfg = ueCb.ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
 
@@ -2069,7 +2098,41 @@ void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status)
       }
       node = next;
    }
-}     
+}
+
+/********************************************************************************
+ *
+ * @brief Increment the Slot by a input factor
+ *
+ * @details
+ *
+ *    Function : schIncrSlot
+ *
+ *    Functionality:
+ *       Increment the slot by a input factor till num of Slots configured in a
+ *       Radio Frame. If it exceeds, move to next sfn.
+ *
+ * @params[in/out] SlotTimingInfo timingInfo
+ *        [in]     uint8_t incr [Increment factor]
+ *        [in]     numSlotsPerRF [Number of Slots configured per RF as per
+ *                                numerology]
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ *******************************************************************/
+void schIncrSlot(SlotTimingInfo *timingInfo, uint8_t incr, uint16_t numSlotsPerRF)
+{
+   timingInfo->slot += incr;
+   if(timingInfo->slot >= numSlotsPerRF)
+   {
+      timingInfo->sfn += timingInfo->slot/numSlotsPerRF;
+      timingInfo->slot %= numSlotsPerRF;
+      if(timingInfo->sfn >  MAX_SFN)
+      {
+         timingInfo->sfn %= MAX_SFN;
+      }
+   }
+}
 /**********************************************************************
   End of file
  **********************************************************************/