warning set 4
[o-du/l2.git] / src / 5gnrsch / sch_slot_ind.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:     5G NR SCH layer
22
23 Type:     C source file
24
25 Desc:     C source code for Entry point fucntions for slot indications
26
27 File:     sch_slot_ind.c
28
29  **********************************************************************/
30
31 /** @file sch_slot_ind.c
32   @brief This module processes slot indications
33  */
34 #include "stdbool.h"
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 */
45 #include "tfu.h"
46 #include "lrg.h"
47
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 */
57 #include "tfu.x"
58 #include "lrg.x"
59 #include "du_log.h"
60 #include "du_app_mac_inf.h"
61 #include "mac_sch_interface.h"
62 #include "sch.h"
63
64 SchMacDlAllocFunc schMacDlAllocOpts[] =
65 {
66         packSchMacDlAlloc,
67         MacProcDlAlloc,
68         packSchMacDlAlloc
69 };
70
71 extern SchCb schCb[SCH_MAX_INST];
72 extern int schFillRar(RarAlloc *rarAlloc, uint16_t raRnti, uint16_t pci, uint8_t
73 offsetPointA);
74
75 /*******************************************************************
76  *
77  * @brief Handles sending DL broadcast alloc to MAC 
78  *
79  * @details
80  *
81  *    Function : sendDlAllocToMac
82  *
83  *    Functionality:
84  *     Sends DL Broadcast Resource Allocation to MAC from SCH
85  *
86  * @params[in] 
87  * @return ROK     - success
88  *         RFAILED - failure
89  *
90  * ****************************************************************/
91 int sendDlAllocToMac(DlAlloc *dlAlloc, Inst inst)
92 {
93         Pst pst;
94
95    memset(&pst, 0, sizeof(Pst));
96    SCH_FILL_RSP_PST(pst, inst);
97         pst.event = EVENT_DL_ALLOC;
98
99         return(*schMacDlAllocOpts[pst.selector])(&pst, dlAlloc);
100
101 }
102 /*******************************************************************
103  *
104  * @brief Handles slot indication at SCH 
105  *
106  * @details
107  *
108  *    Function : schProcessSlotInd
109  *
110  *    Functionality:
111  *     Handles TTI indication received from PHY
112  *
113  * @params[in] 
114  * @return ROK     - success
115  *         RFAILED - failure
116  *
117  * ****************************************************************/
118 uint8_t schProcessSlotInd(SlotIndInfo *slotInd, Inst schInst)
119 {
120    int ret = ROK;
121         uint8_t ssb_rep;
122         uint16_t sfn  = slotInd->sfn;
123         uint16_t slot = slotInd->slot;
124         uint16_t sfnSlot = 0;
125         DlAlloc dlAlloc;
126         memset(&dlAlloc,0,sizeof(DlAlloc));
127    DlBrdcstAlloc *dlBrdcstAlloc = &dlAlloc.brdcstAlloc;
128         RarAlloc *rarAlloc = &dlAlloc.rarAlloc;
129         dlBrdcstAlloc->ssbTrans = NO_SSB;
130    dlBrdcstAlloc->sib1Trans = NO_SIB1;
131         
132
133         SchCellCb *cell = schCb[schInst].cells[schInst];
134
135 #ifdef LTE_L2_MEAS
136    glblTtiCnt++;
137 #endif
138   
139 //   schDlResAlloc(cell, slotInd);
140
141         ssb_rep = cell->cellCfg.ssbSchCfg.ssbPeriod;
142         memcpy(&cell->slotInfo, slotInd, sizeof(SlotIndInfo));
143         dlBrdcstAlloc->ssbIdxSupported = 1;
144
145    if((slot + SCHED_DELTA) >= SCH_NUM_SLOTS)
146         {
147       sfn = (sfn+1)%SCH_MAX_SFN;
148         }
149         slot = ((slot + SCHED_DELTA) % SCH_NUM_SLOTS);
150    sfnSlot = ((sfn * 10) + slot);
151
152         dlAlloc.slotIndInfo.sfn = sfn;
153         dlAlloc.slotIndInfo.slot = slot;
154         dlAlloc.cellId = cell->cellId;
155
156         /* Identify SSB ocassion*/
157         if (sfnSlot % SCH_MIB_TRANS == 0)
158         {
159                 dlBrdcstAlloc->ssbTrans = SSB_TRANSMISSION;
160         }
161         else if (sfnSlot % ssb_rep == 0)
162         {
163                 dlBrdcstAlloc->ssbTrans = SSB_REPEAT;
164         }
165         else
166         {
167            /* not SSB occassion */
168         }
169
170    /* Identify SIB1 occasions */
171    if(sfnSlot % cell->cellCfg.sib1SchCfg.sib1NewTxPeriod == 0)
172         {
173            dlBrdcstAlloc->sib1Trans = SIB1_TRANSMISSION;
174         }
175         else if (sfnSlot % cell->cellCfg.sib1SchCfg.sib1RepetitionPeriod == 0)
176         {
177            dlBrdcstAlloc->sib1Trans = SIB1_REPITITION;
178         }
179         else
180         {
181            /* not SIB1 occassion */
182         }
183
184         if(dlBrdcstAlloc->ssbTrans || dlBrdcstAlloc->sib1Trans)
185         {
186            dlAlloc.isBroadcastPres = true;
187            ret = schBroadcastAlloc(cell, dlBrdcstAlloc,slot);
188       if(ret != ROK)
189       {
190          DU_LOG("\nschBroadcastAlloc failed");
191          RETVALUE(ret);
192       }
193    }
194
195    /* check for RAR */
196         if(cell->dlAlloc[slot]->rarPres == true)
197         {
198            dlAlloc.isRarPres = true;
199            /* RAR info is copied, this was earlier filled in schProcessRachInd */
200            memcpy(&rarAlloc->rarInfo, &cell->dlAlloc[slot]->rarInfo, sizeof(RarInfo));
201
202                 /* pdcch and pdsch data is filled */
203       schFillRar(rarAlloc,
204                    cell->dlAlloc[slot]->rarInfo.raRnti,
205                    cell->cellCfg.phyCellId,
206                    cell->cellCfg.ssbSchCfg.ssbOffsetPointA);
207
208      cell->dlAlloc[slot]->rarPres = false;
209    }
210
211         /* send msg to MAC */
212    ret = sendDlAllocToMac(&dlAlloc, schInst);
213    if(ret != ROK)
214    {
215       DU_LOG("\nSending DL Broadcast allocation from SCH to MAC failed");
216       RETVALUE(ret);
217    }
218     
219         schUlResAlloc(cell, schInst);
220
221         return ret;
222 }
223
224 /**********************************************************************
225   End of file
226  **********************************************************************/
227
228