Merge "MAC Clean-up [Issue-ID: ODUHIGH-212]"
[o-du/l2.git] / src / 5gnrsch / sch.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /************************************************************************
20  
21      Name:     sch.c
22   
23      Type:     C source file
24   
25      Desc:     C source code for scheduler fucntions
26   
27      File:     sch.c
28   
29 **********************************************************************/
30
31 /** @file sch.c
32 @brief This file implements the schedulers main access to MAC layer code.
33 */
34 #include "common_def.h" 
35 #include "du_app_mac_inf.h"
36 #include "lrg.h"
37 #include "tfu.h"
38 #include "du_log.h"
39 #include "rgr.h"
40 #include "rg_sch_inf.h"
41 #include "rg_sch.h"
42
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"
48 #include "sch.h"
49 #include "sch_utils.h"
50
51 extern SchCb schCb[SCH_MAX_INST];
52 void SchFillCfmPst(Pst *reqPst,Pst *cfmPst,RgMngmt *cfm);
53 /* local defines */
54 SchCellCfgCfmFunc SchCellCfgCfmOpts[] = 
55 {
56    packSchCellCfgCfm,     /* LC */
57    MacProcSchCellCfgCfm,  /* TC */
58    packSchCellCfgCfm      /* LWLC */
59 };
60
61
62 /**
63  * @brief Task Initiation function. 
64  *
65  * @details
66  *
67  *     Function : schActvInit
68  *     
69  *     This function is supplied as one of parameters during MAC's 
70  *     task registration. MAC will invoke this function once, after
71  *     it creates and attaches this TAPA Task to a system task.
72  *     
73  *  @param[in]  Ent Entity, the entity ID of this task.     
74  *  @param[in]  Inst Inst, the instance ID of this task.
75  *  @param[in]  Region Region, the region ID registered for memory 
76  *              usage of this task.
77  *  @param[in]  Reason Reason.
78  *  @return  int
79  *      -# ROK
80  **/
81 uint8_t schActvInit(Ent entity, Inst instId, Region region, Reason reason)
82 {
83    Inst inst = (instId  - SCH_INST_START);
84
85    /* Initialize the MAC TskInit structure to zero */
86    cmMemset ((uint8_t *)&schCb[inst], 0, sizeof(schCb));
87
88    /* Initialize the MAC TskInit with received values */
89    schCb[inst].schInit.ent = entity;
90    schCb[inst].schInit.inst = inst;
91    schCb[inst].schInit.region = region;
92    schCb[inst].schInit.pool = 0;
93    schCb[inst].schInit.reason = reason;
94    schCb[inst].schInit.cfgDone = FALSE;
95    schCb[inst].schInit.acnt = FALSE;
96    schCb[inst].schInit.usta = FALSE;
97    schCb[inst].schInit.trc = FALSE;
98    schCb[inst].schInit.procId = SFndProcId();
99
100    return ROK;
101 } /* schActvInit */
102
103 /**
104  * @brief Scheduler instance Configuration Handler. 
105  *
106  * @details
107  *
108  *     Function : SchInstCfg
109  *     
110  *     This function in called by SchProcGenCfgReq(). It handles the
111  *     general configurations of the scheduler instance. Returns
112  *     reason for success/failure of this function.
113  *     
114  *  @param[in]  RgCfg *cfg, the Configuaration information 
115  *  @return  U16
116  *      -# LCM_REASON_NOT_APPL 
117  *      -# LCM_REASON_INVALID_MSGTYPE
118  *      -# LCM_REASON_MEM_NOAVAIL
119  **/
120 PUBLIC U16 SchInstCfg(RgCfg *cfg, Inst  dInst)
121 {
122    uint16_t ret = LCM_REASON_NOT_APPL;
123    Inst     inst = (dInst - SCH_INST_START);
124
125    printf("\nEntered SchInstCfg()");
126    /* Check if Instance Configuration is done already */
127    if (schCb[inst].schInit.cfgDone == TRUE)
128    {
129       return LCM_REASON_INVALID_MSGTYPE;
130    }
131    /* Update the Pst structure for LM interface */
132    cmMemcpy((U8 *)&schCb[inst].schInit.lmPst,
133          (U8 *)&cfg->s.schInstCfg.genCfg.lmPst,
134          sizeof(Pst));
135
136    schCb[inst].schInit.inst = inst;
137    schCb[inst].schInit.lmPst.srcProcId = schCb[inst].schInit.procId;
138    schCb[inst].schInit.lmPst.srcEnt = schCb[inst].schInit.ent;
139    schCb[inst].schInit.lmPst.srcInst = schCb[inst].schInit.inst +
140       SCH_INST_START;
141    schCb[inst].schInit.lmPst.event = EVTNONE;
142
143    schCb[inst].schInit.region = cfg->s.schInstCfg.genCfg.mem.region;
144    schCb[inst].schInit.pool = cfg->s.schInstCfg.genCfg.mem.pool;
145    schCb[inst].genCfg.tmrRes = cfg->s.schInstCfg.genCfg.tmrRes;
146 #ifdef LTE_ADV
147    schCb[inst].genCfg.forceCntrlSrbBoOnPCel =  cfg->s.schInstCfg.genCfg.forceCntrlSrbBoOnPCel;
148    schCb[inst].genCfg.isSCellActDeactAlgoEnable =  cfg->s.schInstCfg.genCfg.isSCellActDeactAlgoEnable;
149 #endif
150    schCb[inst].genCfg.startCellId    = cfg->s.schInstCfg.genCfg.startCellId;
151 #if 0
152    /* Initialzie the timer queue */   
153    cmMemset((U8 *)&schCb[inst].tmrTq, 0, sizeof(CmTqType)*RGSCH_TQ_SIZE);
154    /* Initialize the timer control point */
155    cmMemset((U8 *)&schCb[inst].tmrTqCp, 0, sizeof(CmTqCp));
156    schCb[inst].tmrTqCp.tmrLen = RGSCH_TQ_SIZE;
157
158    /* SS_MT_TMR needs to be enabled as schActvTmr needs instance information */
159    /* Timer Registration request to SSI */
160    if (SRegTmrMt(schCb[inst].schInit.ent, dInst,
161             (S16)schCb[inst].genCfg.tmrRes, schActvTmr) != ROK)
162    {
163       RLOG_ARG0(L_ERROR,DBG_INSTID,inst, "SchInstCfg(): Failed to "
164             "register timer.");
165       RETVALUE(LCM_REASON_MEM_NOAVAIL);
166    }   
167 #endif               
168    /* Set Config done in TskInit */
169    schCb[inst].schInit.cfgDone = TRUE;
170    printf("\nScheduler gen config done");
171
172    return ret;
173 }
174
175 /**
176  * @brief Layer Manager Configuration request handler. 
177  *
178  * @details
179  *
180  *     Function : SchProcGenCfgReq
181  *     
182  *     This function handles the configuration
183  *     request received at scheduler instance from the Layer Manager.
184  *     -# Based on the cfg->hdr.elmId.elmnt value it invokes one of the
185  *        functions rgHdlGenCfg() or rgHdlSapCfg().
186  *     -# Invokes RgMiLrgSchCfgCfm() to send back the confirmation to the LM.
187  *     
188  *  @param[in]  Pst *pst, the post structure     
189  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
190  *  @return  S16
191  *      -# ROK
192  **/
193 int SchProcGenCfgReq(Pst *pst, RgMngmt *cfg)
194 {
195    uint16_t       ret = LCM_PRIM_OK;
196    uint16_t       reason = LCM_REASON_NOT_APPL;
197    RgMngmt   cfm;
198    Pst       cfmPst;
199
200    if(pst->dstInst < SCH_INST_START)
201    {
202       DU_LOG("\nInvalid inst ID");
203       DU_LOG("\nSchProcGenCfgReq(): "
204             "pst->dstInst=%d SCH_INST_START=%d", pst->dstInst,SCH_INST_START); 
205       return ROK;
206    }
207    printf("\nReceived scheduler gen config");
208    /* Fill the post structure for sending the confirmation */
209    memset(&cfmPst, 0 , sizeof(Pst));
210    SchFillCfmPst(pst, &cfmPst, cfg);
211
212    cmMemset((U8 *)&cfm, 0, sizeof(RgMngmt));
213
214 #ifdef LMINT3
215    cfm.hdr.transId =
216       cfg->hdr.transId;
217 #endif
218
219    cfm.hdr.elmId.elmnt = cfg->hdr.elmId.elmnt;
220    switch(cfg->hdr.elmId.elmnt)
221    {
222       case STSCHINST:
223          reason = SchInstCfg(&cfg->t.cfg,pst->dstInst );
224          break;
225       default:
226          ret = LCM_PRIM_NOK;
227          reason = LCM_REASON_INVALID_ELMNT;
228          DU_LOG("\nInvalid Elmnt=%d", cfg->hdr.elmId.elmnt);
229          break;
230    }
231
232    if (reason != LCM_REASON_NOT_APPL)
233    {
234       ret = LCM_PRIM_NOK;
235    }
236
237    cfm.cfm.status = ret;
238    cfm.cfm.reason = reason;
239
240    SchSendCfgCfm(&cfmPst, &cfm);
241    /*   SPutSBuf(pst->region, pst->pool, (Data *)cfg, sizeof(RgMngmt)); */
242
243    return ROK;
244 }/*-- SchProcGenCfgReq --*/
245
246 /**
247  * @brief slot indication from MAC to SCH.
248  *
249  * @details
250  *
251  *     Function : macSchSlotInd 
252  *      
253  *      This API is invoked by PHY to indicate slot indication to Scheduler for
254  *      a cell.
255  *           
256  *  @param[in]  Pst            *pst
257  *  @param[in]  SlotIndInfo    *slotInd
258  *  @return  S16
259  *      -# ROK 
260  *      -# RFAILED 
261  **/
262 uint8_t macSchSlotInd(Pst *pst, SlotIndInfo *slotInd)
263 {
264    Inst  inst = pst->dstInst-SCH_INST_START;
265
266    /* Now call the TOM (Tfu ownership module) primitive to process further */
267    schProcessSlotInd(slotInd, inst);
268
269    return ROK;
270 }  /* macSchSlotInd */
271
272 /*******************************************************************
273  *
274  * @brief Processes Rach indication from MAC 
275  *
276  * @details
277  *
278  *    Function : macSchRachInd
279  *
280  *    Functionality:
281  *      Processes Rach indication from MAC
282  *
283  * @params[in] 
284  * @return ROK     - success
285  *         RFAILED - failure
286  *
287  * ****************************************************************/
288 uint8_t macSchRachInd(Pst *pst, RachIndInfo *rachInd)
289 {
290    Inst  inst = pst->dstInst-SCH_INST_START;
291    DU_LOG("\nSCH : Received Rach indication");
292    schProcessRachInd(rachInd, inst);
293    return ROK;
294 }
295
296 /*******************************************************************
297  *
298  * @brief Processes CRC indication from MAC 
299  *
300  * @details
301  *
302  *    Function : macSchCrcInd
303  *
304  *    Functionality:
305  *      Processes CRC indication from MAC
306  *
307  * @params[in] Post structure
308  *             Crc Indication
309  * @return ROK     - success
310  *         RFAILED - failure
311  *
312  * ****************************************************************/
313 uint8_t macSchCrcInd(Pst *pst, CrcIndInfo *crcInd)
314 {
315    switch(crcInd->crcInd[0])
316    {
317       case CRC_FAILED:
318          DU_LOG("\nSCH : Received CRC indication. CRC Status [FAILURE]");
319          break;
320       case CRC_PASSED:
321          DU_LOG("\nSCH : Received CRC indication. CRC Status [PASS]");
322          break;
323       default:
324          DU_LOG("\nSCH : Invalid CRC state %d", crcInd->crcInd[0]);
325          return RFAILED;
326    }
327    return ROK;
328 }
329
330
331 /**
332  * @brief inti cellCb based on cellCfg
333  *
334  * @details
335  *
336  *     Function : InitSchCellCb 
337  *      
338  *      This API is invoked after receiving schCellCfg
339  *           
340  *  @param[in]  schCellCb *cell
341  *  @param[in]  SchCellCfg *schCellCfg
342  *  @return  int
343  *      -# ROK 
344  *      -# RFAILED 
345  **/
346 int InitSchCellCb(Inst inst, SchCellCfg *schCellCfg)
347 {
348    SchCellCb *cell;
349    SCH_ALLOC(cell, sizeof(SchCellCb));
350    if(!cell)
351    {
352       DU_LOG("\nMemory allocation failed in InitSchCellCb");
353       return RFAILED;
354    }
355
356    cell->cellId = schCellCfg->cellId; 
357    cell->instIdx = inst;
358    switch(schCellCfg->ssbSchCfg.scsCommon)
359    {
360       case SCH_SCS_15KHZ:
361          {
362             cell->numSlots = SCH_NUM_SLOTS;
363          }
364          break;
365       default:
366          DU_LOG("\nSCS %d not supported", schCellCfg->ssbSchCfg.scsCommon);
367    }
368
369    for(uint8_t idx=0; idx<SCH_NUM_SLOTS; idx++)
370    {
371       SchDlSlotInfo *schDlSlotInfo;
372       SchUlSlotInfo *schUlSlotInfo;
373
374       /* DL Alloc */
375       SCH_ALLOC(schDlSlotInfo, sizeof(SchDlSlotInfo));
376       if(!schDlSlotInfo)
377       {
378          DU_LOG("\nMemory allocation failed in InitSchCellCb");
379          return RFAILED;
380       }
381
382       /* UL Alloc */
383       SCH_ALLOC(schUlSlotInfo, sizeof(SchUlSlotInfo));
384       if(!schUlSlotInfo)
385       {
386          DU_LOG("\nMemory allocation failed in InitSchCellCb");
387          return RFAILED;
388       }
389
390       memset(schDlSlotInfo, 0, sizeof(SchDlSlotInfo));
391       memset(schUlSlotInfo, 0, sizeof(SchUlSlotInfo));
392
393       schDlSlotInfo->totalPrb = schUlSlotInfo->totalPrb = MAX_NUM_RB;
394
395       for(uint8_t itr=0; itr<SCH_SYMBOL_PER_SLOT; itr++)
396       {
397          schDlSlotInfo->assignedPrb[itr] = 0;
398          schUlSlotInfo->assignedPrb[itr] = 0;
399       }
400       schUlSlotInfo->schPuschInfo = NULLP;
401
402       for(uint8_t itr=0; itr<MAX_SSB_IDX; itr++)
403       {
404          memset(&schDlSlotInfo->ssbInfo[itr], 0, sizeof(SsbInfo));
405       }
406
407       cell->schDlSlotInfo[idx] = schDlSlotInfo;
408       cell->schUlSlotInfo[idx] = schUlSlotInfo;
409
410    }
411    schCb[inst].cells[inst] = cell;
412
413    DU_LOG("\nCell init completed for cellId:%d", cell->cellId);
414
415    return ROK;   
416 }
417
418 /**
419  * @brief Fill SIB1 configuration
420  *
421  * @details
422  *
423  *     Function : fillSchSib1Cfg
424  *
425  *     Fill SIB1 configuration
426  *
427  *  @param[in]  Inst schInst : scheduler instance
428  *              SchSib1Cfg *sib1SchCfg : cfg to be filled
429  *              uint16_t pci : physical cell Id
430  *              uint8_t offsetPointA : offset
431  *  @return  void
432  **/
433 void fillSchSib1Cfg(Inst schInst, SchSib1Cfg *sib1SchCfg, uint16_t pci, \
434    uint8_t offsetPointA)
435 {
436    uint8_t coreset0Idx = 0;
437    uint8_t searchSpace0Idx = 0;
438    //uint8_t ssbMuxPattern = 0;
439    uint8_t numRbs = 0;
440    uint8_t numSymbols = 0;
441    uint8_t offset = 0;
442    uint8_t oValue = 0;
443    //uint8_t numSearchSpacePerSlot = 0;
444    uint8_t mValue = 0;
445    uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
446    uint8_t slotIndex = 0;
447    uint8_t FreqDomainResource[6] = {0};
448    uint16_t tbSize = 0;
449    uint8_t numPdschSymbols = 12; /* considering pdsch region from 2 to 13 */
450
451    PdcchCfg *pdcch = &(sib1SchCfg->sib1PdcchCfg);
452    PdschCfg *pdsch = &(sib1SchCfg->sib1PdschCfg);
453    BwpCfg *bwp = &(sib1SchCfg->bwp);
454
455    coreset0Idx     = sib1SchCfg->coresetZeroIndex;
456    searchSpace0Idx = sib1SchCfg->searchSpaceZeroIndex;
457
458    /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
459    //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
460    numRbs        = coresetIdxTable[coreset0Idx][1];
461    numSymbols    = coresetIdxTable[coreset0Idx][2];
462    offset        = coresetIdxTable[coreset0Idx][3];
463
464    /* derive the search space params from table 13-11 spec 38.213 */
465    oValue                = searchSpaceIdxTable[searchSpace0Idx][0];
466    //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
467    mValue                = searchSpaceIdxTable[searchSpace0Idx][2];
468    firstSymbol           = searchSpaceIdxTable[searchSpace0Idx][3];
469
470    /* calculate the n0, need to add the formulae, as of now the value is 0 
471     * Need to add the even and odd values of i during configuration 
472     * [(O . 2^u + i . M )  ] mod numSlotsPerSubframe 
473     * assuming u = 0, i = 0, numSlotsPerSubframe = 10
474     * Also, from this configuration, coreset0 is only on even subframe */
475    slotIndex = ((oValue * 1) + (0 * mValue)) % 10; 
476    sib1SchCfg->n0 = slotIndex;
477
478    /* calculate the PRBs */
479    schAllocFreqDomRscType0(((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
480
481    /* fill BWP */
482    bwp->freqAlloc.numPrb   = MAX_NUM_RB; /* whole of BW */
483    bwp->freqAlloc.startPrb = 0;
484    bwp->subcarrierSpacing  = 0;         /* 15Khz */
485    bwp->cyclicPrefix       = 0;              /* normal */
486
487    /* fill the PDCCH PDU */
488    pdcch->coreset0Cfg.coreSet0Size = numRbs;
489    pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
490    pdcch->coreset0Cfg.durationSymbols = numSymbols;
491    memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
492    pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
493    pdcch->coreset0Cfg.regBundleSize = 6;    /* spec-38.211 sec 7.3.2.2 */
494    pdcch->coreset0Cfg.interleaverSize = 2;  /* spec-38.211 sec 7.3.2.2 */
495    pdcch->coreset0Cfg.coreSetType = 0;
496    pdcch->coreset0Cfg.shiftIndex = pci;
497    pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
498    pdcch->numDlDci = 1;
499    pdcch->dci.rnti = SI_RNTI;
500    pdcch->dci.scramblingId = pci;
501    pdcch->dci.scramblingRnti = 0;
502    pdcch->dci.cceIndex = 0;
503    pdcch->dci.aggregLevel = 4;
504    pdcch->dci.beamPdcchInfo.numPrgs = 1;
505    pdcch->dci.beamPdcchInfo.prgSize = 1;
506    pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
507    pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
508    pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
509    pdcch->dci.txPdcchPower.powerValue = 0;
510    pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
511    /* Storing pdschCfg pointer here. Required to access pdsch config while
512       fillig up pdcch pdu */
513    pdcch->dci.pdschCfg = pdsch; 
514
515    /* fill the PDSCH PDU */
516    uint8_t cwCount = 0;
517    pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
518    pdsch->rnti = 0xFFFF; /* SI-RNTI */
519    pdsch->pduIndex = 0;
520    pdsch->numCodewords = 1;
521    for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
522    {
523       pdsch->codeword[cwCount].targetCodeRate = 308;
524       pdsch->codeword[cwCount].qamModOrder = 2;
525       pdsch->codeword[cwCount].mcsIndex = sib1SchCfg->sib1Mcs;
526       pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
527       pdsch->codeword[cwCount].rvIndex = 0;
528       tbSize = schCalcTbSize(sib1SchCfg->sib1PduLen);
529       pdsch->codeword[cwCount].tbSize = tbSize;
530    }
531    pdsch->dataScramblingId                   = pci;
532    pdsch->numLayers                          = 1;
533    pdsch->transmissionScheme                 = 0;
534    pdsch->refPoint                           = 0;
535    pdsch->dmrs.dlDmrsSymbPos                 = 2;
536    pdsch->dmrs.dmrsConfigType                = 0; /* type-1 */
537    pdsch->dmrs.dlDmrsScramblingId            = pci;
538    pdsch->dmrs.scid                          = 0;
539    pdsch->dmrs.numDmrsCdmGrpsNoData          = 1;
540    pdsch->dmrs.dmrsPorts                     = 0;
541    pdsch->dmrs.mappingType                   = DMRS_MAP_TYPE_A; /* Type-A */
542    pdsch->dmrs.nrOfDmrsSymbols               = NUM_DMRS_SYMBOLS;
543    pdsch->dmrs.dmrsAddPos                    = DMRS_ADDITIONAL_POS;
544
545    pdsch->pdschFreqAlloc.resourceAllocType   = 1; /* RAT type-1 RIV format */
546    pdsch->pdschFreqAlloc.freqAlloc.startPrb  = offset + SCH_SSB_NUM_PRB; /* the RB numbering starts from coreset0,
547                                                                             and PDSCH is always above SSB */
548    pdsch->pdschFreqAlloc.freqAlloc.numPrb    = schCalcNumPrb(tbSize,sib1SchCfg->sib1Mcs,numPdschSymbols);
549    pdsch->pdschFreqAlloc.vrbPrbMapping       = 0; /* non-interleaved */
550    pdsch->pdschTimeAlloc.rowIndex            = 1;
551    pdsch->pdschTimeAlloc.timeAlloc.startSymb = 2; /* spec-38.214, Table 5.1.2.1-1 */
552    pdsch->pdschTimeAlloc.timeAlloc.numSymb   = numPdschSymbols;
553    pdsch->beamPdschInfo.numPrgs              = 1;
554    pdsch->beamPdschInfo.prgSize              = 1;
555    pdsch->beamPdschInfo.digBfInterfaces      = 0;
556    pdsch->beamPdschInfo.prg[0].pmIdx         = 0;
557    pdsch->beamPdschInfo.prg[0].beamIdx[0]    = 0;
558    pdsch->txPdschPower.powerControlOffset    = 0;
559    pdsch->txPdschPower.powerControlOffsetSS  = 0;
560
561 }
562
563 /**
564  * @brief Fill SSB start symbol
565  *
566  * @details
567  *
568  *     Function : fillSsbStartSymb 
569  *      
570  *      This API stores SSB start index per beam
571  *           
572  *  @param[in]  SchCellCb     *cellCb
573  *  @return  int
574  *      -# ROK 
575  *      -# RFAILED 
576  **/
577 void fillSsbStartSymb(SchCellCb *cellCb)
578 {
579    uint8_t cnt, scs;
580
581    scs = cellCb->cellCfg.ssbSchCfg.scsCommon;
582    uint8_t ssbStartSymbArr[SCH_MAX_SSB_BEAM];
583
584    memset(ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
585    /* Determine value of "n" based on Section 4.1 of 3GPP TS 38.213 */
586    switch(scs)
587    {
588       case SCH_SCS_15KHZ:
589          {
590             uint8_t symbIdx=0;
591             cnt = 2;/* n = 0, 1 for SCS = 15KHz */
592             for(uint8_t idx=0; idx<cnt; idx++)
593             {
594                /* start symbol determined using {2, 8} + 14n */
595                ssbStartSymbArr[symbIdx++] = 2 + SCH_SYMBOL_PER_SLOT*idx;
596                ssbStartSymbArr[symbIdx++]       = 8 +   SCH_SYMBOL_PER_SLOT*idx;
597             }
598          }
599          break;
600       default:
601          DU_LOG("\nSCS %d is currently not supported", scs);
602    }
603    memset(cellCb->ssbStartSymbArr, 0, sizeof(SCH_MAX_SSB_BEAM));
604    memcpy(cellCb->ssbStartSymbArr, ssbStartSymbArr, SCH_MAX_SSB_BEAM);
605
606 }
607
608 /**
609  * @brief cell config from MAC to SCH.
610  *
611  * @details
612  *
613  *     Function : macSchCellCfgReq
614  *      
615  *      This API is invoked by MAC to send cell config to SCH
616  *           
617  *  @param[in]  Pst            *pst
618  *  @param[in]  SchCellCfg     *schCellCfg
619  *  @return  int
620  *      -# ROK 
621  *      -# RFAILED 
622  **/
623 uint8_t SchHdlCellCfgReq(Pst *pst, SchCellCfg *schCellCfg)
624 {
625    uint8_t ret = ROK;
626    SchCellCb *cellCb;
627    SchCellCfgCfm schCellCfgCfm;
628    Pst rspPst;
629    Inst inst = pst->dstInst-1; 
630
631    InitSchCellCb(inst, schCellCfg);
632    cellCb = schCb[inst].cells[inst]; //cells is of MAX_CELLS, why inst
633    cellCb->macInst = pst->srcInst;
634
635    /* derive the SIB1 config parameters */
636    fillSchSib1Cfg(
637          inst,
638          &(schCellCfg->sib1SchCfg),
639          schCellCfg->phyCellId,
640          schCellCfg->ssbSchCfg.ssbOffsetPointA);
641    memcpy(&cellCb->cellCfg, schCellCfg, sizeof(SchCellCfg));
642
643    /* Fill and send Cell config confirm */
644    memset(&rspPst, 0, sizeof(Pst));
645    FILL_PST_SCH_TO_MAC(rspPst, pst->dstInst);
646    rspPst.event = EVENT_SCH_CELL_CFG_CFM;
647
648    schCellCfgCfm.cellId = schCellCfg->cellId; 
649    schCellCfgCfm.rsp = RSP_OK;
650
651    ret = (*SchCellCfgCfmOpts[rspPst.selector])(&rspPst, &schCellCfgCfm);
652
653    return ret;
654
655 }
656
657 /*******************************************************************
658  *
659  * @brief Processes DL RLC BO info from MAC
660  *
661  * @details
662  *
663  *    Function : macSchDlRlcBoInfo
664  *
665  *    Functionality:
666  *       Processes DL RLC BO info from MAC
667  *
668  * @params[in] 
669  * @return ROK     - success
670  *         RFAILED - failure
671  *
672  * ****************************************************************/
673 uint8_t macSchDlRlcBoInfo(Pst *pst, DlRlcBOInfo *dlBoInfo)
674 {
675    uint16_t  lcIdx;
676    Inst  inst = pst->dstInst-SCH_INST_START;
677    DU_LOG("\nSCH : Received RLC BO Status indication");
678
679    SchCellCb *cell = schCb[inst].cells[inst];
680    SchDlSlotInfo *schDlSlotInfo = \
681                                   cell->schDlSlotInfo[(cell->slotInfo.slot + SCHED_DELTA + PHY_DELTA + MSG4_DELAY) % SCH_NUM_SLOTS];
682
683    for(lcIdx = 0; lcIdx < dlBoInfo->numLc; lcIdx++)
684    {
685       if(dlBoInfo->boInfo[lcIdx].lcId == CCCH_LCID)
686       {
687          SCH_ALLOC(schDlSlotInfo->msg4Info, sizeof(Msg4Info));
688          if(!schDlSlotInfo->msg4Info)
689          {
690             DU_LOG("\nSCH : Memory allocation failed for msg4Info");
691             schDlSlotInfo = NULL;
692             return RFAILED;
693          }
694          schDlSlotInfo->msg4Info->crnti = dlBoInfo->crnti;
695          schDlSlotInfo->msg4Info->ndi = 1;
696          schDlSlotInfo->msg4Info->harqProcNum = 0;
697          schDlSlotInfo->msg4Info->dlAssignIdx = 0;
698          schDlSlotInfo->msg4Info->pucchTpc = 0;
699          schDlSlotInfo->msg4Info->pucchResInd = 0;
700          schDlSlotInfo->msg4Info->harqFeedbackInd = 0;
701          schDlSlotInfo->msg4Info->dciFormatId = 1;
702       }
703    }
704
705    return ROK;
706 }
707
708 /**********************************************************************
709   End of file
710  **********************************************************************/