Fix in DL PRB allocation [Issue-ID: ODUHIGH-380]
[o-du/l2.git] / src / 5gnrsch / sch_utils.c
index b01ca05..ac952c7 100644 (file)
@@ -773,6 +773,34 @@ 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 find first DMRS symbol in PDSCH
+ *
+ * @details
+ *
+ *     Function: findDmrsStartSymbol
+ *
+ *     This function finds first DMRS symbol using DMRS symbol 
+ *     position bitmap.
+ *
+ *  @param[in]  DMRS symbol position bitmap
+ *  @return     Success : First DRMS symbol
+ *              Failure : MAX_SYMB_PER_SLOT 
+ **/
+uint8_t findDmrsStartSymbol(uint16_t dlDmrsSymbBitMap)
+{
+   uint8_t position = 0;
+   uint16_t mask = 1;
+
+   while(position < MAX_SYMB_PER_SLOT)
+   {
+      if(dlDmrsSymbBitMap & mask)
+         break;  
+      mask = mask << 1;
+      position++;
+   }
+   return position;   
+}
 
 /**
  * @brief Function to add a node to a linked list
@@ -1391,8 +1419,61 @@ uint8_t calculateSlotPatternLength(uint8_t scs, uint8_t periodicity)
    }
    return slotPatternLength;
 }
-
 #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)
+{
+   int8_t  idx;
+   uint8_t  numBitsToShift = 0;
+   uint64_t freqDomainResources = 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--)
+   {
+      freqDomainResources |= ((uint64_t)sourceBitMap[idx] << numBitsToShift);
+      numBitsToShift += 8;
+   }
+
+   /* Right shift 3 bits because bits[2-0] are unused in sourceBitMap[5] */
+   freqDomainResources = freqDomainResources >> 3;
+
+   /* 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++)
+   {
+      destBitMap[idx] = freqDomainResources >> numBitsToShift;
+      numBitsToShift += 8;
+   }
+}
+
 /**********************************************************************
          End of file
 **********************************************************************/