[Epic-ID: ODUHIGH-517][Task-ID: ODUHIGH-539][SubTask-Id: ODUHIGH-542] Multi UE| DL...
[o-du/l2.git] / src / 5gnrsch / sch_utils.c
index a53232c..218b70b 100644 (file)
@@ -41,6 +41,7 @@
 #include "lrg.x"           /* layer management typedefs for MAC */
 #include "mac_sch_interface.h"
 #include "sch.h"
+#include "sch_tmr.h"
 #include "sch_utils.h"
 #include "math.h"
 
@@ -773,6 +774,7 @@ 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};
 
+uint8_t schCmnDlRvTbl[4] = {0, 2, 3, 1};
 /**
  * @brief Function to find first DMRS symbol in PDSCH
  *
@@ -892,8 +894,12 @@ CmLList* isPrbAvailable(CmLListCp *freePrbBlockList, uint16_t startPrb, uint16_t
 
       /* Check if requested number of blocks can be allocated from the current block */
       if(freeBlock->numFreePrb < numPrb)
+      {
+         DU_LOG("\nINFO   --> SCH: In isPrbAvailable, numFreePrb:%d is less than reqPrb:%d", freeBlock->numFreePrb, numPrb);
+         node = node->next;
          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)))
@@ -1143,9 +1149,9 @@ uint16_t schCalcTbSizeFromNPrb(uint16_t numPrb, uint16_t mcs, uint8_t numSymbols
  **/
 SchUeCb* schGetUeCb(SchCellCb *cellCb, uint16_t crnti)
 {
-   uint16_t ueIdx;
-   GET_UE_IDX(crnti, ueIdx);
-   return &(cellCb->ueCb[ueIdx -1]);
+   uint16_t ueId;
+   GET_UE_ID(crnti, ueId);
+   return &(cellCb->ueCb[ueId -1]);
 }
 
 /**
@@ -1340,7 +1346,7 @@ bool fillPrbBitmap(uint64_t *prbBitMap, uint16_t startPrb, uint16_t numPrb)
  *         If NULLP, FATAL FAILURE
  *
  * ***********************************************************************/
-LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLcLL action)
+LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLL action)
 {
    CmLList  *node = NULLP;
    LcInfo *lcNode = NULLP;
@@ -1429,6 +1435,11 @@ LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLcLL action)
             }
             return NULLP; 
          }
+      case PRINT:
+      case TRAVERSE_ALL:
+        {
+           break;
+        }
       default:
          {
             DU_LOG("\nERROR  -->  SCH: Action type wrong: %d",action);
@@ -1460,7 +1471,6 @@ LcInfo* handleLcLList(CmLListCp *lcLL, uint8_t lcId, ActionTypeLcLL action)
 uint8_t updateLcListReqPRB(CmLListCp *lcLL, uint8_t lcId, uint32_t payloadSize)
 {
    LcInfo    *lcNode = NULLP;
-
    lcNode = handleLcLList(lcLL, lcId, CREATE);
 
    if(lcNode == NULLP)
@@ -1468,8 +1478,9 @@ uint8_t updateLcListReqPRB(CmLListCp *lcLL, uint8_t lcId, uint32_t payloadSize)
       DU_LOG("\nERROR  -->  SCH : LC is neither present nor able to create in List lcId:%d",lcId);
       return RFAILED;
    }
+
    lcNode->reqBO = payloadSize;
-   lcNode->allocBO = 0; 
+   lcNode->allocBO = 0;
    lcNode->allocPRB = 0; /*Re-Initializing the AllocPRB*/
    return ROK;
 }
@@ -1534,7 +1545,7 @@ void deleteLcLL(CmLListCp *lcLL)
  *        
  *
  *************************************************************************/
-uint32_t calculateEstimateTBSize(uint32_t reqBO, uint16_t mcsIdx,uint8_t numSymbols,\
+uint32_t calculateEstimateTBSize(uint32_t reqBO, uint16_t mcsIdx, uint8_t numSymbols,\
                                    uint16_t maxPRB, uint16_t *estPrb)
 {
    uint32_t tbs = 0, effecBO = 0;
@@ -1559,6 +1570,76 @@ uint32_t calculateEstimateTBSize(uint32_t reqBO, uint16_t mcsIdx,uint8_t numSymb
    effecBO = MIN(tbs,reqBO);
    return (effecBO);
 }
+
+
+/*******************************************************************
+*
+* @brief deleting Page Info node from PageInfo List
+*
+* @details
+*
+*    Function : schDeleteFromPageInfoList
+*
+*    Functionality: deleting page Info node from Page Info List
+*
+* @params[in] CmLListCp *list, CmLList *node 
+*
+* @return void 
+*
+* ****************************************************************/
+void schDeleteFromPageInfoList(CmLListCp *list, CmLList *node)
+{
+   SchPageInfo *pageInfo;
+
+   if(node != NULLP)
+   {
+      pageInfo = (SchPageInfo *)node->node;
+      if(deleteNodeFromLList(list, node) == ROK)
+         SCH_FREE(pageInfo, sizeof(SchPageInfo));
+   }
+}
+
+/*******************************************************************
+*
+* @brief searching for Page at a particular SFN 
+*
+* @details
+*
+*    Function : schPageInfoSearchFromPageList
+*
+*    Functionality: searching for Page at a particular SFN 
+*
+* @params[in] SlotTimingInfo slotInfo, CmLListCp *storedPageList
+*
+* @return pointer to SchPageInfo
+*
+* ****************************************************************/
+CmLList *schPageInfoSearchFromPageList(SlotTimingInfo slotInfo, CmLListCp *storedPageList)
+{
+   CmLList         *node = NULLP;
+   SchPageInfo     *pageInfo = NULLP;
+
+   if(storedPageList->count)
+   {
+      CM_LLIST_FIRST_NODE(storedPageList, node);
+      while(node)
+      {
+         pageInfo = (SchPageInfo*)node->node;
+         if(pageInfo == NULLP)
+         {
+            DU_LOG("\nERROR  --> SCH: PageInfo empty");
+         }
+         else if(pageInfo->pageTxTime.sfn == slotInfo.sfn && 
+               (pageInfo->pageTxTime.slot == slotInfo.slot))
+         {
+            return node;
+         }
+         node = node->next;
+      }
+   }
+   return NULLP;
+}
+
 /*Below function for printing will be used in future so disabling it for now*/
 #if 0
 /****************************************************************************
@@ -1705,57 +1786,89 @@ uint8_t calculateSlotPatternLength(uint8_t scs, uint8_t periodicity)
 }
 #endif
 
-/*
- * As per FAPI spec, 
- * Frequency domain resources is a bitmap defining non-overlapping groups of 6 PRBs in ascending order.
- * [TS38.213 10.1]. Bitmap of uint8 array. 45 bits.
- *
- * As per IAPI,
- * CORESET-freqdom.frequencyDomainResources : The bits of the bitmap have a one-to-one mapping with
- * non-overlapping groups of 6 RBs. The most significant bit of the first word corresponds to
- * the most significant bit defined in 38.331.
- *
- * FAPI and IAPI both are 45 bits. Mapped from bit 0 LS Byte for the FAPI and
- * bit 0 LS U32 entry for IAPI.
- * FAPI is to be filled in following format such that Intel L1 is able to decode it :
- *
- *            FAPI                                 IAPI 
- * FreqDomainResource[0] bits 7-0     ->    nFreqDomain[0] bits 7-0
- * FreqDomainResource[1] bits 7-0     ->    nFreqDomain[0] bits 15-8
- * FreqDomainResource[2] bits 7-0     ->    nFreqDomain[0] bits 23-16
- * FreqDomainResource[3] bits 7-0     ->    nFreqDomain[0] bits 31-24
- * FreqDomainResource[4] bits 7-0     ->    nFreqDomain[1] bits 7-0
- * FreqDomainResource[5] bits 7-0     ->    nFreqDomain[1] bits 15-8
- *
- * where for the last entry bits 7,6 and 5 are don't care in the FAPI and bits
- * 31-13 are don't care in the IAPI.
- */
-void covertFreqDomRsrcMapToIAPIFormat(uint8_t *sourceBitMap, uint8_t *destBitMap)
+/**
+ * @brief Function to find start Symbol Index of Coreset defined in SearchSpace(SS)
+ *
+ * @details
+ *
+ *     Function: findSsStartSymbol
+ *
+ *     This function finds first the startSymbol Index of a CORESET 
+ *     which is defined in SearchSpace.monitoringSymbolWithinSlot parameter
+ *
+ *  @param[in]  uint8_t mSymbolsWithinSlot[2]
+ *        mSymbolsWithinSlot[0] >> MSB as 7th Symbol to LSB as 0th Symbol
+ *        mSymbolsWithinSlot[1] >> 0th bit as 8th Symbol, 1st bit as 9th,
+ *                                   ...,5th bit as 13th symbol
+ *  @return     Success : First SS Symbol Index
+ *              Failure : MAX_SYMB_PER_SLOT(Invalid value of SymbolIndex = 14)
+**/
+uint8_t findSsStartSymbol(uint8_t *mSymbolsWithinSlot)
 {
-   int8_t  idx;
-   uint8_t  numBitsToShift = 0;
-   uint64_t freqDomainResources = 0;
+   uint8_t symbolIdx = 0;
+   uint8_t i = 1, symPos = 0;
 
-   /* Bit operation to create a 64-bit integer that has
-    * 48 LSBs [Bit 47 to Bit 0] mapped to sourceBitMap[0] to sourceBitMap[5]
-    */
-   for(idx = FREQ_DOM_RSRC_SIZE-1; idx >=0; idx--)
+   for(symbolIdx = 0; symbolIdx < MONITORING_SYMB_WITHIN_SLOT_SIZE; symbolIdx++)
    {
-      freqDomainResources |= ((uint64_t)sourceBitMap[idx] << numBitsToShift);
-      numBitsToShift += 8;
+      i = 1, symPos = 0;
+      while(i)
+      {
+         /*The first Symbol(or bit) enabled(set) is the StartSymbol of SS thus
+          *returning if we find that bitPosition */
+         if(mSymbolsWithinSlot[symbolIdx] & i)
+         {
+            /*Adding (SymbolIdx*8) for SymbolIndex between 8 and 13*/
+            return (symPos + (symbolIdx * 8));
+         }
+         i = i << 1;
+         symPos++;
+      }
    }
+   return(MAX_SYMB_PER_SLOT);
+}
 
-   /* Right shift 3 bits because bits[2-0] are unused in sourceBitMap[5] */
-   freqDomainResources = freqDomainResources >> 3;
+/**
+ * @brief Function to count number of RBG from Coreset's FreqDomainResource 
+ *
+ * @details
+ *
+ *     Function: countRBGFrmCoresetFreqRsrc
+ *
+ * This function counts RBG for calculating the coresetSize using CORESET.freqDomainResource 
+ * In this, we will find the number of RBG groups which are allowed for this
+ * coreset
+ *
+ *  @param[in]  uint8_t freqDomainRsrc[6] (As per Spec 38.331, ControlResourceSet.frequencyDomainResources)
+ *              freqDomainRsrc[0] =RBG0 to RBG7
+ *              freqDomainRsrc[1] =RBG8 to RBG15
+ *              ...
+ *              freqDomainRsrc[5] =RBG40 to RBG47
+ *              (Every RBG has 6 PRBs)
+ *  @return     Success : Total Number of RGBs in CORESET which can be allocated
+ *              Failure : 0
+**/
+uint8_t countRBGFrmCoresetFreqRsrc(uint8_t *freqDomainRsrc)
+{
+   uint8_t freqIdx = 0, idx = 1;
+   uint8_t count = 0;
 
-   /* Filling destBitMap such that LSB bit 0 of freqDomainResources maps to LSB 
-    * of first word of destBitMap */
-   numBitsToShift = 0;
-   for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
+   for(freqIdx = 0; freqIdx < FREQ_DOM_RSRC_SIZE; freqIdx++)
    {
-      destBitMap[idx] = freqDomainResources >> numBitsToShift;
-      numBitsToShift += 8;
+      if(freqDomainRsrc[freqIdx] & 0xFF)
+      {
+         idx = 1;
+         count = 0;
+         while(idx)
+         {
+           if(freqDomainRsrc[freqIdx] & idx)
+           {
+               count++;
+           }
+           idx = idx << 1;
+         }
+      }
    }
+   return count;
 }
 
 /**********************************************************************