1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /************************************************************************
25 Desc: C source code for scheduler fucntions
29 **********************************************************************/
32 @brief This file implements the schedulers main access to MAC layer code.
34 #include "common_def.h"
35 #include "du_app_mac_inf.h"
40 #include "rg_sch_inf.h"
43 #include "tfu.x" /* TFU types */
44 #include "lrg.x" /* layer management typedefs for MAC */
45 #include "rgr.x" /* layer management typedefs for MAC */
46 #include "rg_sch_inf.x" /* typedefs for Scheduler */
47 #include "mac_sch_interface.h"
49 #include "sch_utils.h"
51 SchCb schCb[SCH_MAX_INST];
52 void SchFillCfmPst(Pst *reqPst,Pst *cfmPst,RgMngmt *cfm);
55 SchCellCfgCfmFunc SchCellCfgCfmOpts[] =
57 packSchCellCfgCfm, /* LC */
58 MacProcSchCellCfgCfm, /* TC */
59 packSchCellCfgCfm /* LWLC */
64 * @brief Task Initiation function.
68 * Function : schActvInit
70 * This function is supplied as one of parameters during MAC's
71 * task registration. MAC will invoke this function once, after
72 * it creates and attaches this TAPA Task to a system task.
74 * @param[in] Ent Entity, the entity ID of this task.
75 * @param[in] Inst Inst, the instance ID of this task.
76 * @param[in] Region Region, the region ID registered for memory
78 * @param[in] Reason Reason.
82 uint8_t schActvInit(Ent entity, Inst instId, Region region, Reason reason)
84 Inst inst = (instId - SCH_INST_START);
86 /* Initialize the MAC TskInit structure to zero */
87 memset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
89 /* Initialize the MAC TskInit with received values */
90 schCb[inst].schInit.ent = entity;
91 schCb[inst].schInit.inst = inst;
92 schCb[inst].schInit.region = region;
93 schCb[inst].schInit.pool = 0;
94 schCb[inst].schInit.reason = reason;
95 schCb[inst].schInit.cfgDone = FALSE;
96 schCb[inst].schInit.acnt = FALSE;
97 schCb[inst].schInit.usta = FALSE;
98 schCb[inst].schInit.trc = FALSE;
99 schCb[inst].schInit.procId = ODU_GET_PROCID();
105 * @brief Scheduler instance Configuration Handler.
109 * Function : SchInstCfg
111 * This function in called by SchProcGenCfgReq(). It handles the
112 * general configurations of the scheduler instance. Returns
113 * reason for success/failure of this function.
115 * @param[in] RgCfg *cfg, the Configuaration information
117 * -# LCM_REASON_NOT_APPL
118 * -# LCM_REASON_INVALID_MSGTYPE
119 * -# LCM_REASON_MEM_NOAVAIL
121 uint8_t SchInstCfg(RgCfg *cfg, Inst dInst)
123 uint16_t ret = LCM_REASON_NOT_APPL;
124 Inst inst = (dInst - SCH_INST_START);
126 DU_LOG("\nDEBUG --> SCH : Entered SchInstCfg()");
127 /* Check if Instance Configuration is done already */
128 if (schCb[inst].schInit.cfgDone == TRUE)
130 return LCM_REASON_INVALID_MSGTYPE;
132 /* Update the Pst structure for LM interface */
133 memcpy(&schCb[inst].schInit.lmPst,
134 &cfg->s.schInstCfg.genCfg.lmPst,
137 schCb[inst].schInit.inst = inst;
138 schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
139 schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
140 schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
142 schCb[inst].schInit.lmPst.event = EVTNONE;
144 schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
145 schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
146 schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
148 schCb[inst].genCfg.forceCntrlSrbBoOnPCel = cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
149 schCb[inst].genCfg.isSCellActDeactAlgoEnable = cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
151 schCb[inst].genCfg.startCellId = cfg->s.schInstCfg.genCfg.startCellId;
153 /* Initialzie the timer queue */
154 memset(&schCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
155 /* Initialize the timer control point */
156 memset(&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
157 schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
159 /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
160 /* Timer Registration request to SSI */
161 if (ODU_REG_TMR_MT(schCb[inst].schInit.ent, dInst,
162 (int)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
164 DU_LOG("\nERROR --> SCH : SchInstCfg(): Failed to "
166 return (LCM_REASON_MEM_NOAVAIL);
169 /* Set Config done in TskInit */
170 schCb[inst].schInit.cfgDone = TRUE;
171 DU_LOG("\nINFO --> SCH : Scheduler gen config done");
177 * @brief Layer Manager Configuration request handler.
181 * Function : SchProcGenCfgReq
183 * This function handles the configuration
184 * request received at scheduler instance from the Layer Manager.
185 * -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
186 * functions rgHdlGenCfg() or rgHdlSapCfg().
187 * -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
189 * @param[in] Pst *pst, the post structure
190 * @param[in] RgMngmt *cfg, the configuration parameter's structure
194 uint8_t SchProcGenCfgReq(Pst *pst, RgMngmt *cfg)
196 uint8_t ret = LCM_PRIM_OK;
197 uint16_t reason = LCM_REASON_NOT_APPL;
201 if(pst->dstInst < SCH_INST_START)
203 DU_LOG("\nERROR --> SCH : Invalid inst ID");
204 DU_LOG("\nERROR --> SCH : SchProcGenCfgReq(): "
205 "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START);
208 DU_LOG("\nINFO --> SCH : Received scheduler gen config");
209 /* Fill the post structure for sending the confirmation */
210 memset(&cfmPst, 0 , sizeof(Pst));
211 SchFillCfmPst(pst, &cfmPst, cfg);
213 memset(&cfm, 0, sizeof(RgMngmt));
220 cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
221 switch(cfg->hdr.elmId.elmnt)
224 reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
228 reason = LCM_REASON_INVALID_ELMNT;
229 DU_LOG("\nERROR --> SCH : Invalid Elmnt=%d", cfg->hdr.elmId.elmnt);
233 if (reason != LCM_REASON_NOT_APPL)
238 cfm.cfm.status = ret;
239 cfm.cfm.reason = reason;
241 SchSendCfgCfm(&cfmPst, &cfm);
242 /* SPutSBuf(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
245 }/*-- SchProcGenCfgReq --*/
248 * @brief slot indication from MAC to SCH.
252 * Function : MacSchSlotInd
254 * This API is invoked by PHY to indicate slot indication to Scheduler for
257 * @param[in] Pst *pst
258 * @param[in] SlotIndInfo *slotInd
263 uint8_t MacSchSlotInd(Pst *pst, SlotIndInfo *slotInd)
265 Inst inst = pst->dstInst-SCH_INST_START;
267 schProcessSlotInd(slotInd, inst);
270 } /* MacSchSlotInd */
272 /*******************************************************************
274 * @brief Processes Rach indication from MAC
278 * Function : MacSchRachInd
281 * Processes Rach indication from MAC
284 * @return ROK - success
287 * ****************************************************************/
288 uint8_t MacSchRachInd(Pst *pst, RachIndInfo *rachInd)
290 Inst inst = pst->dstInst-SCH_INST_START;
291 DU_LOG("\nINFO --> SCH : Received Rach indication");
292 schProcessRachInd(rachInd, inst);
296 /*******************************************************************
298 * @brief Processes CRC indication from MAC
302 * Function : MacSchCrcInd
305 * Processes CRC indication from MAC
307 * @params[in] Post structure
309 * @return ROK - success
312 * ****************************************************************/
313 uint8_t MacSchCrcInd(Pst *pst, CrcIndInfo *crcInd)
315 switch(crcInd->crcInd[0])
318 DU_LOG("\nDEBUG --> SCH : Received CRC indication. CRC Status [FAILURE]");
321 DU_LOG("\nDEBUG --> SCH : Received CRC indication. CRC Status [PASS]");
324 DU_LOG("\nDEBUG --> SCH : Invalid CRC state %d", crcInd->crcInd[0]);
332 *@brief Returns TDD periodicity in micro seconds
336 * Function : schGetPeriodicityInMsec
338 * This API retunrs TDD periodicity in micro seconds
340 * @param[in] DlUlTxPeriodicity
341 * @return periodicityInMsec
344 uint16_t schGetPeriodicityInMsec(DlUlTxPeriodicity tddPeriod)
346 uint16_t periodicityInMsec = 0;
349 case TX_PRDCTY_MS_0P5:
351 periodicityInMsec = 500;
354 case TX_PRDCTY_MS_0P625:
356 periodicityInMsec = 625;
361 periodicityInMsec = 1000;
364 case TX_PRDCTY_MS_1P25:
366 periodicityInMsec = 1250;
371 periodicityInMsec = 2000;
374 case TX_PRDCTY_MS_2P5:
376 periodicityInMsec = 2500;
381 periodicityInMsec = 5000;
384 case TX_PRDCTY_MS_10:
386 periodicityInMsec = 10000;
391 DU_LOG("\nERROR --> SCH : Invalid DlUlTxPeriodicity:%d", tddPeriod);
395 return periodicityInMsec;
400 * @brief init TDD slot config
404 * Function : schInitTddSlotCfg
406 * This API is invoked after receiving schCellCfg
408 * @param[in] schCellCb *cell
409 * @param[in] SchCellCfg *schCellCfg
414 void schInitTddSlotCfg(SchCellCb *cell, SchCellCfg *schCellCfg)
416 uint16_t periodicityInMicroSec = 0;
417 uint32_t slotBitPos, symbBitPos, bitMask;
418 int8_t slotIdx, symbIdx;
420 periodicityInMicroSec = schGetPeriodicityInMsec(schCellCfg->tddCfg.tddPeriod);
421 schCellCfg->numerology = 1; //TODO: Remove this
422 cell->numSlotsInPeriodicity = (periodicityInMicroSec * pow(2, schCellCfg->numerology))/1000;
423 cell->slotFrmtBitMap = 0;
424 cell->symbFrmtBitMap = 0;
425 slotBitPos = (cell->numSlotsInPeriodicity*2)-1; /* considering 2 bits to represent a slot */
426 symbBitPos = (MAX_SYMB_PER_SLOT*2)-1; /* considering 2 bits to represent a symbol */
427 for(slotIdx = cell->numSlotsInPeriodicity-1; slotIdx >= 0; slotIdx--)
430 /* If the first and last symbol are the same, the entire slot is the same type */
431 if((schCellCfg->tddCfg.slotCfg[slotIdx][symbIdx] == schCellCfg->tddCfg.slotCfg[slotIdx][MAX_SYMB_PER_SLOT-1]) &&
432 schCellCfg->tddCfg.slotCfg[slotIdx][symbIdx] != FLEXI_SLOT)
434 switch(schCellCfg->tddCfg.slotCfg[slotIdx][symbIdx])
438 /*BitMap to be set to 00 */
439 bitMask = 1<<slotBitPos;
440 cell->slotFrmtBitMap = (cell->slotFrmtBitMap & ~(bitMask)) | ((0<<slotBitPos) & bitMask);
442 bitMask = 1<<slotBitPos;
443 cell->slotFrmtBitMap = (cell->slotFrmtBitMap & ~(bitMask)) | ((0<<slotBitPos) & bitMask);
449 /*BitMap to be set to 01 */
450 bitMask = 1<<slotBitPos;
451 cell->slotFrmtBitMap = (cell->slotFrmtBitMap & ~(bitMask)) | ((0<<slotBitPos) & bitMask);
453 bitMask = 1<<slotBitPos;
454 cell->slotFrmtBitMap = (cell->slotFrmtBitMap & ~(bitMask)) | ((1<<slotBitPos) & bitMask);
459 DU_LOG("\nERROR --> SCH : Invalid slot Config in schInitTddSlotCfg");
463 /* slot config is flexible. First set slotBitMap to 10 */
464 bitMask = 1<<slotBitPos;
465 cell->slotFrmtBitMap = (cell->slotFrmtBitMap & ~(bitMask)) | ((1<<slotBitPos) & bitMask);
467 bitMask = 1<<slotBitPos;
468 cell->slotFrmtBitMap = (cell->slotFrmtBitMap & ~(bitMask)) | ((0<<slotBitPos) & bitMask);
470 /* Now set symbol bitmap */
471 for(symbIdx = MAX_SYMB_PER_SLOT-1; symbIdx >= 0; symbIdx--)
473 switch(schCellCfg->tddCfg.slotCfg[slotIdx][symbIdx])
477 /*symbol BitMap to be set to 00 */
478 bitMask = 1<<symbBitPos;
479 cell->symbFrmtBitMap = (cell->symbFrmtBitMap & ~(bitMask)) | ((0<<symbBitPos) & bitMask);
481 bitMask = 1<<symbBitPos;
482 cell->symbFrmtBitMap = (cell->symbFrmtBitMap & ~(bitMask)) | ((0<<symbBitPos) & bitMask);
488 /*symbol BitMap to be set to 01 */
489 bitMask = 1<<symbBitPos;
490 cell->symbFrmtBitMap = (cell->symbFrmtBitMap & ~(bitMask)) | ((0<<symbBitPos) & bitMask);
492 bitMask = 1<<symbBitPos;
493 cell->symbFrmtBitMap = (cell->symbFrmtBitMap & ~(bitMask)) | ((1<<symbBitPos) & bitMask);
499 /*symbol BitMap to be set to 10 */
500 bitMask = 1<<symbBitPos;
501 cell->symbFrmtBitMap = (cell->symbFrmtBitMap & ~(bitMask)) | ((1<<symbBitPos) & bitMask);
503 bitMask = 1<<symbBitPos;
504 cell->symbFrmtBitMap = (cell->symbFrmtBitMap & ~(bitMask)) | ((0<<symbBitPos) & bitMask);
509 DU_LOG("\nERROR --> SCH : Invalid slot Config in schInitTddSlotCfg");
519 * @brief init cellCb based on cellCfg
523 * Function : schInitCellCb
525 * This API is invoked after receiving schCellCfg
527 * @param[in] schCellCb *cell
528 * @param[in] SchCellCfg *schCellCfg
533 uint8_t schInitCellCb(Inst inst, SchCellCfg *schCellCfg)
535 SchCellCb *cell= NULLP;
536 SCH_ALLOC(cell, sizeof(SchCellCb));
539 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb");
543 cell->cellId = schCellCfg->cellId;
544 cell->instIdx = inst;
545 switch(schCellCfg->numerology)
547 case SCH_NUMEROLOGY_0:
549 cell->numSlots = SCH_MU0_NUM_SLOTS;
552 case SCH_NUMEROLOGY_1:
554 cell->numSlots = SCH_MU1_NUM_SLOTS;
557 case SCH_NUMEROLOGY_2:
559 cell->numSlots = SCH_MU2_NUM_SLOTS;
562 case SCH_NUMEROLOGY_3:
564 cell->numSlots = SCH_MU3_NUM_SLOTS;
567 case SCH_NUMEROLOGY_4:
569 cell->numSlots = SCH_MU4_NUM_SLOTS;
573 DU_LOG("\nERROR --> SCH : Numerology %d not supported", schCellCfg->numerology);
576 schInitTddSlotCfg(cell, schCellCfg);
579 SCH_ALLOC(cell->schDlSlotInfo, cell->numSlots * sizeof(SchDlSlotInfo*));
580 if(!cell->schDlSlotInfo)
582 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb for schDlSlotInfo");
586 SCH_ALLOC(cell->schUlSlotInfo, cell->numSlots * sizeof(SchUlSlotInfo*));
587 if(!cell->schUlSlotInfo)
589 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb for schUlSlotInfo");
593 for(uint8_t idx=0; idx<cell->numSlots; idx++)
595 SchDlSlotInfo *schDlSlotInfo;
596 SchUlSlotInfo *schUlSlotInfo;
599 SCH_ALLOC(schDlSlotInfo, sizeof(SchDlSlotInfo));
602 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb");
607 SCH_ALLOC(schUlSlotInfo, sizeof(SchUlSlotInfo));
610 DU_LOG("\nERROR --> SCH : Memory allocation failed in schInitCellCb");
614 schInitDlSlot(schDlSlotInfo);
615 schInitUlSlot(schUlSlotInfo);
617 cell->schDlSlotInfo[idx] = schDlSlotInfo;
618 cell->schUlSlotInfo[idx] = schUlSlotInfo;
621 schCb[inst].cells[inst] = cell;
623 DU_LOG("\nINFO --> SCH : Cell init completed for cellId:%d", cell->cellId);
629 * @brief Fill SIB1 configuration
633 * Function : fillSchSib1Cfg
635 * Fill SIB1 configuration
637 * @param[in] uint8_t bandwidth : total available bandwidth
638 * uint8_t numSlots : total slots per SFN
639 * SchSib1Cfg *sib1SchCfg : cfg to be filled
640 * uint16_t pci : physical cell Id
641 * uint8_t offsetPointA : offset
644 void fillSchSib1Cfg(uint8_t bandwidth, uint8_t numSlots, SchSib1Cfg *sib1SchCfg, uint16_t pci, uint8_t offsetPointA)
646 uint8_t coreset0Idx = 0;
647 uint8_t searchSpace0Idx = 0;
648 //uint8_t ssbMuxPattern = 0;
650 uint8_t numSymbols = 0;
653 //uint8_t numSearchSpacePerSlot = 0;
655 uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
656 uint8_t slotIndex = 0;
657 uint8_t FreqDomainResource[6] = {0};
659 uint8_t numPdschSymbols = 12; /* considering pdsch region from 2 to 13 */
661 PdcchCfg *pdcch = &(sib1SchCfg->sib1PdcchCfg);
662 PdschCfg *pdsch = &(sib1SchCfg->sib1PdschCfg);
663 BwpCfg *bwp = &(sib1SchCfg->bwp);
665 coreset0Idx = sib1SchCfg->coresetZeroIndex;
666 searchSpace0Idx = sib1SchCfg->searchSpaceZeroIndex;
668 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
669 //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
670 numRbs = coresetIdxTable[coreset0Idx][1];
671 numSymbols = coresetIdxTable[coreset0Idx][2];
672 offset = coresetIdxTable[coreset0Idx][3];
674 /* derive the search space params from table 13-11 spec 38.213 */
675 oValue = searchSpaceIdxTable[searchSpace0Idx][0];
676 //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
677 mValue = searchSpaceIdxTable[searchSpace0Idx][2];
678 firstSymbol = searchSpaceIdxTable[searchSpace0Idx][3];
680 /* calculate the n0, need to add the formulae, as of now the value is 0
681 * Need to add the even and odd values of i during configuration
682 * [(O . 2^u + i . M ) ] mod numSlotsPerSubframe
683 * assuming u = 0, i = 0, numSlotsPerSubframe = 10
684 * Also, from this configuration, coreset0 is only on even subframe */
685 slotIndex = ((oValue * 1) + (0 * mValue)) % numSlots;
686 sib1SchCfg->n0 = slotIndex;
688 /* calculate the PRBs */
689 freqDomRscAllocType0(((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
694 case BANDWIDTH_20MHZ:
696 bwp->freqAlloc.numPrb = TOTAL_PRB_20MHZ_MU0;
699 case BANDWIDTH_100MHZ:
701 bwp->freqAlloc.numPrb = TOTAL_PRB_100MHZ_MU1;
705 DU_LOG("\nERROR --> SCH : Bandwidth %d not supported", bandwidth);
708 bwp->freqAlloc.startPrb = 0;
709 bwp->subcarrierSpacing = 0; /* 15Khz */
710 bwp->cyclicPrefix = 0; /* normal */
712 /* fill the PDCCH PDU */
713 pdcch->coresetCfg.coreSetSize = numRbs;
714 pdcch->coresetCfg.startSymbolIndex = firstSymbol;
715 pdcch->coresetCfg.durationSymbols = numSymbols;
716 memcpy(pdcch->coresetCfg.freqDomainResource,FreqDomainResource,6);
717 pdcch->coresetCfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
718 pdcch->coresetCfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
719 pdcch->coresetCfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
720 pdcch->coresetCfg.coreSetType = 0;
721 pdcch->coresetCfg.shiftIndex = pci;
722 pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
724 pdcch->dci.rnti = SI_RNTI;
725 pdcch->dci.scramblingId = pci;
726 pdcch->dci.scramblingRnti = 0;
727 pdcch->dci.cceIndex = 0;
728 pdcch->dci.aggregLevel = 4;
729 pdcch->dci.beamPdcchInfo.numPrgs = 1;
730 pdcch->dci.beamPdcchInfo.prgSize = 1;
731 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
732 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
733 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
734 pdcch->dci.txPdcchPower.powerValue = 0;
735 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
736 /* Storing pdschCfg pointer here. Required to access pdsch config while
737 fillig up pdcch pdu */
738 pdcch->dci.pdschCfg = pdsch;
740 /* fill the PDSCH PDU */
742 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
743 pdsch->rnti = 0xFFFF; /* SI-RNTI */
745 pdsch->numCodewords = 1;
746 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
748 pdsch->codeword[cwCount].targetCodeRate = 308;
749 pdsch->codeword[cwCount].qamModOrder = 2;
750 pdsch->codeword[cwCount].mcsIndex = sib1SchCfg->sib1Mcs;
751 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
752 pdsch->codeword[cwCount].rvIndex = 0;
753 tbSize = schCalcTbSize(sib1SchCfg->sib1PduLen);
754 pdsch->codeword[cwCount].tbSize = tbSize;
756 pdsch->dataScramblingId = pci;
757 pdsch->numLayers = 1;
758 pdsch->transmissionScheme = 0;
760 pdsch->dmrs.dlDmrsSymbPos = 2;
761 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
762 pdsch->dmrs.dlDmrsScramblingId = pci;
763 pdsch->dmrs.scid = 0;
764 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
765 pdsch->dmrs.dmrsPorts = 0;
766 pdsch->dmrs.mappingType = DMRS_MAP_TYPE_A; /* Type-A */
767 pdsch->dmrs.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
768 pdsch->dmrs.dmrsAddPos = DMRS_ADDITIONAL_POS;
770 pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
771 pdsch->pdschFreqAlloc.freqAlloc.startPrb = offset + SCH_SSB_NUM_PRB; /* the RB numbering starts from coreset0,
772 and PDSCH is always above SSB */
773 pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize,sib1SchCfg->sib1Mcs,numPdschSymbols);
774 pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
775 pdsch->pdschTimeAlloc.rowIndex = 1;
776 pdsch->pdschTimeAlloc.timeAlloc.startSymb = 2; /* spec-38.214, Table 5.1.2.1-1 */
777 pdsch->pdschTimeAlloc.timeAlloc.numSymb = numPdschSymbols;
778 pdsch->beamPdschInfo.numPrgs = 1;
779 pdsch->beamPdschInfo.prgSize = 1;
780 pdsch->beamPdschInfo.digBfInterfaces = 0;
781 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
782 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
783 pdsch->txPdschPower.powerControlOffset = 0;
784 pdsch->txPdschPower.powerControlOffsetSS = 0;
789 * @brief Fill SSB start symbol
793 * Function : fillSsbStartSymb
795 * This API stores SSB start index per beam
797 * @param[in] SchCellCb *cellCb
802 void fillSsbStartSymb(SchCellCb *cellCb)
806 scs = cellCb->cellCfg.ssbSchCfg.scsCommon;
807 uint8_t ssbStartSymbArr[SCH_MAX_SSB_BEAM];
809 memset(ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
810 /* Determine value of "n" based on Section 4.1 of 3GPP TS 38.213 */
816 cnt = 2;/* n = 0, 1 for SCS = 15KHz */
817 for(uint8_t idx=0; idx<cnt; idx++)
819 /* start symbol determined using {2, 8} + 14n */
820 ssbStartSymbArr[symbIdx++] = 2 + SCH_SYMBOL_PER_SLOT*idx;
821 ssbStartSymbArr[symbIdx++] = 8 + SCH_SYMBOL_PER_SLOT*idx;
826 DU_LOG("\nERROR --> SCH : SCS %d is currently not supported", scs);
828 memset(cellCb->ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
829 memcpy(cellCb->ssbStartSymbArr, ssbStartSymbArr, SCH_MAX_SSB_BEAM);
834 * @brief cell config from MAC to SCH.
838 * Function : macSchCellCfgReq
840 * This API is invoked by MAC to send cell config to SCH
842 * @param[in] Pst *pst
843 * @param[in] SchCellCfg *schCellCfg
848 uint8_t SchHdlCellCfgReq(Pst *pst, SchCellCfg *schCellCfg)
852 SchCellCfgCfm schCellCfgCfm;
854 Inst inst = pst->dstInst-1;
856 schInitCellCb(inst, schCellCfg);
857 cellCb = schCb[inst].cells[inst]; //cells is of MAX_CELLS, why inst
858 cellCb->macInst = pst->srcInst;
860 /* derive the SIB1 config parameters */
861 fillSchSib1Cfg(schCellCfg->bandwidth, cellCb->numSlots,
862 &(schCellCfg->sib1SchCfg), schCellCfg->phyCellId,
863 schCellCfg->ssbSchCfg.ssbOffsetPointA);
864 memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
866 /* Initializing global variables */
867 cellCb->actvUeBitMap = 0;
868 cellCb->boIndBitMap = 0;
870 /* Fill and send Cell config confirm */
871 memset(&rspPst, 0, sizeof(Pst));
872 FILL_PST_SCH_TO_MAC(rspPst, pst->dstInst);
873 rspPst.event = EVENT_SCH_CELL_CFG_CFM;
875 schCellCfgCfm.cellId = schCellCfg->cellId;
876 schCellCfgCfm.rsp = RSP_OK;
878 ret = (*SchCellCfgCfmOpts[rspPst.selector])(&rspPst, &schCellCfgCfm);
884 /*******************************************************************
886 * @brief Processes DL RLC BO info from MAC
890 * Function : MacSchDlRlcBoInfo
893 * Processes DL RLC BO info from MAC
896 * @return ROK - success
899 * ****************************************************************/
900 uint8_t MacSchDlRlcBoInfo(Pst *pst, DlRlcBoInfo *dlBoInfo)
905 SchUeCb *ueCb = NULLP;
906 SchCellCb *cell = NULLP;
907 SchDlSlotInfo *schDlSlotInfo = NULLP;
909 Inst inst = pst->dstInst-SCH_INST_START;
910 DU_LOG("\nDEBUG --> SCH : Received RLC BO Status indication");
911 cell = schCb[inst].cells[inst];
913 GET_UE_IDX(dlBoInfo->crnti, ueIdx);
914 ueCb = &cell->ueCb[ueIdx-1];
915 lcId = dlBoInfo->lcId;
917 if(lcId == SRB1_LCID || lcId == SRB2_LCID || lcId == SRB3_LCID || \
918 (lcId >= MIN_DRB_LCID && lcId <= MAX_DRB_LCID))
920 SET_ONE_BIT(ueIdx, cell->boIndBitMap);
921 ueCb->dlInfo.dlLcCtxt[lcId].bo = dlBoInfo->dataVolume;
923 else if(lcId != SRB0_LCID)
925 DU_LOG("\nERROR --> SCH : Invalid LC Id %d in MacSchDlRlcBoInfo", lcId);
929 slot = (cell->slotInfo.slot + SCHED_DELTA + PHY_DELTA + BO_DELTA) % cell->numSlots;
930 schDlSlotInfo = cell->schDlSlotInfo[slot];
932 SCH_ALLOC(schDlSlotInfo->dlMsgInfo, sizeof(DlMsgInfo));
933 if(!schDlSlotInfo->dlMsgInfo)
935 DU_LOG("\nERROR --> SCH : Memory allocation failed for dlMsgInfo");
936 schDlSlotInfo = NULL;
939 schDlSlotInfo->dlMsgInfo->crnti = dlBoInfo->crnti;
940 schDlSlotInfo->dlMsgInfo->ndi = 1;
941 schDlSlotInfo->dlMsgInfo->harqProcNum = 0;
942 schDlSlotInfo->dlMsgInfo->dlAssignIdx = 0;
943 schDlSlotInfo->dlMsgInfo->pucchTpc = 0;
944 schDlSlotInfo->dlMsgInfo->pucchResInd = 0;
945 schDlSlotInfo->dlMsgInfo->harqFeedbackInd = 0;
946 schDlSlotInfo->dlMsgInfo->dciFormatId = 1;
947 if(lcId == SRB0_LCID)
948 schDlSlotInfo->dlMsgInfo->isMsg4Pdu = true;
953 /*******************************************************************
955 * @brief Processes BSR indiation from MAC
959 * Function : MacSchBsr
962 * Processes DL BSR from MAC
964 * @params[in] Pst pst
965 * UlBufferStatusRptInd bsrInd
966 * @return ROK - success
969 * ****************************************************************/
970 uint8_t MacSchBsr(Pst *pst, UlBufferStatusRptInd *bsrInd)
972 Inst schInst = pst->dstInst-SCH_INST_START;
973 SchCellCb *cellCb = NULLP;
974 SchUeCb *ueCb = NULLP;
977 DU_LOG("\nDEBUG --> SCH : Received BSR");
978 cellCb = schCb[schInst].cells[schInst];
979 ueCb = schGetUeCb(cellCb, bsrInd->crnti);
981 /* store dataVolume per lcg in uecb */
982 for(lcgIdx = 0; lcgIdx < bsrInd->numLcg; lcgIdx++)
984 ueCb->bsrInfo[lcgIdx].priority = 1; //TODO: determining LCG priority?
985 ueCb->bsrInfo[lcgIdx].dataVol = bsrInd->dataVolInfo[lcgIdx].dataVol;
990 /*******************************************************************
992 * @brief Processes SR UCI indication from MAC
996 * Function : MacSchSrUciInd
999 * Processes SR UCI indication from MAC
1001 * @params[in] Post structure
1003 * @return ROK - success
1006 * ****************************************************************/
1007 uint8_t MacSchSrUciInd(Pst *pst, SrUciIndInfo *uciInd)
1009 Inst inst = pst->dstInst-SCH_INST_START;
1012 SchCellCb *cellCb = schCb[inst].cells[inst];
1014 DU_LOG("\nDEBUG --> SCH : Received SR");
1016 ueCb = schGetUeCb(cellCb, uciInd->crnti);
1018 if(uciInd->numSrBits)
1020 ueCb->srRcvd = true;
1024 /**********************************************************************
1026 **********************************************************************/