Merge "Implementation of TDD M1 100 MHZ MSG1, MSG2, MSG3 & MSG4 changes JIRA-ID...
[o-du/l2.git] / src / 5gnrsch / sch_common.c
index cdcbf90..e064b83 100644 (file)
@@ -77,29 +77,30 @@ uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,
    SsbInfo ssbInfo;
 
    schDlSlotInfo = cell->schDlSlotInfo[slot];
+
    if(dlBrdcstAlloc->ssbTrans)
    {
-      ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA;
+      ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA; //+Kssb
       ssbStartSymb = cell->ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are
-                                                                               supporting only 1 ssb beam */
+                                                                                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 */
+         schDlSlotInfo->assignedPrb[idx] = ssbStartPrb + SCH_SSB_NUM_PRB + 1; /* +1 for kSsb */
       }
    }
 
@@ -116,7 +117,7 @@ uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,
       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 */
+         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)); 
@@ -180,6 +181,7 @@ void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotIndInfo pra
    uint8_t  prachOcas = 0;
    uint8_t  dataType = 0;
    uint8_t  idx = 0;
+   uint8_t  subFrame = 0;
    SchUlSlotInfo *schUlSlotInfo = NULLP;
 
    puschScs      = cell->cellCfg.schInitialUlBwp.bwp.scs;
@@ -193,45 +195,59 @@ void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotIndInfo pra
 
    if((prachOccasionTimingInfo.sfn%x) == y)
    {
+#ifdef NR_TDD
+      subFrame = prachOccasionTimingInfo.slot/2;
+#else
+      subFrame = prachOccasionTimingInfo.slot;
+#endif
       /* check for subFrame number */
-      if ((1 << prachOccasionTimingInfo.slot) & prachSubframe)
+      if ((1 << subFrame) & prachSubframe)
       {
-        /* prach ocassion present in this subframe */
-
-        prachFormat      = prachCfgIdxTable[prachCfgIdx][0];
-        prachStartSymbol = prachCfgIdxTable[prachCfgIdx][4];
-        prachOcas        = prachCfgIdxTable[prachCfgIdx][6];
-
-        /* freq domain resource determination for RACH*/
-        freqStart = cell->cellCfg.schRachCfg.msg1FreqStart;
-        /* numRa determined as 𝑛 belonging {0,1,.., M − 1}, 
-         * where M is given by msg1Fdm */
-        numRa = (cell->cellCfg.schRachCfg.msg1Fdm - 1);
-        for(idx=0; idx<MAX_RACH_NUM_RB_IDX; idx++)
-        {
-           if(numRbForPrachTable[idx][0] == cell->cellCfg.schRachCfg.rootSeqLen)
-           {
-              if(numRbForPrachTable[idx][1] == cell->cellCfg.schRachCfg.prachSubcSpacing)
-              {
-                 if(numRbForPrachTable[idx][2] == puschScs)
-                 {
-                    break;
-                 }
-              }
-           }
-        }
-        numPrachRb = numRbForPrachTable[idx][3];
-        dataType |= SCH_DATATYPE_PRACH;
-        /* Considering first slot in the frame for PRACH */
-        idx = 0;
-        schUlSlotInfo->assignedPrb[idx] = freqStart+numPrachRb;
+         /* prach ocassion present in this subframe */
+#ifdef NR_TDD
+         if(UL_SLOT != schGetSlotSymbFrmt(prachOccasionTimingInfo.slot, cell->slotFrmtBitMap))
+         {
+            DU_LOG("\nERROR  --> SCH : PrachCfgIdx %d doesn't support UL slot", prachCfgIdx);
+         }
+         else
+#endif
+         {
+            prachFormat      = prachCfgIdxTable[prachCfgIdx][0];
+            prachStartSymbol = prachCfgIdxTable[prachCfgIdx][4];
+            prachOcas        = prachCfgIdxTable[prachCfgIdx][6];
+
+            /* freq domain resource determination for RACH*/
+            freqStart = cell->cellCfg.schRachCfg.msg1FreqStart;
+            /* numRa determined as 𝑛 belonging {0,1,.., M − 1}, 
+             * where M is given by msg1Fdm */
+            numRa = (cell->cellCfg.schRachCfg.msg1Fdm - 1);
+            for(idx=0; idx<MAX_RACH_NUM_RB_IDX; idx++)
+            {
+               if(numRbForPrachTable[idx][0] == cell->cellCfg.schRachCfg.rootSeqLen)
+               {
+                  if(numRbForPrachTable[idx][1] == cell->cellCfg.schRachCfg.prachSubcSpacing)
+                  {
+                     if(numRbForPrachTable[idx][2] == puschScs)
+                     {
+                        break;
+                     }
+                  }
+               }
+            }
+            numPrachRb = numRbForPrachTable[idx][3];
+            dataType |= SCH_DATATYPE_PRACH;
+            /* Considering first slot in the frame for PRACH */
+            idx = 0;
+            schUlSlotInfo->assignedPrb[idx] = freqStart+numPrachRb;
+         }
+         ulSchedInfo->dataType = dataType;
+         /* prach info */
+         ulSchedInfo->prachSchInfo.numPrachOcas   = prachOcas;
+         ulSchedInfo->prachSchInfo.prachFormat    = prachFormat;
+         ulSchedInfo->prachSchInfo.numRa          = numRa;
+         ulSchedInfo->prachSchInfo.prachStartSymb = prachStartSymbol;
+         DU_LOG("\nINFO  --> SCH : RACH occassion set for slot %d", prachOccasionTimingInfo.slot);
       }
-      ulSchedInfo->dataType = dataType;
-      /* prach info */
-      ulSchedInfo->prachSchInfo.numPrachOcas   = prachOcas;
-      ulSchedInfo->prachSchInfo.prachFormat    = prachFormat;
-      ulSchedInfo->prachSchInfo.numRa          = numRa;
-      ulSchedInfo->prachSchInfo.prachStartSymb = prachStartSymbol;
    }
 }
 
@@ -482,7 +498,7 @@ uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
    memset(&ulSchedInfo, 0, sizeof(UlSchedInfo));
 
    /* add PHY delta */
-   ADD_DELTA_TO_TIME(cell->slotInfo,ulTimingInfo,PHY_DELTA+SCHED_DELTA);
+   ADD_DELTA_TO_TIME(cell->slotInfo,ulTimingInfo,PHY_DELTA_UL+SCHED_DELTA);
 
    ulSchedInfo.cellId = cell->cellId;
    ulSchedInfo.slotIndInfo.cellId = ulSchedInfo.cellId;
@@ -490,7 +506,8 @@ uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
    ulSchedInfo.slotIndInfo.slot = ulTimingInfo.slot;
 
    /* Schedule resources for PRACH */
-   schPrachResAlloc(cell, &ulSchedInfo, ulTimingInfo);
+   if(cell->firstSib1Transmitted)
+    schPrachResAlloc(cell, &ulSchedInfo, ulTimingInfo);
 
    schUlSlotInfo = cell->schUlSlotInfo[ulTimingInfo.slot]; 
    if(schUlSlotInfo->schPuschInfo)
@@ -710,7 +727,7 @@ uint16_t schAllocPucchResource(SchCellCb *cell, uint16_t crnti, uint16_t slot)
  *
  * ****************************************************************/
 uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t crnti,
-      uint16_t accumalatedSize, uint16_t slot)
+      uint32_t *accumalatedSize, uint16_t slot)
 {
    uint8_t ueIdx;
    uint16_t tbSize = 0;
@@ -777,7 +794,9 @@ uint8_t schDlRsrcAllocDlMsg(DlMsgAlloc *dlMsgAlloc, SchCellCb *cell, uint16_t cr
       pdsch->codeword[cwCount].mcsIndex = ueCb.ueCfg.dlModInfo.mcsIndex;
       pdsch->codeword[cwCount].mcsTable = ueCb.ueCfg.dlModInfo.mcsTable;
       pdsch->codeword[cwCount].rvIndex = 0;
-      tbSize = schCalcTbSize(accumalatedSize);
+      tbSize = schCalcTbSize(*accumalatedSize);
+      if(tbSize < *accumalatedSize)
+         *accumalatedSize = tbSize;
       pdsch->codeword[cwCount].tbSize = tbSize;
    }
    pdsch->dataScramblingId = cell->cellCfg.phyCellId;