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 Entry point fucntions
29 **********************************************************************/
31 /** @file sch_common.c
32 @brief This module performs common scheduling
35 #include "envopt.h" /* environment options */
36 #include "envdep.h" /* environment dependent */
37 #include "envind.h" /* environment independent */
38 #include "gen.h" /* general layer */
39 #include "ssi.h" /* system service interface */
40 #include "cm_tkns.h" /* Common Token Defines */
41 #include "cm_llist.h" /* Common Link List Defines */
42 #include "cm_hash.h" /* Common Hash List Defines */
43 #include "cm_mblk.h" /* common memory link list library */
44 #include "cm_lte.h" /* Common LTE Defines */
48 #include "gen.x" /* general layer typedefs */
49 #include "ssi.x" /* system services typedefs */
50 #include "cm5.x" /* system services */
51 #include "cm_tkns.x" /* Common Token Definitions */
52 #include "cm_llist.x" /* Common Link List Definitions */
53 #include "cm_lib.x" /* Common Library Definitions */
54 #include "cm_hash.x" /* Common Hash List Definitions */
55 #include "cm_mblk.x" /* common memory link list library */
56 #include "cm_lte.x" /* Common LTE Defines */
60 #include "du_app_mac_inf.h"
61 #include "mac_sch_interface.h"
63 #include "sch_utils.h"
65 extern SchCb schCb[SCH_MAX_INST];
66 extern uint16_t prachCfgIdxTable[MAX_PRACH_CONFIG_IDX][8];
67 extern uint16_t numRbForPrachTable[MAX_RACH_NUM_RB_IDX][5];
69 SchMacUlSchInfoFunc schMacUlSchInfoOpts[] =
77 * @brief Time domain allocation for SSB
81 * Function : ssbDlTdAlloc
83 * This function handles common scheduling for DL
85 * @param[in] uint8_t scs, uint8_t *ssbStartSym
88 void ssbDlTdAlloc(uint8_t scs, uint8_t *ssbStartSymb)
91 /* Determine value of "n" based on Section 4.1 of 3GPP TS 38.213 */
97 n = 2;/* n = 0, 1 for SCS = 15KHz */
98 for(uint8_t idx=0; idx<n; idx++)
100 /* start symbol determined using {2, 8} + 14n */
101 ssbStartSymb[symbIdx++] = 2 + SCH_SYMBOL_PER_SLOT*idx;
102 ssbStartSymb[symbIdx++] = 8 + SCH_SYMBOL_PER_SLOT*idx;
107 DU_LOG("\nSCS %d is currently not supported", scs);
112 * @brief common resource allocation for SSB
116 * Function : schBroadcastAlloc
118 * This function handles common scheduling for DL
120 * @param[in] SchCellCb *cell, cell cb
121 * @param[in] DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
124 uint8_t schBroadcastAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc,
128 uint8_t scs, ssbStartPrb, ssbStartSymb, idx;
129 uint8_t ssbStartSymbArr[SCH_MAX_SSB_BEAM];
133 dlAlloc = cell->dlAlloc[slot];
134 if(dlBrdcstAlloc->ssbTrans)
136 scs = cell->cellCfg.ssbSchCfg.scsCommon;
137 ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA;
139 memset(ssbStartSymbArr, 0, SCH_MAX_SSB_BEAM);
140 ssbDlTdAlloc(scs, ssbStartSymbArr);
141 ssbStartSymb = ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are supporting only 1 ssb beam */
142 /* Assign interface structure */
143 for(idx=0; idx<dlBrdcstAlloc->ssbIdxSupported; idx++)
145 ssbInfo.ssbIdx = idx;
146 ssbInfo.fdAlloc.ssbStartPrbIdx = ssbStartPrb;
147 ssbInfo.fdAlloc.ssbPrbDuration = SCH_SSB_PRB_DURATION;
148 ssbInfo.tdAlloc.ssbStartSymbIdx = ssbStartSymb;
149 ssbInfo.tdAlloc.ssbSymbolDuration = SCH_SSB_SYMB_DURATION;
150 dlBrdcstAlloc->ssbInfo[idx] = ssbInfo;
151 dlAlloc->ssbInfo[idx] = ssbInfo;
155 dlAlloc->ssbPres = true;
156 dlAlloc->ssbIdxSupported = dlBrdcstAlloc->ssbIdxSupported;
157 for(idx=ssbStartSymb; idx<ssbStartSymb+SCH_SSB_SYMB_DURATION; idx++)
159 dlAlloc->assignedPrb[idx] = ssbStartPrb + SCH_SSB_PRB_DURATION + 1; /* +1 for kSsb */
164 /* SIB1 allocation */
165 if(dlBrdcstAlloc->sib1Trans)
167 dlAlloc->sib1Pres = true;
168 for(idx=0; idx<SCH_SYMBOL_PER_SLOT; idx++)
170 dlAlloc->assignedPrb[idx] = ssbStartPrb + SCH_SSB_PRB_DURATION + 1 + 10; /* 10 PRBs for sib1 */
172 memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg, &cell->cellCfg.sib1SchCfg.sib1PdcchCfg, sizeof(PdcchCfg));
173 memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdschCfg, &cell->cellCfg.sib1SchCfg.sib1PdschCfg, sizeof(PdschCfg));
178 /*******************************************************************
180 * @brief Handles sending UL scheduler info to MAC
184 * Function : sendUlSchInfoToMac
187 * Sends UL Sch info to MAC from SCH
190 * @return ROK - success
193 * ****************************************************************/
194 int sendUlSchInfoToMac(UlSchInfo *ulSchInfo, Inst inst)
198 memset(&pst, 0, sizeof(Pst));
199 SCH_FILL_RSP_PST(pst, inst);
200 pst.event = EVENT_UL_SCH_INFO;
202 return(*schMacUlSchInfoOpts[pst.selector])(&pst, ulSchInfo);
206 * @brief resource allocation for PRACH
210 * Function : schPrachResAlloc
212 * This function handles PRACH allocation
214 * @param[in] SchCellCb *cell, cell cb
215 * @param[in] UlSchInfo *ulSchInfo, UL scheduling info
218 int schPrachResAlloc(SchCellCb *cell, UlSchInfo *ulSchInfo)
220 uint8_t numPrachRb = 0;
222 uint8_t freqStart = 0;
225 uint8_t prachCfgIdx = 0;
226 uint8_t prachFormat = 0;
229 uint16_t prachSubframe = 0;
230 uint8_t prachStartSymbol = 0;
231 uint8_t prachOcas = 0;
232 uint8_t dataType = 0;
234 SchUlAlloc *ulAlloc = NULLP;
236 sfn = cell->slotInfo.sfn;
237 slot = cell->slotInfo.slot;
238 ulAlloc = cell->ulAlloc[cell->slotInfo.slot];
239 prachCfgIdx = cell->cellCfg.schRachCfg.prachCfgIdx;
241 /* derive the prachCfgIdx table paramters */
242 x = prachCfgIdxTable[prachCfgIdx][1];
243 y = prachCfgIdxTable[prachCfgIdx][2];
244 prachSubframe = prachCfgIdxTable[prachCfgIdx][3];
248 /* prach occasion does not lie in this SFN */
249 DU_LOG("\nPRACH ocassion doesn't lie in this SFN");
252 /* check for subFrame number */
253 if ((1 << slot) & prachSubframe)
255 /* prach ocassion present in this subframe */
257 prachFormat = prachCfgIdxTable[prachCfgIdx][0];
258 prachStartSymbol = prachCfgIdxTable[prachCfgIdx][4];
259 prachOcas = prachCfgIdxTable[prachCfgIdx][6];
261 /* freq domain resource determination for RACH*/
262 freqStart = cell->cellCfg.schRachCfg.msg1FreqStart;
263 /* numRa determined as 𝑛 belonging {0,1,.., M − 1},
264 * where M is given by msg1Fdm */
265 numRa = (cell->cellCfg.schRachCfg.msg1Fdm - 1);
266 for(idx=0; idx<MAX_RACH_NUM_RB_IDX; idx++)
268 if(numRbForPrachTable[idx][0] == cell->cellCfg.schRachCfg.rootSeqIdx)
271 numPrachRb = numRbForPrachTable[idx][3];
272 dataType |= SCH_DATATYPE_PRACH;
273 /* Considering first slot in the frame for PRACH */
275 ulAlloc->assignedPrb[idx] = freqStart+numPrachRb;
278 /* Fill UL SCH Info */
279 ulSchInfo->cellId = cell->cellId;
280 ulSchInfo->slotIndInfo.sfn = sfn;
281 ulSchInfo->slotIndInfo.slot = slot;
282 ulSchInfo->dataType = dataType;
284 ulSchInfo->prachSchInfo.numPrachOcas = prachOcas;
285 ulSchInfo->prachSchInfo.prachFormat = prachFormat;
286 ulSchInfo->prachSchInfo.numRa = numRa;
287 ulSchInfo->prachSchInfo.prachStartSymb = prachStartSymbol;
293 * @brief resource allocation for UL
297 * Function : schUlResAlloc
299 * This function handles UL Resource allocation
301 * @param[in] SchCellCb *cell, cellCb
304 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
308 /* Schedule resources for PRACH */
309 schPrachResAlloc(cell, &ulSchInfo);
311 ret = sendUlSchInfoToMac(&ulSchInfo, schInst);
314 DU_LOG("\nSending UL Sch info from SCH to MAC failed");
319 /**********************************************************************
321 **********************************************************************/