+/**
+ * @brief Checks if PRACH can be scheduled in current slot
+ *
+ * @details
+ *
+ * Function : schCheckPrachOcc
+ *
+ * This function checks if PRACH can be scheduled in
+ * current slot
+ *
+ * @param[in] Cell Cb
+ * Slot timing
+ * @return TRUE
+ * FALSE
+ **/
+bool schCheckPrachOcc(SchCellCb *cell, SlotTimingInfo prachOccasionTimingInfo)
+{
+ uint8_t prachCfgIdx = 0;
+ uint8_t x = 0;
+ uint8_t y = 0;
+ uint8_t subFrame = 0;
+ uint16_t prachSubframe = 0;
+
+ prachCfgIdx = cell->cellCfg.schRachCfg.prachCfgIdx;
+
+ /* derive the prachCfgIdx table paramters */
+ x = prachCfgIdxTable[prachCfgIdx][1];
+ y = prachCfgIdxTable[prachCfgIdx][2];
+ prachSubframe = prachCfgIdxTable[prachCfgIdx][3];
+
+ if((prachOccasionTimingInfo.sfn%x) == y)
+ {
+ subFrame = prachOccasionTimingInfo.slot/pow(2, cell->cellCfg.numerology);
+
+ /* check for subFrame number */
+ if ((1 << subFrame) & prachSubframe)
+ {
+ /* prach ocassion present in this subframe */
+#ifdef NR_TDD
+ if(UL_SLOT != schGetSlotSymbFrmt(prachOccasionTimingInfo.slot % cell->numSlotsInPeriodicity,\
+ cell->slotFrmtBitMap))
+ {
+ DU_LOG("\nERROR --> SCH : PrachCfgIdx %d doesn't support UL slot", prachCfgIdx);
+ return FALSE;
+ }
+#endif
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/**
+ * @brief Calculate number of PRBs to be allocated for PRACH
+ *
+ * @details
+ *
+ * Function : schCalcPrachNumRb
+ *
+ * Calculate number of PRBs to be allocated for PRACH
+ *
+ * @param[in] SchCellCb *cell, cell cb
+ * @return Number of PRBs
+ **/
+uint8_t schCalcPrachNumRb(SchCellCb *cell)
+{
+ uint8_t tableIdx = 0;
+ uint16_t puschScs = convertScsEnumValToScsVal(cell->cellCfg.schInitialUlBwp.bwp.scs);
+
+ for(tableIdx=0; tableIdx < MAX_RACH_NUM_RB_IDX; tableIdx++)
+ {
+ if((numRbForPrachTable[tableIdx][0] == cell->cellCfg.schRachCfg.rootSeqLen) &&
+ (numRbForPrachTable[tableIdx][1] == cell->cellCfg.schRachCfg.prachSubcSpacing) &&
+ (numRbForPrachTable[tableIdx][2] == puschScs))
+ {
+ return numRbForPrachTable[tableIdx][3];
+ }
+ }
+ return 0;
+}
+
+/**
+ * @brief resource allocation for PRACH
+ *
+ * @details
+ *
+ * Function : schPrachResAlloc
+ *
+ * This function handles PRACH allocation
+ *
+ * @param[in] SchCellCb *cell, cell cb
+ * @param[in] UlSchedInfo *ulSchedInfo, UL scheduling info
+ * @return void
+ **/
+void schPrachResAlloc(SchCellCb *cell, UlSchedInfo *ulSchedInfo, SlotTimingInfo prachOccasionTimingInfo)
+{
+ uint8_t numPrachRb = 0;
+ uint8_t numRa = 0;
+ uint8_t prachCfgIdx = 0;
+ uint8_t prachFormat = 0;
+ uint8_t prachStartSymbol = 0;
+ uint8_t prachDuration = 0;
+ uint8_t prachOcas = 0;
+ uint8_t dataType = 0;
+ uint16_t freqStart = 0;
+
+ if(cell == NULLP)
+ {
+ DU_LOG("\nERROR --> SCH : schPrachResAlloc(): Received cellCb is null");
+ return;
+ }
+
+ /* If this slot is not a PRACH occassion, return */
+ if(!schCheckPrachOcc(cell, prachOccasionTimingInfo))
+ return;
+
+ prachCfgIdx = cell->cellCfg.schRachCfg.prachCfgIdx;
+ prachFormat = prachCfgIdxTable[prachCfgIdx][0];
+ prachStartSymbol = prachCfgIdxTable[prachCfgIdx][4];
+ prachOcas = prachCfgIdxTable[prachCfgIdx][6];
+ prachDuration = prachCfgIdxTable[prachCfgIdx][7];
+
+ /* numRa determined as 𝑛 belonging {0,1,.., M − 1},
+ * where M is given by msg1Fdm */
+ numRa = (cell->cellCfg.schRachCfg.msg1Fdm - 1);
+
+ /* freq domain resource determination for RACH*/
+ freqStart = cell->cellCfg.schRachCfg.msg1FreqStart;
+ numPrachRb = schCalcPrachNumRb(cell);
+ /* Allocate PRACH resources from the UL resource bitmap */
+ allocatePrbUl(cell, prachOccasionTimingInfo, prachStartSymbol, prachDuration, &freqStart, numPrachRb);
+
+ /* prach info */
+ dataType |= SCH_DATATYPE_PRACH;
+ ulSchedInfo->dataType = dataType;
+ 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);
+}