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 rach handling functions
29 **********************************************************************/
32 @brief This file implements the rach handling.
36 #include "envopt.h" /* environment options */
37 #include "envdep.h" /* environment dependent */
38 #include "envind.h" /* environment independent */
39 #include "gen.h" /* general layer */
40 #include "ssi.h" /* system service interface */
41 #include "cm_tkns.h" /* Common Token Defines */
42 #include "cm_llist.h" /* Common Link List Defines */
43 #include "cm_hash.h" /* Common Hash List Defines */
44 #include "cm_mblk.h" /* common memory link list library */
45 #include "cm_lte.h" /* Common LTE Defines */
49 #include "gen.x" /* general layer typedefs */
50 #include "ssi.x" /* system services typedefs */
51 #include "cm5.x" /* system services */
52 #include "cm_tkns.x" /* Common Token Definitions */
53 #include "cm_llist.x" /* Common Link List Definitions */
54 #include "cm_lib.x" /* Common Library Definitions */
55 #include "cm_hash.x" /* Common Hash List Definitions */
56 #include "cm_mblk.x" /* common memory link list library */
57 #include "cm_lte.x" /* Common LTE Defines */
61 #include "du_app_mac_inf.h"
62 #include "mac_sch_interface.h"
64 #include "sch_utils.h"
66 extern SchCb schCb[SCH_MAX_INST];
67 extern int8_t coresetIdxTable[MAX_CORESET_INDEX][4];
68 extern int8_t searchSpaceIdxTable[MAX_SEARCH_SPACE_INDEX][4];
71 * @brief calculate ra-rnti function.
75 * Function : calculateRaRnti
77 * This function calculates ra-rnti
79 * @param[in] symbol index
80 * @param[in] slot index
81 * @param[in] frequency index
84 uint16_t calculateRaRnti(uint8_t symbolIdx, uint8_t slotIdx, uint8_t freqIdx)
87 uint8_t ulCarrierIdx = 0; /* configured to 0 */
88 raRnti = (1+symbolIdx+(14*slotIdx)+(14*80*freqIdx)+(14*80*8*ulCarrierIdx));
93 * @brief create raCb function.
97 * Function : createSchRaCb
99 * This function create raCb
102 * @param[in] shed instance
105 void createSchRaCb(uint16_t tcrnti, Inst schInst)
107 schCb[schInst].cells[schInst]->raCb[0].tcrnti = tcrnti;
111 * @brief process rach indication function.
115 * Function : schProcessRachInd
117 * This function process rach indication
119 * @param[in] rachInd parameters
120 * @param[in] shed instance
123 uint8_t schProcessRachInd(RachIndInfo *rachInd, Inst schInst)
125 SchCellCb *cell = schCb[schInst].cells[schInst];
128 SchDlAlloc *dlAlloc =
129 cell->dlAlloc[(rachInd->timingInfo.slot+SCHED_DELTA+RAR_DELAY)%SCH_NUM_SLOTS]; /* RAR will sent in the next slot */
130 RarInfo *rarInfo = &(dlAlloc->rarInfo);
132 /* rar message presense in next slot ind and will be scheduled */
133 dlAlloc->rarPres = true;
135 /* calculate the ra-rnti value */
136 raRnti = calculateRaRnti(rachInd->symbolIdx,rachInd->slotIdx,rachInd->freqIdx);
138 /* create raCb at SCH */
139 createSchRaCb(rachInd->crnti,schInst);
142 rarInfo->raRnti = raRnti;
143 rarInfo->tcrnti = rachInd->crnti;
144 rarInfo->RAPID = rachInd->preambleIdx;
145 rarInfo->ta = rachInd->timingAdv;
146 rarInfo->msg3StartRb = 0; /* will be set during implementation of msg3 */
147 rarInfo->msg3NumRb = 0; /* will be set during implementation of msg3 */
153 * @brief fill RAR info function.
157 * Function : calculateRaRnti
159 * This function fills pdcch and pdsch info for RAR
161 * @param[in] rar Allocation info
164 * @param[in] offset to pointA to determine freq alloc
167 uint8_t schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t offsetPointA)
170 uint8_t coreset0Idx = 0;
172 uint8_t firstSymbol = 0;
173 uint8_t numSymbols = 0;
175 uint8_t FreqDomainResource[6] = {0};
176 SchBwpDlCfg *initialBwp = &schCb[inst].cells[inst]->cellCfg.schInitialBwp;
178 PdcchCfg *pdcch = &rarAlloc->rarPdcchCfg;
179 PdschCfg *pdsch = &rarAlloc->rarPdschCfg;
181 coreset0Idx = initialBwp->pdcchCommon.raSearchSpace.coresetId;
183 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
184 numRbs = coresetIdxTable[coreset0Idx][1];
185 numSymbols = coresetIdxTable[coreset0Idx][2];
186 offset = coresetIdxTable[coreset0Idx][3];
188 /* calculate time domain parameters */
189 // note: since slot value is made sl1, RAR can be sent at all slots
190 uint16_t mask = 0x2000;
191 for(firstSymbol=0; firstSymbol<14;firstSymbol++)
193 if(initialBwp->pdcchCommon.raSearchSpace.monitoringSymbol & mask)
199 /* calculate the PRBs */
200 freqDomResourceAlloc( ((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
202 /* fill the PDCCH PDU */
203 pdcch->pdcchBwpCfg.BWPSize = initialBwp->bwp.numPrb;
204 pdcch->pdcchBwpCfg.BWPStart = initialBwp->bwp.firstPrb;
205 pdcch->pdcchBwpCfg.subcarrierSpacing = initialBwp->bwp.scs;
206 pdcch->pdcchBwpCfg.cyclicPrefix = initialBwp->bwp.cyclicPrefix;
207 pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
208 pdcch->coreset0Cfg.durationSymbols = numSymbols;
209 memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
210 pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
211 pdcch->coreset0Cfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
212 pdcch->coreset0Cfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
213 pdcch->coreset0Cfg.coreSetType = 0;
214 pdcch->coreset0Cfg.shiftIndex = pci;
215 pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
217 pdcch->dci.rnti = raRnti; /* RA-RNTI */
218 pdcch->dci.scramblingId = pci;
219 pdcch->dci.scramblingRnti = 0;
220 pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
221 pdcch->dci.aggregLevel = 4;
222 pdcch->dci.beamPdcchInfo.numPrgs = 1;
223 pdcch->dci.beamPdcchInfo.prgSize = 1;
224 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
225 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
226 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
227 pdcch->dci.txPdcchPower.powerValue = 0;
228 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
229 pdcch->dci.pdschCfg = pdsch;
231 /* fill the PDSCH PDU */
233 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
234 pdsch->rnti = raRnti; /* RA-RNTI */
236 pdsch->pdschBwpCfg.BWPSize = initialBwp->bwp.numPrb;
237 pdsch->pdschBwpCfg.BWPStart = initialBwp->bwp.firstPrb;
238 pdsch->numCodewords = 1;
239 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
241 pdsch->codeword[cwCount].targetCodeRate = 308;
242 pdsch->codeword[cwCount].qamModOrder = 2;
243 pdsch->codeword[cwCount].mcsIndex = 4; /* mcs configured to 4 */
244 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
245 pdsch->codeword[cwCount].rvIndex = 0;
246 pdsch->codeword[cwCount].tbSize = 80/8; /* 38.214: Table 5.1.3.2-1,
247 devided by 8 to get the value in bytes */
249 pdsch->dataScramblingId = pci;
250 pdsch->numLayers = 1;
251 pdsch->transmissionScheme = 0;
253 pdsch->dmrs.dlDmrsSymbPos = 2;
254 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
255 pdsch->dmrs.dlDmrsScramblingId = pci;
256 pdsch->dmrs.scid = 0;
257 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
258 pdsch->dmrs.dmrsPorts = 0;
259 pdsch->freqAlloc.resourceAlloc = 1; /* RAT type-1 RIV format */
260 pdsch->freqAlloc.rbStart = offset + SCH_SSB_PRB_DURATION; /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
261 /* formula used for calculation of rbSize, 38.213 section 5.1.3.2 *
262 * Ninfo = S . Nre . R . Qm . v *
263 * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh *
264 * Nre = min(156,Nre') . nPrb */
265 pdsch->freqAlloc.rbSize = 1; /* This value is calculated from above formulae */
266 pdsch->freqAlloc.vrbPrbMapping = 0; /* non-interleaved */
267 pdsch->timeAlloc.startSymbolIndex = 2; /* spec-38.214, Table 5.1.2.1-1 */
268 pdsch->timeAlloc.numSymbols = 12;
269 pdsch->beamPdschInfo.numPrgs = 1;
270 pdsch->beamPdschInfo.prgSize = 1;
271 pdsch->beamPdschInfo.digBfInterfaces = 0;
272 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
273 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
274 pdsch->txPdschPower.powerControlOffset = 0;
275 pdsch->txPdschPower.powerControlOffsetSS = 0;
280 /**********************************************************************
282 **********************************************************************/