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];
70 uint16_t calculateRaRnti(uint8_t symbolIdx, uint8_t slotIdx, uint8_t freqIdx)
73 uint8_t ulCarrierIdx = 0; /* configured to 0 */
74 raRnti = (1+symbolIdx+(14*slotIdx)+(14*80*freqIdx)+(14*80*8*ulCarrierIdx));
78 void createSchRaCb(uint16_t tcrnti, Inst schInst)
80 schCb[schInst].cells[schInst]->raCb[0].tcrnti = tcrnti;
83 int schProcessRachInd(RachIndInfo *rachInd, Inst schInst)
85 SchCellCb *cell = schCb[schInst].cells[schInst];
87 uint16_t sfn = rachInd->timingInfo.sfn; /* get the current timing info */
88 uint16_t slot = rachInd->timingInfo.slot;
89 uint16_t sfnSlot = ((sfn * 10) + slot + 1); /* scheduled in the next slot */
92 if(sfnSlot % cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod == 0)
94 /* the next slot has SIB1 occasion, so send it after 2 slot */
99 /* send RAR in the next slot */
104 if((slot+rarDelay) % SCH_NUM_SLOTS == 0)
106 sfn = (sfn+1) % SCH_MAX_SFN;
109 slot = ((slot + rarDelay) % SCH_NUM_SLOTS);
111 SchDlAlloc *dlAlloc = cell->dlAlloc[slot]; /* RAR will sent in the next slot */
112 RarInfo *rarInfo = &(dlAlloc->rarInfo);
114 /* rar message presense in next slot ind and will be scheduled */
115 dlAlloc->rarPres = true;
117 /* calculate the ra-rnti value */
119 raRnti = calculateRaRnti(rachInd->symbolIdx,rachInd->slotIdx,rachInd->freqIdx);
121 /* create raCb at SCH */
122 createSchRaCb(rachInd->crnti,schInst);
125 rarInfo->raRnti = raRnti;
126 rarInfo->tcrnti = rachInd->crnti;
127 rarInfo->RAPID = rachInd->preambleIdx;
128 rarInfo->ta = rachInd->timingAdv;
129 rarInfo->msg3StartRb = 0; /* will be set during implementation of msg3 */
130 rarInfo->msg3NumRb = 0; /* will be set during implementation of msg3 */
135 int schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t offsetPointA)
137 uint8_t coreset0Idx = 0;
138 uint8_t searchSpace0Idx = 0;
139 //uint8_t ssbMuxPattern = 0;
141 uint8_t numSymbols = 0;
143 //uint8_t oValue = 0;
144 //uint8_t numSearchSpacePerSlot = 0;
145 //uint8_t mValue = 0;
146 uint8_t firstSymbol = 0; /* need to calculate using formula mentioned in 38.213 */
147 uint8_t FreqDomainResource[6] = {0};
149 PdcchCfg *pdcch = &rarAlloc->rarPdcchCfg;
150 PdschCfg *pdsch = &rarAlloc->rarPdschCfg;
155 /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
156 //ssbMuxPattern = coresetIdxTable[coreset0Idx][0];
157 numRbs = coresetIdxTable[coreset0Idx][1];
158 numSymbols = coresetIdxTable[coreset0Idx][2];
159 offset = coresetIdxTable[coreset0Idx][3];
161 /* derive the search space params from table 13-11 spec 38.213 */
162 //oValue = searchSpaceIdxTable[searchSpace0Idx][0];
163 //numSearchSpacePerSlot = searchSpaceIdxTable[searchSpace0Idx][1];
164 //mValue = searchSpaceIdxTable[searchSpace0Idx][2];
165 firstSymbol = searchSpaceIdxTable[searchSpace0Idx][3];
167 /* calculate the PRBs */
168 freqDomResourceAlloc( ((offsetPointA-offset)/6), (numRbs/6), FreqDomainResource);
170 /* fill the PDCCH PDU */
171 pdcch->pdcchBwpCfg.BWPSize = MAX_NUM_RB; /* whole of BW */
172 pdcch->pdcchBwpCfg.BWPStart = 0;
173 pdcch->pdcchBwpCfg.subcarrierSpacing = 0; /* 15Khz */
174 pdcch->pdcchBwpCfg.cyclicPrefix = 0; /* normal */
175 pdcch->coreset0Cfg.startSymbolIndex = firstSymbol;
176 pdcch->coreset0Cfg.durationSymbols = numSymbols;
177 memcpy(pdcch->coreset0Cfg.freqDomainResource,FreqDomainResource,6);
178 pdcch->coreset0Cfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
179 pdcch->coreset0Cfg.regBundleSize = 6; /* spec-38.211 sec 7.3.2.2 */
180 pdcch->coreset0Cfg.interleaverSize = 2; /* spec-38.211 sec 7.3.2.2 */
181 pdcch->coreset0Cfg.coreSetType = 0;
182 pdcch->coreset0Cfg.shiftIndex = pci;
183 pdcch->coreset0Cfg.precoderGranularity = 0; /* sameAsRegBundle */
185 pdcch->dci.rnti = raRnti; /* RA-RNTI */
186 pdcch->dci.scramblingId = pci;
187 pdcch->dci.scramblingRnti = 0;
188 pdcch->dci.cceIndex = 0;
189 pdcch->dci.aggregLevel = 4;
190 pdcch->dci.beamPdcchInfo.numPrgs = 1;
191 pdcch->dci.beamPdcchInfo.prgSize = 1;
192 pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
193 pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
194 pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
195 pdcch->dci.txPdcchPower.powerValue = 0;
196 pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
197 pdcch->dci.pdschCfg = pdsch;
199 /* fill the PDSCH PDU */
201 pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
202 pdsch->rnti = raRnti; /* RA-RNTI */
204 pdsch->pdschBwpCfg.BWPSize = MAX_NUM_RB; /* whole of BW */
205 pdsch->pdschBwpCfg.BWPStart = 0;
206 pdsch->numCodewords = 1;
207 for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
209 pdsch->codeword[cwCount].targetCodeRate = 308;
210 pdsch->codeword[cwCount].qamModOrder = 2;
211 pdsch->codeword[cwCount].mcsIndex = 4; /* msc configured to 4 */
212 pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
213 pdsch->codeword[cwCount].rvIndex = 0;
214 pdsch->codeword[cwCount].tbSize = 768;
216 pdsch->dataScramblingId = pci;
217 pdsch->numLayers = 1;
218 pdsch->transmissionScheme = 0;
220 pdsch->dmrs.dlDmrsSymbPos = 2;
221 pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
222 pdsch->dmrs.dlDmrsScramblingId = pci;
223 pdsch->dmrs.scid = 0;
224 pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
225 pdsch->dmrs.dmrsPorts = 0;
226 pdsch->freqAlloc.resourceAlloc = 1; /* RAT type-1 RIV format */
227 pdsch->freqAlloc.rbStart = offset + SCH_SSB_PRB_DURATION; /* the RB numbering starts from coreset0, and PDSCH is always above SSB */
228 /* formula used for calculation of rbSize, 38.213 section 5.1.3.2 *
229 * Ninfo = S . Nre . R . Qm . v *
230 * Nre' = Nsc . NsymPdsch - NdmrsSymb - Noh *
231 * Nre = min(156,Nre') . nPrb */
232 pdsch->freqAlloc.rbSize = 1; /* This value is calculated from above formulae */
233 pdsch->freqAlloc.vrbPrbMapping = 0; /* non-interleaved */
234 pdsch->timeAlloc.startSymbolIndex = 2; /* spec-38.214, Table 5.1.2.1-1 */
235 pdsch->timeAlloc.numSymbols = 12;
236 pdsch->beamPdschInfo.numPrgs = 1;
237 pdsch->beamPdschInfo.prgSize = 1;
238 pdsch->beamPdschInfo.digBfInterfaces = 0;
239 pdsch->beamPdschInfo.prg[0].pmIdx = 0;
240 pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
241 pdsch->txPdschPower.powerControlOffset = 0;
242 pdsch->txPdschPower.powerControlOffsetSS = 0;
247 /**********************************************************************
249 **********************************************************************/