Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / du_app / du_mgr_main.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 /* This file is the entry point for DU APP */
20
21 #include "du_mgr_main.h"
22 #include "du_sctp.h"
23
24 extern S16 kwUlActvTsk (Pst *, Buffer *);
25 extern S16 kwUlActvInit (Ent, Inst, Region, Reason);
26 extern S16 kwDlActvTsk (Pst *, Buffer *);
27 extern S16 kwDlActvInit (Ent, Inst, Region, Reason);
28 extern S16 rgActvTsk (Pst *, Buffer *);
29 extern S16 rgActvInit (Ent, Inst, Region, Reason);
30
31 DuCfgParams ducfgparam; //global variable to hold all configs
32
33
34 /*******************************************************************
35  *
36  * @brief Initializes DU APP
37  *
38  * @details
39  *
40  *    Function : duAppInit
41  *
42  *    Functionality:
43  *       - Registers and attaches TAPA tasks belonging to 
44  *         DU_APP sys task
45  *
46  * @params[in] system task ID
47  * @return ROK     - success
48  *         RFAILED - failure
49  *
50  * ****************************************************************/
51 S16 duAppInit(SSTskId sysTskId)
52 {
53    /* Register DU APP TAPA Task for DU */
54    if(SRegTTsk((Ent)ENTDUAPP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
55             duActvInit, (ActvTsk)duActvTsk) != ROK)
56    {
57       return RFAILED;
58    }
59    /* Attach DU APP TAPA Task for DU */
60    if (SAttachTTsk((Ent)ENTDUAPP, (Inst)0, sysTskId)!= ROK)
61    {
62       return RFAILED;
63    }
64
65    printf("\nDU APP created and registered \
66          to %d sys task\n", sysTskId);
67    return ROK;
68 }
69
70 /*******************************************************************
71  *
72  * @brief Initializes SCTP task
73  *
74  * @details
75  *
76  *    Function : sctpInit
77  *
78  *    Functionality:
79  *       - Registers and attaches TAPA tasks for SCTP receiver 
80  *
81  * @params[in] system task ID
82  * @return ROK     - success
83  *         RFAILED - failure
84  *
85  * ****************************************************************/
86 S16 sctpInit(SSTskId sysTskId)
87 {
88    /* Register SCTP TAPA Task */
89    if(SRegTTsk((Ent)ENTSCTP, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
90             sctpActvInit, (ActvTsk)sctpActvTsk) != ROK)
91    {
92       return RFAILED;
93    }
94    /* Attach SCTP TAPA Task */
95    if (SAttachTTsk((Ent)ENTSCTP, (Inst)0, sysTskId)!= ROK)
96    {
97       return RFAILED;
98    }
99
100    printf("\nSCTP TAPA task created and registered to %d sys task\n", 
101          sysTskId);
102    return ROK;
103 }
104
105 /*******************************************************************
106  *
107  * @brief Initializes RLC DL, MAC TAPA task
108  *
109  * @details
110  *
111  *    Function : rlcDlInit
112  *
113  *    Functionality:
114  *       - Registers and attaches TAPA tasks for MAC and RLC DL
115  *
116  * @params[in] system task ID
117  * @return ROK     - success
118  *         RFAILED - failure
119  *
120  * ****************************************************************/
121 S16 rlcDlInit(SSTskId sysTskId)
122 {
123    /* Register RLC DL TAPA Task */
124    if(SRegTTsk((Ent)ENTKW, (Inst)1, (Ttype)TTNORM, (Prior)PRIOR0,
125             kwDlActvInit, (ActvTsk)kwDlActvTsk) != ROK)
126    {
127       return RFAILED;
128    }
129    /* Attach RLC DL Task */
130    if (SAttachTTsk((Ent)ENTKW, (Inst)1, sysTskId)!= ROK)
131    {
132       return RFAILED;
133    }
134
135    /* Register MAC TAPA Task */
136    if(SRegTTsk((Ent)ENTRG, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
137             rgActvInit, (ActvTsk)rgActvTsk) != ROK)
138    {
139       return RFAILED;
140    }
141    /* Attach MAC Task */
142    if (SAttachTTsk((Ent)ENTRG, (Inst)0, sysTskId)!= ROK)
143    {
144       return RFAILED;
145    }
146
147    printf("\nRLC DL and MAC TAPA task created and registered to \
148          %d sys task\n", sysTskId);
149    return ROK;
150 }
151
152 /*******************************************************************
153  *
154  * @brief Initializes RLC UL TAPA task
155  *
156  * @details
157  *
158  *    Function : rlcUlInit
159  *
160  *    Functionality:
161  *       - Registers and attaches TAPA task for RLC UL
162  *
163  * @params[in] system task ID
164  * @return ROK     - success
165  *         RFAILED - failure
166  *
167  * ****************************************************************/
168 S16 rlcUlInit(SSTskId sysTskId)
169 {
170    /* Register RLC UL TAPA Task */
171    if(SRegTTsk((Ent)ENTKW, (Inst)0, (Ttype)TTNORM, (Prior)PRIOR0,
172             kwUlActvInit, (ActvTsk)kwUlActvTsk) != ROK)
173    {
174       return RFAILED;
175    }
176    /* Attach RLC DL Task */
177    if (SAttachTTsk((Ent)ENTKW, (Inst)0, sysTskId)!= ROK)
178    {
179       return RFAILED;
180    }
181    printf("\nRLC UL TAPA task created and registered to \
182          %d sys task\n", sysTskId);
183    return ROK;
184 }
185
186 /*******************************************************************
187  *
188  * @brief Initializes system and TAPA tasks
189  *
190  * @details
191  *
192  *    Function : commonInit
193  *
194  *    Functionality:
195  *       - Registers and attaches system and TAPA tasks
196  *
197  * @params[in] void
198  * @return ROK     - success
199  *         RFAILED - failure
200  *
201  * ****************************************************************/
202 S16 commonInit()
203 {
204    /* Declare system task Ids */
205    SSTskId du_app_stsk, sctp_stsk, rlc_ul_stsk, rlc_mac_cl_stsk;
206
207    pthread_attr_t attr;
208
209    SSetProcId(DU_PROC);
210    //TODO: check regarding cores and add info here
211
212    /* system task for DU APP */
213    SCreateSTsk(PRIOR0, &du_app_stsk);
214    //TODO: check core info to pin the above task to whcih core
215
216    /* system task for RLC_DL and MAC */
217    SCreateSTsk(PRIOR0, &rlc_mac_cl_stsk);
218    pthread_attr_init(&attr);
219    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
220    //TODO: check core info to pin the above task to whcih core
221
222    /* system task for RLC UL */
223    SCreateSTsk(PRIOR1, &rlc_ul_stsk);
224    //TODO: check core info to pin the above task to whcih core
225
226    /* system task for SCTP receiver thread */
227    SCreateSTsk(PRIOR3, &sctp_stsk);
228    //TODO: check core info to pin the above task to whcih core
229
230    /* Create TAPA tasks */
231    if(duAppInit(du_app_stsk) != ROK)
232    {
233       printf("\nDU APP TAPA Task initialization failed");
234       return RFAILED;
235    }
236
237    if(sctpInit(sctp_stsk) != ROK)
238    {
239       printf("\nSCTP TAPA Task initialization failed");
240       return RFAILED;
241    }
242
243    if(rlcDlInit(rlc_mac_cl_stsk) != ROK)
244    {
245       printf("\nRLC DL Tapa Task initialization failed");
246       return RFAILED;
247    } 
248
249    if(rlcUlInit(rlc_ul_stsk) != ROK)
250    {
251      printf("\nRLC UL Tapa Task initialization failed");
252      return RFAILED;
253    } 
254    return ROK;
255 }
256
257 /*******************************************************************
258  *
259  * @brief Initializes the DU
260  *
261  * @details
262  *
263  *    Function : duInit
264  *
265  *    Functionality:
266  *       - Calls commonInit
267  *       - Registers DU Layers
268  *
269  * @params[in] void
270  * @return ROK     - success
271  *         RFAILED - failure
272  *
273  * ****************************************************************/
274 S16 duInit()
275 {
276    int ret = ROK;
277    if(commonInit() != ROK)
278    {
279       ret = RFAILED;
280    } 
281  
282    return ret;
283 }
284
285 /*******************************************************************
286  *
287  * @brief Entry point for the DU APP 
288  *
289  * @details
290  *
291  *    Function : main
292  *
293  *    Functionality:
294  *      - Read config params into duCfgParams
295  *      - Initiate the init functions
296  *
297  * @params[in] void
298  * @return ROK     - success
299  *         RFAILED - failure
300  *
301  * ****************************************************************/
302 S16 tst(void)
303 {
304
305    //Initialize TAPA layers
306    if(duInit() != ROK)
307    {
308       return RFAILED;
309    } 
310
311    //Read all the configs from du_utils.c into duCfgParams
312    duReadCfg();
313
314 #if 0
315    //Establish SCTP connection
316    while(ret == -1)
317    {
318       printf("\nEstablishing SCTP link with CU... \n");
319       //ret = establishSctp(); //To be implemeted in du_sctp.c
320    }
321 #endif
322    return ROK;
323 }/* end of main()*/
324
325 /**********************************************************************
326          End of file
327 **********************************************************************/