Merge "MAC SCH interface for RACH config"
[o-du/l2.git] / src / 5gnrsch / sch_common.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
26
27 File:     sch_common.c
28
29  **********************************************************************/
30
31 /** @file sch_common.c
32   @brief This module performs common scheduling
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 extern SchCb schCb[SCH_MAX_INST];
65
66 /**
67  * @brief Time domain allocation for SSB
68  *
69  * @details
70  *
71  *     Function : ssbDlTdAlloc 
72  *     
73  *     This function handles common scheduling for DL
74  *     
75  *  @param[in]  schCellCb *cell, cell cb
76  *  @param[in]  DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
77  *  @return  void
78  **/
79 void ssbDlTdAlloc(uint8_t scs, uint8_t *ssbStartSymb)
80 {
81    uint8_t n;
82         /* Determine value of "n" based on Section 4.1 of 3GPP TS 38.213 */
83         switch(scs)
84         {
85                 case SCH_SCS_15KHZ:
86                         {
87                            uint8_t symbIdx=0;
88                            n = 2;/* n = 0, 1 for SCS = 15KHz */
89                                 for(uint8_t idx=0; idx<n; idx++)
90                                 {
91                /* start symbol determined using {2, 8} + 14n */
92                                         ssbStartSymb[symbIdx++] = 2 + SCH_SYMBOL_PER_SLOT*idx;
93                                         ssbStartSymb[symbIdx++] = 8 + SCH_SYMBOL_PER_SLOT*idx;
94                                 }
95                         }
96                         break;
97                 default:
98                         DU_LOG("\nSCS %d is currently not supported", scs);
99         }
100 }
101 /**
102  * @brief common resource allocation for SSB
103  *
104  * @details
105  *
106  *     Function : schCmnDlAlloc
107  *     
108  *     This function handles common scheduling for DL
109  *     
110  *  @param[in]  SchCellCb *cell, cell cb
111  *  @param[in]  DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
112  *  @return  void
113  **/
114 uint8_t schCmnDlAlloc(SchCellCb *cell, DlBrdcstAlloc *dlBrdcstAlloc)
115 {
116         /* schedule SSB */
117         uint8_t scs, ssbStartPrb, ssbStartSymb, idx;
118         uint8_t ssbStartSymbArr[SCH_MAX_SSB_BEAM];
119         SchDlAlloc *dlAlloc;
120         SsbInfo ssbInfo;
121
122         dlAlloc = cell->dlAlloc[cell->slotInfo.slot];
123         if(dlBrdcstAlloc->ssbTrans)
124         {
125                 scs = cell->cellCfg.ssbSchCfg.scsCommon;
126                 ssbStartPrb = \
127                    (cell->cellCfg.ssbSchCfg.ssbOffsetPointA)/SCH_NUM_SC_PRB;
128
129                 memset(ssbStartSymbArr, 0, SCH_MAX_SSB_BEAM);
130                 ssbDlTdAlloc(scs, ssbStartSymbArr);
131                 ssbStartSymb = ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are supporting only 1 ssb beam */
132                 /* Assign interface structure */
133                 for(idx=0; idx<dlBrdcstAlloc->ssbIdxSupported; idx++)
134                 {
135                         ssbInfo.ssbIdx = idx;
136                         ssbInfo.fdAlloc.ssbStartPrbIdx = ssbStartPrb;
137                         ssbInfo.fdAlloc.ssbPrbDuration = SCH_SSB_PRB_DURATION;
138                         ssbInfo.tdAlloc.ssbStartSymbIdx = ssbStartSymb;
139                         ssbInfo.tdAlloc.ssbSymbolDuration = SCH_SSB_SYMB_DURATION;
140                         dlBrdcstAlloc->ssbInfo[idx] = ssbInfo;
141                         dlAlloc->ssbInfo[idx] = ssbInfo;
142
143                 }
144
145                 dlAlloc->ssbPres = true;
146                 dlAlloc->ssbIdxSupported = dlBrdcstAlloc->ssbIdxSupported;
147                 for(idx=ssbStartSymb; idx<ssbStartSymb+SCH_SSB_SYMB_DURATION; idx++)
148                 {
149                         dlAlloc->assignedPrb[idx] = SCH_SSB_PRB_DURATION + 1; /* +1 for kSsb */
150                 }
151
152         }
153
154         /* SIB1 allocation */
155         if(dlBrdcstAlloc->sib1Trans)
156         {
157            memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg, &cell->cellCfg.sib1SchCfg.sib1PdcchCfg, sizeof(Sib1PdcchCfg)); 
158            memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdschCfg, &cell->cellCfg.sib1SchCfg.sib1PdschCfg, sizeof(Sib1PdschCfg)); 
159         }
160         return ROK;
161 }
162
163
164 /**********************************************************************
165   End of file
166  **********************************************************************/
167