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